Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 7f060ad

Browse files
committed
Call cudaSetDevice in OpenMP mode.
1 parent 5c9222b commit 7f060ad

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

coreneuron/gpu/nrn_acc_manager.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include <pat_api.h>
2929
#endif
3030

31+
#if defined(CORENEURON_ENABLE_GPU) && defined(CORENEURON_PREFER_OPENMP_OFFLOAD) && defined(_OPENMP)
32+
#include <cuda_runtime_api.h>
33+
#endif
34+
3135
namespace coreneuron {
3236
extern InterleaveInfo* interleave_info;
3337
void copy_ivoc_vect_to_device(const IvocVect& iv, IvocVect& div);
@@ -60,6 +64,12 @@ void cnrn_target_set_default_device(int device_num) {
6064
#elif defined(CORENEURON_ENABLE_GPU) && defined(CORENEURON_PREFER_OPENMP_OFFLOAD) && \
6165
defined(_OPENMP)
6266
omp_set_default_device(device_num);
67+
// It seems that with NVHPC 21.9 then only setting the default OpenMP device
68+
// is not enough: there were errors on some nodes when not-the-0th GPU was
69+
// used. These seemed to be related to the NMODL instance structs, which are
70+
// allocated using cudaMallocManaged.
71+
auto const cuda_code = cudaSetDevice(device_num);
72+
assert(cuda_code == cudaSuccess);
6373
#else
6474
throw std::runtime_error(
6575
"cnrn_target_set_default_device() not implemented without OpenACC/OpenMP and gpu build");

0 commit comments

Comments
 (0)