Skip to content

Commit

Permalink
Merge branch 'master' into hines/nmodlrandom-simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
nrnhines authored Dec 26, 2023
2 parents fe40ca3 + 2cf7248 commit 37314d7
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 15 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ option(NRN_ENABLE_RX3D "Enable rx3d support" ${NRN_ENABLE_RX3D_DEFAULT})
option(NRN_ENABLE_CORENEURON "Enable CoreNEURON support" ${NRN_ENABLE_CORENEURON_DEFAULT})
option(NRN_ENABLE_BACKTRACE "Enable pretty-printed backtraces" ${NRN_ENABLE_BACKTRACE_DEFAULT})
option(NRN_ENABLE_TESTS "Enable unit tests" ${NRN_ENABLE_TESTS_DEFAULT})
option(NRN_ENABLE_MATH_OPT "Enable extra math optimisations (to enable SIMD)"
${NRN_ENABLE_MATH_OPT_DEFAULT})
set(NRN_ENABLE_MODEL_TESTS
"${NRN_ENABLE_MODEL_TESTS_DEFAULT}"
CACHE STRING "Comma-separated list of detailed models to enable tests of.")
Expand All @@ -94,11 +96,11 @@ option(NRN_ENABLE_MOD_COMPATIBILITY "Enable CoreNEURON compatibility for MOD fil
${NRN_ENABLE_MOD_COMPATIBILITY_DEFAULT})
option(NRN_ENABLE_REL_RPATH "Use relative RPATH in binaries. for relocatable installs/Python"
${NRN_ENABLE_REL_RPATH_DEFAULT})
option(NRN_WHEEL_BUILD ${NRN_WHEEL_BUILD_DEFAULT})
option(NRN_BINARY_DIST_BUILD ${NRN_BINARY_DIST_BUILD_DEFAULT})
option(NRN_WHEEL_STATIC_READLINE "Use static readline libraries for the wheels."
${NRN_WHEEL_STATIC_READLINE_DEFAULT})
mark_as_advanced(NRN_ENABLE_REL_RPATH)
mark_as_advanced(NRN_WHEEL_BUILD)
mark_as_advanced(NRN_BINARY_DIST_BUILD)

# =============================================================================
# Build options (string)
Expand Down Expand Up @@ -214,7 +216,7 @@ include(cmake/modules/FindPythonModule.cmake)
include(cmake/Coverage.cmake)

# set CMAKE_BUILD_TYPE and associated flags using allowableBuildTypes and CMAKE_BUILD_TYPE_DEFAULT
set(allowableBuildTypes Custom Debug Release RelWithDebInfo Fast)
set(allowableBuildTypes Custom Debug Release RelWithDebInfo Fast FastDebug)
include(ReleaseDebugAutoFlags)

# Try and emit an intelligent warning if the version number currently set in the CMake project(...)
Expand Down Expand Up @@ -929,7 +931,7 @@ if(BUILD_TYPE_UPPER MATCHES "CUSTOM")
else()
set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS_${BUILD_TYPE_UPPER}}")
endif()
string(JOIN " " COMPILER_FLAGS "${COMPILER_FLAGS}" ${NRN_COMPILE_FLAGS})
string(JOIN " " COMPILER_FLAGS "${COMPILER_FLAGS}" ${NRN_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS})

message(STATUS "")
message(STATUS "Configured NEURON ${PROJECT_VERSION}")
Expand Down
1 change: 1 addition & 0 deletions ci/win_build_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cd $BUILD_SOURCESDIRECTORY/build
-DNRN_ENABLE_PYTHON=ON \
-DNRN_ENABLE_RX3D=ON \
-DNRN_RX3D_OPT_LEVEL=2 \
-DNRN_BINARY_DIST_BUILD=ON \
-DPYTHON_EXECUTABLE=/c/Python38/python.exe \
-DNRN_ENABLE_PYTHON_DYNAMIC=ON \
-DNRN_PYTHON_DYNAMIC='c:/Python38/python.exe;c:/Python39/python.exe;c:/Python310/python.exe;c:/Python311/python.exe' \
Expand Down
3 changes: 2 additions & 1 deletion cmake/BuildOptionDefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(NRN_ENABLE_REL_RPATH_DEFAULT OFF)
set(NRN_AVOID_ABSOLUTE_PATHS_DEFAULT OFF)
set(NRN_NMODL_CXX_FLAGS_DEFAULT "-O0")
set(NRN_SANITIZERS_DEFAULT "")
set(NRN_ENABLE_MATH_OPT_DEFAULT OFF)

# Some distributions may set the prefix. To avoid errors, unset it
set(NRN_PYTHON_DYNAMIC_DEFAULT "")
Expand All @@ -43,7 +44,7 @@ set(PYTHON_EXECUTABLE_DEFAULT "")
set(IV_LIB_DEFAULT "")

# For wheel deployment
set(NRN_WHEEL_BUILD_DEFAULT OFF)
set(NRN_BINARY_DIST_BUILD_DEFAULT OFF)
set(NRN_WHEEL_STATIC_READLINE_DEFAULT OFF)

# we add some coreneuron options in order to check support like GPU
Expand Down
22 changes: 21 additions & 1 deletion cmake/CompilerFlagsHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ set(SUPPORTED_COMPILER_LANGUAGE_LIST "C;CXX")
foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "XL")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_XLC ON)
elseif(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "Intel")
elseif(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "Intel"
OR CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_ICC ON)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_MSVC)
Expand All @@ -27,6 +28,10 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
endif()
endforeach()

set(UNSAFE_MATH_FLAG
"-ffinite-math-only -fno-math-errno -funsafe-math-optimizations -fno-associative-math")
set(FASTDEBUG_FLAG "-g -O1")

# Set optimization flags for each compiler
foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})

Expand All @@ -39,6 +44,7 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "-O0")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FAST "-O3")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTDEBUG ${FASTDEBUG_FLAG})
set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "-qstackprotect")
set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-qpic=small")
set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "-qhot")
Expand All @@ -59,9 +65,11 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "-O0")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FAST "-O3")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTDEBUG ${FASTDEBUG_FLAG})
set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "-fstack-protector")
set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-fPIC")
set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "-ftree-vectorize")
set(CMAKE_${COMPILER_LANGUAGE}_UNSAFE_MATH ${UNSAFE_MATH_FLAG})
set(IGNORE_UNKNOWN_PRAGMA_FLAGS "-Wno-unknown-pragmas")

if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_VERSION VERSION_GREATER "4.7.0")
Expand All @@ -82,6 +90,11 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "-O0")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FAST "-O3")
if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTDEBUG "${FASTDEBUG_FLAG} -fp-model precise")
else()
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTDEBUG "${FASTDEBUG_FLAG} -fp-model consistent")
endif()
set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "-fstack-protector")
set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-fpic")
set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "")
Expand All @@ -94,11 +107,18 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "-O0")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FAST "-O3")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTDEBUG "-g -O1")
set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "")
set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-fPIC")
set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "")
if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "PGI")
set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "")
endif()
if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "Clang")
set(CMAKE_${COMPILER_LANGUAGE}_UNSAFE_MATH ${UNSAFE_MATH_FLAG})
endif()
if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "NVHPC")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTDEBUG "${FASTDEBUG_FLAG} -fno-omit-frame-pointer")
endif()
endif()
endforeach()
50 changes: 46 additions & 4 deletions cmake/ReleaseDebugAutoFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ endif()
# Release : Release mode, no debuginfo
# RelWithDebInfo : Distribution mode, basic optimizations for portable code with debuginfos
# Fast : Maximum level of optimization. Target native architecture, not portable code
# FastDebug: Similar to Debug with a bit higher level optimisations (-O1) and other compiler
# flags so that it's faster than -O0 but still produces consistent results for
# testing and debugging purposes.
# ~~~

include(CompilerFlagsHelpers)
Expand All @@ -33,17 +36,56 @@ set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NONE} ${CMAKE_CXX_STACK_PROTECTION} ${CMAKE_CXX_IGNORE_WARNINGS}"
)

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_OPT_NORMAL} ${CMAKE_C_IGNORE_WARNINGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_IGNORE_WARNINGS}")
set(C_UNSAFE_MATH_FLAGS "")
set(CXX_UNSAFE_MATH_FLAGS "")
if(NRN_ENABLE_MATH_OPT)
set(C_UNSAFE_MATH_FLAGS ${CMAKE_C_UNSAFE_MATH})
set(CXX_UNSAFE_MATH_FLAGS ${CMAKE_CXX_UNSAFE_MATH})
endif()

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_OPT_NORMAL} ${CMAKE_C_IGNORE_WARNINGS} ${C_UNSAFE_MATH_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_IGNORE_WARNINGS} ${CXX_UNSAFE_MATH_FLAGS}")

set(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_OPT_NORMAL} ${CMAKE_C_IGNORE_WARNINGS}")
"${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_OPT_NORMAL} ${CMAKE_C_IGNORE_WARNINGS} ${C_UNSAFE_MATH_FLAGS}"
)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_IGNORE_WARNINGS}")
"${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_IGNORE_WARNINGS} ${CXX_UNSAFE_MATH_FLAGS}"
)

set(CMAKE_C_FLAGS_FAST
"${CMAKE_C_OPT_FAST} ${CMAKE_C_LINK_TIME_OPT} ${CMAKE_C_GEN_NATIVE} ${CMAKE_C_IGNORE_WARNINGS}")
set(CMAKE_CXX_FLAGS_FAST
"${CMAKE_CXX_OPT_FAST} ${CMAKE_CXX_LINK_TIME_OPT} ${CMAKE_CXX_GEN_NATIVE} ${CMAKE_CXX_IGNORE_WARNINGS}"
)

set(CMAKE_C_FLAGS_FASTDEBUG "${CMAKE_C_OPT_FASTDEBUG} ${CMAKE_C_IGNORE_WARNINGS}")
set(CMAKE_CXX_FLAGS_FASTDEBUG "${CMAKE_CXX_OPT_FASTDEBUG} ${CMAKE_CXX_IGNORE_WARNINGS}")
# ~~~

# for binary distributions, avoid addition of OpenMP specific flag as compiler on end-user machine
# may not support it.
if(NOT DEFINED NRN_BINARY_DIST_BUILD OR NOT NRN_BINARY_DIST_BUILD)
include(CheckCXXCompilerFlag)
# Check support for OpenMP SIMD constructs
set(SIMD_FLAGS "")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(SIMD_FLAGS "-qopenmp-simd")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(SIMD_FLAGS "-openmp:experimental")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(SIMD_FLAGS "-openmp-simd")
else() # not ICC, MSVC, or Clang => GCC and others
set(SIMD_FLAGS "-fopenmp-simd")
endif()

check_cxx_compiler_flag("${SIMD_FLAGS}" COMPILER_SUPPORT_SIMD)
if(COMPILER_SUPPORT_SIMD)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAGS}")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no support for OpenMP SIMD construct")
endif()
endif()
16 changes: 14 additions & 2 deletions docs/cmake_doc/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ together using the following instructions:
.. code-block:: shell
git clone https://github.com/neuronsimulator/nrn # latest development branch
git clone https://github.com/neuronsimulator/nrn -b 8.0.0 # specific release version 8.0.0
git clone https://github.com/neuronsimulator/nrn -b 8.2.3 # specific release version 8.2.3
cd nrn
..
.. warning:: To build NEURON from source you either need to clone the
NEURON Git repository or download a source code archive that includes
Git submodules, such as the ``full-src-package-X.Y.Z.tar.gz`` file in
Git submodules, such as the ``nrn-full-src-package-X.Y.Z.tar.gz`` file in
the `NEURON
releases <https://github.com/neuronsimulator/nrn/releases>`__ on
GitHub. The tarballs like ``Source code (tar.gz)`` or
Expand Down Expand Up @@ -662,3 +662,15 @@ NRN_PYTHON_EXTRA_FOR_TESTS:STRING=
built with support for, for use in tests of error messages and reporting.
For these purposes, minor versions (3.X and 3.Y) are considered different
and patch versions (3.8.X and 3.8.Y) are considered to be the same.

NRN_ENABLE_MATH_OPT:BOOL=OFF
-------------------------------------
Enable extra math optimisations.

When using compilers like GCC and Clang, one needs to explicitly use compiler
flags like `-funsafe-math-optimizations` in order to generate SIMD/vectorised
code using vector math library. This flag adds these extra compiler flags
to enable SIMD code.

Note: Compilers like Intel, NVHPC, Cray etc enable such optimisations
by default.
4 changes: 2 additions & 2 deletions packaging/python/build_wheels.bash
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ build_wheel_linux() {

CMAKE_DEFS="NRN_MPI_DYNAMIC=$3"
if [ "$USE_STATIC_READLINE" == "1" ]; then
CMAKE_DEFS="$CMAKE_DEFS,NRN_WHEEL_BUILD=ON,NRN_WHEEL_STATIC_READLINE=ON"
CMAKE_DEFS="$CMAKE_DEFS,NRN_BINARY_DIST_BUILD=ON,NRN_WHEEL_STATIC_READLINE=ON"
fi

if [ "$2" == "coreneuron" ]; then
Expand Down Expand Up @@ -148,7 +148,7 @@ build_wheel_osx() {

CMAKE_DEFS="NRN_MPI_DYNAMIC=$3"
if [ "$USE_STATIC_READLINE" == "1" ]; then
CMAKE_DEFS="$CMAKE_DEFS,NRN_WHEEL_BUILD=ON,NRN_WHEEL_STATIC_READLINE=ON"
CMAKE_DEFS="$CMAKE_DEFS,NRN_BINARY_DIST_BUILD=ON,NRN_WHEEL_STATIC_READLINE=ON"
fi

# We need to "fix" the platform tag if the Python installer is universal2
Expand Down
2 changes: 1 addition & 1 deletion src/coreneuron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ endif()
# Do not set this when building wheels. The nrnivmodl workflow means that we do not know what
# compiler will be invoked with these flags, so we have to use flags that are as generic as
# possible.
if(NOT DEFINED NRN_WHEEL_BUILD OR NOT NRN_WHEEL_BUILD)
if(NOT DEFINED NRN_BINARY_DIST_BUILD OR NOT NRN_BINARY_DIST_BUILD)
list(APPEND CORENRN_EXTRA_CXX_FLAGS "${IGNORE_UNKNOWN_PRAGMA_FLAGS}")
endif()

Expand Down

0 comments on commit 37314d7

Please sign in to comment.