Coverage for python/lsst/sconsUtils/tools/cuda.py: 64%
32 statements
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-26 19:26 +0000
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-26 19:26 +0000
1# This file is part of sconsUtils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""
23cuda
25CUDA Tool for SCons
27"""
29import os
31import SCons.Defaults
32import SCons.Scanner.C
33import SCons.Tool
35CUDAScanner = SCons.Scanner.C.CScanner()
38# this object emitters add '.linkinfo' suffixed files as extra targets
39# these files are generated by nvcc. The reason to do this is to remove
40# the extra .linkinfo files when calling scons -c
41def CUDANVCCStaticObjectEmitter(target, source, env):
42 tgt, src = SCons.Defaults.StaticObjectEmitter(target, source, env)
43 for _ in src:
44 lifile = os.path.splitext(src[0].rstr())[0] + ".linkinfo" # noqa F841
45 # tgt.append(lifile)
46 return tgt, src
49def CUDANVCCSharedObjectEmitter(target, source, env):
50 tgt, src = SCons.Defaults.SharedObjectEmitter(target, source, env)
51 for _ in src:
52 lifile = os.path.splitext(src[0].rstr())[0] + ".linkinfo" # noqa F841
53 # tgt.append(lifile)
54 return tgt, src
57def generate(env):
58 staticObjBuilder, sharedObjBuilder = SCons.Tool.createObjBuilders(env)
59 staticObjBuilder.add_action(".cu", "$STATICNVCCCMD")
60 staticObjBuilder.add_emitter(".cu", CUDANVCCStaticObjectEmitter)
61 sharedObjBuilder.add_action(".cu", "$SHAREDNVCCCMD")
62 sharedObjBuilder.add_emitter(".cu", CUDANVCCSharedObjectEmitter)
63 SCons.Tool.SourceFileScanner.add_scanner(".cu", CUDAScanner)
65 # default compiler
66 env["NVCC"] = "nvcc"
68 # default flags for the NVCC compiler
69 env["NVCCFLAGS"] = ""
70 env["STATICNVCCFLAGS"] = ""
71 env["SHAREDNVCCFLAGS"] = ""
72 env["ENABLESHAREDNVCCFLAG"] = "-shared"
73 env["NVCCCMDLINE"] = ""
75 # default NVCC commands
76 env["STATICNVCCCMD"] = (
77 "$NVCC -o $TARGET -c $NVCCFLAGS $_CPPINCFLAGS $STATICNVCCFLAGS $NVCCCMDLINE $SOURCES"
78 )
79 env["SHAREDNVCCCMD"] = (
80 "$NVCC -o $TARGET -c $NVCCFLAGS $_CPPINCFLAGS $SHAREDNVCCFLAGS"
81 " $ENABLESHAREDNVCCFLAG $NVCCCMDLINE $SOURCES"
82 )
85def exists(env):
86 return env.Detect("nvcc")