Skip to content

Commit 6f4ae45

Browse files
authored
CoreNEURON GPU build integration improvements (#707)
* CoreNEURON GPU build integration improvements - For GPU we need to build CoreNEURON statically. Those libraries needs to be linked to special directly (dlopen is not supported) - CoreNEURON now prepares necessary link library flag for NEURON - If user specify -coreneuron as an argument to nrnivmodl then necessary coreneuron libraries are linked to special directly. * If -coreneuron is provided to nrnivmodl then nrnivmodl-core is automatically called * Test now use nrnivmodl -coreneuron flag * Enable binary special if CoreNEURON is enabled * Emit error if -coreneuron is used without enabling it * Address review comments, update coreneuron submodule
1 parent 1759767 commit 6f4ae45

6 files changed

Lines changed: 42 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ if(NRN_ENABLE_CORENEURON)
289289
add_external_project(coreneuron)
290290
set(CORENEURON_DIR ${PROJECT_SOURCE_DIR}/external/coreneuron)
291291
endif()
292+
get_property (CORENEURON_LIB_LINK_FLAGS GLOBAL PROPERTY CORENEURON_LIB_LINK_FLAGS)
293+
set(NRN_ENABLE_BINARY_SPECIAL ON)
292294
endif()
293295

294296
# =============================================================================
@@ -506,6 +508,8 @@ if(cmake_generator_tolower MATCHES "makefile")
506508
message(STATUS "--------------+--------------------------------------------------------------")
507509
message(STATUS " Build option | Status")
508510
message(STATUS "--------------+--------------------------------------------------------------")
511+
message(STATUS "C COMPILER | ${CMAKE_C_COMPILER}")
512+
message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
509513
message(STATUS "BUILD_TYPE | ${CMAKE_BUILD_TYPE} (allowed: ${allowableBuildTypes})")
510514
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS}")
511515
message(STATUS "Shared | ${NRN_ENABLE_SHARED}")
@@ -574,6 +578,7 @@ if(cmake_generator_tolower MATCHES "makefile")
574578
message(STATUS "CoreNEURON | ${NRN_ENABLE_CORENEURON}")
575579
if(NRN_ENABLE_CORENEURON)
576580
message(STATUS " PATH | ${CORENEURON_DIR}")
581+
message(STATUS " LINK FLAGS | ${CORENEURON_LIB_LINK_FLAGS}")
577582
endif()
578583
message(STATUS "--------------+--------------------------------------------------------------")
579584
message(STATUS " See documentation : https://www.neuron.yale.edu/neuron/")

bin/nrnivmodl.in

100644100755
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -e
33

44
ARCH=@host_cpu@
55
MODSUBDIR=@modsubdir@
6+
USER_PWD=`pwd`
67

78
if test "x${NRNHOME}" = x ; then
89
prefix=@prefix@
@@ -43,6 +44,12 @@ if which xcrun; then
4344
fi
4445
fi
4546

47+
LinkCoreNEURON=false
48+
if [ "$1" = "-coreneuron" ] ; then
49+
LinkCoreNEURON=true
50+
shift
51+
fi
52+
4653
UserINCFLAGS=""
4754
if [ "$1" = "-incflags" ] ; then
4855
UserINCFLAGS="$2"
@@ -162,7 +169,19 @@ if test -n "$cfiles" ; then
162169
COBJS=`echo "$cfiles" | sed 's/\.c/.o/g'`
163170
fi
164171

165-
@NRN_BINARY_SPECIAL_TRUE@@USING_CMAKE_TRUE@make -j 4 -f "${MAKEFILEDIR}/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "COBJFILES=$COBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" special &&
172+
# call nrnivmodl-core if CoreNEURON is enabled and requested via CLI
173+
if [ "$LinkCoreNEURON" = true ] ; then
174+
:
175+
@USING_CMAKE_FALSE@ printf "ERROR : CoreNEURON is not compatible with autotools, build with CMake build system!\n"
176+
@USING_CMAKE_FALSE@ exit 1
177+
@USING_CMAKE_TRUE@@CORENEURON_ENABLED_FALSE@ printf "ERROR : CoreNEURON support is not enabled!\n"
178+
@USING_CMAKE_TRUE@@CORENEURON_ENABLED_FALSE@ exit 1
179+
@USING_CMAKE_TRUE@@CORENEURON_ENABLED_TRUE@ cd $USER_PWD
180+
@USING_CMAKE_TRUE@@CORENEURON_ENABLED_TRUE@ $bindir/nrnivmodl-core $MODSUBDIR
181+
@USING_CMAKE_TRUE@@CORENEURON_ENABLED_TRUE@ cd $MODSUBDIR
182+
fi
183+
184+
@NRN_BINARY_SPECIAL_TRUE@@USING_CMAKE_TRUE@make -j 4 -f "${MAKEFILEDIR}/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "COBJFILES=$COBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" "LinkCoreNEURON=$LinkCoreNEURON" special &&
166185
@NRN_BINARY_SPECIAL_TRUE@@USING_CMAKE_FALSE@make -j 4 -f "${MAKEFILEDIR}/nrniv_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "COBJFILES=$COBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" special &&
167186
@NRN_BINARY_SPECIAL_TRUE@ echo "Successfully created $MODSUBDIR/special"
168187

@@ -172,7 +191,7 @@ fi
172191
@NRN_BINARY_SPECIAL_FALSE@ mdir='${NRNHOME}'/share/nrn/demo/release/${MODSUBDIR}
173192
@NRN_BINARY_SPECIAL_FALSE@fi
174193
@NRN_BINARY_SPECIAL_FALSE@@USING_CMAKE_FALSE@make -j 4 -f "$MAKEFILEDIR/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODLO" "COBJFILES=$CLO" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" libnrnmech.la
175-
@NRN_BINARY_SPECIAL_FALSE@@USING_CMAKE_TRUE@make -j 4 -f "$MAKEFILEDIR/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "COBJFILES=$COBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" libnrnmech.la VERBOSE=1
194+
@NRN_BINARY_SPECIAL_FALSE@@USING_CMAKE_TRUE@make -j 4 -f "$MAKEFILEDIR/nrnmech_makefile" "ROOT=${prefix}" "MODOBJFILES=$MODOBJS" "COBJFILES=$COBJS" "UserLDFLAGS=$UserLDFLAGS" "UserINCFLAGS=$UserINCFLAGS" "LinkCoreNEURON=$LinkCoreNEURON" libnrnmech.la VERBOSE=1
176195
@NRN_BINARY_SPECIAL_FALSE@ echo '#!/bin/sh
177196
@NRN_BINARY_SPECIAL_FALSE@if test "x${NRNHOME}" = "x" ; then
178197
@NRN_BINARY_SPECIAL_FALSE@ NRNHOME='"\"${prefix}\""'

bin/nrnivmodl_makefile_cmake.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ else
6666
extra_lib_link = $(NRNLIB_FLAGS)
6767
endif
6868

69+
# add coreneuron flags
70+
ifeq ($(LinkCoreNEURON), true)
71+
EXTRA_LDFLAGS = @CORENEURON_LIB_LINK_FLAGS@
72+
endif
73+
6974
# If no DESTDIR (we are probably just building) we use $ORIGIN (@loader_path in OSX)
7075
_ORIGIN := $(if $(filter Darwin,$(OS_NAME)),@loader_path,$$ORIGIN)
7176
_SONAME := -Wl,$(if $(filter Darwin,$(OS_NAME)),-install_name${_cm}@rpath/,-soname${_cm})$(notdir ${mech_lib})
@@ -82,7 +87,7 @@ C_GREEN := \033[32m
8287
special: $(mech_lib)
8388
@printf " => $(C_GREEN)LINKING$(C_RESET) executable $(special) LDFLAGS are: $(LDFLAGS)\n"
8489
(cd .. ; $(CXX_LINK_EXE) -I $(incdir) -I $(incdir)/nrncvode -DAUTO_DLOPEN_NRNMECH=0 $(datadir)/nrnmain.cpp -o $(special) \
85-
-L $(OBJS_DIR) -l$(mech_libname) $(NRNLIB_FLAGS) -l$(mech_libname) $(extra_lib_link) -Wl,-rpath,'$(DESTDIR_RPATH)' -Wl,-rpath,$(libdir) $(LDFLAGS))
90+
-L $(OBJS_DIR) -l$(mech_libname) $(NRNLIB_FLAGS) -l$(mech_libname) $(extra_lib_link) -Wl,-rpath,'$(DESTDIR_RPATH)' -Wl,-rpath,$(libdir) $(LDFLAGS) $(EXTRA_LDFLAGS))
8691

8792
$(mech_lib): $(mech_lib_type)
8893

cmake/ConfigFileSetting.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ set(libdir \${exec_prefix}/lib)
4747
set(USING_CMAKE_FALSE "#")
4848
set(USING_CMAKE_TRUE "")
4949

50+
if(NRN_ENABLE_CORENEURON)
51+
set(CORENEURON_ENABLED_TRUE "")
52+
set(CORENEURON_ENABLED_FALSE "#")
53+
else()
54+
set(CORENEURON_ENABLED_TRUE "#")
55+
set(CORENEURON_ENABLED_FALSE "")
56+
endif()
57+
5058
# ~~~
5159
# A variable that doesn't start out as #undef but as #define needs an
5260
# explicit @...@ replacement in the .h.in files.

test/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ if(NRN_ENABLE_PYTHON AND PYTEST_FOUND)
110110
add_custom_target(
111111
coreneuron_mod ALL
112112
COMMAND
113-
${CMAKE_COMMAND} -E env ${TEST_ENV} $ENV{SHELL} ${CMAKE_BINARY_DIR}/bin/nrnivmodl .
114-
COMMAND
115-
${CMAKE_COMMAND} -E env ${TEST_ENV} $ENV{SHELL} ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core .
113+
${CMAKE_COMMAND} -E env ${TEST_ENV} $ENV{SHELL} ${CMAKE_BINARY_DIR}/bin/nrnivmodl -coreneuron .
116114
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/mod)
117115
add_dependencies(coreneuron_mod nrniv nrniv-core)
118116

0 commit comments

Comments
 (0)