Skip to content

Commit ea352dd

Browse files
authored
GPU build improvements for NEURON integration (BlueBrain/CoreNeuron#373)
* Update README with latest workflow * Avoid linking to C++ MPI libraries - MPI C++ bindings are removed from MPI - avoid linking mpi c++ library for simplicity - print mpi c/c++ compiler * Improvemenets for GPU build integration with NEURON - create property CORENEURON_LIB_LINK_FLAGS with necessary LDFLAGS to link coreneuron with neuron via nrnivmodl - suppress additional PGI warnings which are not necessary to emit with old mod2c - minor change in nrn_setup.hpp : functions declarated as static in the header result into warning as definitions are in .cpp file * Update weights from GPU before copying to NEURON CoreNEURON Repo SHA: BlueBrain/CoreNeuron@dca1dc0
1 parent 71df8ea commit ea352dd

8 files changed

Lines changed: 50 additions & 10 deletions

File tree

cmake/coreneuron/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ endif()
159159
if(CORENRN_ENABLE_MPI)
160160
find_package(MPI REQUIRED)
161161
add_definitions("-DNRNMPI=1")
162+
# avoid linking to C++ bindings
163+
add_definitions("-DMPI_NO_CPPBIND=1")
164+
add_definitions("-DOMPI_SKIP_MPICXX=1")
165+
add_definitions("-DMPICH_SKIP_MPICXX=1")
162166
else()
163167
add_definitions("-DNRNMPI=0")
164168
add_definitions("-DNRN_MULTISEND=0")
@@ -369,6 +373,8 @@ if(cmake_generator_tolower MATCHES "makefile")
369373
message(STATUS " Build option | Status")
370374
message(STATUS "--------------------+--------------------------------------------------------")
371375

376+
message(STATUS "C COMPILER | ${CMAKE_C_COMPILER}")
377+
message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
372378
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
373379
message(STATUS "Build Type | ${COMPILE_LIBRARY_TYPE}")
374380
message(STATUS "MPI | ${CORENRN_ENABLE_MPI}")

cmake/coreneuron/OpenAccHelper.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ if(CORENRN_ENABLE_GPU)
2323
# workaround for old PGI version
2424
add_definitions(-DPG_ACC_BUGS)
2525
set(ACC_FLAGS "-acc")
26-
# disable very verbose diagnosis messages
27-
set(PGI_DIAG_FLAGS "--diag_suppress 177")
26+
# disable very verbose diagnosis messages and obvious warnings for mod2c
27+
set(PGI_DIAG_FLAGS "--diag_suppress 161,177,550")
2828
# some of the mod files can have too many functions, increase inline level
2929
set(PGI_INLINE_FLAGS "-Minline=size:200,levels:10")
3030
# C/C++ compiler flags
@@ -37,6 +37,14 @@ if(CORENRN_ENABLE_GPU)
3737
message(WARNING "Non-PGI compiler : make sure to add required compiler flags to enable OpenACC")
3838
endif()
3939

40+
# set property for neuron to link with coreneuron libraries
41+
set_property(
42+
GLOBAL
43+
PROPERTY
44+
CORENEURON_LIB_LINK_FLAGS
45+
"-acc -rdynamic -lrt -Wl,--whole-archive -L${CMAKE_HOST_SYSTEM_PROCESSOR} -lcorenrnmech -L${CMAKE_INSTALL_PREFIX}/lib -lcoreneuron -lcudacoreneuron -Wl,--no-whole-archive ${CUDA_cudart_static_LIBRARY}"
46+
)
47+
4048
# find_cuda produce verbose messages : use new behavior to use _ROOT variables
4149
if(POLICY CMP0074)
4250
cmake_policy(SET CMP0074 NEW)
@@ -49,4 +57,6 @@ else(CORENRN_ENABLE_GPU)
4957
# OpenACC pragmas are not guarded, disable all unknown pragm warnings
5058
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
5159
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
60+
set_property(GLOBAL PROPERTY CORENEURON_LIB_LINK_FLAGS
61+
"-L${CMAKE_HOST_SYSTEM_PROCESSOR} -lcorenrnmech")
5262
endif(CORENRN_ENABLE_GPU)

external/mod2c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 2b3ff22c4a785db174e915dc36a9ead5543ba673
1+
Subproject commit 7b0623a2e70dc0ab0f143719f725efb2526964b5

src/coreneuron/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ add_library(corenrnmech ${COMPILE_LIBRARY_TYPE} ${CORENEURON_HEADER_FILES} ${ENG
168168

169169
target_link_libraries(
170170
coreneuron
171-
${MPI_CXX_LIBRARIES}
171+
${MPI_C_LIBRARIES}
172172
${reportinglib_LIBRARY}
173173
${sonatareport_LIBRARY}
174174
${link_cudacoreneuron}
@@ -207,8 +207,7 @@ add_dependencies(coreneuron scopmath)
207207
include_directories(${CORENEURON_PROJECT_SOURCE_DIR})
208208
add_executable(nrniv-core "apps/coreneuron.cpp")
209209

210-
target_link_libraries(nrniv-core corenrnmech ${reportinglib_LIBRARY} ${sonatareport_LIBRARY}
211-
${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
210+
target_link_libraries(nrniv-core corenrnmech ${reportinglib_LIBRARY} ${sonatareport_LIBRARY})
212211

213212
set_target_properties(nrniv-core PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
214213

src/coreneuron/apps/main1.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,13 @@ extern "C" int run_solve_core(int argc, char** argv) {
595595

596596
// copy weights back to NEURON NetCon
597597
if (nrn2core_all_weights_return_) {
598+
599+
// first update weights from gpu
600+
update_weights_from_gpu(nrn_threads, nrn_nthread);
601+
602+
// store weight pointers
598603
std::vector<double*> weights(nrn_nthread, NULL);
604+
599605
// could be one thread more (empty) than in NEURON but does not matter
600606
for (int i=0; i < nrn_nthread; ++i) {
601607
weights[i] = nrn_threads[i].weights;

src/coreneuron/gpu/nrn_acc_manager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,24 @@ void update_voltage_from_gpu(NrnThread* nt) {
765765
}
766766
}
767767

768+
/**
769+
* Copy weights from GPU to CPU
770+
*
771+
* User may record NetCon weights at the end of simulation.
772+
* For this purpose update weights of all NrnThread objects
773+
* from GPU to CPU.
774+
*/
775+
void update_weights_from_gpu(NrnThread* threads, int nthreads) {
776+
for (int i = 0; i < nthreads; i++) {
777+
NrnThread* nt = threads + i;
778+
size_t n_weight = nt->n_weight;
779+
if (nt->compute_gpu && n_weight > 0) {
780+
double* weights = nt->weights;
781+
#pragma acc update host(weights[0 : n_weight])
782+
}
783+
}
784+
}
785+
768786
void update_matrix_from_gpu(NrnThread* _nt) {
769787
#ifdef _OPENACC
770788
if (_nt->compute_gpu && (_nt->end > 0)) {

src/coreneuron/gpu/nrn_acc_manager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void update_net_receive_buffer(NrnThread* _nt);
2121
void realloc_net_receive_buffer(NrnThread* nt, Memb_list* ml);
2222
void update_net_send_buffer_on_host(NrnThread* nt, NetSendBuffer_t* nsb);
2323
void update_voltage_from_gpu(NrnThread* nt);
24+
void update_weights_from_gpu(NrnThread* threads, int nthreads);
2425
void init_gpu();
2526

2627
} // namespace coreneuron

src/coreneuron/io/nrn_setup.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ THE POSSIBILITY OF SUCH DAMAGE.
3737
#include "coreneuron/io/mem_layout_util.hpp"
3838

3939
namespace coreneuron {
40-
static void read_phase1(NrnThread& nt, UserParams& userParams);
41-
static void read_phase2(NrnThread& nt, UserParams& userParams);
42-
static void read_phase3(NrnThread& nt, UserParams& userParams);
43-
static void read_phasegap(NrnThread& nt, UserParams& userParams);
40+
void read_phase1(NrnThread& nt, UserParams& userParams);
41+
void read_phase2(NrnThread& nt, UserParams& userParams);
42+
void read_phase3(NrnThread& nt, UserParams& userParams);
43+
void read_phasegap(NrnThread& nt, UserParams& userParams);
4444
static void setup_ThreadData(NrnThread& nt);
4545

4646
// Functions to load and clean data;

0 commit comments

Comments
 (0)