Skip to content

Commit 352bb6b

Browse files
committed
Fix CPU-only builds when NRN_ENABLE_GPU=OFF
treeset.cpp: include neuron/gpu/offload.hpp unconditionally so nrn_pragma_acc macros are no-op stubs without GPU/OpenACC. nrnivmodl.in: prefix every line of GPU-only nocmodl guards (not just the if). gpu.py: skip _sync_to_hoc when HOC gpu_* methods are absent (non-GPU builds). test_fast_imem.py: import backend_helper only when backend tests will run; ship backend_helper.py with basic_tests SCRIPT_PATTERNS.
1 parent e6ddbae commit 352bb6b

6 files changed

Lines changed: 28 additions & 16 deletions

File tree

bin/nrnivmodl.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ while [ "$1" ] ; do
107107
done
108108

109109
@NRN_ENABLE_GPU_TRUE@if [ "$ForceNOCMODL" = true ]; then
110-
echo "ERROR: -nocmodl is not supported with NRN_ENABLE_GPU builds. Use NMODL (default) instead."
111-
exit 1
112-
fi
110+
@NRN_ENABLE_GPU_TRUE@ echo "ERROR: -nocmodl is not supported with NRN_ENABLE_GPU builds. Use NMODL (default) instead."
111+
@NRN_ENABLE_GPU_TRUE@ exit 1
112+
@NRN_ENABLE_GPU_TRUE@fi
113113
@NRN_ENABLE_GPU_TRUE@if [ -n "$UserNMODLBIN" ] && echo "$UserNMODLBIN" | grep -q nocmodl; then
114-
echo "ERROR: NOCMODL cannot be used with NRN_ENABLE_GPU builds. Use NMODL (default) instead."
115-
exit 1
116-
fi
114+
@NRN_ENABLE_GPU_TRUE@ echo "ERROR: NOCMODL cannot be used with NRN_ENABLE_GPU builds. Use NMODL (default) instead."
115+
@NRN_ENABLE_GPU_TRUE@ exit 1
116+
@NRN_ENABLE_GPU_TRUE@fi
117117

118118
echo "$PWD"
119119

share/lib/python/neuron/gpu.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def _sync_to_hoc(self):
130130
pc = self._pc()
131131
except Exception:
132132
return
133+
# HOC gpu_* methods are registered only when NRN_ENABLE_GPU is set at build time.
134+
if not hasattr(pc, "gpu_enable"):
135+
return
133136
pc.gpu_enable(int(self._enable))
134137
pc.gpu_backend(self._backend)
135138
pc.gpu_device_count(int(self._device_count))

src/neuron/gpu/offload.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#define nrn_gpu_pragma_omp(x)
2525
#endif
2626

27+
// nrnoc GPU paths (e.g. treeset.cpp) use the same names as CoreNEURON offload.hpp.
28+
#define nrn_pragma_acc(x) nrn_gpu_pragma_acc(x)
29+
#define nrn_pragma_omp(x) nrn_gpu_pragma_omp(x)
30+
2731
#include <cstddef>
2832
#include <stdexcept>
2933
#include <string_view>

src/nrnoc/treeset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include "utils/profile/profiler_interface.h"
2323
#include "multicore.h"
2424

25+
#include "neuron/gpu/offload.hpp"
2526
#if defined(NRN_ENABLE_GPU)
26-
#include "coreneuron/utils/offload.hpp"
2727
#include "neuron/gpu/sync.hpp"
2828
#endif
2929

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ if(NRN_ENABLE_PYTHON)
385385
PRELOAD_SANITIZER
386386
ENVIRONMENT "CC=${CMAKE_C_COMPILER}"
387387
COMMAND "${exe}" ${pytest} "./test/${group}"
388-
SCRIPT_PATTERNS "test/${group}/*.json" "test/${group}/*.py")
388+
SCRIPT_PATTERNS "test/${group}/*.json" "test/${group}/*.py"
389+
"test/coreneuron/backend_helper.py")
389390
endforeach()
390391
endforeach()
391392

test/pytest_coreneuron/test_fast_imem.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,18 @@ def cmp(name, **kwargs):
292292
import sys
293293
from pathlib import Path
294294

295-
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "coreneuron"))
296-
from backend_helper import (
297-
disable_test_backend,
298-
enable_test_backend,
299-
is_native_backend_test,
300-
)
301-
302-
if is_native_backend_test() or coreneuron_available():
295+
run_backend_tests = coreneuron_available()
296+
backend_dir = Path(__file__).resolve().parent.parent / "coreneuron"
297+
if (backend_dir / "backend_helper.py").is_file():
298+
sys.path.insert(0, str(backend_dir))
299+
from backend_helper import (
300+
disable_test_backend,
301+
enable_test_backend,
302+
is_native_backend_test,
303+
)
304+
305+
run_backend_tests = run_backend_tests or is_native_backend_test()
306+
if run_backend_tests:
303307
tolerance = 5e-11
304308
enable_test_backend()
305309
run(tstop)

0 commit comments

Comments
 (0)