/[escript]/trunk/site_scons/site_tools/nvcc.py
ViewVC logotype

Contents of /trunk/site_scons/site_tools/nvcc.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5706 - (show annotations)
Mon Jun 29 03:41:36 2015 UTC (3 years, 7 months ago) by sshaw
File MIME type: text/x-python
File size: 3699 byte(s)
all python files now force use of python3 prints and division syntax to stop sneaky errors appearing in py3 environs
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 from __future__ import print_function, division
13
14 import SCons.Tool
15 import SCons.Scanner.C
16 import SCons.Defaults
17 import subprocess
18 from tempfile import TemporaryFile
19
20 CUDASuffixes = ['.cu']
21
22 # make a CUDAScanner for finding #includes
23 # cuda uses the c preprocessor, so we can use the CScanner
24 CUDAScanner = SCons.Scanner.C.CScanner()
25
26 class ToolCudaWarning(SCons.Warnings.Warning):
27 pass
28
29 class CudaCompilerNotFound(ToolCudaWarning):
30 pass
31
32 SCons.Warnings.enableWarningClass(ToolCudaWarning)
33
34 def _detect(env):
35 """ Try to detect the CUDA compiler """
36 try:
37 nvcc = env['NVCC']
38 except KeyError:
39 nvcc = env.WhereIs('nvcc')
40
41 try:
42 p=subprocess.call([nvcc,'-V'], stdout=TemporaryFile())
43 except:
44 raise SCons.Errors.StopError(CudaCompilerNotFound(
45 "The NVIDIA CUDA compiler could not be found. Try setting "
46 "'nvcc' in your options file or on the command line."))
47 return nvcc
48
49 def add_common_nvcc_variables(env):
50 """
51 Add underlying common "NVIDIA CUDA compiler" variables that
52 are used by multiple builders.
53 """
54
55 # "NVCC common command line"
56 if not env.has_key('_NVCCCOMCOM'):
57 # prepend -Xcompiler before each flag
58
59 # these flags are common to both static and shared compilations
60 env['_NVCCCOMCOM'] = '${_concat("-Xcompiler ", CPPFLAGS, "", __env__)} $_CPPDEFFLAGS $_CPPINCFLAGS'
61
62 # wrap up all these environment variables inside -Xcompiler ""
63 env['_NVCCWRAPCFLAGS'] = '${_concat("-Xcompiler ", CFLAGS, "", __env__)}'
64 env['_NVCCWRAPSHCFLAGS'] = '${_concat("-Xcompiler ", SHCFLAGS, "", __env__)}'
65 env['_NVCCWRAPCCFLAGS'] = '${_concat("-Xcompiler ", CCFLAGS, "", __env__)}'
66 env['_NVCCWRAPSHCCFLAGS'] = '${_concat("-Xcompiler ", SHCCFLAGS, "", __env__)}'
67 # XXX should these be wrapped as well? not sure -jph
68 #env['_NVCCWRAPCXXFLAGS'] = '${_concat("-Xcompiler ", CXXFLAGS, "", __env__)}'
69 #env['_NVCCWRAPSHCXXFLAGS'] = '${_concat("-Xcompiler ", SHCXXFLAGS, "", __env__)}'
70
71 def generate(env):
72 """
73 Add Builders and construction variables for CUDA compilers to an Environment.
74 """
75
76 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
77
78 for suffix in CUDASuffixes:
79 # Add this suffix to the list of things buildable by Object
80 static_obj.add_action('$CUDAFILESUFFIX', '$NVCCCOM')
81 shared_obj.add_action('$CUDAFILESUFFIX', '$SHNVCCCOM')
82 static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
83 shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
84
85 # Add this suffix to the list of things scannable
86 SCons.Tool.SourceFileScanner.add_scanner(suffix, CUDAScanner)
87
88 add_common_nvcc_variables(env)
89
90 # set the "CUDA Compiler Command" environment variable
91 env['NVCC'] = _detect(env)
92 env['SHNVCC'] = env['NVCC']
93
94 # set the include path, and pass both c compiler flags and c++ compiler flags
95 env['NVCCFLAGS'] = SCons.Util.CLVar('')
96 env['SHNVCCFLAGS'] = SCons.Util.CLVar('') + ' -shared'
97
98 # 'NVCC Command'
99 env['NVCCCOM'] = '$NVCC -o $TARGET -c $NVCCFLAGS $_NVCCWRAPCFLAGS $_NVCCWRAPCCFLAGS $_NVCCCOMCOM $SOURCES'
100 env['SHNVCCCOM'] = '$SHNVCC -o $TARGET -c $SHNVCCFLAGS $_NVCCWRAPSHCFLAGS $_NVCCWRAPSHCCFLAGS $_NVCCCOMCOM $SOURCES'
101
102 # the suffix of CUDA source files is '.cu'
103 env['CUDAFILESUFFIX'] = '.cu'
104
105
106 def exists(env):
107 return _detect(env)
108

  ViewVC Help
Powered by ViewVC 1.1.26