Skip to content

Commit 487cc83

Browse files
authored
CMake build options refactoring for Makefile and removing PG_ACC_BUGS (BlueBrain/CoreNeuron#455)
* CMake build options refactoring for Makefile * move all makefile related options into single file MakefileBuildOptions.cmake * remove all option processing from extra/CMakeLists.txt * fix with neuron linking : type CN_PGI_ACC_FLAGS -> PGI_ACC_FLAGS * Use PGI archive module because of issue with latest NVHPC modules * fix ISPC build issue and nrnivmodl-core failure on OSX * Avoid P2 UC2 ndoes as GPFS is not mounted (HELP-13390) * Use spack branch only if specified * Remove use of PG_ACC_BUGS * PG_ACC_BUGS was added when we saw bugs with PGI compiler version 16.3 * Except the case of union, no more real buggy scenario exists * So remove all usages of PG_ACC_BUGS * Remove some hardcoded ion array size by const variable * update mod2c to master * mods files and cpp translated files are in same x86_64/corenrn/mod2c directory CoreNEURON Repo SHA: BlueBrain/CoreNeuron@d4ed738
1 parent 7c1a004 commit 487cc83

File tree

17 files changed

+184
-161
lines changed

17 files changed

+184
-161
lines changed

bin/CMakeLists.txt

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,15 @@
55
# =============================================================================
66

77
# =============================================================================
8-
# Prepare nrnivmodl-core script with correct compiler flags
8+
# Copy first into build directory as it will be used for special-core
99
# =============================================================================
10-
11-
# extract the COMPILE_DEFINITIONS property from the directory.
12-
get_directory_property(CORENRN_COMPILE_FLAGS COMPILE_DEFINITIONS)
13-
if(CORENRN_COMPILE_FLAGS)
14-
set(CORENRN_COMPILE_DEFS "")
15-
foreach(flag ${CORENRN_COMPILE_FLAGS})
16-
set(CORENRN_COMPILE_DEFS "${CORENRN_COMPILE_DEFS} -D${flag}")
17-
endforeach()
18-
endif()
19-
20-
# ~~~
21-
# find_cuda uses FindThreads that adds below imported target we shouldn't add
22-
# imported target to link line
23-
# ~~~
24-
list(REMOVE_ITEM CORENRN_LINK_LIBS "Threads::Threads")
25-
# replicate CMake magic to transform system libs to -l<libname>
26-
foreach(link_lib ${CORENRN_LINK_LIBS})
27-
if(${link_lib} MATCHES "\-l.*")
28-
string(APPEND CORENRN_LINK_DEFS " ${link_lib}")
29-
continue()
30-
endif()
31-
get_filename_component(path ${link_lib} DIRECTORY)
32-
if(NOT path)
33-
string(APPEND CORENRN_LINK_DEFS " -l${link_lib}")
34-
elseif("${path}" MATCHES "^(/lib|/lib64|/usr/lib|/usr/lib64)$")
35-
get_filename_component(libname ${link_lib} NAME_WE)
36-
string(REGEX REPLACE "^lib" "" libname ${libname})
37-
string(APPEND CORENRN_LINK_DEFS " -l${libname}")
38-
else()
39-
string(APPEND CORENRN_LINK_DEFS " ${link_lib}")
40-
endif()
41-
endforeach()
42-
43-
# PGI compiler add --c++14;-A option for c++14 flag
44-
string(REPLACE ";" " " CXX14_STANDARD_COMPILE_OPTION "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}")
45-
46-
# compiler flags depending on BUILD_TYPE (configured as BUILD_TYPE_<LANG>_FLAGS)
47-
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
48-
set(BUILD_TYPE_C_FLAGS "${CMAKE_C_FLAGS_${_BUILD_TYPE}}")
49-
set(BUILD_TYPE_CXX_FLAGS "${CMAKE_CXX_FLAGS_${_BUILD_TYPE}}")
50-
message(STATUS "CXX Compile flags from BUILD_TYPE (${_BUILD_TYPE}): ${BUILD_TYPE_CXX_FLAGS}")
51-
52-
# nmodl options
53-
if(CORENRN_ENABLE_NMODL)
54-
set(nmodl_arguments_c "host --c passes --inline ${CORENRN_NMODL_FLAGS}")
55-
set(nmodl_arguments_ispc "host --ispc passes --inline ${CORENRN_NMODL_FLAGS}")
56-
else()
57-
set(nmodl_arguments_c "")
58-
set(nmodl_arguments_ispc "")
59-
endif()
60-
61-
# name of nmodl/mod2c binary
62-
get_filename_component(nmodl_name ${CORENRN_MOD2CPP_BINARY} NAME)
63-
set(nmodl_binary_name ${nmodl_name})
64-
65-
# =============================================================================
66-
# Install first into build directory and then to install prefix
67-
# =============================================================================
68-
6910
configure_file(nrnivmodl_core_makefile.in
7011
${CMAKE_BINARY_DIR}/share/coreneuron/nrnivmodl_core_makefile @ONLY)
7112
configure_file(nrnivmodl-core.in ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core @ONLY)
7213

14+
# =============================================================================
15+
# Install for end users
16+
# =============================================================================
7317
install(FILES ${CMAKE_BINARY_DIR}/share/coreneuron/nrnivmodl_core_makefile
7418
DESTINATION share/coreneuron)
7519
install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core DESTINATION bin)

bin/nrnivmodl-core.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ else
100100
fi
101101

102102
# temporary directory where mod files will be copied
103-
temp_mod_dir=@CMAKE_HOST_SYSTEM_PROCESSOR@/core/mods
103+
temp_mod_dir=@CMAKE_HOST_SYSTEM_PROCESSOR@/corenrn/mod2c
104104
mkdir -p $temp_mod_dir
105105

106106
# copy mod files with include files. note that ${ROOT_DIR}/share
@@ -109,7 +109,7 @@ set +e
109109
for mod_dir in ${ROOT_DIR}/share/modfile $params_MODS_PATH;
110110
do
111111
# copy mod files and include files
112-
files=`ls $mod_dir/*.mod $mod_dir/*.inc 2>/dev/null`
112+
files=`ls $mod_dir/*.mod $mod_dir/*.inc $mod_dir/*.h* 2>/dev/null`
113113
for f in $files;
114114
do
115115
# copy mod files only if it's changed (to avoid rebuild)

bin/nrnivmodl_core_makefile.in

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ OUTPUT_DIR = @CMAKE_HOST_SYSTEM_PROCESSOR@
1515
DESTDIR =
1616
TARGET_LIB_TYPE = $(BUILD_TYPE)
1717

18+
# required for OSX to execute nrnivmodl-core
19+
OSX_SYSROOT=@CMAKE_OSX_SYSROOT@
20+
ifneq ($(OSX_SYSROOT),)
21+
export SDKROOT := $(OSX_SYSROOT)
22+
endif
23+
1824
# CoreNEURON installation directories
1925
CORENRN_BIN_DIR := $(ROOT)/bin
2026
CORENRN_LIB_DIR := $(ROOT)/lib
@@ -35,7 +41,7 @@ MOD_TO_CPP_DIR = $(OUTPUT_DIR)/corenrn/mod2c
3541
MOD_OBJS_DIR = $(OUTPUT_DIR)/corenrn/build
3642

3743
# Linked libraries gathered by CMake
38-
LDFLAGS = $(LINKFLAGS) @CORENRN_LINK_DEFS@
44+
LDFLAGS = $(LINKFLAGS) @CORENRN_COMMON_LDFLAGS@
3945
CORENRNLIB_FLAGS = -L$(CORENRN_LIB_DIR) -lcoreneuron
4046
CORENRNLIB_FLAGS += $(if @reportinglib_LIB_DIR@, -W$(subst ;, -W,l,-rpath,@reportinglib_LIB_DIR@),)
4147
CORENRNLIB_FLAGS += $(if @sonatareport_LIB_DIR@, -W$(subst ;, -W,l,-rpath,@sonatareport_LIB_DIR@),)
@@ -49,8 +55,8 @@ INCLUDES += $(if @reportinglib_INCLUDE_DIR@, -I$(subst ;, -I,@reportinglib_INCLU
4955

5056
# C++ compilation and link commands
5157
CXX = @CMAKE_CXX_COMPILER@
52-
CXXFLAGS = @BUILD_TYPE_CXX_FLAGS@ @CMAKE_CXX_FLAGS@ @CXX14_STANDARD_COMPILE_OPTION@ @PGI_INLINE_FLAGS@
53-
CXX_COMPILE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ @CORENRN_COMPILE_DEFS@ $(INCLUDES)
58+
CXXFLAGS = @CORENRN_CXX_FLAGS@
59+
CXX_COMPILE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ @CORENRN_COMMON_COMPILE_DEFS@ $(INCLUDES)
5460
CXX_LINK_EXE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_EXE_LINKER_FLAGS@
5561
CXX_SHARED_LIB_CMD = $(CXX) $(CXXFLAGS) @CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS@ @CMAKE_SHARED_LIBRARY_CXX_FLAGS@ @CMAKE_SHARED_LINKER_FLAGS@
5662

@@ -61,6 +67,16 @@ ISPC_COMPILE_CMD = $(ISPC) @CMAKE_ISPC_FLAGS@ -I$(CORENRN_INC_DIR)
6167
# env variables required for mod2c or nmodl
6268
MOD2CPP_ENV_VAR = PYTHONPATH=@CORENRN_NMODL_PYTHONPATH@:${CORENRN_LIB_DIR}/python MODLUNIT=$(CORENRN_SHARE_MOD2CPP_DIR)/nrnunits.lib
6369

70+
# nmodl options
71+
ifeq (@CORENRN_ENABLE_NMODL@, ON)
72+
ifeq (@CORENRN_ENABLE_GPU@, ON)
73+
nmodl_arguments_c=@NMODL_ACC_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
74+
else
75+
nmodl_arguments_c=@NMODL_CPU_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
76+
endif
77+
nmodl_arguments_ispc=@NMODL_ISPC_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
78+
endif
79+
6480
# name of the mechanism library with suffix if provided
6581
COREMECH_LIB_NAME = corenrnmech$(if $(MECHLIB_SUFFIX),_$(MECHLIB_SUFFIX),)
6682
COREMECH_LIB_PATH = $(OUTPUT_DIR)/lib$(COREMECH_LIB_NAME)$(LIB_SUFFIX)
@@ -144,13 +160,17 @@ C_RESET := \033[0m
144160
C_GREEN := \033[32m
145161

146162
# Default nmodl flags. Override if MOD2CPP_RUNTIME_FLAGS is not empty
147-
NMODL_FLAGS_ISPC = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),@nmodl_arguments_ispc@)
148-
MOD2CPP_FLAGS_C = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),@nmodl_arguments_c@)
163+
ifeq (@CORENRN_ENABLE_NMODL@, ON)
164+
MOD2CPP_FLAGS_ISPC = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),$(nmodl_arguments_ispc))
165+
MOD2CPP_FLAGS_C = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),$(nmodl_arguments_c))
166+
endif
167+
149168
ifeq (@CORENRN_ENABLE_ISPC@, ON)
150-
$(info Default nmodl flags: @nmodl_arguments_ispc@)
169+
$(info Default NMODL flags: @nmodl_arguments_ispc@)
151170
else
152-
$(info Default nmodl flags: @nmodl_arguments_c@)
171+
$(info Default NMODL flags: @nmodl_arguments_c@)
153172
endif
173+
154174
ifneq ($(MOD2CPP_RUNTIME_FLAGS),)
155175
$(warning Runtime nmodl flags (they replace the default ones): $(MOD2CPP_RUNTIME_FLAGS))
156176
endif
@@ -198,7 +218,7 @@ $(MOD_OBJS_DIR)/%.obj: $(MOD_TO_CPP_DIR)/%.ispc | $(MOD_OBJS_DIR)
198218

199219
# translate MOD files to ISPC using NMODL
200220
$(mod_ispc_files): $(MOD_TO_CPP_DIR)/%.ispc: $(MODS_PATH)/%.mod | $(MOD_TO_CPP_DIR)
201-
$(MOD2CPP_ENV_VAR) $(MOD2CPP_BINARY_PATH) $< -o $(MOD_TO_CPP_DIR)/ $(NMODL_FLAGS_ISPC)
221+
$(MOD2CPP_ENV_VAR) $(MOD2CPP_BINARY_PATH) $< -o $(MOD_TO_CPP_DIR)/ $(MOD2CPP_FLAGS_ISPC)
202222

203223
# translate MOD files to CPP using mod2c/NMODL
204224
$(mod_cpp_files): $(MOD_TO_CPP_DIR)/%.cpp: $(MODS_PATH)/%.mod | $(MOD_TO_CPP_DIR)

cmake/coreneuron/CMakeLists.txt

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ set(LIKWID_DIR
9595
""
9696
CACHE PATH "Path to likwid performance analysis suite")
9797

98-
set(CORENRN_FRONTEND_C_COMPILER
99-
gcc
100-
CACHE FILEPATH "C compiler for building mod2c [frontend]")
101-
set(CORENRN_FRONTEND_CXX_COMPILER
102-
g++
103-
CACHE FILEPATH "C++ compiler for building mod2c [frontend]")
104-
10598
if(CORENEURON_AS_SUBPROJECT)
10699
set(CORENRN_ENABLE_UNIT_TESTS OFF)
107100
endif()
@@ -126,11 +119,6 @@ include(OpenAccHelper)
126119
find_package(PythonInterp REQUIRED)
127120
find_package(Perl REQUIRED)
128121

129-
# =============================================================================
130-
# ISPC should compile with --pic by default
131-
# =============================================================================
132-
set(CMAKE_ISPC_FLAGS "--pic ${CMAKE_ISPC_FLAGS}")
133-
134122
# =============================================================================
135123
# Common build options
136124
# =============================================================================
@@ -147,7 +135,6 @@ endif()
147135
# Build option specific compiler flags
148136
# =============================================================================
149137
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "PGI")
150-
add_definitions(-DSWAP_ENDIAN_DISABLE_ASM)
151138
# PGI with llvm code generation doesn't have necessary assembly intrinsic headers
152139
add_definitions(-DEIGEN_DONT_VECTORIZE=1)
153140
endif()
@@ -168,7 +155,6 @@ endif()
168155

169156
if(CORENRN_ENABLE_ISPC)
170157
enable_language(ISPC)
171-
add_definitions("-DISPC_INTEROP=1")
172158
set(CORENRN_ENABLE_NMODL ON)
173159
endif()
174160

@@ -283,7 +269,6 @@ if(CORENRN_ENABLE_NMODL)
283269
if(CORENRN_ENABLE_GPU)
284270
string(APPEND CORENRN_NMODL_FLAGS " acc --oacc")
285271
endif()
286-
separate_arguments(NMODL_EXTRA_FLAGS_LIST UNIX_COMMAND "${CORENRN_NMODL_FLAGS}")
287272
else()
288273
include(AddMod2cSubmodule)
289274
set(CORENRN_MOD2CPP_BINARY ${CMAKE_BINARY_DIR}/bin/mod2c_core${CMAKE_EXECUTABLE_SUFFIX})
@@ -309,10 +294,17 @@ if(CORENRN_ENABLE_LIKWID_PROFILING)
309294
add_definitions("-DLIKWID_PERFMON")
310295
endif()
311296

297+
# =============================================================================
298+
# Common CXX flags : ignore unknown pragma warnings
299+
# =============================================================================
300+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
301+
312302
# =============================================================================
313303
# Add main directories
314304
# =============================================================================
315305
add_subdirectory(coreneuron)
306+
307+
include(MakefileBuildOptions)
316308
add_subdirectory(extra)
317309

318310
if(CORENRN_ENABLE_UNIT_TESTS)
@@ -325,14 +317,6 @@ endif()
325317
install(FILES CMake/coreneuron-config.cmake DESTINATION share/cmake)
326318
install(EXPORT coreneuron DESTINATION share/cmake)
327319

328-
# just for printing the compiler flags in the build status
329-
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UPPER)
330-
if(BUILD_TYPE_UPPER MATCHES "CUSTOM")
331-
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS}")
332-
else()
333-
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS_${BUILD_TYPE_UPPER}}")
334-
endif()
335-
336320
if(NOT CORENEURON_AS_SUBPROJECT)
337321
# =============================================================================
338322
# Setup Doxygen documentation
@@ -402,7 +386,7 @@ if(cmake_generator_tolower MATCHES "makefile")
402386

403387
message(STATUS "C COMPILER | ${CMAKE_C_COMPILER}")
404388
message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
405-
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
389+
message(STATUS "COMPILE FLAGS | ${CORENRN_CXX_FLAGS}")
406390
message(STATUS "Build Type | ${COMPILE_LIBRARY_TYPE}")
407391
message(STATUS "MPI | ${CORENRN_ENABLE_MPI}")
408392
if(CORENRN_ENABLE_MPI)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# =============================================================================
2+
# Common CXX and ISPC flags
3+
# =============================================================================
4+
5+
# ISPC should compile with --pic by default
6+
set(CMAKE_ISPC_FLAGS "${CMAKE_ISPC_FLAGS} --pic")
7+
8+
# =============================================================================
9+
# NMODL CLI options : common and backend specific
10+
# =============================================================================
11+
# if user pass arguments then use those as common arguments
12+
if ("${CORENRN_NMODL_FLAGS}" STREQUAL "")
13+
set(NMODL_COMMON_ARGS "passes --inline")
14+
else()
15+
set(NMODL_COMMON_ARGS ${CORENRN_NMODL_FLAGS})
16+
endif()
17+
18+
set(NMODL_CPU_BACKEND_ARGS "host --c")
19+
set(NMODL_ISPC_BACKEND_ARGS "host --ispc")
20+
set(NMODL_ACC_BACKEND_ARGS "host --c acc --oacc")
21+
22+
# =============================================================================
23+
# Extract Compile definitions : common to all backend
24+
# =============================================================================
25+
get_directory_property(COMPILE_DEFS COMPILE_DEFINITIONS)
26+
if(COMPILE_DEFS)
27+
set(CORENRN_COMMON_COMPILE_DEFS "")
28+
foreach(flag ${COMPILE_DEFS})
29+
set(CORENRN_COMMON_COMPILE_DEFS "${CORENRN_COMMON_COMPILE_DEFS} -D${flag}")
30+
endforeach()
31+
endif()
32+
33+
# =============================================================================
34+
# link flags : common to all backend
35+
# =============================================================================
36+
# ~~~
37+
# find_cuda uses FindThreads that adds below imported target we
38+
# shouldn't add imported target to link line
39+
# ~~~
40+
list(REMOVE_ITEM CORENRN_LINK_LIBS "Threads::Threads")
41+
42+
# replicate CMake magic to transform system libs to -l<libname>
43+
foreach(link_lib ${CORENRN_LINK_LIBS})
44+
if(${link_lib} MATCHES "\-l.*")
45+
string(APPEND CORENRN_COMMON_LDFLAGS " ${link_lib}")
46+
continue()
47+
endif()
48+
get_filename_component(path ${link_lib} DIRECTORY)
49+
if(NOT path)
50+
string(APPEND CORENRN_COMMON_LDFLAGS " -l${link_lib}")
51+
elseif("${path}" MATCHES "^(/lib|/lib64|/usr/lib|/usr/lib64)$")
52+
get_filename_component(libname ${link_lib} NAME_WE)
53+
string(REGEX REPLACE "^lib" "" libname ${libname})
54+
string(APPEND CORENRN_COMMON_LDFLAGS " -l${libname}")
55+
else()
56+
string(APPEND CORENRN_COMMON_LDFLAGS " ${link_lib}")
57+
endif()
58+
endforeach()
59+
60+
# =============================================================================
61+
# compile flags : common to all backend
62+
# =============================================================================
63+
# PGI compiler adds --c++14;-A option for C++14, remove ";"
64+
string(REPLACE ";" " " CXX14_STD_FLAGS "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}")
65+
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
66+
set(CORENRN_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE}} ${CXX14_STD_FLAGS}")
67+
68+
# =============================================================================
69+
# nmodl/mod2c related options : TODO
70+
# =============================================================================
71+
# name of nmodl/mod2c binary
72+
get_filename_component(nmodl_name ${CORENRN_MOD2CPP_BINARY} NAME)
73+
set(nmodl_binary_name ${nmodl_name})

0 commit comments

Comments
 (0)