Skip to content

Commit

Permalink
CMake build options refactoring for Makefile and removing PG_ACC_BUGS (
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
pramodk authored Jan 8, 2021
1 parent 7c1a004 commit 487cc83
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 161 deletions.
64 changes: 4 additions & 60 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,15 @@
# =============================================================================

# =============================================================================
# Prepare nrnivmodl-core script with correct compiler flags
# Copy first into build directory as it will be used for special-core
# =============================================================================

# extract the COMPILE_DEFINITIONS property from the directory.
get_directory_property(CORENRN_COMPILE_FLAGS COMPILE_DEFINITIONS)
if(CORENRN_COMPILE_FLAGS)
set(CORENRN_COMPILE_DEFS "")
foreach(flag ${CORENRN_COMPILE_FLAGS})
set(CORENRN_COMPILE_DEFS "${CORENRN_COMPILE_DEFS} -D${flag}")
endforeach()
endif()

# ~~~
# find_cuda uses FindThreads that adds below imported target we shouldn't add
# imported target to link line
# ~~~
list(REMOVE_ITEM CORENRN_LINK_LIBS "Threads::Threads")
# replicate CMake magic to transform system libs to -l<libname>
foreach(link_lib ${CORENRN_LINK_LIBS})
if(${link_lib} MATCHES "\-l.*")
string(APPEND CORENRN_LINK_DEFS " ${link_lib}")
continue()
endif()
get_filename_component(path ${link_lib} DIRECTORY)
if(NOT path)
string(APPEND CORENRN_LINK_DEFS " -l${link_lib}")
elseif("${path}" MATCHES "^(/lib|/lib64|/usr/lib|/usr/lib64)$")
get_filename_component(libname ${link_lib} NAME_WE)
string(REGEX REPLACE "^lib" "" libname ${libname})
string(APPEND CORENRN_LINK_DEFS " -l${libname}")
else()
string(APPEND CORENRN_LINK_DEFS " ${link_lib}")
endif()
endforeach()

# PGI compiler add --c++14;-A option for c++14 flag
string(REPLACE ";" " " CXX14_STANDARD_COMPILE_OPTION "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}")

# compiler flags depending on BUILD_TYPE (configured as BUILD_TYPE_<LANG>_FLAGS)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
set(BUILD_TYPE_C_FLAGS "${CMAKE_C_FLAGS_${_BUILD_TYPE}}")
set(BUILD_TYPE_CXX_FLAGS "${CMAKE_CXX_FLAGS_${_BUILD_TYPE}}")
message(STATUS "CXX Compile flags from BUILD_TYPE (${_BUILD_TYPE}): ${BUILD_TYPE_CXX_FLAGS}")

# nmodl options
if(CORENRN_ENABLE_NMODL)
set(nmodl_arguments_c "host --c passes --inline ${CORENRN_NMODL_FLAGS}")
set(nmodl_arguments_ispc "host --ispc passes --inline ${CORENRN_NMODL_FLAGS}")
else()
set(nmodl_arguments_c "")
set(nmodl_arguments_ispc "")
endif()

# name of nmodl/mod2c binary
get_filename_component(nmodl_name ${CORENRN_MOD2CPP_BINARY} NAME)
set(nmodl_binary_name ${nmodl_name})

# =============================================================================
# Install first into build directory and then to install prefix
# =============================================================================

configure_file(nrnivmodl_core_makefile.in
${CMAKE_BINARY_DIR}/share/coreneuron/nrnivmodl_core_makefile @ONLY)
configure_file(nrnivmodl-core.in ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core @ONLY)

# =============================================================================
# Install for end users
# =============================================================================
install(FILES ${CMAKE_BINARY_DIR}/share/coreneuron/nrnivmodl_core_makefile
DESTINATION share/coreneuron)
install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core DESTINATION bin)
4 changes: 2 additions & 2 deletions bin/nrnivmodl-core.in
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ else
fi

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

# copy mod files with include files. note that ${ROOT_DIR}/share
Expand All @@ -109,7 +109,7 @@ set +e
for mod_dir in ${ROOT_DIR}/share/modfile $params_MODS_PATH;
do
# copy mod files and include files
files=`ls $mod_dir/*.mod $mod_dir/*.inc 2>/dev/null`
files=`ls $mod_dir/*.mod $mod_dir/*.inc $mod_dir/*.h* 2>/dev/null`
for f in $files;
do
# copy mod files only if it's changed (to avoid rebuild)
Expand Down
36 changes: 28 additions & 8 deletions bin/nrnivmodl_core_makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ OUTPUT_DIR = @CMAKE_HOST_SYSTEM_PROCESSOR@
DESTDIR =
TARGET_LIB_TYPE = $(BUILD_TYPE)

# required for OSX to execute nrnivmodl-core
OSX_SYSROOT=@CMAKE_OSX_SYSROOT@
ifneq ($(OSX_SYSROOT),)
export SDKROOT := $(OSX_SYSROOT)
endif

# CoreNEURON installation directories
CORENRN_BIN_DIR := $(ROOT)/bin
CORENRN_LIB_DIR := $(ROOT)/lib
Expand All @@ -35,7 +41,7 @@ MOD_TO_CPP_DIR = $(OUTPUT_DIR)/corenrn/mod2c
MOD_OBJS_DIR = $(OUTPUT_DIR)/corenrn/build

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

# C++ compilation and link commands
CXX = @CMAKE_CXX_COMPILER@
CXXFLAGS = @BUILD_TYPE_CXX_FLAGS@ @CMAKE_CXX_FLAGS@ @CXX14_STANDARD_COMPILE_OPTION@ @PGI_INLINE_FLAGS@
CXX_COMPILE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ @CORENRN_COMPILE_DEFS@ $(INCLUDES)
CXXFLAGS = @CORENRN_CXX_FLAGS@
CXX_COMPILE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ @CORENRN_COMMON_COMPILE_DEFS@ $(INCLUDES)
CXX_LINK_EXE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_EXE_LINKER_FLAGS@
CXX_SHARED_LIB_CMD = $(CXX) $(CXXFLAGS) @CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS@ @CMAKE_SHARED_LIBRARY_CXX_FLAGS@ @CMAKE_SHARED_LINKER_FLAGS@

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

# nmodl options
ifeq (@CORENRN_ENABLE_NMODL@, ON)
ifeq (@CORENRN_ENABLE_GPU@, ON)
nmodl_arguments_c=@NMODL_ACC_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
else
nmodl_arguments_c=@NMODL_CPU_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
endif
nmodl_arguments_ispc=@NMODL_ISPC_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
endif

# name of the mechanism library with suffix if provided
COREMECH_LIB_NAME = corenrnmech$(if $(MECHLIB_SUFFIX),_$(MECHLIB_SUFFIX),)
COREMECH_LIB_PATH = $(OUTPUT_DIR)/lib$(COREMECH_LIB_NAME)$(LIB_SUFFIX)
Expand Down Expand Up @@ -144,13 +160,17 @@ C_RESET := \033[0m
C_GREEN := \033[32m

# Default nmodl flags. Override if MOD2CPP_RUNTIME_FLAGS is not empty
NMODL_FLAGS_ISPC = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),@nmodl_arguments_ispc@)
MOD2CPP_FLAGS_C = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),@nmodl_arguments_c@)
ifeq (@CORENRN_ENABLE_NMODL@, ON)
MOD2CPP_FLAGS_ISPC = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),$(nmodl_arguments_ispc))
MOD2CPP_FLAGS_C = $(if $(MOD2CPP_RUNTIME_FLAGS),$(MOD2CPP_RUNTIME_FLAGS),$(nmodl_arguments_c))
endif

ifeq (@CORENRN_ENABLE_ISPC@, ON)
$(info Default nmodl flags: @nmodl_arguments_ispc@)
$(info Default NMODL flags: @nmodl_arguments_ispc@)
else
$(info Default nmodl flags: @nmodl_arguments_c@)
$(info Default NMODL flags: @nmodl_arguments_c@)
endif

ifneq ($(MOD2CPP_RUNTIME_FLAGS),)
$(warning Runtime nmodl flags (they replace the default ones): $(MOD2CPP_RUNTIME_FLAGS))
endif
Expand Down Expand Up @@ -198,7 +218,7 @@ $(MOD_OBJS_DIR)/%.obj: $(MOD_TO_CPP_DIR)/%.ispc | $(MOD_OBJS_DIR)

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

# translate MOD files to CPP using mod2c/NMODL
$(mod_cpp_files): $(MOD_TO_CPP_DIR)/%.cpp: $(MODS_PATH)/%.mod | $(MOD_TO_CPP_DIR)
Expand Down
32 changes: 8 additions & 24 deletions cmake/coreneuron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ set(LIKWID_DIR
""
CACHE PATH "Path to likwid performance analysis suite")

set(CORENRN_FRONTEND_C_COMPILER
gcc
CACHE FILEPATH "C compiler for building mod2c [frontend]")
set(CORENRN_FRONTEND_CXX_COMPILER
g++
CACHE FILEPATH "C++ compiler for building mod2c [frontend]")

if(CORENEURON_AS_SUBPROJECT)
set(CORENRN_ENABLE_UNIT_TESTS OFF)
endif()
Expand All @@ -126,11 +119,6 @@ include(OpenAccHelper)
find_package(PythonInterp REQUIRED)
find_package(Perl REQUIRED)

# =============================================================================
# ISPC should compile with --pic by default
# =============================================================================
set(CMAKE_ISPC_FLAGS "--pic ${CMAKE_ISPC_FLAGS}")

# =============================================================================
# Common build options
# =============================================================================
Expand All @@ -147,7 +135,6 @@ endif()
# Build option specific compiler flags
# =============================================================================
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "PGI")
add_definitions(-DSWAP_ENDIAN_DISABLE_ASM)
# PGI with llvm code generation doesn't have necessary assembly intrinsic headers
add_definitions(-DEIGEN_DONT_VECTORIZE=1)
endif()
Expand All @@ -168,7 +155,6 @@ endif()

if(CORENRN_ENABLE_ISPC)
enable_language(ISPC)
add_definitions("-DISPC_INTEROP=1")
set(CORENRN_ENABLE_NMODL ON)
endif()

Expand Down Expand Up @@ -283,7 +269,6 @@ if(CORENRN_ENABLE_NMODL)
if(CORENRN_ENABLE_GPU)
string(APPEND CORENRN_NMODL_FLAGS " acc --oacc")
endif()
separate_arguments(NMODL_EXTRA_FLAGS_LIST UNIX_COMMAND "${CORENRN_NMODL_FLAGS}")
else()
include(AddMod2cSubmodule)
set(CORENRN_MOD2CPP_BINARY ${CMAKE_BINARY_DIR}/bin/mod2c_core${CMAKE_EXECUTABLE_SUFFIX})
Expand All @@ -309,10 +294,17 @@ if(CORENRN_ENABLE_LIKWID_PROFILING)
add_definitions("-DLIKWID_PERFMON")
endif()

# =============================================================================
# Common CXX flags : ignore unknown pragma warnings
# =============================================================================
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IGNORE_UNKNOWN_PRAGMA_FLAGS}")

# =============================================================================
# Add main directories
# =============================================================================
add_subdirectory(coreneuron)

include(MakefileBuildOptions)
add_subdirectory(extra)

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

# just for printing the compiler flags in the build status
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UPPER)
if(BUILD_TYPE_UPPER MATCHES "CUSTOM")
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS_${BUILD_TYPE_UPPER}}")
endif()

if(NOT CORENEURON_AS_SUBPROJECT)
# =============================================================================
# Setup Doxygen documentation
Expand Down Expand Up @@ -402,7 +386,7 @@ if(cmake_generator_tolower MATCHES "makefile")

message(STATUS "C COMPILER | ${CMAKE_C_COMPILER}")
message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
message(STATUS "COMPILE FLAGS | ${CORENRN_CXX_FLAGS}")
message(STATUS "Build Type | ${COMPILE_LIBRARY_TYPE}")
message(STATUS "MPI | ${CORENRN_ENABLE_MPI}")
if(CORENRN_ENABLE_MPI)
Expand Down
73 changes: 73 additions & 0 deletions cmake/coreneuron/MakefileBuildOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# =============================================================================
# Common CXX and ISPC flags
# =============================================================================

# ISPC should compile with --pic by default
set(CMAKE_ISPC_FLAGS "${CMAKE_ISPC_FLAGS} --pic")

# =============================================================================
# NMODL CLI options : common and backend specific
# =============================================================================
# if user pass arguments then use those as common arguments
if ("${CORENRN_NMODL_FLAGS}" STREQUAL "")
set(NMODL_COMMON_ARGS "passes --inline")
else()
set(NMODL_COMMON_ARGS ${CORENRN_NMODL_FLAGS})
endif()

set(NMODL_CPU_BACKEND_ARGS "host --c")
set(NMODL_ISPC_BACKEND_ARGS "host --ispc")
set(NMODL_ACC_BACKEND_ARGS "host --c acc --oacc")

# =============================================================================
# Extract Compile definitions : common to all backend
# =============================================================================
get_directory_property(COMPILE_DEFS COMPILE_DEFINITIONS)
if(COMPILE_DEFS)
set(CORENRN_COMMON_COMPILE_DEFS "")
foreach(flag ${COMPILE_DEFS})
set(CORENRN_COMMON_COMPILE_DEFS "${CORENRN_COMMON_COMPILE_DEFS} -D${flag}")
endforeach()
endif()

# =============================================================================
# link flags : common to all backend
# =============================================================================
# ~~~
# find_cuda uses FindThreads that adds below imported target we
# shouldn't add imported target to link line
# ~~~
list(REMOVE_ITEM CORENRN_LINK_LIBS "Threads::Threads")

# replicate CMake magic to transform system libs to -l<libname>
foreach(link_lib ${CORENRN_LINK_LIBS})
if(${link_lib} MATCHES "\-l.*")
string(APPEND CORENRN_COMMON_LDFLAGS " ${link_lib}")
continue()
endif()
get_filename_component(path ${link_lib} DIRECTORY)
if(NOT path)
string(APPEND CORENRN_COMMON_LDFLAGS " -l${link_lib}")
elseif("${path}" MATCHES "^(/lib|/lib64|/usr/lib|/usr/lib64)$")
get_filename_component(libname ${link_lib} NAME_WE)
string(REGEX REPLACE "^lib" "" libname ${libname})
string(APPEND CORENRN_COMMON_LDFLAGS " -l${libname}")
else()
string(APPEND CORENRN_COMMON_LDFLAGS " ${link_lib}")
endif()
endforeach()

# =============================================================================
# compile flags : common to all backend
# =============================================================================
# PGI compiler adds --c++14;-A option for C++14, remove ";"
string(REPLACE ";" " " CXX14_STD_FLAGS "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
set(CORENRN_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE}} ${CXX14_STD_FLAGS}")

# =============================================================================
# nmodl/mod2c related options : TODO
# =============================================================================
# name of nmodl/mod2c binary
get_filename_component(nmodl_name ${CORENRN_MOD2CPP_BINARY} NAME)
set(nmodl_binary_name ${nmodl_name})
Loading

0 comments on commit 487cc83

Please sign in to comment.