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

Commit 1fe45cd

Browse files
authored
CoreNEURON CMake refactoring for NEURON integration (5 years of cleanup!) (#198)
* Support for building coreneuron as submodule - avoid using of PROJECT_SOURCE_DIR - consistently include top level directory * Support for find_package - add cmake configs for coreneuron-config.cmake - export targets - create libcorenrnmech.so similar to neuron under <arch>/.libs/ - change share/coreneuron/nrnivmodl_core_makefile to bin/nrnivmodl_core_makefile - do --init --recursive automatically for submodule * CMake cleanup and refactoring - remove unnecessary cmake options : CORENEURON_MAIN, ENABLE_OPENACC_INFO, ENABLE_CUDA_MODULES, ENABLE_OMP_RUNTIME_SCHEDULE * Remove EXPORT_MECHS_FUNCTIONS and related options * Deprecate tests for building additional mechanisms using cmake option as we are moving towards nrnivmodl-core workflow. * Remove missing ENABLE_CUDA_MODULES related config; remove formatbuild target for mod2c clang-format * More substantial changes for mod2c_from_file and other cmake options - Remove DefineInstallationPaths.cmake - Remove BlueGenePortability.cmake - Remove FindBBPTestData.cmake - Minimize FindSLURM.cmake - Remove ADDITIONAL_MECHPATH and ADDITIONAL_MECHS - Remove mod2c_from_file macro in cmake * Remove halfgap.mod from coreneuron_exec and build special-core during build - make gap mod file from main coreneuron library - still test gap juction test by creating special-core * Change cmake modules structure and build special-core when necessary * Change CMake options from X to NRNCORE_X consistently. * cmake-format on all CMakeLists.txt * Add build status * Remove use of GNUInstallDirs and releated variables * Add missing headear and tweak to nrnivmodl-core workflow * Update README
1 parent ceb9731 commit 1fe45cd

File tree

66 files changed

+1084
-2478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1084
-2478
lines changed

CMake/AddMod2cSubmodule.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
7+
include(ExternalProject)
8+
include(FindPkgConfig)
9+
10+
find_path(MOD2C_PROJ NAMES CMakeLists.txt PATHS "${CORENEURON_PROJECT_SOURCE_DIR}/external/mod2c")
11+
find_package_handle_standard_args(MOD2C REQUIRED_VARS MOD2C_PROJ)
12+
13+
if(NOT MOD2C_FOUND)
14+
find_package(Git 1.8.3 QUIET)
15+
if(NOT ${GIT_FOUND})
16+
message(FATAL_ERROR "git not found, clone repository with --recursive")
17+
endif()
18+
message(STATUS "Sub-module mod2c missing : running git submodule update --init --recursive")
19+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --
20+
${CORENEURON_PROJECT_SOURCE_DIR}/external/mod2c
21+
WORKING_DIRECTORY ${CORENEURON_PROJECT_SOURCE_DIR})
22+
else()
23+
message(STATUS "Using mod2c submodule from ${MOD2C_PROJ}")
24+
endif()
25+
26+
set(ExternalProjectCMakeArgs
27+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
28+
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
29+
-DCMAKE_C_COMPILER=${CORENRN_FRONTEND_C_COMPILER}
30+
-DCMAKE_CXX_COMPILER=${CORENRN_FRONTEND_CXX_COMPILER})
31+
32+
externalproject_add(mod2c
33+
BUILD_ALWAYS
34+
1
35+
SOURCE_DIR
36+
${CORENEURON_PROJECT_SOURCE_DIR}/external/mod2c
37+
GIT_SUBMODULES
38+
CMAKE_ARGS
39+
${ExternalProjectCMakeArgs})

CMake/CMakeDetermineISPCCompiler.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
17
# Find the compiler
28
find_program(
39
CMAKE_ISPC_COMPILER

CMake/CMakeISPCInformation.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
17
# This file sets the basic flags for the FOO compiler
28
set(CMAKE_INCLUDE_FLAG_ISPC "-I")
39

CMake/CMakeTestISPCCompiler.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# For now just do nothing in here
2-
31
if(CMAKE_ISPC_COMPILER_FORCED)
42
# The compiler configuration was forced by the user.
53
# Assume the user has configured all compiler information.
@@ -9,7 +7,6 @@ endif()
97

108
set(CMAKE_ISPC_COMPILER_WORKS 1 CACHE INTERNAL "")
119

12-
1310
# Remove any cached result from an older CMake version.
1411
# We now store this in CMakeISPCCompiler.cmake.
1512
unset(CMAKE_ISPC_COMPILER_WORKS CACHE)

CMake/ClangFormatHelper.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
7+
set(CLANG_FORMAT_MIN_VERSION "4.0")
8+
set(CLANG_FORMAT_MAX_VERSION "4.9")
9+
10+
find_package(ClangFormat)
11+
12+
if(CLANG_FORMAT_FOUND)
13+
message(INFO "clang-format ${CLANG_FORMAT_EXECUTABLE} (${CLANG_FORMAT_VERSION}) found")
14+
endif()
15+
16+
if(CLANG_FORMAT_FOUND)
17+
file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/.clang-format DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
18+
19+
# all source files under coreneuron directory
20+
file(GLOB_RECURSE SRC_FILES_FOR_CLANG_FORMAT
21+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/*.c
22+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/*.cpp
23+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/*.h*
24+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/*.ipp*)
25+
26+
# exclude ezoption headers
27+
list(REMOVE_ITEM SRC_FILES_FOR_CLANG_FORMAT
28+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/utils/ezoption/ezOptionParser.hpp
29+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/utils/endianness.h
30+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/utils/swap_endian.h)
31+
32+
# exclude random123
33+
file(GLOB_RECURSE RANDOM123_FILES
34+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/utils/randoms/Random123/*.cpp
35+
${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/utils/randoms/Random123/*.h)
36+
37+
foreach(R123_PATH ${RANDOM123_FILES})
38+
list(REMOVE_ITEM SRC_FILES_FOR_CLANG_FORMAT ${R123_PATH})
39+
endforeach(R123_PATH)
40+
41+
add_custom_target(clang-format
42+
COMMAND ${CMAKE_COMMAND} -DSOURCE_FILES:STRING="${SRC_FILES_FOR_CLANG_FORMAT}"
43+
-DCLANG_FORMAT_EXECUTABLE=${CLANG_FORMAT_EXECUTABLE} -P
44+
"${CORENEURON_PROJECT_SOURCE_DIR}/CMake/ClangFormatUtils.cmake")
45+
endif()

CMake/ClangFormatUtils.cmake

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
string(REPLACE " " ";" FILES_TO_FORMAT ${SOURCE_FILES})
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
26

3-
FOREACH(SRC_FILE ${FILES_TO_FORMAT})
4-
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file -fallback-style=none ${SRC_FILE})
5-
ENDFOREACH()
7+
string(REPLACE " "
8+
";"
9+
FILES_TO_FORMAT
10+
${SOURCE_FILES})
11+
12+
foreach(SRC_FILE ${FILES_TO_FORMAT})
13+
execute_process(
14+
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file -fallback-style=none ${SRC_FILE})
15+
endforeach()

CMake/CrayPortability.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
7+
if(IS_DIRECTORY "/opt/cray")
8+
set(CRAY_SYSTEM TRUE)
9+
endif()
10+
11+
if(CRAY_SYSTEM)
12+
# default build type is static for cray
13+
if(NOT DEFINED COMPILE_LIBRARY_TYPE)
14+
set(COMPILE_LIBRARY_TYPE "STATIC")
15+
endif()
16+
17+
## Cray wrapper take care of everything!
18+
set(MPI_LIBRARIES "")
19+
set(MPI_C_LIBRARIES "")
20+
set(MPI_CXX_LIBRARIES "")
21+
22+
# instead of -rdynamic, cray wrapper needs either -dynamic or -static(default)
23+
# also cray compiler needs fPIC flag
24+
if(COMPILE_LIBRARY_TYPE STREQUAL "SHARED")
25+
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-dynamic")
26+
27+
# TODO: add Cray compiler flag configurations in CompilerFlagsHelpers.cmake
28+
# Cray compilers need PIC flag
29+
if(CMAKE_C_COMPILER_IS_CRAY)
30+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
31+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
32+
endif()
33+
34+
else()
35+
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
36+
endif()
37+
else()
38+
# default is shared library
39+
if(NOT DEFINED COMPILE_LIBRARY_TYPE)
40+
set(COMPILE_LIBRARY_TYPE "SHARED")
41+
endif()
42+
endif()

CMake/NmodlHelper.cmake

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
7+
# Macro sets up build rule for .cpp files from .mod files. Parameters:
8+
# KEY name : An arbitrary name to keep track of output .c files
9+
# MODFILE input : The path to the mod file
10+
# OUTTYPE <SERIAL|ISPC> : The output type (optional, defaults to serial)
11+
#
12+
# Because nmodl/mod2c_core wants to write the .cpp file in the same directory as the mod file, we copy the
13+
# mod file to the binary directory first
14+
#
15+
# The macro appends the names of the output files to NMODL_${name}_OUTPUTS and the names of the mod
16+
# files (without directories) to NMODL_${name}_MODS
17+
18+
macro(nmodl_to_cpp_target)
19+
20+
# first parse the arguments
21+
set(options)
22+
set(oneValueArgs TARGET MODFILE KEY)
23+
set(multiValueArgs)
24+
cmake_parse_arguments(mod2c "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
25+
26+
if("${mod2c_MODFILE}" STREQUAL "")
27+
message(FATAL_ERROR "mod2c_target requires a MODFILE argument")
28+
endif()
29+
if("${mod2c_KEY}" STREQUAL "")
30+
message(FATAL_ERROR "mod2c_target requires a KEY argument")
31+
endif()
32+
33+
# get name of mod file and it's path
34+
get_filename_component(mod2c_source_ ${mod2c_MODFILE} ABSOLUTE)
35+
get_filename_component(mod2c_modname_ ${mod2c_MODFILE} NAME)
36+
37+
# check for nmodl target
38+
if("${mod2c_TARGET}" STREQUAL "serial")
39+
string(REGEX
40+
REPLACE "\\.mod$"
41+
".cpp"
42+
mod2c_outname_
43+
"${mod2c_modname_}")
44+
set(nmodl_modearg "--c")
45+
elseif("${mod2c_TARGET}" STREQUAL "ispc")
46+
file(STRINGS ${mod2c_MODFILE} mod2c_mod_artcell REGEX "ARTIFICIAL_CELL")
47+
if(NOT "${mod2c_mod_artcell}" STREQUAL "")
48+
string(REGEX
49+
REPLACE "\\.mod$"
50+
".cpp"
51+
mod2c_outname_
52+
"${mod2c_modname_}")
53+
set(nmodl_modearg "--c")
54+
else()
55+
string(REGEX
56+
REPLACE "\\.mod$"
57+
".ispc"
58+
mod2c_outname_
59+
"${mod2c_modname_}")
60+
string(REGEX
61+
REPLACE "\\.mod$"
62+
".cpp"
63+
mod2c_wrapper_outname_
64+
"${mod2c_modname_}")
65+
set(nmodl_modearg "--ispc")
66+
endif()
67+
elseif("${mod2c_TARGET}" STREQUAL "")
68+
# default case
69+
string(REGEX
70+
REPLACE "\\.mod$"
71+
".cpp"
72+
mod2c_outname_
73+
"${mod2c_modname_}")
74+
set(nmodl_modearg "--c")
75+
else()
76+
message(
77+
SEND_ERROR
78+
"mod2c_target only supports serial and ispc generation for now: \"${mod2c_TARGET}\"")
79+
endif()
80+
81+
set(mod2c_output_ "${CMAKE_CURRENT_BINARY_DIR}/${mod2c_outname_}")
82+
list(APPEND NMODL_${mod2c_KEY}_OUTPUTS "${mod2c_output_}")
83+
84+
if(DEFINED mod2c_wrapper_outname_)
85+
set(mod2c_wrapper_output_ "${CMAKE_CURRENT_BINARY_DIR}/${mod2c_wrapper_outname_}")
86+
list(APPEND NMODL_${mod2c_KEY}_OUTPUTS "${mod2c_wrapper_output_}")
87+
unset(mod2c_wrapper_outname_)
88+
endif()
89+
90+
list(APPEND NMODL_${mod2c_KEY}_MODS "${mod2c_modname_}")
91+
if(CORENRN_ENABLE_NMODL AND NMODL_FOUND)
92+
add_custom_command(OUTPUT ${mod2c_output_} ${mod2c_wrapper_output_}
93+
DEPENDS ${mod2c_MODFILE} ${CORENRN_NMODL_BINARY}
94+
COMMAND ${CMAKE_COMMAND} -E copy "${mod2c_source_}"
95+
"${CMAKE_CURRENT_BINARY_DIR}"
96+
COMMAND ${CORENRN_NMODL_COMMAND} "${mod2c_modname_}" -o "${CMAKE_CURRENT_BINARY_DIR}"
97+
host ${nmodl_modearg} passes --inline ${NMODL_EXTRA_FLAGS_LIST}
98+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
99+
else()
100+
add_custom_command(OUTPUT ${mod2c_output_}
101+
DEPENDS ${mod2c_MODFILE} mod2c ${CORENRN_NMODL_BINARY}
102+
COMMAND ${CMAKE_COMMAND} -E copy "${mod2c_source_}"
103+
"${CMAKE_CURRENT_BINARY_DIR}"
104+
COMMAND ${CORENRN_NMODL_COMMAND} "${mod2c_modname_}"
105+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
106+
endif()
107+
endmacro()

CMake/OpenAccHelper.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
6+
7+
if(CORENRN_ENABLE_GPU)
8+
set(COMPILE_LIBRARY_TYPE "STATIC")
9+
if(CORENRN_ENABLE_CUDA_UNIFIED_MEMORY)
10+
add_definitions(-DUNIFIED_MEMORY)
11+
endif()
12+
if(${CMAKE_C_COMPILER_ID} STREQUAL "PGI")
13+
add_definitions(-DPG_ACC_BUGS)
14+
set(ACC_FLAGS "-acc -Minline=size:200,levels:10")
15+
set(CMAKE_C_FLAGS "${ACC_FLAGS} ${CMAKE_C_FLAGS}")
16+
set(CMAKE_CXX_FLAGS "${ACC_FLAGS} ${CMAKE_CXX_FLAGS}")
17+
else()
18+
message(WARNING "Non-PGI compiler : make sure to add required compiler flags to enable OpenACC")
19+
endif()
20+
21+
find_package(CUDA 5.0 REQUIRED)
22+
set(CUDA_SEPARABLE_COMPILATION ON)
23+
add_definitions(-DCUDA_PROFILING)
24+
else(CORENRN_ENABLE_GPU)
25+
# OpenACC pragmas are not guarded, disable all unknown pragm warnings
26+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
27+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
28+
endif(CORENRN_ENABLE_GPU)

CMake/TestScriptUtils.cmake

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
# Copyright (c) 2016, Blue Brain Project
2-
# All rights reserved.
3-
4-
# Redistribution and use in source and binary forms, with or without modification,
5-
# are permitted provided that the following conditions are met:
6-
# 1. Redistributions of source code must retain the above copyright notice,
7-
# this list of conditions and the following disclaimer.
8-
# 2. Redistributions in binary form must reproduce the above copyright notice,
9-
# this list of conditions and the following disclaimer in the documentation
10-
# and/or other materials provided with the distribution.
11-
# 3. Neither the name of the copyright holder nor the names of its contributors
12-
# may be used to endorse or promote products derived from this software
13-
# without specific prior written permission.
14-
15-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25-
# THE POSSIBILITY OF SUCH DAMAGE.
26-
1+
# =============================================================================
2+
# Copyright (C) 2016-2019 Blue Brain Project
3+
#
4+
# See top-level LICENSE file for details.
5+
# =============================================================================
276

287
# Utility functions for manipulating test labels and producing
298
# tests from scripts:

0 commit comments

Comments
 (0)