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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4987 - (hide annotations)
Wed Jun 4 00:59:41 2014 UTC (4 years, 9 months ago) by caltinay
File MIME type: text/x-python
File size: 2965 byte(s)
scons nvcc tool.

1 caltinay 4987 """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    
16     CUDASuffixes = ['.cu']
17    
18     # make a CUDAScanner for finding #includes
19     # cuda uses the c preprocessor, so we can use the CScanner
20     CUDAScanner = SCons.Scanner.C.CScanner()
21    
22     def add_common_nvcc_variables(env):
23     """
24     Add underlying common "NVIDIA CUDA compiler" variables that
25     are used by multiple builders.
26     """
27    
28     # "NVCC common command line"
29     if not env.has_key('_NVCCCOMCOM'):
30     # prepend -Xcompiler before each flag
31    
32     # these flags are common to both static and shared compilations
33     env['_NVCCCOMCOM'] = '${_concat("-Xcompiler ", CPPFLAGS, "", __env__)} $_CPPDEFFLAGS $_CPPINCFLAGS'
34    
35     # wrap up all these environment variables inside -Xcompiler ""
36     env['_NVCCWRAPCFLAGS'] = '${_concat("-Xcompiler ", CFLAGS, "", __env__)}'
37     env['_NVCCWRAPSHCFLAGS'] = '${_concat("-Xcompiler ", SHCFLAGS, "", __env__)}'
38     env['_NVCCWRAPCCFLAGS'] = '${_concat("-Xcompiler ", CCFLAGS, "", __env__)}'
39     env['_NVCCWRAPSHCCFLAGS'] = '${_concat("-Xcompiler ", SHCCFLAGS, "", __env__)}'
40     # XXX should these be wrapped as well? not sure -jph
41     #env['_NVCCWRAPCXXFLAGS'] = '${_concat("-Xcompiler ", CXXFLAGS, "", __env__)}'
42     #env['_NVCCWRAPSHCXXFLAGS'] = '${_concat("-Xcompiler ", SHCXXFLAGS, "", __env__)}'
43    
44     def generate(env):
45     """
46     Add Builders and construction variables for CUDA compilers to an Environment.
47     """
48    
49     static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
50    
51     for suffix in CUDASuffixes:
52     # Add this suffix to the list of things buildable by Object
53     static_obj.add_action('$CUDAFILESUFFIX', '$NVCCCOM')
54     shared_obj.add_action('$CUDAFILESUFFIX', '$SHNVCCCOM')
55     static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
56     shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
57    
58     # Add this suffix to the list of things scannable
59     SCons.Tool.SourceFileScanner.add_scanner(suffix, CUDAScanner)
60    
61     add_common_nvcc_variables(env)
62    
63     # set the "CUDA Compiler Command" environment variable
64     env['NVCC'] = 'nvcc'
65     env['SHNVCC'] = 'nvcc'
66    
67     # set the include path, and pass both c compiler flags and c++ compiler flags
68     env['NVCCFLAGS'] = SCons.Util.CLVar('')
69     env['SHNVCCFLAGS'] = SCons.Util.CLVar('') + ' -shared'
70    
71     # 'NVCC Command'
72     env['NVCCCOM'] = '$NVCC -o $TARGET -c $NVCCFLAGS $_NVCCWRAPCFLAGS $_NVCCWRAPCCFLAGS $_NVCCCOMCOM $SOURCES'
73     env['SHNVCCCOM'] = '$SHNVCC -o $TARGET -c $SHNVCCFLAGS $_NVCCWRAPSHCFLAGS $_NVCCWRAPSHCCFLAGS $_NVCCCOMCOM $SOURCES'
74    
75     # the suffix of CUDA source files is '.cu'
76     env['CUDAFILESUFFIX'] = '.cu'
77    
78    
79     def exists(env):
80     return env.Detect('nvcc')
81    

  ViewVC Help
Powered by ViewVC 1.1.26