/[escript]/trunk/cusplibrary/build/nvcc.py
ViewVC logotype

Contents of /trunk/cusplibrary/build/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: 5229 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 """SCons.Tool.nvcc
17
18 Tool-specific initialization for NVIDIA CUDA Compiler.
19
20 There normally shouldn't be any need to import this module directly.
21 It will usually be imported through the generic SCons.Tool.Tool()
22 selection method.
23
24 """
25 from __future__ import print_function, division
26
27
28 import SCons.Tool
29 import SCons.Scanner.C
30 import SCons.Defaults
31 import os
32 import platform
33
34
35 def get_cuda_paths():
36 """Determines CUDA {bin,lib,include} paths
37
38 returns (bin_path,lib_path,inc_path)
39 """
40
41 # determine defaults
42 if os.name == 'nt':
43 bin_path = 'C:/CUDA/bin'
44 lib_path = 'C:/CUDA/lib'
45 inc_path = 'C:/CUDA/include'
46 elif os.name == 'posix':
47 bin_path = '/usr/local/cuda/bin'
48 lib_path = '/usr/local/cuda/lib'
49 inc_path = '/usr/local/cuda/include'
50 else:
51 raise ValueError, 'Error: unknown OS. Where is nvcc installed?'
52
53 if platform.machine()[-2:] == '64':
54 lib_path += '64'
55
56 # override with environement variables
57 if 'CUDA_BIN_PATH' in os.environ:
58 bin_path = os.path.abspath(os.environ['CUDA_BIN_PATH'])
59 if 'CUDA_LIB_PATH' in os.environ:
60 lib_path = os.path.abspath(os.environ['CUDA_LIB_PATH'])
61 if 'CUDA_INC_PATH' in os.environ:
62 inc_path = os.path.abspath(os.environ['CUDA_INC_PATH'])
63
64 return (bin_path,lib_path,inc_path)
65
66
67
68 CUDASuffixes = ['.cu']
69
70 # make a CUDAScanner for finding #includes
71 # cuda uses the c preprocessor, so we can use the CScanner
72 CUDAScanner = SCons.Scanner.C.CScanner()
73
74 def add_common_nvcc_variables(env):
75 """
76 Add underlying common "NVIDIA CUDA compiler" variables that
77 are used by multiple builders.
78 """
79
80 # "NVCC common command line"
81 if not env.has_key('_NVCCCOMCOM'):
82 # nvcc needs '-I' prepended before each include path, regardless of platform
83 env['_NVCCWRAPCPPPATH'] = '${_concat("-I ", CPPPATH, "", __env__)}'
84 # prepend -Xcompiler before each flag
85 env['_NVCCWRAPCFLAGS'] = '${_concat("-Xcompiler ", CFLAGS, "", __env__)}'
86 env['_NVCCWRAPSHCFLAGS'] = '${_concat("-Xcompiler ", SHCFLAGS, "", __env__)}'
87 env['_NVCCWRAPCCFLAGS'] = '${_concat("-Xcompiler ", CCFLAGS, "", __env__)}'
88 env['_NVCCWRAPSHCCFLAGS'] = '${_concat("-Xcompiler ", SHCCFLAGS, "", __env__)}'
89 # assemble the common command line
90 env['_NVCCCOMCOM'] = '${_concat("-Xcompiler ", CPPFLAGS, "", __env__)} $_CPPDEFFLAGS $_NVCCWRAPCPPPATH'
91
92 def generate(env):
93 """
94 Add Builders and construction variables for CUDA compilers to an Environment.
95 """
96
97 # create a builder that makes PTX files from .cu files
98 ptx_builder = SCons.Builder.Builder(action = '$NVCC -ptx $NVCCFLAGS $_NVCCWRAPCFLAGS $NVCCWRAPCCFLAGS $_NVCCCOMCOM $SOURCES -o $TARGET',
99 emitter = {},
100 suffix = '.ptx',
101 src_suffix = CUDASuffixes)
102 env['BUILDERS']['PTXFile'] = ptx_builder
103
104 # create builders that make static & shared objects from .cu files
105 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
106
107 for suffix in CUDASuffixes:
108 # Add this suffix to the list of things buildable by Object
109 static_obj.add_action('$CUDAFILESUFFIX', '$NVCCCOM')
110 shared_obj.add_action('$CUDAFILESUFFIX', '$SHNVCCCOM')
111 static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter)
112 shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter)
113
114 # Add this suffix to the list of things scannable
115 SCons.Tool.SourceFileScanner.add_scanner(suffix, CUDAScanner)
116
117 add_common_nvcc_variables(env)
118
119 # set the "CUDA Compiler Command" environment variable
120 # windows is picky about getting the full filename of the executable
121 if os.name == 'nt':
122 env['NVCC'] = 'nvcc.exe'
123 env['SHNVCC'] = 'nvcc.exe'
124 else:
125 env['NVCC'] = 'nvcc'
126 env['SHNVCC'] = 'nvcc'
127
128 # set the include path, and pass both c compiler flags and c++ compiler flags
129 env['NVCCFLAGS'] = SCons.Util.CLVar('')
130 env['SHNVCCFLAGS'] = SCons.Util.CLVar('') + ' -shared'
131
132 # 'NVCC Command'
133 env['NVCCCOM'] = '$NVCC -ccbin=g++-4.8 -o $TARGET -c $NVCCFLAGS $_NVCCWRAPCFLAGS $NVCCWRAPCCFLAGS $_NVCCCOMCOM $SOURCES'
134 env['SHNVCCCOM'] = '$SHNVCC -ccbin=g++-4.8 -o $TARGET -c $SHNVCCFLAGS $_NVCCWRAPSHCFLAGS $_NVCCWRAPSHCCFLAGS $_NVCCCOMCOM $SOURCES'
135
136 # the suffix of CUDA source files is '.cu'
137 env['CUDAFILESUFFIX'] = '.cu'
138
139 # XXX add code to generate builders for other miscellaneous
140 # CUDA files here, such as .gpu, etc.
141
142 # XXX intelligently detect location of nvcc and cuda libraries here
143 (bin_path,lib_path,inc_path) = get_cuda_paths()
144
145 env.PrependENVPath('PATH', bin_path)
146
147 def exists(env):
148 return env.Detect('nvcc')
149

  ViewVC Help
Powered by ViewVC 1.1.26