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

Improve nrnivmodl-core workflow and integration with nmodl/mod2c #388

Merged
merged 35 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3237bd4
WIP : make now builds special-core for tests
pramodk Aug 30, 2020
20c3714
nrnivmodl-core cleanup
pramodk Aug 31, 2020
f9fda3c
Remove unused CMake module and code for new workflow
pramodk Aug 31, 2020
d0b6e8c
- remove libnrnmech which is not used (?)
pramodk Aug 31, 2020
a1afb6a
apply cmake-format
pramodk Aug 31, 2020
14bdb07
install mod files from /share
pramodk Aug 31, 2020
add49a7
fix test links
pramodk Aug 31, 2020
ecaebff
Add dependency between coreneuron_test for mech library
pramodk Aug 31, 2020
bc50840
linking fixes for GPU build
pramodk Aug 31, 2020
fbcb09f
Small changes/refactoring in nrnivmodl-core.in
pramodk Sep 2, 2020
d73a646
intermediate commit
pramodk Sep 3, 2020
7637e14
Refactoring of target rules
pramodk Sep 3, 2020
23cd2df
Cleanup makefile rules more
pramodk Sep 3, 2020
abb1b0b
refactoring more targets
pramodk Sep 3, 2020
2277111
more makefile refactor
pramodk Sep 3, 2020
eae303d
fixed non-ispc targets
pramodk Sep 4, 2020
a6540f5
fix missing single quotes for rpath
pramodk Sep 4, 2020
6ed9a26
symlink nrnunits
pramodk Sep 4, 2020
f3b7081
travis verbose
pramodk Sep 4, 2020
1fc9b8e
fix link error in static builds
pramodk Sep 4, 2020
d82a8c8
Set visiblity to hidden to avoid double free
pramodk Sep 5, 2020
0ac5343
undo visibility hidden; instead avoid linking licoreneuron
pramodk Sep 5, 2020
6763bd3
Set rpath for build time exes
pramodk Sep 5, 2020
d0b9961
Add coreneuron library linking
pramodk Sep 7, 2020
2678cc2
libcoreneuron is built with SHARED and vice-a-versa
pramodk Sep 7, 2020
1ced129
Allow undefined reference in shared library
pramodk Sep 7, 2020
5208532
limit to two parallel builds with make
pramodk Sep 7, 2020
e461e0c
Add dependency with nmodl target
pramodk Sep 7, 2020
ab3c381
More cleanup and documentation; serial build
pramodk Sep 7, 2020
c8501c9
rename target used by neuron : coreneuron_test to nrniv-core
pramodk Sep 8, 2020
a4d36dc
update tests with the target
pramodk Sep 8, 2020
250eb92
Change INSTALL_ to CORENRN_ prefix and address review comment
pramodk Sep 15, 2020
8dfa544
Add install target and re-introduce -d option by popular demand
pramodk Sep 15, 2020
7e9fa20
Build libcornrnmech static one always required for nrniv-core
pramodk Sep 21, 2020
1035a0d
Add CLI option to choose static or shared build
pramodk Sep 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ script:
else
cmake ${cmake_option} -DCMAKE_INSTALL_PREFIX=$HOME/CoreNeuron -DPYTHON_EXECUTABLE=$(which python3) ..;
fi
- cmake --build .
- make
- ctest --output-on-failure
- make install

Expand Down
95 changes: 0 additions & 95 deletions CMake/NmodlHelper.cmake

This file was deleted.

9 changes: 9 additions & 0 deletions CMake/config/CompilerFlagsHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,12 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
endif()

endforeach()

# ===============================================================================
# Allow undefined reference in shared library as mod files will be linked later
# ===============================================================================
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(UNDEFINED_SYMBOLS_IGNORE_FLAG "-undefined dynamic_lookup")
string(APPEND CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS " ${UNDEFINED_SYMBOLS_IGNORE_FLAG}")
string(APPEND CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS " ${UNDEFINED_SYMBOLS_IGNORE_FLAG}")
endif()
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ include(OpenAccHelper)
# Common dependencies
# =============================================================================
find_package(PythonInterp REQUIRED)
find_package(Perl REQUIRED)

# =============================================================================
# ISPC should compile with --pic by default
Expand Down Expand Up @@ -144,7 +145,11 @@ endif()
# OpenACC needs to build static library in order to have global/routines working.
# See https://www.pgroup.com/userforum/viewtopic.php?t=5350
# ~~~
if(CORENRN_ENABLE_SHARED AND NOT CORENRN_ENABLE_GPU)
if(CORENRN_ENABLE_GPU)
set(CORENRN_ENABLE_SHARED OFF)
endif()

if(CORENRN_ENABLE_SHARED)
set(COMPILE_LIBRARY_TYPE "SHARED")
else()
set(COMPILE_LIBRARY_TYPE "STATIC")
Expand Down Expand Up @@ -247,6 +252,7 @@ if(CORENRN_ENABLE_NMODL)
set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}")
set(nmodl_PYTHONPATH "${CMAKE_BINARY_DIR}/lib")
set(CORENRN_NMODL_PYTHONPATH "${nmodl_PYTHONPATH}:$ENV{PYTHONPATH}")
set(NMODL_TARGET_TO_DEPEND nmodl)
endif()
include_directories(${CORENRN_NMODL_INCLUDE})
# set correct arguments for nmodl for cpu/gpu target
Expand Down
87 changes: 22 additions & 65 deletions coreneuron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,47 +50,10 @@ set(KINDERIV_PYTHON_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/kinderiv.py")
set(KINDERIV_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/_kinderiv.h")

set(NMODL_UNITS_FILE "${CMAKE_BINARY_DIR}/share/nrnunits.lib")
set(INBUILT_MOD_PATH "mechanism/mech/modfile")
set(INBUILT_MOD_FILES
expsyn.mod
exp2syn.mod
hh.mod
netstim.mod
passive.mod
pattern.mod
stim.mod)

# Has helper macro for generating cpp file from mod2c
include(NmodlHelper)

# =============================================================================
# Command for MOD to CPP conversion
# =============================================================================
set(CORENRN_NMODL_COMMAND env "MODLUNIT=${NMODL_UNITS_FILE}"
"PYTHONPATH=${CORENRN_NMODL_PYTHONPATH}" ${CORENRN_NMODL_BINARY})

if(${CORENRN_ENABLE_ISPC})
set(NMODL_CODEGEN_TARGET ispc)
else()
set(NMODL_CODEGEN_TARGET serial)
endif()

# configure every mod file to configure with mod2c/nmodl
foreach(MOD ${INBUILT_MOD_FILES})
nmodl_to_cpp_target(KEY INBUILT_MOD MODFILE "${INBUILT_MOD_PATH}/${MOD}" TARGET
${NMODL_CODEGEN_TARGET})
endforeach()

set_source_files_properties(${NMODL_INBUILT_MOD_OUTPUTS} PROPERTIES GENERATED TRUE)

# for ispc generated files, we need add extra compilation flags
if(CORENRN_ENABLE_ISPC)
set(NMODL_ISPC_INBUILT_MOD_OUTPUTS ${NMODL_INBUILT_MOD_OUTPUTS})
list(FILTER NMODL_ISPC_INBUILT_MOD_OUTPUTS INCLUDE REGEX ".*\.ispc$")
set_source_files_properties(${NMODL_ISPC_INBUILT_MOD_OUTPUTS} PROPERTIES LANGUAGE ISPC)
set_source_files_properties(${NMODL_ISPC_INBUILT_MOD_OUTPUTS} PROPERTIES COMPILE_FLAGS
"-I${CORENRN_NMODL_INCLUDE} --pic")
endif()
# copy inbuilt mod files to share
file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/mechanism/mech/modfile
DESTINATION ${CMAKE_BINARY_DIR}/share)

# =============================================================================
# coreneuron GPU library
Expand Down Expand Up @@ -155,18 +118,14 @@ add_custom_target(kin_deriv_header DEPENDS "${KINDERIV_HEADER_FILE}")
# main coreneuron library
add_library(
coreneuron ${COMPILE_LIBRARY_TYPE} ${CORENEURON_HEADER_FILES} ${CORENEURON_TEMPLATE_FILES}
${CORENEURON_CODE_FILES} ${cudacorenrn_objs} ${NMODL_INBUILT_MOD_OUTPUTS})
${CORENEURON_CODE_FILES} ${cudacorenrn_objs} ${NMODL_INBUILT_MOD_OUTPUTS})

# need to have _kinderiv.h for mod2c generated files
add_dependencies(coreneuron kin_deriv_header)

# scopmath is created separately for nrnivmodl-core workflow
add_library(scopmath STATIC ${CORENEURON_HEADER_FILES} ${SCOPMATH_CODE_FILES})

# minimal main and dimplic file for nrnivmodl-core workflow
add_library(corenrnmech ${COMPILE_LIBRARY_TYPE} ${CORENEURON_HEADER_FILES} ${ENGINEMECH_CODE_FILE}
${DIMPLIC_CODE_FILE})

target_link_libraries(
coreneuron
${MPI_C_LIBRARIES}
Expand All @@ -182,35 +141,26 @@ target_include_directories(coreneuron SYSTEM
target_include_directories(coreneuron SYSTEM
PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR}/external/CLI11/include)

target_link_libraries(corenrnmech scopmath coreneuron)

set_target_properties(
coreneuron corenrnmech scopmath ${link_cudacoreneuron}
coreneuron scopmath ${link_cudacoreneuron}
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/lib POSITION_INDEPENDENT_CODE ON)

# =============================================================================
# create special-core with halfgap.mod for tests
# =============================================================================
add_custom_command(
TARGET coreneuron POST_BUILD
COMMAND ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core
add_custom_target(
nrniv-core ALL
COMMAND ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core -b STATIC
${CORENEURON_PROJECT_SOURCE_DIR}/tests/integration/ring_gap/mod
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}/special-core
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}/bin
BYPRODUCTS
${CMAKE_BINARY_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}/special-core
COMMENT "Running nrnivmodl-core with halfgap.mod")
add_dependencies(coreneuron scopmath)
add_dependencies(nrniv-core scopmath coreneuron ${NMODL_TARGET_TO_DEPEND})

# =============================================================================
# create nrnivmodl-core
# =============================================================================
# coreneuron executable
include_directories(${CORENEURON_PROJECT_SOURCE_DIR})
add_executable(nrniv-core "apps/coreneuron.cpp")

target_link_libraries(nrniv-core corenrnmech ${reportinglib_LIBRARY} ${sonatareport_LIBRARY})

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

# =============================================================================
# Extract link definitions to be used with nrnivmodl-core
Expand Down Expand Up @@ -255,6 +205,7 @@ if(NOT CORENRN_ENABLE_NMODL)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/share/mod2c/")
add_custom_target(link_units ALL COMMAND ${CMAKE_COMMAND} -E create_symlink "${NMODL_UNITS_FILE}"
"${CMAKE_BINARY_DIR}/share/mod2c/nrnunits.lib")
add_dependencies(nrniv-core link_units)
endif()

# main program required for building special-core
Expand All @@ -266,7 +217,7 @@ file(COPY apps/coreneuron.cpp DESTINATION ${CMAKE_BINARY_DIR}/share/coreneuron)

# coreneuron main libraries
install(
TARGETS coreneuron corenrnmech ${link_cudacoreneuron}
TARGETS coreneuron ${link_cudacoreneuron}
EXPORT coreneuron
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
Expand Down Expand Up @@ -297,8 +248,14 @@ if(NOT CORENRN_ENABLE_NMODL)
endif()

# install nrniv-core app
install(TARGETS nrniv-core DESTINATION bin)
install(
PROGRAMS ${CMAKE_BINARY_DIR}/bin/${CMAKE_HOST_SYSTEM_PROCESSOR}/special-core
DESTINATION bin
RENAME nrniv-core)
install(FILES apps/coreneuron.cpp DESTINATION share/coreneuron)

# install random123 and nmodl headers
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION include)

# install mod files
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/modfile DESTINATION share)
Loading