Skip to content

Commit 983de4b

Browse files
committed
GPU support for spack package
1 parent 3fc2438 commit 983de4b

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ The following options can be set to include / exclude parts of the project:
5151

5252
Respective scripts can be found in this directory.
5353

54+
We also provide a spack package for GPRat in [`spack-repo/packages`](spack-repo/packages) for portable and convenient compilation. When the repository is added to spack, GPRat can be installed with `spack install gprat~cuda~bindings~examples blas={mkl,openblas}`
55+
5456
## How To Run
5557

5658
GPRat contains several examples. One to run the C++ code, one to run the Python code as well as two reference

examples/gprat_cpp/run_gprat_spack.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ if command -v spack &> /dev/null; then
1919
export CXX=g++
2020
export CC=gcc
2121
spack install gprat%[email protected] blas=openblas
22-
spack load gprat blas=openblas
22+
spack load gprat%gcc blas=openblas
2323
elif [[ "$HOSTNAME" == "simcl1n1" || "$HOSTNAME" == "simcl1n2" ]]; then
2424
# Check if the gprat_gpu_clang environment exists
2525
module load clang/17.0.1
2626
export CXX=clang++
2727
export CC=clang
28-
spack install gprat%[email protected] blas=openblas +cuda
28+
GPRAT_WITH_CUDA=ON
29+
spack install gprat%[email protected] blas=openblas +cuda cuda_arch=80 ^[email protected]
2930
spack load gprat blas=openblas +cuda
3031
else
3132
echo "Hostname is $HOSTNAME — no action taken."
@@ -45,7 +46,7 @@ export APEX_DISABLE=1
4546
rm -rf build && mkdir build && cd build
4647

4748
# Configure the project
48-
cmake .. -DCMAKE_BUILD_TYPE=Release
49+
cmake .. -DCMAKE_BUILD_TYPE=Release -DGPRAT_WITH_CUDA=${GPRAT_WITH_CUDA}
4950

5051
# Build the project
5152
make -j
@@ -56,10 +57,10 @@ make -j
5657
if [[ -z "$1" ]]; then
5758
echo "Input parameter is missing. Using default: Run computations on CPU"
5859
elif [[ "$1" == "gpu" ]]; then
59-
use_gpu="--use_gpu"
60+
GPU="--use_gpu"
6061
elif [[ "$1" != "cpu" ]]; then
6162
echo "Please specify input parameter: cpu/gpu"
6263
exit 1
6364
fi
6465

65-
./gprat_cpp $1
66+
./gprat_cpp $GPU

spack-repo/packages/gprat/package.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Gprat(CMakePackage, CudaPackage):#, ROCmPackage):
5656
depends_on("openblas fortran=false", when="blas=openblas")
5757

5858
# CUDA
59-
depends_on("cuda +allow-unsupported-compilers", when="+cuda")
59+
depends_on("cuda@12.0.1 +allow-unsupported-compilers", when="+cuda")
6060
depends_on("[email protected]: +cuda", when="+cuda")
6161

6262
# ROCm not supported yet
@@ -67,6 +67,10 @@ class Gprat(CMakePackage, CudaPackage):#, ROCmPackage):
6767

6868
# Conflicts
6969
conflicts("blas=openblas", when="@0.1.0")
70+
# Require clang when building with +cuda
71+
conflicts('+cuda', when='%gcc', msg='CUDA builds of GPRat require clang, not gcc')
72+
# GPU support requires at least version 0.3.0
73+
conflicts('+cuda', when='@:0.2.0')
7074

7175
def cmake_args(self):
7276
spec, args = self.spec, []
@@ -78,12 +82,17 @@ def cmake_args(self):
7882
]
7983
if self.spec.satisfies("+cuda"):
8084
args += [self.define("GPRAT_WITH_CUDA", "ON")]
85+
args += [self.define("CMAKE_CUDA_COMPILER", "clang++")]
86+
87+
cuda_arch_list = spec.variants['cuda_arch'].value
88+
cuda_arch = cuda_arch_list[0]
89+
if cuda_arch != 'none':
90+
args.append('-DCMAKE_CUDA_ARCHITECTURES={0}'.format(cuda_arch))
8191
else:
8292
args += [self.define("GPRAT_WITH_CUDA", "OFF")]
8393

8494
if self.spec.satisfies("blas=mkl"):
8595
args += [self.define("GPRAT_ENABLE_MKL", "ON")]
8696
else:
8797
args += [self.define("GPRAT_ENABLE_MKL", "OFF")]
88-
8998
return args

0 commit comments

Comments
 (0)