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

Commit df95cea

Browse files
authored
Random123 + OpenACC: do not compile as CUDA (#797)
* Random123 + OpenACC: compile as C++, not CUDA. * Sprinkle magic attributes for nvc++/OpenMP. * cuda_profile.cu: inline contents in other .cpp files.
1 parent 49bd200 commit df95cea

File tree

9 files changed

+293
-427
lines changed

9 files changed

+293
-427
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ option(CORENRN_ENABLE_CALIPER_PROFILING "Enable Caliper instrumentation" OFF)
132132
option(CORENRN_ENABLE_LIKWID_PROFILING "Enable LIKWID instrumentation" OFF)
133133
option(CORENRN_ENABLE_CUDA_UNIFIED_MEMORY "Enable CUDA unified memory support" OFF)
134134
option(CORENRN_ENABLE_UNIT_TESTS "Enable unit tests execution" ON)
135-
option(CORENRN_ENABLE_GPU "Enable GPU support using OpenACC" OFF)
135+
option(CORENRN_ENABLE_GPU "Enable GPU support using OpenACC or OpenMP" OFF)
136136
option(CORENRN_ENABLE_SHARED "Enable shared library build" ON)
137137
option(CORENRN_ENABLE_LEGACY_UNITS "Enable legacy FARADAY, R, etc" OFF)
138138
option(CORENRN_ENABLE_PRCELLSTATE "Enable NRN_PRCELLSTATE debug feature" OFF)

coreneuron/CMakeLists.txt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ file(
3131
"utils/*.cpp"
3232
"utils/*/*.c"
3333
"utils/*/*.cpp")
34-
file(GLOB_RECURSE CORENEURON_CUDA_FILES "*.cu")
3534
set(SCOPMATH_CODE_FILES
3635
"sim/scopmath/abort.cpp" "sim/scopmath/crout_thread.cpp" "sim/scopmath/newton_thread.cpp"
3736
"sim/scopmath/sparse_thread.cpp" "sim/scopmath/ssimplic_thread.cpp")
@@ -116,31 +115,15 @@ if(CORENRN_ENABLE_GPU)
116115
${CMAKE_CURRENT_BINARY_DIR}/netstim.cpp
117116
${CMAKE_CURRENT_BINARY_DIR}/netstim_inhpoisson.cpp
118117
${CMAKE_CURRENT_BINARY_DIR}/pattern.cpp
119-
${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.cpp
120118
${CMAKE_CURRENT_SOURCE_DIR}/io/nrn_setup.cpp
121119
${CMAKE_CURRENT_SOURCE_DIR}/io/setup_fornetcon.cpp
122120
${CMAKE_CURRENT_SOURCE_DIR}/io/corenrn_data_return.cpp
123121
${CMAKE_CURRENT_SOURCE_DIR}/io/global_vars.cpp)
124122

125123
set_source_files_properties(${OPENACC_EXCLUDED_FILES} PROPERTIES COMPILE_FLAGS
126124
"-DDISABLE_OPENACC")
127-
# nrnran123.cpp is a symlink to nrnran123.cu, in GPU builds we compile this as CUDA code (so we
128-
# want to remove the .cpp here), while in non-GPU builds we compile it as plain C++. Unfortunately
129-
# CMake <v3.20 does not pass explicit -x <lang> options based on the LANGUAGE property
130-
# (https://cmake.org/cmake/help/latest/policy/CMP0119.html), so using a single .cu file and
131-
# setting LANGUAGE=CXX in non-GPU builds does not work.
132-
list(APPEND CORENEURON_CODE_FILES ${CORENEURON_CUDA_FILES})
133-
if(CORENRN_ACCELERATOR_OFFLOAD STREQUAL "OpenMP")
134-
list(REMOVE_ITEM CORENEURON_CODE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.cu")
135-
elseif(CORENRN_ACCELERATOR_OFFLOAD STREQUAL "OpenACC")
136-
list(REMOVE_ITEM CORENEURON_CODE_FILES
137-
"${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.cpp")
138-
else()
139-
message(
140-
FATAL_ERROR
141-
"Don't know how to build Random123 compatibility layer for GPU with ${CORENRN_ACCELERATOR_OFFLOAD} offload."
142-
)
143-
endif()
125+
# Only compile the explicit CUDA implementation of the Hines solver in GPU builds.
126+
list(APPEND CORENEURON_CODE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/permute/cellorder.cu)
144127

145128
# Eigen-3.5+ provides better GPU support. However, some functions cannot be called directly from
146129
# within an OpenACC region. Therefore, we need to wrap them in a special API (decorate them with

coreneuron/gpu/nrn_acc_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "coreneuron/utils/profile/profiler_interface.h"
1818
#include "coreneuron/permute/cellorder.hpp"
1919
#include "coreneuron/permute/data_layout.hpp"
20-
#include "coreneuron/utils/profile/cuda_profile.h"
2120
#include "coreneuron/sim/scopmath/newton_struct.h"
2221
#include "coreneuron/coreneuron.hpp"
2322
#include "coreneuron/utils/nrnoc_aux.hpp"

coreneuron/utils/memory_utils.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <fstream>
2626
#include <unistd.h>
2727
#include "coreneuron/utils/memory_utils.h"
28-
#include "coreneuron/utils/profile/cuda_profile.h"
2928
#include "coreneuron/mpi/nrnmpi.h"
3029
#include "coreneuron/mpi/core/nrnmpi.hpp"
3130
#include "coreneuron/apps/corenrn_parameters.hpp"
@@ -36,6 +35,10 @@
3635
#include <malloc.h>
3736
#endif
3837

38+
#ifdef CORENEURON_ENABLE_GPU
39+
#include "cuda_profiler_api.h"
40+
#endif
41+
3942
namespace coreneuron {
4043
double nrn_mallinfo(void) {
4144
// -ve mem usage for non-supported platforms
@@ -108,7 +111,16 @@ void report_mem_usage(const char* message, bool all_ranks) {
108111
mem_avg);
109112
#ifdef CORENEURON_ENABLE_GPU
110113
if (corenrn_param.gpu) {
111-
print_gpu_memory_usage();
114+
size_t free_byte, total_byte;
115+
cudaError_t cuda_status = cudaMemGetInfo(&free_byte, &total_byte);
116+
if (cudaSuccess != cuda_status) {
117+
std::printf("cudaMemGetInfo failed: %s\n", cudaGetErrorString(cuda_status));
118+
}
119+
constexpr double MiB{1. / (1024. * 1024.)};
120+
std::printf(" GPU Memory (MiBs) : Used = %f, Free = %f, Total = %f\n",
121+
(total_byte - free_byte) * MiB,
122+
free_byte * MiB,
123+
total_byte * MiB);
112124
}
113125
#endif
114126
}

coreneuron/utils/profile/cuda_profile.cu

Lines changed: 0 additions & 40 deletions
This file was deleted.

coreneuron/utils/profile/cuda_profile.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

coreneuron/utils/randoms/nrnran123.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)