ISCE_INSAR/scons_tools/cuda.py

161 lines
5.9 KiB
Python
Raw Normal View History

2019-01-16 19:40:08 +00:00
"""
SCons.Tool.cuda
CUDA Tool for SCons
"""
import os
import sys
import SCons.Tool
import SCons.Scanner.C
import SCons.Defaults
CUDAScanner = SCons.Scanner.C.CScanner()
def CUDANVCCStaticObjectEmitter(target, source, env):
tgt, src = SCons.Defaults.StaticObjectEmitter(target, source, env)
for file in tgt:
lifile = os.path.splitext(file.rstr())[0] + '.linkinfo'
env.SideEffect( lifile, file )
env.Clean( file, lifile )
return tgt, src
def CUDANVCCSharedObjectEmitter(target, source, env):
tgt, src = SCons.Defaults.SharedObjectEmitter(target, source, env)
for file in tgt:
lifile = os.path.splitext(file.rstr())[0] + '.linkinfo'
env.SideEffect( lifile, file )
env.Clean( file, lifile )
return tgt, src
def generate(env):
staticObjBuilder, sharedObjBuilder = SCons.Tool.createObjBuilders(env);
staticObjBuilder.add_action('.cu', '$STATICNVCCCMD')
staticObjBuilder.add_emitter('.cu', CUDANVCCStaticObjectEmitter)
sharedObjBuilder.add_action('.cu', '$SHAREDNVCCCMD')
sharedObjBuilder.add_emitter('.cu', CUDANVCCSharedObjectEmitter)
SCons.Tool.SourceFileScanner.add_scanner('.cu', CUDAScanner)
# default compiler
env['NVCC'] = 'nvcc'
# Since nvcc limits what GCC versions are usable, add an option to point to a
# compatible GCC for the nvcc compilation
if 'NVCC_CCBIN' in env:
print('User requested specific system compiler for nvcc.')
env['NVCCFLAGS'] = '-ccbin ' + env['NVCC_CCBIN']
else:
print('Assuming default system compiler for nvcc.')
env['NVCCFLAGS'] = ''
# default flags for the NVCC compiler
env['STATICNVCCFLAGS'] = ''
env['SHAREDNVCCFLAGS'] = ''
various updates from ARIA-related projects (#149) * add Dockerfile and SConfigISCE to build cuda-enabled modules * add Dockerfile and SConfigISCE to build cuda-enabled modules * set correct name * update for centos7 and cuda-dev image * restore * disable GPUampcor * update * save * sync up Dockerfile updates * fix base image * change docker image names * create gpu vs. cpu specific tags * update with nodata WBD Stitcher * fix segmentation fault when running sciflo workflows - remove dependencies that downgrade the `geos` conda package * sync fix for segmentation fault to cuda builds * ping ffi to version 1.12.2 Latest version of ffi, 1.13.0, breaks installation of fpm: ``` $ sudo gem install --no-ri --no-rdoc fpm Fetching: cabin-0.9.0.gem (100%) Successfully installed cabin-0.9.0 Fetching: backports-3.17.2.gem (100%) Successfully installed backports-3.17.2 Fetching: arr-pm-0.0.10.gem (100%) Successfully installed arr-pm-0.0.10 Fetching: clamp-1.0.1.gem (100%) Successfully installed clamp-1.0.1 Fetching: ffi-1.13.0.gem (100%) ERROR: Error installing fpm: ffi requires Ruby version >= 2.3. ``` TODO: remove pin when ffi's backwards compatiblity is restored. * comment out unused import * add build circleci job to PR tests * pin ffi in cuda build * revert logging hackery * fix "target_include_directories called with non-compilable target type" errors * Keep source directory for topsStack Co-authored-by: dustinlo <dustin.k.lo@jpl.nasa.gov> Co-authored-by: shitong01 <stchin@ntu.edu.sg> Co-authored-by: Ryan Burns <47790121+rtburns-jpl@users.noreply.github.com>
2020-07-16 23:08:57 +00:00
env['ENABLESHAREDNVCCFLAG'] = '-std=c++11 -shared -Xcompiler -fPIC -I/opt/conda/include'
2019-01-16 19:40:08 +00:00
# default NVCC commands
env['STATICNVCCCMD'] = '$NVCC -o $TARGET -c $NVCCFLAGS $STATICNVCCFLAGS $SOURCES'
env['SHAREDNVCCCMD'] = '$NVCC -o $TARGET -c $NVCCFLAGS $SHAREDNVCCFLAGS $ENABLESHAREDNVCCFLAG $SOURCES'
# helpers
home=os.environ.get('HOME', '')
programfiles=os.environ.get('PROGRAMFILES', '')
homedrive=os.environ.get('HOMEDRIVE', '')
# find CUDA Toolkit path and set CUDA_TOOLKIT_PATH
try:
cudaToolkitPath = env['CUDA_TOOLKIT_PATH']
except:
paths=[home + '/NVIDIA_CUDA_TOOLKIT',
home + '/Apps/NVIDIA_CUDA_TOOLKIT',
home + '/Apps/NVIDIA_CUDA_TOOLKIT',
home + '/Apps/CudaToolkit',
home + '/Apps/CudaTK',
'/usr/local/NVIDIA_CUDA_TOOLKIT',
'/usr/local/CUDA_TOOLKIT',
'/usr/local/cuda_toolkit',
'/usr/local/CUDA',
'/usr/local/cuda',
'/Developer/NVIDIA CUDA TOOLKIT',
'/Developer/CUDA TOOLKIT',
'/Developer/CUDA',
programfiles + 'NVIDIA Corporation/NVIDIA CUDA TOOLKIT',
programfiles + 'NVIDIA Corporation/NVIDIA CUDA',
programfiles + 'NVIDIA Corporation/CUDA TOOLKIT',
programfiles + 'NVIDIA Corporation/CUDA',
programfiles + 'NVIDIA/NVIDIA CUDA TOOLKIT',
programfiles + 'NVIDIA/NVIDIA CUDA',
programfiles + 'NVIDIA/CUDA TOOLKIT',
programfiles + 'NVIDIA/CUDA',
programfiles + 'CUDA TOOLKIT',
programfiles + 'CUDA',
homedrive + '/CUDA TOOLKIT',
homedrive + '/CUDA']
pathFound = False
for path in paths:
if os.path.isdir(path):
pathFound = True
print('scons: CUDA Toolkit found in ' + path)
cudaToolkitPath = path
break
if not pathFound:
sys.exit("Cannot find the CUDA Toolkit path. Please modify your SConscript or add the path in cudaenv.py")
env['CUDA_TOOLKIT_PATH'] = cudaToolkitPath
'''
# find CUDA SDK path and set CUDA_SDK_PATH
try:
cudaSDKPath = env['CUDA_SDK_PATH']
except:
paths=[home + '/NVIDIA_CUDA_SDK', # i am just guessing here
home + '/Apps/NVIDIA_CUDA_SDK',
home + '/Apps/CudaSDK',
'/usr/local/NVIDIA_CUDA_SDK',
'/usr/local/CUDASDK',
'/usr/local/cuda_sdk',
'/Developer/NVIDIA CUDA SDK',
'/Developer/CUDA SDK',
'/Developer/CUDA',
'/Developer/GPU Computing/C',
programfiles + 'NVIDIA Corporation/NVIDIA CUDA SDK',
programfiles + 'NVIDIA/NVIDIA CUDA SDK',
programfiles + 'NVIDIA CUDA SDK',
programfiles + 'CudaSDK',
homedrive + '/NVIDIA CUDA SDK',
homedrive + '/CUDA SDK',
homedrive + '/CUDA/SDK']
pathFound = False
for path in paths:
if os.path.isdir(path):
pathFound = True
print('scons: CUDA SDK found in ' + path)
cudaSDKPath = path
break
if not pathFound:
sys.exit("Cannot find the CUDA SDK path. Please set env['CUDA_SDK_PATH'] to point to your SDK path")
env['CUDA_SDK_PATH'] = cudaSDKPath
# cuda libraries
if env['PLATFORM'] == 'posix':
cudaSDKSubLibDir = '/linux'
elif env['PLATFORM'] == 'darwin':
cudaSDKSubLibDir = '/darwin'
else:
cudaSDKSubLibDir = ''
'''
# add nvcc to PATH
env.PrependENVPath('PATH', cudaToolkitPath + '/bin')
# add required libraries
#env.Append(CPPPATH=[cudaSDKPath + '/common/inc', cudaToolkitPath + '/include'])
#env.Append(LIBPATH=[cudaSDKPath + '/lib', cudaSDKPath + '/common/lib' + cudaSDKSubLibDir, cudaToolkitPath + '/lib'])
env.Append(CUDACPPPATH=[cudaToolkitPath + '/include'])
env.Append(CUDALIBPATH=[cudaToolkitPath + '/lib', cudaToolkitPath + '/lib64', '/lib64'])
2019-01-16 19:40:08 +00:00
env.Append(CUDALIBS=['cudart'])
def exists(env):
return env.Detect('nvcc')