Skip to content

Commit

Permalink
Merge branch 'master' into header-hygiene-cabcode
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc authored Jul 8, 2024
2 parents 23cf5c0 + c2b939c commit abedb68
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 215 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ include("${CODING_CONV_CMAKE}/3rdparty.cmake")
cpp_cc_git_submodule(Random123)
cpp_cc_git_submodule(eigen)

if(NRN_ENABLE_CORENEURON)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/external/Random123/include/Random123"
DESTINATION "${CMAKE_BINARY_DIR}/include/")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/external/eigen/Eigen"
DESTINATION "${CMAKE_BINARY_DIR}/include/")
endif()

# =================================================================================================
# Enable sanitizer support if the NRN_SANITIZERS variable is set. Comes befores PythonHelper.cmake.
# =================================================================================================
Expand Down
10 changes: 1 addition & 9 deletions bin/nrnivmodl-core.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ APP_NAME="$(basename "$0")"

# directory and parent directory of this script
PARENT_DIR="$(dirname "$BASH_SOURCE")/.."

# prefer perl exe set by neuron wrappers in case of wheel
PERL_EXE="${CORENRN_PERLEXE:-@PERL_EXECUTABLE@}"
# in case of mac installer, wrapper is not used and hence
# check if binary exist. otherwise, just rely on perl being
# in default $PATH
if [ ! -f "${PERL_EXE}" ]; then PERL_EXE="$(which perl)"; fi

ROOT_DIR="$("${PERL_EXE}" -e "use Cwd 'abs_path'; print abs_path('$PARENT_DIR')")"
ROOT_DIR="$(readlink -f "$PARENT_DIR")"

# default arguments : number of parallel builds and default mod file path
PARALLEL_BUILDS=4
Expand Down
9 changes: 2 additions & 7 deletions bin/nrnivmodl_core_makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ endif
# binary used during build. If they don't exist then simply use python and
# perl as the name of binaries.
CORENRN_PYTHONEXE ?= @NRN_DEFAULT_PYTHON_EXECUTABLE@
CORENRN_PERLEXE ?= @PERL_EXECUTABLE@
ifeq ($(wildcard $(CORENRN_PYTHONEXE)),)
CORENRN_PYTHONEXE=python
endif
ifeq ($(wildcard $(CORENRN_PERLEXE)),)
CORENRN_PERLEXE=perl
endif

CXXFLAGS = @CORENRN_CXX_FLAGS@
CXX_COMPILE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ $(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@

# env variables required for mod2c or nmodl
NMODL_ENV_VAR = @CORENRN_SANITIZER_ENABLE_ENVIRONMENT_STRING@ PYTHONPATH=${PYTHONPATH}:@CORENRN_NMODL_PYTHONPATH@:${CORENRN_LIB_DIR}/python MODLUNIT=$(CORENRN_SHARE_NMODL_DIR)/nrnunits.lib
NMODL_ENV_VAR = @CORENRN_SANITIZER_ENABLE_ENVIRONMENT_STRING@ PYTHONPATH=${PYTHONPATH}:${CORENRN_LIB_DIR}/python MODLUNIT=$(CORENRN_SHARE_NMODL_DIR)/nrnunits.lib

ifeq (@CORENRN_ENABLE_GPU@, ON)
nmodl_arguments_c=@NMODL_ACC_BACKEND_ARGS@ @NMODL_COMMON_ARGS@
Expand Down Expand Up @@ -100,7 +96,6 @@ endif
# Binary of NMODL depending on CMake option activated
ifeq (@nmodl_FOUND@, TRUE)
NMODL_BINARY_PATH = $(if $(NMODL_BINARY),$(NMODL_BINARY), @CORENRN_NMODL_BINARY@)
INCLUDES += -I@CORENRN_NMODL_INCLUDE@
else
NMODL_BINARY_PATH = $(if $(NMODL_BINARY),$(NMODL_BINARY), $(CORENRN_BIN_DIR)/@nmodl_binary_name@)
endif
Expand Down Expand Up @@ -189,7 +184,7 @@ $(mod_cpp_files): $(MOD_TO_CPP_DIR)/%.cpp: $(MODS_PATH)/%.mod | $(MOD_TO_CPP_DIR

# generate mod registration function. Dont overwrite if it's not changed
$(MOD_FUNC_CPP): build_always | $(MOD_TO_CPP_DIR)
$(CORENRN_PERLEXE) $(CORENRN_SHARE_CORENRN_DIR)/mod_func.c.pl $(mod_files_names) > $(MOD_FUNC_CPP).tmp
bash $(CORENRN_SHARE_CORENRN_DIR)/mod_func.c.sh $(mod_files_names) > $(MOD_FUNC_CPP).tmp
diff -q $(MOD_FUNC_CPP).tmp $(MOD_FUNC_CPP) || \
mv $(MOD_FUNC_CPP).tmp $(MOD_FUNC_CPP)

Expand Down
3 changes: 2 additions & 1 deletion ci/win_install_deps.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ C:\Python39\python.exe -m pip install numpy==1.19.3 "cython < 3" || goto :error
C:\Python310\python.exe -m pip install numpy==1.21.3 "cython < 3" || goto :error
C:\Python311\python.exe -m pip install numpy==1.23.5 "cython < 3" || goto :error
C:\Python312\python.exe -m pip install numpy==1.26.3 "cython < 3" || goto :error
C:\Python312\python.exe -m pip install setuptools || goto :error
:: setuptools 70.2 leads to an error
C:\Python312\python.exe -m pip install setuptools==70.1.1 || goto :error

:: install nsis
nsis-3.05-setup.exe /S || goto :error
Expand Down
1 change: 0 additions & 1 deletion cmake/NanoBindMinimal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ function(make_nanobind_target TARGET_NAME PYINC)
endif()
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17)
set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE True)
set_property(TARGET ${TARGET_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
endfunction()
7 changes: 1 addition & 6 deletions cmake/coreneuron/packages/Findnmodl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
# ::
# set(CORENRN_NMODL_DIR "" CACHE PATH "Path to nmodl source-to-source compiler installation")
# find_package(nmodl REQUIRED)
# include_directories(${nmodl_INCLUDE_DIRS})
# target_link_libraries(foo ${nmodl_LIBRARIES})
#
# This module sets the following variables:
#
# ::
#
# nmodl_FOUND - set to true if the library is found
# nmodl_INCLUDE - list of required include directories
# nmodl_BINARY - the nmodl binary
# ~~~

Expand All @@ -35,13 +33,10 @@ find_program(
NAMES nmodl${CMAKE_EXECUTABLE_SUFFIX}
HINTS "${CORENRN_NMODL_DIR}/bin" QUIET)

find_path(nmodl_INCLUDE "nmodl.hpp" HINTS "${CORENRN_NMODL_DIR}/include")
find_path(nmodl_PYTHONPATH "nmodl/__init__.py" HINTS "${CORENRN_NMODL_DIR}/lib")

# Checks 'REQUIRED', 'QUIET' and versions.
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
nmodl
FOUND_VAR nmodl_FOUND
REQUIRED_VARS nmodl_BINARY nmodl_INCLUDE nmodl_PYTHONPATH)
REQUIRED_VARS nmodl_BINARY)
2 changes: 1 addition & 1 deletion external/nmodl
Submodule nmodl updated 53 files
+0 −1 .github/workflows/nmodl-doc.yml
+1 −2 CMakeLists.txt
+1 −1 azure-pipelines.yml
+181 −0 docs/contents/globals.rst
+1 −0 docs/index.rst
+1 −1 pyproject.toml
+1 −0 requirements.txt
+1 −2 src/CMakeLists.txt
+15 −217 src/codegen/codegen_coreneuron_cpp_visitor.cpp
+2 −29 src/codegen/codegen_coreneuron_cpp_visitor.hpp
+205 −0 src/codegen/codegen_cpp_visitor.cpp
+41 −7 src/codegen/codegen_cpp_visitor.hpp
+106 −67 src/codegen/codegen_neuron_cpp_visitor.cpp
+4 −1 src/codegen/codegen_neuron_cpp_visitor.hpp
+22 −9 src/main.cpp
+0 −20 src/nmodl.hpp
+9 −0 src/parser/nmodl_driver.cpp
+9 −7 src/parser/nmodl_driver.hpp
+6 −4 src/printer/code_printer.cpp
+8 −6 src/printer/code_printer.hpp
+4 −1 src/pybind/CMakeLists.txt
+51 −29 src/pybind/pyembed.cpp
+3 −117 src/pybind/pyembed.hpp
+53 −66 src/pybind/wrapper.cpp
+62 −0 src/pybind/wrapper.hpp
+15 −22 src/solver/CMakeLists.txt
+20 −0 src/solver/solver.hpp.inc
+38 −6 src/utils/blame.cpp
+5 −1 src/utils/blame.hpp
+2 −2 src/visitors/main.cpp
+46 −12 src/visitors/semantic_analysis_visitor.cpp
+3 −0 src/visitors/semantic_analysis_visitor.hpp
+2 −8 src/visitors/sympy_conductance_visitor.cpp
+46 −51 src/visitors/sympy_solver_visitor.cpp
+5 −3 src/visitors/sympy_solver_visitor.hpp
+0 −1 test/integration/mod/glia_sparse.mod
+2 −2 test/unit/codegen/main.cpp
+1 −1 test/unit/crout/crout.cpp
+1 −1 test/unit/newton/newton.cpp
+2 −2 test/unit/visitor/main.cpp
+28 −0 test/unit/visitor/semantic_analysis.cpp
+41 −6 test/unit/visitor/sympy_solver.cpp
+3 −1 test/usecases/CMakeLists.txt
+7 −0 test/usecases/at_time/example.mod
+30 −0 test/usecases/at_time/simulate.py
+2 −2 test/usecases/global/simulate.py
+47 −0 test/usecases/global/test_top_local.py
+20 −4 test/usecases/global/thread_variable.mod
+25 −0 test/usecases/global/top_local.mod
+30 −0 test/usecases/kinetic/X2Y.mod
+37 −0 test/usecases/kinetic/simulate.py
+27 −0 test/usecases/net_receive/NetReceiveCalls.mod
+30 −0 test/usecases/net_receive/test_calls.py
6 changes: 6 additions & 0 deletions packaging/python/build_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
cython<3
packaging
numpy==1.17.5;python_version=='3.8'
numpy==1.19.3;python_version=='3.9' and platform_machine=='x86_64'
numpy==1.21.3;python_version=='3.9' and platform_machine=='arm64'
numpy==1.21.3;python_version=='3.10'
numpy==1.23.5;python_version=='3.11'
numpy==1.26.0;python_version=='3.12'
58 changes: 21 additions & 37 deletions packaging/python/build_wheels.bash
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ fi

py_ver=""

clone_install_nmodl_requirements() {
clone_nmodl_and_add_requirements() {
git config --global --add safe.directory /root/nrn
git submodule update --init --recursive --force --depth 1 -- external/nmodl
pip install -r external/nmodl/requirements.txt
# We only want the _build_ dependencies
sed -e '/^# runtime dependencies/,$ d' external/nmodl/requirements.txt >> my_requirements.txt
}


Expand All @@ -52,29 +53,6 @@ setup_venv() {
}


pip_numpy_install() {
# numpy is special as we want the minimum wheel version
numpy_ver="numpy"
case "$py_ver" in
36) numpy_ver="numpy==1.12.1" ;;
37) numpy_ver="numpy==1.14.6" ;;
38) numpy_ver="numpy==1.17.5" ;;
39) numpy_ver="numpy==1.19.3" ;;
310) numpy_ver="numpy==1.21.3" ;;
311) numpy_ver="numpy==1.23.5" ;;
312) numpy_ver="numpy==1.26.0" ;;
*) echo "Error: numpy version not specified for this python!" && exit 1;;
esac

# older version for apple m1 as building from source fails
if [[ `uname -m` == 'arm64' && "$py_ver" == "39" ]]; then
numpy_ver="numpy==1.21.3"
fi

echo " - pip install $numpy_ver"
pip install $numpy_ver
}

build_wheel_linux() {
echo "[BUILD WHEEL] Building with interpreter $1"
local skip=
Expand All @@ -83,11 +61,7 @@ build_wheel_linux() {

echo " - Installing build requirements"
pip install auditwheel
pip install -r packaging/python/build_requirements.txt
pip_numpy_install

echo " - Building..."
rm -rf dist build
cp packaging/python/build_requirements.txt my_requirements.txt

CMAKE_DEFS="NRN_MPI_DYNAMIC=$3"
if [ "$USE_STATIC_READLINE" == "1" ]; then
Expand All @@ -96,10 +70,17 @@ build_wheel_linux() {

if [ "$2" == "coreneuron" ]; then
setup_args="--enable-coreneuron"
clone_install_nmodl_requirements
clone_nmodl_and_add_requirements
CMAKE_DEFS="${CMAKE_DEFS},LINK_AGAINST_PYTHON=OFF"
fi

cat my_requirements.txt
pip install -r my_requirements.txt
pip check

echo " - Building..."
rm -rf dist build

# Workaround for https://github.com/pypa/manylinux/issues/1309
git config --global --add safe.directory "*"

Expand Down Expand Up @@ -135,15 +116,11 @@ build_wheel_osx() {
(( $skip )) && return 0

echo " - Installing build requirements"
pip install -U delocate -r packaging/python/build_requirements.txt
pip_numpy_install

echo " - Building..."
rm -rf dist build
cp packaging/python/build_requirements.txt my_requirements.txt

if [ "$2" == "coreneuron" ]; then
setup_args="--enable-coreneuron"
clone_install_nmodl_requirements
clone_nmodl_and_add_requirements
CMAKE_DEFS="${CMAKE_DEFS},LINK_AGAINST_PYTHON=OFF"
fi

Expand All @@ -152,6 +129,13 @@ build_wheel_osx() {
CMAKE_DEFS="$CMAKE_DEFS,NRN_BINARY_DIST_BUILD=ON,NRN_WHEEL_STATIC_READLINE=ON"
fi

cat my_requirements.txt
pip install -U delocate -r my_requirements.txt
pip check

echo " - Building..."
rm -rf dist build

# We need to "fix" the platform tag if the Python installer is universal2
# See:
# * https://github.com/pypa/setuptools/issues/2520
Expand Down
48 changes: 5 additions & 43 deletions src/coreneuron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ configure_file(${PROJECT_SOURCE_DIR}/src/coreneuron/config/config.cpp.in
# =============================================================================
include(OpenAccHelper)

# =============================================================================
# Common dependencies
# =============================================================================
find_package(Perl REQUIRED)

# =============================================================================
# Common build options
# =============================================================================
Expand Down Expand Up @@ -259,21 +254,13 @@ if(NOT "${CORENRN_NMODL_DIR}" STREQUAL "" AND NOT nmodl_FOUND)
endif()
if(nmodl_FOUND)
set(CORENRN_NMODL_BINARY ${nmodl_BINARY})
set(CORENRN_NMODL_INCLUDE ${nmodl_INCLUDE})
# path to python interface
set(ENV{PYTHONPATH} "${nmodl_PYTHONPATH}:$ENV{PYTHONPATH}")
set(CORENRN_NMODL_PYTHONPATH $ENV{PYTHONPATH})
else()
set(NMODL_ENABLE_PYTHON_BINDINGS
OFF
CACHE BOOL "Enable NMODL python bindings")
nrn_add_external_project(nmodl DISABLE_ADD)
add_subdirectory(${PROJECT_SOURCE_DIR}/external/nmodl ${CMAKE_BINARY_DIR}/external/nmodl)
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/bin/nmodl${CMAKE_EXECUTABLE_SUFFIX})
set(CORENRN_NMODL_INCLUDE ${CMAKE_BINARY_DIR}/include)
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)
set(NMODL_PROJECT_BINARY_DIR ${CMAKE_BINARY_DIR}/external/nmodl)
# install nrnunits.lib and libpywrapper.so from external/nmodl
Expand Down Expand Up @@ -360,23 +347,20 @@ if(NRN_ENABLE_MPI)
list(APPEND CORENEURON_CODE_FILES "mpi/core/resolve.cpp")
endif()

file(COPY ${PROJECT_SOURCE_DIR}/external/Random123/include/Random123
DESTINATION ${CMAKE_BINARY_DIR}/include)
list(APPEND CORENEURON_CODE_FILES ${PROJECT_BINARY_DIR}/coreneuron/config/config.cpp)

set(ENGINEMECH_CODE_FILE "mechanism/mech/enginemech.cpp")

# for external mod files we need to generate modl_ref function in mod_func.c
set(MODFUNC_PERL_SCRIPT "mechanism/mech/mod_func.c.pl")

set(MODFUNC_SHELL_SCRIPT "mechanism/mech/mod_func.c.sh")
set(NMODL_UNITS_FILE "${CMAKE_BINARY_DIR}/share/mod2c/nrnunits.lib")

# =============================================================================
# Copy files that are required by nrnivmodl-core to the build tree at build time.
# =============================================================================
cpp_cc_build_time_copy(
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/${MODFUNC_PERL_SCRIPT}"
OUTPUT "${CMAKE_BINARY_DIR}/share/coreneuron/mod_func.c.pl"
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/${MODFUNC_SHELL_SCRIPT}"
OUTPUT "${CMAKE_BINARY_DIR}/share/coreneuron/mod_func.c.sh"
NO_TARGET)
cpp_cc_build_time_copy(
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/${ENGINEMECH_CODE_FILE}"
Expand All @@ -387,7 +371,7 @@ cpp_cc_build_time_copy(
OUTPUT "${CMAKE_BINARY_DIR}/share/coreneuron/coreneuron.cpp"
NO_TARGET)
set(nrnivmodl_core_dependencies
"${CMAKE_BINARY_DIR}/share/coreneuron/mod_func.c.pl"
"${CMAKE_BINARY_DIR}/share/coreneuron/mod_func.c.sh"
"${CMAKE_BINARY_DIR}/share/coreneuron/enginemech.cpp"
"${CMAKE_BINARY_DIR}/share/coreneuron/coreneuron.cpp")
# Set up build rules that copy builtin mod files from src/coreneuron/mechanism/mech/modfile/*.mod to
Expand Down Expand Up @@ -420,25 +404,6 @@ if(CORENRN_ENABLE_GPU)
# https://forums.developer.nvidia.com/t/cannot-dynamically-load-a-shared-library-containing-both-openacc-and-cuda-code/210972
# this cannot be included in the same shared library as the rest of the OpenACC code.
set(CORENEURON_CUDA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/permute/cellorder.cu)

# Eigen functions cannot be called directly from OpenACC regions, but Eigen is sort-of compatible
# with being compiled as CUDA code. Because of
# https://forums.developer.nvidia.com/t/cannot-dynamically-load-a-shared-library-containing-both-openacc-and-cuda-code/210972
# this has to mean `nvc++ -cuda` rather than `nvcc`. We explicitly instantiate Eigen functions for
# different matrix sizes in partial_piv_lu.cpp (with CUDA attributes but without OpenACC or OpenMP
# annotations) and dispatch to these from a wrapper in partial_piv_lu.h that does have
# OpenACC/OpenMP annotations.
if(EXISTS ${CORENRN_NMODL_INCLUDE}/partial_piv_lu/partial_piv_lu.cpp)
list(APPEND CORENEURON_CODE_FILES ${CORENRN_NMODL_INCLUDE}/partial_piv_lu/partial_piv_lu.cpp)
if(CORENRN_ENABLE_GPU
AND CORENRN_HAVE_NVHPC_COMPILER
AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# In this case OpenAccHelper.cmake passes -gpu=debug, which makes these Eigen functions
# extremely slow. Downgrade that to -gpu=lineinfo for this file.
set_source_files_properties(${CORENRN_NMODL_INCLUDE}/partial_piv_lu/partial_piv_lu.cpp
PROPERTIES COMPILE_FLAGS "-gpu=lineinfo,nodebug -O1")
endif()
endif()
endif()

# =============================================================================
Expand Down Expand Up @@ -706,7 +671,7 @@ install(
FILES_MATCHING
PATTERN "*.h*"
PATTERN "*.ipp")
install(FILES ${MODFUNC_PERL_SCRIPT} ${ENGINEMECH_CODE_FILE} DESTINATION share/coreneuron)
install(FILES ${MODFUNC_SHELL_SCRIPT} ${ENGINEMECH_CODE_FILE} DESTINATION share/coreneuron)

# copy nmodl for nrnivmodl-core
install(PROGRAMS ${CORENRN_NMODL_BINARY} DESTINATION bin)
Expand All @@ -724,9 +689,6 @@ if(CORENRN_ENABLE_SHARED)
install(FILES ${corenrn_mech_library} DESTINATION lib)
endif()

# 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)

Expand Down
Loading

0 comments on commit abedb68

Please sign in to comment.