/[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 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 8 months ago) by sshaw
File MIME type: text/x-python
File size: 4294 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2015 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 """SCons.Tool.nvcc
18
19 Tool-specific initialization for NVIDIA CUDA Compiler.
20
21 There normally shouldn't be any need to import this module directly.
22 It will usually be imported through the generic SCons.Tool.Tool()
23 selection method.
24
25 This file copied with modifications from: http://www.scons.org/wiki/CudaTool
26 """
27
28 from __future__ import print_function, division
29
30 import SCons.Tool
31 import SCons.Scanner.C
32 import SCons.Defaults
33 import subprocess
34 from tempfile import TemporaryFile
35
36 CUDASuffixes = ['.cu']
37
38 # make a CUDAScanner for finding #includes
39 # cuda uses the c preprocessor, so we can use the CScanner
40 CUDAScanner = SCons.Scanner.C.CScanner()
41
42 class ToolCudaWarning(SCons.Warnings.Warning):
43 pass
44
45 class CudaCompilerNotFound(ToolCudaWarning):
46 pass
47
48 SCons.Warnings.enableWarningClass(ToolCudaWarning)
49
50 def _detect(env):
51 """ Try to detect the CUDA compiler """
52 try:
53 nvcc = env['NVCC']
54 except KeyError:
55 nvcc = env.WhereIs('nvcc')
56
57 try:
58 p=subprocess.call([nvcc,'-V'], stdout=TemporaryFile())
59 except:
60 raise SCons.Errors.StopError(CudaCompilerNotFound(
61 "The NVIDIA CUDA compiler could not be found. Try setting "
62 "'nvcc' in your options file or on the command line."))
63 return nvcc
64
65 def add_common_nvcc_variables(env):
66 """
67 Add underlying common "NVIDIA CUDA compiler" variables that
68 are used by multiple builders.
69 """
70
71 # "NVCC common command line"
72 if not env.has_key('_NVCCCOMCOM'):
73 # prepend -Xcompiler before each flag
74
75 # these flags are common to both static and shared compilations
76 env['_NVCCCOMCOM'] = '${_concat("-Xcompiler ", CPPFLAGS, "", __env__)} $_CPPDEFFLAGS $_CPPINCFLAGS'
77
78 # wrap up all these environment variables inside -Xcompiler ""
79 env['_NVCCWRAPCFLAGS'] = '${_concat("-Xcompiler ", CFLAGS, "", __env__)}'
80 env['_NVCCWRAPSHCFLAGS'] = '${_concat("-Xcompiler ", SHCFLAGS, "", __env__)}'
81 env['_NVCCWRAPCCFLAGS'] = '${_concat("-Xcompiler ", CCFLAGS, "", __env__)}'
82 env['_NVCCWRAPSHCCFLAGS'] = '${_concat("-Xcompiler ", SHCCFLAGS, "", __env__)}'
83 # XXX should these be wrapped as well? not sure -jph
84 #env['_NVCCWRAPCXXFLAGS'] = '${_concat("-Xcompiler ", CXXFLAGS, "", __env__)}'
85 #env['_NVCCWRAPSHCXXFLAGS'] = '${_concat("-Xcompiler ", SHCXXFLAGS, "", __env__)}'
86
87 def generate(env):
88 """
89 Add Builders and construction variables for CUDA compilers to an Environment.
90 """
91
92 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
93
94 for suffix in CUDASuffixes:
95 # Add this suffix to the list of things buildable by Object
96 static_obj.add_action('$CUDAFILESUFFIX', '$NVCCCOM')
97 shared_obj.add_action('$CUDAFILESUFFIX', '$SHNVCCCOM')
98 static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
99 shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
100
101 # Add this suffix to the list of things scannable
102 SCons.Tool.SourceFileScanner.add_scanner(suffix, CUDAScanner)
103
104 add_common_nvcc_variables(env)
105
106 # set the "CUDA Compiler Command" environment variable
107 env['NVCC'] = _detect(env)
108 env['SHNVCC'] = env['NVCC']
109
110 # set the include path, and pass both c compiler flags and c++ compiler flags
111 env['NVCCFLAGS'] = SCons.Util.CLVar('')
112 env['SHNVCCFLAGS'] = SCons.Util.CLVar('') + ' -shared'
113
114 # 'NVCC Command'
115 env['NVCCCOM'] = '$NVCC -o $TARGET -c $NVCCFLAGS $_NVCCWRAPCFLAGS $_NVCCWRAPCCFLAGS $_NVCCCOMCOM $SOURCES'
116 env['SHNVCCCOM'] = '$SHNVCC -o $TARGET -c $SHNVCCFLAGS $_NVCCWRAPSHCFLAGS $_NVCCWRAPSHCCFLAGS $_NVCCCOMCOM $SOURCES'
117
118 # the suffix of CUDA source files is '.cu'
119 env['CUDAFILESUFFIX'] = '.cu'
120
121
122 def exists(env):
123 return _detect(env)
124

  ViewVC Help
Powered by ViewVC 1.1.26