/[escript]/branches/diaplayground/site_scons/site_tools/nvcc.py
ViewVC logotype

Contents of /branches/diaplayground/site_scons/site_tools/nvcc.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5085 - (show annotations)
Mon Jun 30 01:20:41 2014 UTC (4 years, 9 months ago) by caltinay
File MIME type: text/x-python
File size: 3650 byte(s)
Make nvcc really configurable and report version, fail when not found.

1 """SCons.Tool.nvcc
2
3 Tool-specific initialization for NVIDIA CUDA Compiler.
4
5 There normally shouldn't be any need to import this module directly.
6 It will usually be imported through the generic SCons.Tool.Tool()
7 selection method.
8
9 This file copied with modifications from: http://www.scons.org/wiki/CudaTool
10 """
11
12 import SCons.Tool
13 import SCons.Scanner.C
14 import SCons.Defaults
15 import subprocess
16 from tempfile import TemporaryFile
17
18 CUDASuffixes = ['.cu']
19
20 # make a CUDAScanner for finding #includes
21 # cuda uses the c preprocessor, so we can use the CScanner
22 CUDAScanner = SCons.Scanner.C.CScanner()
23
24 class ToolCudaWarning(SCons.Warnings.Warning):
25 pass
26
27 class CudaCompilerNotFound(ToolCudaWarning):
28 pass
29
30 SCons.Warnings.enableWarningClass(ToolCudaWarning)
31
32 def _detect(env):
33 """ Try to detect the CUDA compiler """
34 try:
35 nvcc = env['NVCC']
36 except KeyError:
37 nvcc = env.WhereIs('nvcc')
38
39 try:
40 p=subprocess.call([nvcc,'-V'], stdout=TemporaryFile())
41 except:
42 raise SCons.Errors.StopError(CudaCompilerNotFound(
43 "The NVIDIA CUDA compiler could not be found. Try setting "
44 "'nvcc' in your options file or on the command line."))
45 return nvcc
46
47 def add_common_nvcc_variables(env):
48 """
49 Add underlying common "NVIDIA CUDA compiler" variables that
50 are used by multiple builders.
51 """
52
53 # "NVCC common command line"
54 if not env.has_key('_NVCCCOMCOM'):
55 # prepend -Xcompiler before each flag
56
57 # these flags are common to both static and shared compilations
58 env['_NVCCCOMCOM'] = '${_concat("-Xcompiler ", CPPFLAGS, "", __env__)} $_CPPDEFFLAGS $_CPPINCFLAGS'
59
60 # wrap up all these environment variables inside -Xcompiler ""
61 env['_NVCCWRAPCFLAGS'] = '${_concat("-Xcompiler ", CFLAGS, "", __env__)}'
62 env['_NVCCWRAPSHCFLAGS'] = '${_concat("-Xcompiler ", SHCFLAGS, "", __env__)}'
63 env['_NVCCWRAPCCFLAGS'] = '${_concat("-Xcompiler ", CCFLAGS, "", __env__)}'
64 env['_NVCCWRAPSHCCFLAGS'] = '${_concat("-Xcompiler ", SHCCFLAGS, "", __env__)}'
65 # XXX should these be wrapped as well? not sure -jph
66 #env['_NVCCWRAPCXXFLAGS'] = '${_concat("-Xcompiler ", CXXFLAGS, "", __env__)}'
67 #env['_NVCCWRAPSHCXXFLAGS'] = '${_concat("-Xcompiler ", SHCXXFLAGS, "", __env__)}'
68
69 def generate(env):
70 """
71 Add Builders and construction variables for CUDA compilers to an Environment.
72 """
73
74 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
75
76 for suffix in CUDASuffixes:
77 # Add this suffix to the list of things buildable by Object
78 static_obj.add_action('$CUDAFILESUFFIX', '$NVCCCOM')
79 shared_obj.add_action('$CUDAFILESUFFIX', '$SHNVCCCOM')
80 static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
81 shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
82
83 # Add this suffix to the list of things scannable
84 SCons.Tool.SourceFileScanner.add_scanner(suffix, CUDAScanner)
85
86 add_common_nvcc_variables(env)
87
88 # set the "CUDA Compiler Command" environment variable
89 env['NVCC'] = _detect(env)
90 env['SHNVCC'] = env['NVCC']
91
92 # set the include path, and pass both c compiler flags and c++ compiler flags
93 env['NVCCFLAGS'] = SCons.Util.CLVar('')
94 env['SHNVCCFLAGS'] = SCons.Util.CLVar('') + ' -shared'
95
96 # 'NVCC Command'
97 env['NVCCCOM'] = '$NVCC -o $TARGET -c $NVCCFLAGS $_NVCCWRAPCFLAGS $_NVCCWRAPCCFLAGS $_NVCCCOMCOM $SOURCES'
98 env['SHNVCCCOM'] = '$SHNVCC -o $TARGET -c $SHNVCCFLAGS $_NVCCWRAPSHCFLAGS $_NVCCWRAPSHCCFLAGS $_NVCCCOMCOM $SOURCES'
99
100 # the suffix of CUDA source files is '.cu'
101 env['CUDAFILESUFFIX'] = '.cu'
102
103
104 def exists(env):
105 return _detect(env)
106

  ViewVC Help
Powered by ViewVC 1.1.26