Page MenuHomec4science

detect.py
No OneTemporary

File Metadata

Created
Fri, May 3, 16:54

detect.py

import SCons
from os.path import join, abspath, exists, isdir, basename
from SCons.Script import Configure
# ------------------------------------------------------------------------------
def _get_path(env, ext, module_var):
path = ""
if module_var in env['ENV']:
root = abspath(env['ENV'][module_var])
if not exists(root) or not isdir(root):
raise RuntimeError("{} is set to a non-existing path '{}'".format(
module_var, root))
path = join(root, ext)
if not exists(path) or not isdir(path):
raise RuntimeError("{} does not contain '{}' directory".format(
module_var, ext))
return path
# ------------------------------------------------------------------------------
def FindFFTW(env, components=[], module_var='FFTW_ROOT'):
"""Find FFTW3 and set relevant environment variables"""
if not env.get('should_configure', True):
return
fftw_include = _get_path(env, 'include', module_var)
fftw_library = _get_path(env, 'lib', module_var)
# Setting up FFTW
wishes = ['main'] + components
# Components
lib_names = {'main': 'fftw3',
'thread': 'fftw3_threads',
'omp': 'fftw3_omp'}
inc_names = ['fftw3.h']
# Checking list of wishes
try:
libs = [lib_names[i] for i in wishes]
except KeyError:
raise SCons.Errors.StopError(
'Incompatible FFTW wishlist {0}'.format(wishes))
conf_env = env.Clone()
conf_env.AppendUnique(LIBS=libs)
conf_env.AppendUnique(CPPPATH=[fftw_include])
conf_env.AppendUnique(LIBPATH=[fftw_library])
conf = Configure(conf_env)
if not conf.CheckLibWithHeader(libs, inc_names, 'c++'):
raise SCons.Errors.StopError(
'Failed to find libraries {0} or '
'headers {1}.'.format(str(lib_names), str(inc_names)))
conf_env = conf.Finish()
# Override modified variables
for var in "LIBS CPPPATH LIBPATH".split():
env[var] = conf_env[var]
# ------------------------------------------------------------------------------
def FindBoost(env, headers=['boost/version.hpp'], module_var='BOOST_ROOT'):
"""Find Boost and set relevant environment variables"""
if not env.get('should_configure', True):
return
boost_include = _get_path(env, 'include', module_var)
conf_env = env.Clone()
conf_env.AppendUnique(CPPPATH=[boost_include])
conf = Configure(conf_env)
if not conf.CheckCXXHeader(headers):
raise SCons.Errors.StopError(
'Failed to find Boost headers {}'.format(headers))
conf_env = conf.Finish()
# Override modified variables
env['CPPPATH'] = conf_env['CPPPATH']
# ------------------------------------------------------------------------------
def FindThrust(env, backend='omp', module_var='THRUST_ROOT'):
"""Find Thrust and set relevant environment variables"""
if not env.get('should_configure', True):
return
thrust_include = _get_path(env, 'include', module_var)
conf_env = env.Clone()
conf_env.AppendUnique(CPPPATH=[thrust_include])
if basename(env['CXX']) == "clang++":
conf_env.AppendUnique(CXXFLAGS=["-Wno-unused-local-typedef"])
if backend == 'omp':
conf_env.AppendUnique(CPPDEFINES=[
"THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP"
])
elif backend == 'cuda':
conf_env.AppendUnique(CPPDEFINES=[
"THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA",
"USE_CUDA"
])
conf = Configure(conf_env)
if not conf.CheckCXXHeader('thrust/version.h'):
raise SCons.Errors.StopError(
'Failed to find Thrust')
conf_env = conf.Finish()
for key in "CXXFLAGS CPPPATH CPPDEFINES".split():
env[key] = conf_env[key]
# ------------------------------------------------------------------------------
def FindCuda(env):
"""Detect cuda on clusters"""
if not env.get('should_configure', True):
return
if 'CUDA_ROOT' in env['ENV']:
env['CUDA_TOOLKIT_PATH'] = env['ENV']['CUDA_ROOT']
else:
env['CUDA_TOOLKIT_PATH'] = '/opt/cuda'
env['CUDA_COMPONENTS'] = ['cufft']
env['CUDA_ARCH_FLAG'] = '-arch=sm_60'
colors = env['COLOR_DICT']
if not env['verbose']:
env['NVCCCOMSTR'] = env['SHCXXCOMSTR']
env['SHLINKCOMSTR'] = \
u'{0}[Linking (cuda)] {1}$TARGET{2}'.format(colors['purple'],
colors['blue'],
colors['end'])
env.AppendUnique(CXXFLAGS=[
"-expt-extended-lambda", # experimental lambda support
"-expt-relaxed-constexpr", # experimental constexpr
])
if env['build_type'] == 'debug':
env.AppendUnique(CXXFLAGS="-G")
env.Tool('nvcc')
# ------------------------------------------------------------------------------
def FindGTest(env):
"""A tool to configure GoogleTest"""
if not env.get('should_configure', True):
return
conf = Configure(env)
if not conf.CheckCXXHeader('gtest/gtest.h'):
raise SCons.Errors.StopError(
'Failed to find GoogleTest header\n' +
"Run 'git submodule update --init --recursive " +
"third-party/googletest'")
env = conf.Finish()

Event Timeline