Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building GPU-enabled GalSim using NVIDIA compiler #1230

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def all_files_from(dir, ext=''):

copt = {
'gcc' : ['-O2','-std=c++11','-fvisibility=hidden','-fopenmp'],
'gcc w/ GPU' : ['-O2','-std=c++11','-fvisibility=hidden','-fopenmp','-foffload=nvptx-none'],
'gcc w/ GPU' : ['-O2','-std=c++11','-fvisibility=hidden','-fopenmp','-foffload=nvptx-none','-DGALSIM_USE_GPU'],
'icc' : ['-O2','-vec-report0','-std=c++11','-openmp'],
'clang' : ['-O2','-std=c++11',
'-Wno-shorten-64-to-32','-fvisibility=hidden','-stdlib=libc++'],
Expand All @@ -85,18 +85,20 @@ def all_files_from(dir, ext=''):
'clang w/ GPU' : ['-O2','-msse2','-std=c++11','-fopenmp','-fopenmp-targets=nvptx64-nvidia-cuda',
'-Wno-openmp-mapping','-Wno-unknown-cuda-version',
'-Wno-shorten-64-to-32','-fvisibility=hidden', '-DGALSIM_USE_GPU'],
'nvc++' : ['-O2','-std=c++11','-mp=gpu','-DGALSIM_USE_GPU'],
'unknown' : [],
}
lopt = {
'gcc' : ['-fopenmp'],
'gcc w/ GPU' : ['-fopenmp','-foffload=nvptx-none'],
'gcc w/ GPU' : ['-fopenmp','-foffload=nvptx-none', '-foffload=-lm'],
'icc' : ['-openmp'],
'clang' : ['-stdlib=libc++'],
'clang w/ OpenMP' : ['-stdlib=libc++','-fopenmp'],
'clang w/ Intel OpenMP' : ['-stdlib=libc++','-liomp5'],
'clang w/ manual OpenMP' : ['-stdlib=libc++','-lomp'],
'clang w/ GPU' : ['-fopenmp','-fopenmp-targets=nvptx64-nvidia-cuda',
'-Wno-openmp-mapping','-Wno-unknown-cuda-version'],
'nvc++' : ['-mp=gpu'],
'unknown' : [],
}

Expand Down Expand Up @@ -143,6 +145,9 @@ def get_compiler_type(compiler, check_unknown=True, output=False):
line = lines[0].decode(encoding='UTF-8')
if line.startswith('Configured'):
line = lines[1].decode(encoding='UTF-8')
# nvc++ version info starts with a blank line
if line.strip() == "":
line = lines[1].decode(encoding='UTF-8')

if 'clang' in line:
# clang 3.7 is the first with openmp support. But Apple lies about the version
Expand Down Expand Up @@ -180,6 +185,8 @@ def get_compiler_type(compiler, check_unknown=True, output=False):
print("Yay! This version of gcc supports GPU!")
return 'gcc w/ GPU'
return 'gcc'
elif 'nvc++' in line or 'nvcc' in line or 'NVIDIA' in line:
return 'nvc++'
elif 'clang' in cc:
return 'clang'
elif 'gcc' in cc or 'g++' in cc:
Expand Down Expand Up @@ -762,6 +769,12 @@ def fix_compiler(compiler, njobs):
except (AttributeError, ValueError):
pass

# nvc++ doesn't support -Wno-unused-result
try:
compiler.compiler_so.remove("-Wno-unused-result")
except (AttributeError, ValueError):
pass

# Figure out what compiler it will use
comp_type = get_compiler_type(compiler, output=True)
cc = compiler.compiler_so[0]
Expand Down
8 changes: 8 additions & 0 deletions src/Silicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,9 @@ namespace galsim {
// Get the location where the photon strikes the silicon:
double x0 = photonsX[i]; // in pixels
double y0 = photonsY[i]; // in pixels
#ifdef DEBUGLOGGING
jamesp-epcc marked this conversation as resolved.
Show resolved Hide resolved
xdbg<<"x0,y0 = "<<x0<<','<<y0;
#endif

// get uniform random number for conversion depth from randomArray
// (4th of 4 numbers for this photon)
Expand All @@ -1390,10 +1392,14 @@ namespace galsim {
x0 += dxdz * dz_pixel; // dx in pixels
y0 += dydz * dz_pixel; // dy in pixels
}
#ifdef DEBUGLOGGING
xdbg<<" => "<<x0<<','<<y0;
#endif
// This is the reverse of depth. zconv is how far above the substrate the e- converts.
double zconv = _sensorThickness - dz;
#ifdef DEBUGLOGGING
xdbg<<"zconv = "<<zconv<<std::endl;
#endif
if (zconv < 0.0) continue; // Throw photon away if it hits the bottom
// TODO: Do something more realistic if it hits the bottom.

Expand All @@ -1405,7 +1411,9 @@ namespace galsim {
x0 += diffStep * randomArray[(i-i1)*4];
y0 += diffStep * randomArray[(i-i1)*4+1];
}
#ifdef DEBUGLOGGING
xdbg<<" => "<<x0<<','<<y0<<std::endl;
#endif
double flux = photonsFlux[i];

#ifdef DEBUGLOGGING
Expand Down
Loading