From c243a003b1fc9f936ac081e9817c0ae5099c5278 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Tue, 26 Sep 2023 16:35:14 -0400 Subject: [PATCH 01/79] Bring nanobind. Using it for Vector.from_numpy --- .gitmodules | 3 +++ CMakeLists.txt | 2 ++ external/nanobind | 1 + src/nrnpython/CMakeLists.txt | 17 +++++++++++++- src/nrnpython/nrnpy_hoc.cpp | 43 ++++++++++++++++-------------------- 5 files changed, 41 insertions(+), 25 deletions(-) create mode 160000 external/nanobind diff --git a/.gitmodules b/.gitmodules index a2538c164c..5cc789115f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "external/CLI11"] path = external/CLI11 url = https://github.com/CLIUtils/CLI11.git +[submodule "external/nanobind"] + path = external/nanobind + url = https://github.com/wjakob/nanobind diff --git a/CMakeLists.txt b/CMakeLists.txt index ec4701030e..9ed919dce2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,6 +431,8 @@ endif() if(NRN_ENABLE_PYTHON) # Make sure the USE_PYTHON macro is defined in the C++ code list(APPEND NRN_COMPILE_DEFS USE_PYTHON) + # Activate nanobind + nrn_add_external_project(nanobind) endif() # ============================================================================= diff --git a/external/nanobind b/external/nanobind new file mode 160000 index 0000000000..70abddc0f7 --- /dev/null +++ b/external/nanobind @@ -0,0 +1 @@ +Subproject commit 70abddc0f77d3867d41ca54033cdc5b35dd136da diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 1a2c045b72..3141666b26 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -10,6 +10,21 @@ add_link_options(${NRN_LINK_FLAGS}) add_library(rxdmath SHARED ${CMAKE_CURRENT_SOURCE_DIR}/rxdmath.cpp) install(TARGETS rxdmath DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) +# ============================================================================= +# minimal nanobind interface +# ============================================================================= +add_library(nanobind INTERFACE) +target_sources(nanobind INTERFACE + ${NB_DIR}/src/common.cpp + ${NB_DIR}/src/error.cpp + ${NB_DIR}/src/nb_internals.cpp + ${NB_DIR}/src/nb_static_property.cpp + ${NB_DIR}/src/nb_type.cpp + ${NB_DIR}/src/nb_func.cpp + ${NB_DIR}/src/implicit.cpp + ) +target_include_directories(nanobind INTERFACE "${NB_DIR}/include" "${NB_DIR}/ext/robin_map/include") + # ============================================================================= # nrnpython libraries (one lib per python) # ============================================================================= @@ -38,7 +53,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) list(GET NRN_PYTHON_LIBRARIES ${val} pylib) add_library(nrnpython${pyver} SHARED ${NRN_NRNPYTHON_SRC_FILES}) target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) - target_link_libraries(nrnpython${pyver} nrniv_lib ${Readline_LIBRARY}) + target_link_libraries(nrnpython${pyver} nrniv_lib ${Readline_LIBRARY} nanobind) if(NRN_LINK_AGAINST_PYTHON) target_link_libraries(nrnpython${pyver} ${pylib}) endif() diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 6414df11a6..b9ad2ad1b7 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -21,6 +21,10 @@ #include #include +#include + +namespace nb = nanobind; + extern PyTypeObject* psection_type; extern std::vector py_exposed_classes; @@ -2392,53 +2396,44 @@ static IvocVect* nrnpy_vec_from_python(void* v) { if (ho->ctemplate->sym != nrnpy_pyobj_sym_) { hoc_execerror(hoc_object_name(ho), " is not a PythonObject"); } - PyObject* po = nrnpy_hoc2pyobject(ho); - Py_INCREF(po); - if (!PySequence_Check(po)) { - if (!PyIter_Check(po)) { + // We borrow the list, so there's an INCREF and all items are alive + nb::object po = nb::borrow(nrnpy_hoc2pyobject(ho)); + + if (!PySequence_Check(po.ptr())) { + if (!PyIter_Check(po.ptr())) { hoc_execerror(hoc_object_name(ho), " does not support the Python Sequence or Iterator protocol"); } - PyObject* iterator = PyObject_GetIter(po); - assert(iterator != NULL); - int i = 0; - PyObject* p; - while ((p = PyIter_Next(iterator)) != NULL) { - if (!PyNumber_Check(p)) { + for(nb::handle item : po) { + if (!PyNumber_Check(item.ptr())) { char buf[50]; - Sprintf(buf, "item %d not a number", i); + Sprintf(buf, "Some list items are not a number"); hoc_execerror(buf, 0); } - hv->push_back(PyFloat_AsDouble(p)); - Py_DECREF(p); - ++i; + hv->push_back(PyFloat_AsDouble(item.ptr())); } - Py_DECREF(iterator); } else { - int size = PySequence_Size(po); - // printf("size = %d\n", size); + int size = nb::len(po); hv->resize(size); double* x = vector_vec(hv); long stride; - char* y = double_array_interface(po, stride); + char* y = double_array_interface(po.ptr(), stride); if (y) { for (int i = 0, j = 0; i < size; ++i, j += stride) { x[i] = *(double*) (y + j); } } else { - for (int i = 0; i < size; ++i) { - PyObject* p = PySequence_GetItem(po, i); - if (!PyNumber_Check(p)) { + for (long i=0; i Date: Tue, 26 Sep 2023 17:00:06 -0400 Subject: [PATCH 02/79] format fixes. Dont run nanobind cmake --- CMakeLists.txt | 4 ++-- cmake/ExternalProjectHelper.cmake | 2 +- src/nrnpython/CMakeLists.txt | 18 +++++++++--------- src/nrnpython/nrnpy_hoc.cpp | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ed919dce2..1eb05e7cbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,8 +431,8 @@ endif() if(NRN_ENABLE_PYTHON) # Make sure the USE_PYTHON macro is defined in the C++ code list(APPEND NRN_COMPILE_DEFS USE_PYTHON) - # Activate nanobind - nrn_add_external_project(nanobind) + # Ensure nanobind is there, but dont import, we don't want its CMake + nrn_add_external_project(nanobind, False) endif() # ============================================================================= diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 3abadf7e58..78cc026818 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,7 +29,7 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 3141666b26..7b87e9a927 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -14,15 +14,15 @@ install(TARGETS rxdmath DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) # minimal nanobind interface # ============================================================================= add_library(nanobind INTERFACE) -target_sources(nanobind INTERFACE - ${NB_DIR}/src/common.cpp - ${NB_DIR}/src/error.cpp - ${NB_DIR}/src/nb_internals.cpp - ${NB_DIR}/src/nb_static_property.cpp - ${NB_DIR}/src/nb_type.cpp - ${NB_DIR}/src/nb_func.cpp - ${NB_DIR}/src/implicit.cpp - ) +target_sources( + nanobind + INTERFACE ${NB_DIR}/src/common.cpp + ${NB_DIR}/src/error.cpp + ${NB_DIR}/src/nb_internals.cpp + ${NB_DIR}/src/nb_static_property.cpp + ${NB_DIR}/src/nb_type.cpp + ${NB_DIR}/src/nb_func.cpp + ${NB_DIR}/src/implicit.cpp) target_include_directories(nanobind INTERFACE "${NB_DIR}/include" "${NB_DIR}/ext/robin_map/include") # ============================================================================= diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index b9ad2ad1b7..d6cf81b345 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -2404,7 +2404,7 @@ static IvocVect* nrnpy_vec_from_python(void* v) { hoc_execerror(hoc_object_name(ho), " does not support the Python Sequence or Iterator protocol"); } - for(nb::handle item : po) { + for (nb::handle item: po) { if (!PyNumber_Check(item.ptr())) { char buf[50]; Sprintf(buf, "Some list items are not a number"); @@ -2423,7 +2423,7 @@ static IvocVect* nrnpy_vec_from_python(void* v) { x[i] = *(double*) (y + j); } } else { - for (long i=0; i Date: Wed, 27 Sep 2023 13:54:01 -0400 Subject: [PATCH 03/79] Fix. clone depth 1 by default --- CMakeLists.txt | 2 +- cmake/ExternalProjectHelper.cmake | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eb05e7cbf..c1df1794b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,7 +432,7 @@ if(NRN_ENABLE_PYTHON) # Make sure the USE_PYTHON macro is defined in the C++ code list(APPEND NRN_COMPILE_DEFS USE_PYTHON) # Ensure nanobind is there, but dont import, we don't want its CMake - nrn_add_external_project(nanobind, False) + nrn_add_external_project(nanobind False) endif() # ============================================================================= diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 78cc026818..3701f62ebc 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,7 +29,8 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} + # Shallow clone by default. Developers should clone recursivelly + COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init --depth=1 -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) From 0ced67c962a3a7327e885da7d23f0a2f769352d8 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Thu, 28 Sep 2023 00:03:37 -0400 Subject: [PATCH 04/79] Fix compilation w nanobind when NOT NRN_ENABLE_PYTHON_DYNAMIC --- CMakeLists.txt | 1 + cmake/NanoBindMinimal.cmake | 18 ++++++++++++++++++ src/nrniv/CMakeLists.txt | 1 + src/nrnpython/CMakeLists.txt | 15 --------------- 4 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 cmake/NanoBindMinimal.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c1df1794b6..6160561809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -433,6 +433,7 @@ if(NRN_ENABLE_PYTHON) list(APPEND NRN_COMPILE_DEFS USE_PYTHON) # Ensure nanobind is there, but dont import, we don't want its CMake nrn_add_external_project(nanobind False) + include(NanoBindMinimal) endif() # ============================================================================= diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake new file mode 100644 index 0000000000..9832c32a7a --- /dev/null +++ b/cmake/NanoBindMinimal.cmake @@ -0,0 +1,18 @@ +# ============================================================================= +# minimal nanobind interface +# ============================================================================= + +set(NB_DIR "external/nanobind") + +add_library(nanobind INTERFACE) +target_sources( + nanobind + INTERFACE ${NB_DIR}/src/common.cpp + ${NB_DIR}/src/error.cpp + ${NB_DIR}/src/nb_internals.cpp + ${NB_DIR}/src/nb_static_property.cpp + ${NB_DIR}/src/nb_type.cpp + ${NB_DIR}/src/nb_func.cpp + ${NB_DIR}/src/implicit.cpp) + +target_include_directories(nanobind INTERFACE ${NB_DIR}/include ${NB_DIR}/ext/robin_map/include) diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index 0e2064ac4d..51cacabae2 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -419,6 +419,7 @@ cpp_cc_configure_sanitizers(TARGET nrniv_lib) target_include_directories(nrniv_lib PUBLIC "${NRN_OC_GEN}") if(NRN_ENABLE_PYTHON AND NOT NRN_ENABLE_PYTHON_DYNAMIC) target_include_directories(nrniv_lib PUBLIC "${NRN_DEFAULT_PYTHON_INCLUDES}") + target_link_libraries(nrniv_lib nanobind) endif() if(NRN_ENABLE_THREADS) target_link_libraries(nrniv_lib Threads::Threads) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 7b87e9a927..dd79aedfa8 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -10,21 +10,6 @@ add_link_options(${NRN_LINK_FLAGS}) add_library(rxdmath SHARED ${CMAKE_CURRENT_SOURCE_DIR}/rxdmath.cpp) install(TARGETS rxdmath DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) -# ============================================================================= -# minimal nanobind interface -# ============================================================================= -add_library(nanobind INTERFACE) -target_sources( - nanobind - INTERFACE ${NB_DIR}/src/common.cpp - ${NB_DIR}/src/error.cpp - ${NB_DIR}/src/nb_internals.cpp - ${NB_DIR}/src/nb_static_property.cpp - ${NB_DIR}/src/nb_type.cpp - ${NB_DIR}/src/nb_func.cpp - ${NB_DIR}/src/implicit.cpp) -target_include_directories(nanobind INTERFACE "${NB_DIR}/include" "${NB_DIR}/ext/robin_map/include") - # ============================================================================= # nrnpython libraries (one lib per python) # ============================================================================= From cdf47c5b267a16223d3e179840f5a46f2a035079 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Thu, 28 Sep 2023 00:04:32 -0400 Subject: [PATCH 05/79] Improve nrnpy_vec_from_python so it uses list getitem when possible. Cleanup --- src/nrnpython/nrnpy_hoc.cpp | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index d6cf81b345..448c8ec555 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -2389,6 +2389,16 @@ static char* double_array_interface(PyObject* po, long& stride) { return static_cast(data); } + +inline double pyobj_to_double_or_fail(PyObject* obj, long obj_id) { + if (!PyNumber_Check(obj)) { + char buf[50]; + Sprintf(buf, "item %d is not a valid number", obj_id); + hoc_execerror(buf, 0); + } + return PyFloat_AsDouble(obj); +} + static IvocVect* nrnpy_vec_from_python(void* v) { Vect* hv = (Vect*) v; // printf("%s.from_array\n", hoc_object_name(hv->obj_)); @@ -2404,33 +2414,31 @@ static IvocVect* nrnpy_vec_from_python(void* v) { hoc_execerror(hoc_object_name(ho), " does not support the Python Sequence or Iterator protocol"); } + long i = 0; for (nb::handle item: po) { - if (!PyNumber_Check(item.ptr())) { - char buf[50]; - Sprintf(buf, "Some list items are not a number"); - hoc_execerror(buf, 0); - } - hv->push_back(PyFloat_AsDouble(item.ptr())); + hv->push_back(pyobj_to_double_or_fail(item.ptr(), i++)); } } else { int size = nb::len(po); hv->resize(size); double* x = vector_vec(hv); long stride; - char* y = double_array_interface(po.ptr(), stride); - if (y) { + char* array_interface_ptr = double_array_interface(po.ptr(), stride); + if (array_interface_ptr) { for (int i = 0, j = 0; i < size; ++i, j += stride) { - x[i] = *(double*) (y + j); + x[i] = *(double*) (array_interface_ptr + j); } } else { - for (long i = 0; i < size; ++i) { - auto item = po[i]; - if (!PyNumber_Check(item.ptr())) { - char buf[50]; - Sprintf(buf, "item %d not a number", i); - hoc_execerror(buf, 0); + if (PyList_Check(po.ptr())) { + // If it's a list, convert to the good type so operator[] is more efficient + nb::list list_obj{std::move(po)}; + for (long i = 0; i < size; ++i) { + x[i] = pyobj_to_double_or_fail(list_obj[i].ptr(), i); + } + } else { + for (long i = 0; i < size; ++i) { + x[i] = pyobj_to_double_or_fail(po[i].ptr(), i); } - x[i] = PyFloat_AsDouble(item.ptr()); } } } From 9e2e0e71c1a3d8adf08fbc2f541e0cef48d6003e Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Thu, 28 Sep 2023 16:10:50 -0400 Subject: [PATCH 06/79] Create nanobind target with better flags. No default visibility --- cmake/NanoBindMinimal.cmake | 28 ++++++++++++++++------------ src/nrniv/CMakeLists.txt | 1 + src/nrnpython/CMakeLists.txt | 6 +++++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index 9832c32a7a..0adbc6538e 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -2,17 +2,21 @@ # minimal nanobind interface # ============================================================================= -set(NB_DIR "external/nanobind") +set(NB_DIR ${PROJECT_SOURCE_DIR}/external/nanobind) -add_library(nanobind INTERFACE) -target_sources( - nanobind - INTERFACE ${NB_DIR}/src/common.cpp - ${NB_DIR}/src/error.cpp - ${NB_DIR}/src/nb_internals.cpp - ${NB_DIR}/src/nb_static_property.cpp - ${NB_DIR}/src/nb_type.cpp - ${NB_DIR}/src/nb_func.cpp - ${NB_DIR}/src/implicit.cpp) +set(NB_SOURCE_FILES + ${NB_DIR}/src/common.cpp + ${NB_DIR}/src/error.cpp + ${NB_DIR}/src/nb_internals.cpp + ${NB_DIR}/src/nb_static_property.cpp + ${NB_DIR}/src/nb_type.cpp + ${NB_DIR}/src/nb_func.cpp + ${NB_DIR}/src/implicit.cpp) -target_include_directories(nanobind INTERFACE ${NB_DIR}/include ${NB_DIR}/ext/robin_map/include) +function(make_nanobind_target target_name pyinc) + add_library(${target_name} OBJECT ${NB_SOURCE_FILES}) + target_include_directories(${target_name} PUBLIC ${NB_DIR}/include) + target_include_directories(${target_name} PRIVATE ${NB_DIR}/ext/robin_map/include ${pyinc}) + set_property(TARGET ${target_name} PROPERTY C_VISIBILITY_PRESET hidden) + set_property(TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE True) +endfunction() diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index 51cacabae2..e5973afb34 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -419,6 +419,7 @@ cpp_cc_configure_sanitizers(TARGET nrniv_lib) target_include_directories(nrniv_lib PUBLIC "${NRN_OC_GEN}") if(NRN_ENABLE_PYTHON AND NOT NRN_ENABLE_PYTHON_DYNAMIC) target_include_directories(nrniv_lib PUBLIC "${NRN_DEFAULT_PYTHON_INCLUDES}") + make_nanobind_target(nanobind ${NRN_DEFAULT_PYTHON_INCLUDES}) target_link_libraries(nrniv_lib nanobind) endif() if(NRN_ENABLE_THREADS) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index dd79aedfa8..c0ac8ce0f0 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -32,13 +32,17 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) ${PROJECT_BINARY_DIR}/src/ivos ${PROJECT_BINARY_DIR}/src/oc ${IV_INCLUDE_DIR}) + foreach(val RANGE ${NRN_PYTHON_ITERATION_LIMIT}) list(GET NRN_PYTHON_VERSIONS ${val} pyver) list(GET NRN_PYTHON_INCLUDES ${val} pyinc) list(GET NRN_PYTHON_LIBRARIES ${val} pylib) + make_nanobind_target(nanobind ${pyinc}) + add_library(nrnpython${pyver} SHARED ${NRN_NRNPYTHON_SRC_FILES}) target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) - target_link_libraries(nrnpython${pyver} nrniv_lib ${Readline_LIBRARY} nanobind) + target_link_libraries(nrnpython${pyver} PUBLIC nrniv_lib) + target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} nanobind) if(NRN_LINK_AGAINST_PYTHON) target_link_libraries(nrnpython${pyver} ${pylib}) endif() From 05ed787128fea56d6e6e96d5ae9aeea2d3cca3f1 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Thu, 28 Sep 2023 22:43:27 -0400 Subject: [PATCH 07/79] Unique nanobind targets, one for each dyn python --- src/nrnpython/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index c0ac8ce0f0..dea0638ee4 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -37,14 +37,15 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) list(GET NRN_PYTHON_VERSIONS ${val} pyver) list(GET NRN_PYTHON_INCLUDES ${val} pyinc) list(GET NRN_PYTHON_LIBRARIES ${val} pylib) - make_nanobind_target(nanobind ${pyinc}) + set(nanobind_target "nanobind_py${pyver}") + make_nanobind_target(${nanobind_target} ${pyinc}) add_library(nrnpython${pyver} SHARED ${NRN_NRNPYTHON_SRC_FILES}) target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) target_link_libraries(nrnpython${pyver} PUBLIC nrniv_lib) - target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} nanobind) + target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} ${nanobind_target}) if(NRN_LINK_AGAINST_PYTHON) - target_link_libraries(nrnpython${pyver} ${pylib}) + target_link_libraries(nrnpython${pyver} PUBLIC ${pylib}) endif() add_dependencies(nrnpython${pyver} nrniv_lib) list(APPEND nrnpython_lib_list nrnpython${pyver}) From 6e4d02cdacc667d29345b527f3bd7f44f3efb85f Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Mon, 2 Oct 2023 00:01:53 +0100 Subject: [PATCH 08/79] Improve build as per the original script --- cmake/NanoBindMinimal.cmake | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index 0adbc6538e..ec60faebae 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -13,10 +13,15 @@ set(NB_SOURCE_FILES ${NB_DIR}/src/nb_func.cpp ${NB_DIR}/src/implicit.cpp) -function(make_nanobind_target target_name pyinc) - add_library(${target_name} OBJECT ${NB_SOURCE_FILES}) - target_include_directories(${target_name} PUBLIC ${NB_DIR}/include) - target_include_directories(${target_name} PRIVATE ${NB_DIR}/ext/robin_map/include ${pyinc}) - set_property(TARGET ${target_name} PROPERTY C_VISIBILITY_PRESET hidden) - set_property(TARGET ${target_name} PROPERTY POSITION_INDEPENDENT_CODE True) +function(make_nanobind_target TARGET_NAME PYINC) + add_library(${TARGET_NAME} OBJECT ${NB_SOURCE_FILES}) + target_include_directories(${TARGET_NAME} PUBLIC ${NB_DIR}/include) + target_include_directories(${TARGET_NAME} PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) + target_compile_definitions(${TARGET_NAME} PUBLIC -DNB_SHARED) + target_compile_definitions(${TARGET_NAME} PRIVATE -DNB_BUILD) + target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) + target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17) + set_property(TARGET ${TARGET_NAME} PROPERTY C_VISIBILITY_PRESET hidden) + set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE True) + set_property(TARGET ${TARGET_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) endfunction() From a183cda53e3610482e5fcc7f6627044180c53fe7 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Wed, 18 Oct 2023 18:21:05 +0200 Subject: [PATCH 09/79] For an object lib use setting similar to static lib --- cmake/NanoBindMinimal.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index ec60faebae..bd3876ec0b 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -17,11 +17,9 @@ function(make_nanobind_target TARGET_NAME PYINC) add_library(${TARGET_NAME} OBJECT ${NB_SOURCE_FILES}) target_include_directories(${TARGET_NAME} PUBLIC ${NB_DIR}/include) target_include_directories(${TARGET_NAME} PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) - target_compile_definitions(${TARGET_NAME} PUBLIC -DNB_SHARED) - target_compile_definitions(${TARGET_NAME} PRIVATE -DNB_BUILD) target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) + target_compile_definitions(${TARGET_NAME} PRIVATE -D_CRT_SECURE_NO_WARNINGS) target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17) - set_property(TARGET ${TARGET_NAME} PROPERTY C_VISIBILITY_PRESET hidden) set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE True) set_property(TARGET ${TARGET_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) endfunction() From 45473c40b83eae436c67e99b09d85558c0454728 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Wed, 18 Oct 2023 18:59:50 +0200 Subject: [PATCH 10/79] Address Sonar checks --- src/nrnpython/nrnpy_hoc.cpp | 53 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 448c8ec555..780129454f 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -1987,7 +1987,6 @@ static PyObject* hocobj_getitem(PyObject* self, Py_ssize_t ix) { } static int hocobj_setitem(PyObject* self, Py_ssize_t i, PyObject* arg) { - // printf("hocobj_setitem %d\n", i); int err = -1; PyHocObject* po = (PyHocObject*) self; if (po->type_ > PyHoc::HocArray) { @@ -2409,6 +2408,7 @@ static IvocVect* nrnpy_vec_from_python(void* v) { // We borrow the list, so there's an INCREF and all items are alive nb::object po = nb::borrow(nrnpy_hoc2pyobject(ho)); + // If it's not a sequence, try iterating over it if (!PySequence_Check(po.ptr())) { if (!PyIter_Check(po.ptr())) { hoc_execerror(hoc_object_name(ho), @@ -2416,30 +2416,35 @@ static IvocVect* nrnpy_vec_from_python(void* v) { } long i = 0; for (nb::handle item: po) { - hv->push_back(pyobj_to_double_or_fail(item.ptr(), i++)); + hv->push_back(pyobj_to_double_or_fail(item.ptr(), i)); + i++; + } + return hv; + } + + int size = nb::len(po); + hv->resize(size); + double* x = vector_vec(hv); + + // If sequence provides __array_interface__ use it + long stride; + char* array_interface_ptr = double_array_interface(po.ptr(), stride); + if (array_interface_ptr) { + for (int i = 0, j = 0; i < size; ++i, j += stride) { + x[i] = *(double*) (array_interface_ptr + j); + } + return hv; + } + + // If it's a normal list, convert to the good type so operator[] is more efficient + if (PyList_Check(po.ptr())) { + nb::list list_obj{std::move(po)}; + for (long i = 0; i < size; ++i) { + x[i] = pyobj_to_double_or_fail(list_obj[i].ptr(), i); } } else { - int size = nb::len(po); - hv->resize(size); - double* x = vector_vec(hv); - long stride; - char* array_interface_ptr = double_array_interface(po.ptr(), stride); - if (array_interface_ptr) { - for (int i = 0, j = 0; i < size; ++i, j += stride) { - x[i] = *(double*) (array_interface_ptr + j); - } - } else { - if (PyList_Check(po.ptr())) { - // If it's a list, convert to the good type so operator[] is more efficient - nb::list list_obj{std::move(po)}; - for (long i = 0; i < size; ++i) { - x[i] = pyobj_to_double_or_fail(list_obj[i].ptr(), i); - } - } else { - for (long i = 0; i < size; ++i) { - x[i] = pyobj_to_double_or_fail(po[i].ptr(), i); - } - } + for (long i = 0; i < size; ++i) { + x[i] = pyobj_to_double_or_fail(po[i].ptr(), i); } } return hv; @@ -3045,7 +3050,7 @@ static PyObject* py_hocobj_mul(PyObject* obj1, PyObject* obj2) { static PyObject* py_hocobj_div(PyObject* obj1, PyObject* obj2) { return py_hocobj_math("div", obj1, obj2); } -static PyMemberDef hocobj_members[] = {{NULL, 0, 0, 0, NULL}}; +static PyMemberDef hocobj_members[] = {{nullptr, 0, 0, 0, nullptr}}; #include "nrnpy_hoc.h" From d1661062ba7f0b4d47749bb2c2e9691b104e28d6 Mon Sep 17 00:00:00 2001 From: Fernando Pereira Date: Thu, 19 Oct 2023 01:12:38 +0200 Subject: [PATCH 11/79] Avoid warnings from 3rd party includes --- cmake/NanoBindMinimal.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index bd3876ec0b..ebc947c02f 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -15,8 +15,8 @@ set(NB_SOURCE_FILES function(make_nanobind_target TARGET_NAME PYINC) add_library(${TARGET_NAME} OBJECT ${NB_SOURCE_FILES}) - target_include_directories(${TARGET_NAME} PUBLIC ${NB_DIR}/include) - target_include_directories(${TARGET_NAME} PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) + target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${NB_DIR}/include) + target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) target_compile_definitions(${TARGET_NAME} PRIVATE -D_CRT_SECURE_NO_WARNINGS) target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17) From a4f9219f9b3ee9b0f408008366dd7932e267f060 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 24 May 2024 14:32:33 +0200 Subject: [PATCH 12/79] Upgrade to v2.0.0 --- external/nanobind | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/nanobind b/external/nanobind index 70abddc0f7..8d7f1ee062 160000 --- a/external/nanobind +++ b/external/nanobind @@ -1 +1 @@ -Subproject commit 70abddc0f77d3867d41ca54033cdc5b35dd136da +Subproject commit 8d7f1ee0621c17fa370b704b2100ffa0243d5bfb From 5789e33e39c4273ce6a0821868a4a34192cefa42 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 24 May 2024 15:04:34 +0200 Subject: [PATCH 13/79] foobar --- CMakeLists.txt | 8 ++++---- cmake/NanoBindMinimal.cmake | 11 +---------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92de662852..87a9058c69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -575,6 +575,10 @@ endif() # ============================================================================= add_subdirectory(src/sparse13) add_subdirectory(src/gnu) +if(NRN_ENABLE_PYTHON) + add_subdirectory(src/nrnpython) +endif() + add_subdirectory(src/nrniv) # Collect the environment variables that are needed to execute NEURON from the build directory. This @@ -602,10 +606,6 @@ if(NRN_ENABLE_PYTHON) endif() add_subdirectory(bin) -if(NRN_ENABLE_PYTHON) - add_subdirectory(src/nrnpython) -endif() - if(NRN_MACOS_BUILD) add_subdirectory(src/mac) endif() diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index ebc947c02f..087f1919d6 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -4,17 +4,8 @@ set(NB_DIR ${PROJECT_SOURCE_DIR}/external/nanobind) -set(NB_SOURCE_FILES - ${NB_DIR}/src/common.cpp - ${NB_DIR}/src/error.cpp - ${NB_DIR}/src/nb_internals.cpp - ${NB_DIR}/src/nb_static_property.cpp - ${NB_DIR}/src/nb_type.cpp - ${NB_DIR}/src/nb_func.cpp - ${NB_DIR}/src/implicit.cpp) - function(make_nanobind_target TARGET_NAME PYINC) - add_library(${TARGET_NAME} OBJECT ${NB_SOURCE_FILES}) + add_library(${TARGET_NAME} OBJECT ${NB_DIR}/src/nb_combined.cpp) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${NB_DIR}/include) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) From 7ef1aa90b4b6d4b2124dc29c937f917aaf8857d8 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 24 May 2024 15:07:43 +0200 Subject: [PATCH 14/79] foobar --- src/nrnpython/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 2646f95a60..d95f9fa4ca 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -63,7 +63,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) install(TARGETS nrnpython${pyver} DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) endforeach() else() - add_library(nrnpython OBJECT ${NRNPYTHON_FILES_LIST}) + add_library(nrnpython SHARED ${NRNPYTHON_FILES_LIST}) add_dependencies(nrnpython generated_source_files) set_property(TARGET nrnpython PROPERTY POSITION_INDEPENDENT_CODE ON) target_include_directories(nrnpython PUBLIC ${INCLUDE_DIRS}) From 33384b00488ff501bd1386c4fe5d4604b8c1f0bd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 May 2024 13:09:19 +0000 Subject: [PATCH 15/79] Fix formatting --- src/nrnpython/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index d95f9fa4ca..f2d369aeb7 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -63,7 +63,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) install(TARGETS nrnpython${pyver} DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) endforeach() else() - add_library(nrnpython SHARED ${NRNPYTHON_FILES_LIST}) + add_library(nrnpython SHARED ${NRNPYTHON_FILES_LIST}) add_dependencies(nrnpython generated_source_files) set_property(TARGET nrnpython PROPERTY POSITION_INDEPENDENT_CODE ON) target_include_directories(nrnpython PUBLIC ${INCLUDE_DIRS}) From 6d283787e880a4416df20e3ed7294e4424d4141d Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 24 May 2024 15:56:45 +0200 Subject: [PATCH 16/79] SHARED => STATIC --- src/nrnpython/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index d95f9fa4ca..501339248f 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -63,7 +63,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) install(TARGETS nrnpython${pyver} DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) endforeach() else() - add_library(nrnpython SHARED ${NRNPYTHON_FILES_LIST}) + add_library(nrnpython STATIC ${NRNPYTHON_FILES_LIST}) add_dependencies(nrnpython generated_source_files) set_property(TARGET nrnpython PROPERTY POSITION_INDEPENDENT_CODE ON) target_include_directories(nrnpython PUBLIC ${INCLUDE_DIRS}) From a7e14ac8a291d60ef13a2849072f874ce65e2ee7 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 28 May 2024 10:05:52 +0200 Subject: [PATCH 17/79] debug --- .github/workflows/neuron-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/neuron-ci.yml b/.github/workflows/neuron-ci.yml index f702b71872..aed97e549b 100644 --- a/.github/workflows/neuron-ci.yml +++ b/.github/workflows/neuron-ci.yml @@ -435,7 +435,10 @@ jobs: # * add 'live-debug-ci' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - name: live debug session on failure (manual steps required, check `.github/neuron-ci.yml`) - if: failure() && contains(github.event.pull_request.title, 'live-debug-ci') + uses: mxschmitt/action-tmate@v3 + if: failure() + + - name: live debug session on failure (manual steps required, check `.github/neuron-ci.yml`) uses: mxschmitt/action-tmate@v3 # see https://github.com/orgs/community/discussions/26822 From d8353bd7e9772d3e6a2e887f95df328fe53ebe36 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 28 May 2024 14:02:51 +0200 Subject: [PATCH 18/79] Fix shared / object / static --- cmake/NanoBindMinimal.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index 087f1919d6..1434650522 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -5,7 +5,7 @@ set(NB_DIR ${PROJECT_SOURCE_DIR}/external/nanobind) function(make_nanobind_target TARGET_NAME PYINC) - add_library(${TARGET_NAME} OBJECT ${NB_DIR}/src/nb_combined.cpp) + add_library(${TARGET_NAME} STATIC ${NB_DIR}/src/nb_combined.cpp) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${NB_DIR}/include) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) From fb8caa845932759ab372cd9fffc995b354094817 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 28 May 2024 14:05:44 +0200 Subject: [PATCH 19/79] Revert "debug" This reverts commit a7e14ac8a291d60ef13a2849072f874ce65e2ee7. --- .github/workflows/neuron-ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/neuron-ci.yml b/.github/workflows/neuron-ci.yml index aed97e549b..f702b71872 100644 --- a/.github/workflows/neuron-ci.yml +++ b/.github/workflows/neuron-ci.yml @@ -435,10 +435,7 @@ jobs: # * add 'live-debug-ci' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - name: live debug session on failure (manual steps required, check `.github/neuron-ci.yml`) - uses: mxschmitt/action-tmate@v3 - if: failure() - - - name: live debug session on failure (manual steps required, check `.github/neuron-ci.yml`) + if: failure() && contains(github.event.pull_request.title, 'live-debug-ci') uses: mxschmitt/action-tmate@v3 # see https://github.com/orgs/community/discussions/26822 From 087edbc8143434605ee608e9cb10db8afb90b376 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 28 May 2024 14:40:22 +0200 Subject: [PATCH 20/79] More --- src/nrnpython/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 501339248f..2646f95a60 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -63,7 +63,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) install(TARGETS nrnpython${pyver} DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) endforeach() else() - add_library(nrnpython STATIC ${NRNPYTHON_FILES_LIST}) + add_library(nrnpython OBJECT ${NRNPYTHON_FILES_LIST}) add_dependencies(nrnpython generated_source_files) set_property(TARGET nrnpython PROPERTY POSITION_INDEPENDENT_CODE ON) target_include_directories(nrnpython PUBLIC ${INCLUDE_DIRS}) From 47c3167b2631228e1326c84464b42fb9194cb5b9 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 28 May 2024 16:39:12 +0200 Subject: [PATCH 21/79] Debug windows... --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 985eae0ae0..d77f7ec8ac 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -76,7 +76,7 @@ jobs: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() && contains(github.event.pull_request.title, 'live-debug-win') + if: failure() uses: mxschmitt/action-tmate@v3 - name: Upload build artifact From b847e73453eb64803486f70b4933491aab4e7923 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 11:38:24 +0200 Subject: [PATCH 22/79] Export nrnpy_hoc --- src/nrnpython/nrnpy_hoc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index 47a1de6d1f..28a1801ecd 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -1,5 +1,8 @@ #include "nrnpython.h" + +NB_EXPORT PyObject* nrnpy_hoc(); + static PyType_Slot nrnpy_HocObjectType_slots[] = { {Py_tp_dealloc, (void*) hocobj_dealloc}, {Py_tp_repr, (void*) hocobj_repr}, From 6f26ef04521cadd0413ea6a64245b861defe1d80 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 12:09:33 +0200 Subject: [PATCH 23/79] Export more symbols for microsoft --- src/nrnpython/nrnpython.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 310d3ff9d2..978d1387b2 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -94,3 +94,5 @@ extern "C" PyObject* nrn_hocobj_ptr(double*); int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); + +NB_EXPORT void nrnpython_reg_real(); From b8f38bf787389324e7f9c775b4e5df3de89beeec Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 12:24:12 +0200 Subject: [PATCH 24/79] include --- src/nrnpython/nrnpython.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 978d1387b2..dc1dcb4e47 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -1,5 +1,7 @@ #pragma once +#include + #ifdef _WIN64 #define MS_WIN64 #define MS_WIN32 From 6fe9eaa4083281ca04ede06918ad28f2547ac563 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 14:28:37 +0200 Subject: [PATCH 25/79] Simplify CI --- .github/workflows/windows.yml | 9 +++++---- ci/win_build_cmake.sh | 2 +- ci/win_install_deps.cmd | 15 --------------- ci/win_test_installer.cmd | 3 --- src/nrnpython/nrnpy_hoc.h | 1 - 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d77f7ec8ac..f05b679c29 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -75,10 +75,6 @@ jobs: # To enable it, you have to: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() - uses: mxschmitt/action-tmate@v3 - - name: Upload build artifact uses: actions/upload-artifact@v4 with: @@ -95,6 +91,11 @@ jobs: shell: cmd working-directory: ${{runner.workspace}}\nrn + - name: live debug session on failure (manual steps required, check `.github/windows.yml`) + if: failure() + uses: mxschmitt/action-tmate@v3 + + - name: Publish Release Installer working-directory: ${{runner.workspace}}\nrn if: inputs.tag != '' diff --git a/ci/win_build_cmake.sh b/ci/win_build_cmake.sh index c3c84ad37e..9c5b8c0168 100755 --- a/ci/win_build_cmake.sh +++ b/ci/win_build_cmake.sh @@ -32,7 +32,7 @@ cd $BUILD_SOURCESDIRECTORY/build -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;c:/Python312/python.exe' \ + -DNRN_PYTHON_DYNAMIC='c:/Python38/python.exe' \ -DCMAKE_INSTALL_PREFIX='/c/nrn-install' \ -DMPI_CXX_LIB_NAMES:STRING=msmpi \ -DMPI_C_LIB_NAMES:STRING=msmpi \ diff --git a/ci/win_install_deps.cmd b/ci/win_install_deps.cmd index 2284b911c0..5af79aa365 100644 --- a/ci/win_install_deps.cmd +++ b/ci/win_install_deps.cmd @@ -4,31 +4,16 @@ :: install python python-3.8.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python38 || goto :error -python-3.9.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python39 || goto :error -python-3.10.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python310 || goto :error -python-3.11.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python311 || goto :error -python-3.12.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python312 || goto :error :: fix msvcc version for all python3 pwsh -command "(Get-Content C:\Python38\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1916'':' | Out-File C:\Python38\Lib\distutils\cygwinccompiler.py" -pwsh -command "(Get-Content C:\Python39\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1927'':' | Out-File C:\Python39\Lib\distutils\cygwinccompiler.py" -pwsh -command "(Get-Content C:\Python310\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1929'':' | Out-File C:\Python310\Lib\distutils\cygwinccompiler.py" -pwsh -command "(Get-Content C:\Python311\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1934'':' | Out-File C:\Python311\Lib\distutils\cygwinccompiler.py" :: fix msvc runtime library for all python pwsh -command "(Get-Content C:\Python38\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python38\Lib\distutils\cygwinccompiler.py" -pwsh -command "(Get-Content C:\Python39\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python39\Lib\distutils\cygwinccompiler.py" -pwsh -command "(Get-Content C:\Python310\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python310\Lib\distutils\cygwinccompiler.py" -pwsh -command "(Get-Content C:\Python311\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python311\Lib\distutils\cygwinccompiler.py" :: install numpy C:\Python38\python.exe -m pip install numpy==1.17.5 "cython < 3" || goto :error -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 :: install nsis nsis-3.05-setup.exe /S || goto :error diff --git a/ci/win_test_installer.cmd b/ci/win_test_installer.cmd index e6a5ab967f..744b1047e9 100644 --- a/ci/win_test_installer.cmd +++ b/ci/win_test_installer.cmd @@ -18,9 +18,6 @@ if not exist association.hoc.out (start /wait /REALTIME %cd%\ci\association.hoc) :: test all pythons C:\Python38\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" -C:\Python39\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" -C:\Python310\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" -C:\Python311\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" :: install numpy dependency python -m pip install numpy :: run also using whatever is system python diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index 28a1801ecd..b3f9a235fc 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -2,7 +2,6 @@ NB_EXPORT PyObject* nrnpy_hoc(); - static PyType_Slot nrnpy_HocObjectType_slots[] = { {Py_tp_dealloc, (void*) hocobj_dealloc}, {Py_tp_repr, (void*) hocobj_repr}, From 2a4b45f15dbbda0d470fdf152fa63fd3cd6c7db4 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 14:56:34 +0200 Subject: [PATCH 26/79] Revert "Simplify CI" This reverts commit 6fe9eaa4083281ca04ede06918ad28f2547ac563. --- .github/workflows/windows.yml | 9 ++++----- ci/win_build_cmake.sh | 2 +- ci/win_install_deps.cmd | 15 +++++++++++++++ ci/win_test_installer.cmd | 3 +++ src/nrnpython/nrnpy_hoc.h | 1 + 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f05b679c29..d77f7ec8ac 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -75,6 +75,10 @@ jobs: # To enable it, you have to: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) + - name: live debug session on failure (manual steps required, check `.github/windows.yml`) + if: failure() + uses: mxschmitt/action-tmate@v3 + - name: Upload build artifact uses: actions/upload-artifact@v4 with: @@ -91,11 +95,6 @@ jobs: shell: cmd working-directory: ${{runner.workspace}}\nrn - - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() - uses: mxschmitt/action-tmate@v3 - - - name: Publish Release Installer working-directory: ${{runner.workspace}}\nrn if: inputs.tag != '' diff --git a/ci/win_build_cmake.sh b/ci/win_build_cmake.sh index 9c5b8c0168..c3c84ad37e 100755 --- a/ci/win_build_cmake.sh +++ b/ci/win_build_cmake.sh @@ -32,7 +32,7 @@ cd $BUILD_SOURCESDIRECTORY/build -DNRN_BINARY_DIST_BUILD=ON \ -DPYTHON_EXECUTABLE=/c/Python38/python.exe \ -DNRN_ENABLE_PYTHON_DYNAMIC=ON \ - -DNRN_PYTHON_DYNAMIC='c:/Python38/python.exe' \ + -DNRN_PYTHON_DYNAMIC='c:/Python38/python.exe;c:/Python39/python.exe;c:/Python310/python.exe;c:/Python311/python.exe;c:/Python312/python.exe' \ -DCMAKE_INSTALL_PREFIX='/c/nrn-install' \ -DMPI_CXX_LIB_NAMES:STRING=msmpi \ -DMPI_C_LIB_NAMES:STRING=msmpi \ diff --git a/ci/win_install_deps.cmd b/ci/win_install_deps.cmd index 5af79aa365..2284b911c0 100644 --- a/ci/win_install_deps.cmd +++ b/ci/win_install_deps.cmd @@ -4,16 +4,31 @@ :: install python python-3.8.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python38 || goto :error +python-3.9.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python39 || goto :error +python-3.10.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python310 || goto :error +python-3.11.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python311 || goto :error +python-3.12.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python312 || goto :error :: fix msvcc version for all python3 pwsh -command "(Get-Content C:\Python38\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1916'':' | Out-File C:\Python38\Lib\distutils\cygwinccompiler.py" +pwsh -command "(Get-Content C:\Python39\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1927'':' | Out-File C:\Python39\Lib\distutils\cygwinccompiler.py" +pwsh -command "(Get-Content C:\Python310\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1929'':' | Out-File C:\Python310\Lib\distutils\cygwinccompiler.py" +pwsh -command "(Get-Content C:\Python311\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1934'':' | Out-File C:\Python311\Lib\distutils\cygwinccompiler.py" :: fix msvc runtime library for all python pwsh -command "(Get-Content C:\Python38\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python38\Lib\distutils\cygwinccompiler.py" +pwsh -command "(Get-Content C:\Python39\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python39\Lib\distutils\cygwinccompiler.py" +pwsh -command "(Get-Content C:\Python310\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python310\Lib\distutils\cygwinccompiler.py" +pwsh -command "(Get-Content C:\Python311\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python311\Lib\distutils\cygwinccompiler.py" :: install numpy C:\Python38\python.exe -m pip install numpy==1.17.5 "cython < 3" || goto :error +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 :: install nsis nsis-3.05-setup.exe /S || goto :error diff --git a/ci/win_test_installer.cmd b/ci/win_test_installer.cmd index 744b1047e9..e6a5ab967f 100644 --- a/ci/win_test_installer.cmd +++ b/ci/win_test_installer.cmd @@ -18,6 +18,9 @@ if not exist association.hoc.out (start /wait /REALTIME %cd%\ci\association.hoc) :: test all pythons C:\Python38\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" +C:\Python39\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" +C:\Python310\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" +C:\Python311\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y" :: install numpy dependency python -m pip install numpy :: run also using whatever is system python diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index b3f9a235fc..28a1801ecd 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -2,6 +2,7 @@ NB_EXPORT PyObject* nrnpy_hoc(); + static PyType_Slot nrnpy_HocObjectType_slots[] = { {Py_tp_dealloc, (void*) hocobj_dealloc}, {Py_tp_repr, (void*) hocobj_repr}, From 0e889f22ba7b76fc14c5c4742a31cc1b9c49a62a Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 14:56:56 +0200 Subject: [PATCH 27/79] Simplify CI --- .github/workflows/windows.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d77f7ec8ac..62aa54ad86 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -75,10 +75,6 @@ jobs: # To enable it, you have to: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() - uses: mxschmitt/action-tmate@v3 - - name: Upload build artifact uses: actions/upload-artifact@v4 with: @@ -95,6 +91,10 @@ jobs: shell: cmd working-directory: ${{runner.workspace}}\nrn + - name: live debug session on failure (manual steps required, check `.github/windows.yml`) + if: failure() + uses: mxschmitt/action-tmate@v3 + - name: Publish Release Installer working-directory: ${{runner.workspace}}\nrn if: inputs.tag != '' From 60ae462a5afa974d72a0b858d4da28c37fb50b5c Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 15:28:27 +0200 Subject: [PATCH 28/79] better linkage --- src/nrnpython/nrnpython.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index dc1dcb4e47..8a9c88915c 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -16,6 +16,8 @@ #undef _XOPEN_SOURCE #include "nrnwrap_Python.h" +#include "nrnpy.h" + #endif /*USE_PYTHON*/ #include @@ -97,4 +99,4 @@ int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); -NB_EXPORT void nrnpython_reg_real(); +NB_EXPORT extern "C" void nrnpython_reg_real(neuron::python::impl_ptrs*); From 741295f9370a3aa8525af5aa9275421b88a8d9eb Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 15:35:08 +0200 Subject: [PATCH 29/79] Position is important --- src/nrnpython/nrnpython.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 8a9c88915c..fea12a2772 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -99,4 +99,4 @@ int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); -NB_EXPORT extern "C" void nrnpython_reg_real(neuron::python::impl_ptrs*); +extern "C" NB_EXPORT void nrnpython_reg_real(neuron::python::impl_ptrs*); From c280d6ffe3809716c796e4caed0eaf3d0a3827c2 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 29 May 2024 18:01:12 +0200 Subject: [PATCH 30/79] More export for windows --- src/nrnpython/grids.cpp | 2 +- src/nrnpython/grids.h | 35 ++++++++++++++++++++++---- src/nrnpython/inithoc.cpp | 3 +++ src/nrnpython/inithoc.hpp | 10 ++++++++ src/nrnpython/nb_defs.h | 49 +++++++++++++++++++++++++++++++++++++ src/nrnpython/nrnpy_hoc.cpp | 2 -- src/nrnpython/nrnpy_hoc.h | 12 ++++++++- src/nrnpython/nrnpython.h | 3 +-- 8 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 src/nrnpython/inithoc.hpp create mode 100644 src/nrnpython/nb_defs.h diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 23040d396d..189e206756 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -415,7 +415,7 @@ extern "C" int ICS_insert(int grid_list_index, return new_Grid->insert(grid_list_index); } -int ICS_insert_inhom(int grid_list_index, +extern "C" int ICS_insert_inhom(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 1f5e9f1042..b58e6748c2 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -4,6 +4,8 @@ Date: 10/28/16 Description: Header File for grids.cpp. Allows access to Grid_node and Flux_pair structs and their respective functions ******************************************************************/ +#include "nb_defs.h" + #include #include #include @@ -394,6 +396,8 @@ extern Grid_node* Parallel_grids[100]; // Array of Grid_node * lists void make_dt_ptr(PyHocObject* my_dt_ptr); +extern "C" NB_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr); + // Create a single Grid_node /* Parameters: Python object that includes array of double pointers, size of x, y, and z dimensions @@ -404,7 +408,7 @@ void make_dt_ptr(PyHocObject* my_dt_ptr); // void free_Grid(Grid_node *grid); // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids -extern "C" int ECS_insert(int grid_list_index, +extern "C" NB_EXPORT int ECS_insert(int grid_list_index, PyHocObject* my_states, int my_num_states_x, int my_num_states_y, @@ -437,7 +441,7 @@ Grid_node* ICS_make_Grid(PyHocObject* my_states, double* ics_alphas); // Insert an ICS_Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids -extern "C" int ICS_insert(int grid_list_index, +extern "C" NB_EXPORT int ICS_insert(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, @@ -453,7 +457,7 @@ extern "C" int ICS_insert(int grid_list_index, double atolscale, double* ics_alphas); -extern "C" int ICS_insert_inhom(int grid_list_index, +extern "C" NB_EXPORT int ICS_insert_inhom(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, @@ -471,8 +475,29 @@ extern "C" int ICS_insert_inhom(int grid_list_index, // Set the diffusion coefficients for a given grid_id -extern "C" int set_diffusion(int, int, double*, int); - +extern "C" NB_EXPORT int set_diffusion(int, int, double*, int); + +extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability); +extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha); +extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, + int index_in_list, + int64_t* nodes_per_seg, + int64_t* nodes_per_seg_start_indices, + PyObject* neuron_pointers); +extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, + int index_in_list, + PyObject* neuron_pointers, + double* scale_factors); +extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers); +extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers, + PyObject* scale_factors); +extern "C" NB_EXPORT void delete_by_id(int id); // Delete a specific Grid_node "find" from the list "head" int remove(Grid_node** head, Grid_node* find); diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index 184ccafc00..b84798b30e 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -1,4 +1,7 @@ #include "../../nrnconf.h" + +#include "inithoc.hpp" + #include "nrnmpiuse.h" #include #include diff --git a/src/nrnpython/inithoc.hpp b/src/nrnpython/inithoc.hpp new file mode 100644 index 0000000000..81345ec9f2 --- /dev/null +++ b/src/nrnpython/inithoc.hpp @@ -0,0 +1,10 @@ +#include "nb_defs.h" + +struct _object; +using PyObject = struct _object; + +extern "C" NB_EXPORT PyObject* PyInit_hoc(); +#if !defined(MINHG) +extern "C" NB_EXPORT void modl_reg(); +#endif + diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h new file mode 100644 index 0000000000..c001e00954 --- /dev/null +++ b/src/nrnpython/nb_defs.h @@ -0,0 +1,49 @@ +#pragma once + +#if defined(_WIN32) +# define NB_EXPORT __declspec(dllexport) +# define NB_IMPORT __declspec(dllimport) +# define NB_INLINE __forceinline +# define NB_NOINLINE __declspec(noinline) +# define NB_INLINE_LAMBDA +#else +# define NB_EXPORT __attribute__ ((visibility("default"))) +# define NB_IMPORT NB_EXPORT +# define NB_INLINE inline __attribute__((always_inline)) +# define NB_NOINLINE __attribute__((noinline)) +# if defined(__clang__) +# define NB_INLINE_LAMBDA __attribute__((always_inline)) +# else +# define NB_INLINE_LAMBDA +# endif +#endif + +#if defined(__GNUC__) && !defined(_WIN32) +# define NB_NAMESPACE nanobind __attribute__((visibility("hidden"))) +#else +# define NB_NAMESPACE nanobind +#endif + +#if defined(__GNUC__) +# define NB_UNLIKELY(x) __builtin_expect(bool(x), 0) +# define NB_LIKELY(x) __builtin_expect(bool(x), 1) +#else +# define NB_LIKELY(x) x +# define NB_UNLIKELY(x) x +#endif + +#if defined(NB_SHARED) +# if defined(NB_BUILD) +# define NB_CORE NB_EXPORT +# else +# define NB_CORE NB_IMPORT +# endif +#else +# define NB_CORE +#endif + +#if !defined(NB_SHARED) && defined(__GNUC__) && !defined(_WIN32) +# define NB_EXPORT_SHARED __attribute__ ((visibility("hidden"))) +#else +# define NB_EXPORT_SHARED +#endif diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 0df08c5fa8..cec83073b1 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -72,8 +72,6 @@ extern IvocVect* (*nrnpy_vec_from_python_p_)(void*); extern Object** (*nrnpy_vec_to_python_p_)(void*); extern Object** (*nrnpy_vec_as_numpy_helper_)(int, double*); extern Object* (*nrnpy_rvp_rxd_to_callable)(Object*); -extern "C" int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ); // called by ctypes. -extern "C" int nrnpy_set_gui_callback(PyObject*); extern Symbol* ivoc_alias_lookup(const char* name, Object* ob); class NetCon; extern int nrn_netcon_weight(NetCon*, double**); diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index 28a1801ecd..7ecf200f34 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -1,7 +1,17 @@ #include "nrnpython.h" - NB_EXPORT PyObject* nrnpy_hoc(); +extern "C" NB_EXPORT PyObject* nrn_hocobj_ptr(double*); +extern "C" NB_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ); +extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, + PyObject* plotshape_plot0, + PyObject* get_mech_object_0, + PyObject* store_savestate, + PyObject* restore_savestate); +extern "C" NB_EXPORT int nrnpy_set_gui_callback(PyObject*); +extern "C" NB_EXPORT PyObject* get_plotshape_data(PyObject* sp); +extern "C" NB_EXPORT int nrnpy_vec_math_register(PyObject* callback); +extern "C" NB_EXPORT int nrnpy_rvp_pyobj_callback_register(PyObject* callback); static PyType_Slot nrnpy_HocObjectType_slots[] = { {Py_tp_dealloc, (void*) hocobj_dealloc}, diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index fea12a2772..472411317a 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "nb_defs.h" #ifdef _WIN64 #define MS_WIN64 @@ -94,7 +94,6 @@ struct Symbol; bool nrn_chk_data_handle(const neuron::container::data_handle&); PyObject* nrn_hocobj_handle(neuron::container::data_handle d); -extern "C" PyObject* nrn_hocobj_ptr(double*); int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); From 232dba325e02019ec6196652c415729bfc4cc5f5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 May 2024 16:22:06 +0000 Subject: [PATCH 31/79] Fix formatting --- src/nrnpython/grids.cpp | 28 ++++----- src/nrnpython/grids.h | 122 ++++++++++++++++++++------------------ src/nrnpython/inithoc.hpp | 1 - src/nrnpython/nb_defs.h | 56 ++++++++--------- src/nrnpython/nrnpy_hoc.h | 8 +-- 5 files changed, 109 insertions(+), 106 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 189e206756..2872a317f4 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -416,20 +416,20 @@ extern "C" int ICS_insert(int grid_list_index, } extern "C" int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas) { + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas) { ICS_Grid_node* new_Grid = new ICS_Grid_node(my_states, num_nodes, neighbors, diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index b58e6748c2..a39b9cff82 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -409,21 +409,21 @@ extern "C" NB_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_ // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids extern "C" NB_EXPORT int ECS_insert(int grid_list_index, - PyHocObject* my_states, - int my_num_states_x, - int my_num_states_y, - int my_num_states_z, - double my_dc_x, - double my_dc_y, - double my_dc_z, - double my_dx, - double my_dy, - double my_dz, - PyHocObject* my_alpha, - PyHocObject* my_permeability, - int, - double, - double); + PyHocObject* my_states, + int my_num_states_x, + int my_num_states_y, + int my_num_states_z, + double my_dc_x, + double my_dc_y, + double my_dc_z, + double my_dx, + double my_dy, + double my_dz, + PyHocObject* my_alpha, + PyHocObject* my_permeability, + int, + double, + double); Grid_node* ICS_make_Grid(PyHocObject* my_states, long num_nodes, @@ -442,61 +442,65 @@ Grid_node* ICS_make_Grid(PyHocObject* my_states, // Insert an ICS_Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids extern "C" NB_EXPORT int ICS_insert(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas); + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas); extern "C" NB_EXPORT int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas); + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas); // Set the diffusion coefficients for a given grid_id extern "C" NB_EXPORT int set_diffusion(int, int, double*, int); -extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability); -extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha); +extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, + int grid_id, + PyHocObject* my_permeability); +extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, + int grid_id, + PyHocObject* my_alpha); extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, - int index_in_list, - int64_t* nodes_per_seg, - int64_t* nodes_per_seg_start_indices, - PyObject* neuron_pointers); + int index_in_list, + int64_t* nodes_per_seg, + int64_t* nodes_per_seg_start_indices, + PyObject* neuron_pointers); extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* neuron_pointers, - double* scale_factors); + int index_in_list, + PyObject* neuron_pointers, + double* scale_factors); extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers); + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers); extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers, - PyObject* scale_factors); + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers, + PyObject* scale_factors); extern "C" NB_EXPORT void delete_by_id(int id); // Delete a specific Grid_node "find" from the list "head" int remove(Grid_node** head, Grid_node* find); diff --git a/src/nrnpython/inithoc.hpp b/src/nrnpython/inithoc.hpp index 81345ec9f2..5e9541e2cf 100644 --- a/src/nrnpython/inithoc.hpp +++ b/src/nrnpython/inithoc.hpp @@ -7,4 +7,3 @@ extern "C" NB_EXPORT PyObject* PyInit_hoc(); #if !defined(MINHG) extern "C" NB_EXPORT void modl_reg(); #endif - diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h index c001e00954..0ef934a826 100644 --- a/src/nrnpython/nb_defs.h +++ b/src/nrnpython/nb_defs.h @@ -1,49 +1,49 @@ #pragma once #if defined(_WIN32) -# define NB_EXPORT __declspec(dllexport) -# define NB_IMPORT __declspec(dllimport) -# define NB_INLINE __forceinline -# define NB_NOINLINE __declspec(noinline) -# define NB_INLINE_LAMBDA +#define NB_EXPORT __declspec(dllexport) +#define NB_IMPORT __declspec(dllimport) +#define NB_INLINE __forceinline +#define NB_NOINLINE __declspec(noinline) +#define NB_INLINE_LAMBDA #else -# define NB_EXPORT __attribute__ ((visibility("default"))) -# define NB_IMPORT NB_EXPORT -# define NB_INLINE inline __attribute__((always_inline)) -# define NB_NOINLINE __attribute__((noinline)) -# if defined(__clang__) -# define NB_INLINE_LAMBDA __attribute__((always_inline)) -# else -# define NB_INLINE_LAMBDA -# endif +#define NB_EXPORT __attribute__((visibility("default"))) +#define NB_IMPORT NB_EXPORT +#define NB_INLINE inline __attribute__((always_inline)) +#define NB_NOINLINE __attribute__((noinline)) +#if defined(__clang__) +#define NB_INLINE_LAMBDA __attribute__((always_inline)) +#else +#define NB_INLINE_LAMBDA +#endif #endif #if defined(__GNUC__) && !defined(_WIN32) -# define NB_NAMESPACE nanobind __attribute__((visibility("hidden"))) +#define NB_NAMESPACE nanobind __attribute__((visibility("hidden"))) #else -# define NB_NAMESPACE nanobind +#define NB_NAMESPACE nanobind #endif #if defined(__GNUC__) -# define NB_UNLIKELY(x) __builtin_expect(bool(x), 0) -# define NB_LIKELY(x) __builtin_expect(bool(x), 1) +#define NB_UNLIKELY(x) __builtin_expect(bool(x), 0) +#define NB_LIKELY(x) __builtin_expect(bool(x), 1) #else -# define NB_LIKELY(x) x -# define NB_UNLIKELY(x) x +#define NB_LIKELY(x) x +#define NB_UNLIKELY(x) x #endif #if defined(NB_SHARED) -# if defined(NB_BUILD) -# define NB_CORE NB_EXPORT -# else -# define NB_CORE NB_IMPORT -# endif +#if defined(NB_BUILD) +#define NB_CORE NB_EXPORT +#else +#define NB_CORE NB_IMPORT +#endif #else -# define NB_CORE +#define NB_CORE #endif #if !defined(NB_SHARED) && defined(__GNUC__) && !defined(_WIN32) -# define NB_EXPORT_SHARED __attribute__ ((visibility("hidden"))) +#define NB_EXPORT_SHARED __attribute__((visibility("hidden"))) #else -# define NB_EXPORT_SHARED +#define NB_EXPORT_SHARED #endif diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index 7ecf200f34..3ce1be5625 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -4,10 +4,10 @@ NB_EXPORT PyObject* nrnpy_hoc(); extern "C" NB_EXPORT PyObject* nrn_hocobj_ptr(double*); extern "C" NB_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ); extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, - PyObject* plotshape_plot0, - PyObject* get_mech_object_0, - PyObject* store_savestate, - PyObject* restore_savestate); + PyObject* plotshape_plot0, + PyObject* get_mech_object_0, + PyObject* store_savestate, + PyObject* restore_savestate); extern "C" NB_EXPORT int nrnpy_set_gui_callback(PyObject*); extern "C" NB_EXPORT PyObject* get_plotshape_data(PyObject* sp); extern "C" NB_EXPORT int nrnpy_vec_math_register(PyObject* callback); From 4c3abd8f813b3ff13cf09feda54dadaf602a344c Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 00:24:16 +0200 Subject: [PATCH 32/79] NB_EXPORT for RXD --- src/nrnpython/grids.cpp | 28 ++++----- src/nrnpython/grids.h | 122 ++++++++++++++++++++------------------ src/nrnpython/inithoc.hpp | 1 - src/nrnpython/nb_defs.h | 56 ++++++++--------- src/nrnpython/nrnpy_hoc.h | 8 +-- src/nrnpython/rxd.cpp | 4 +- src/nrnpython/rxd.h | 107 +++++++++++++++++++++++++++++++-- 7 files changed, 214 insertions(+), 112 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 189e206756..2872a317f4 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -416,20 +416,20 @@ extern "C" int ICS_insert(int grid_list_index, } extern "C" int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas) { + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas) { ICS_Grid_node* new_Grid = new ICS_Grid_node(my_states, num_nodes, neighbors, diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index b58e6748c2..a39b9cff82 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -409,21 +409,21 @@ extern "C" NB_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_ // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids extern "C" NB_EXPORT int ECS_insert(int grid_list_index, - PyHocObject* my_states, - int my_num_states_x, - int my_num_states_y, - int my_num_states_z, - double my_dc_x, - double my_dc_y, - double my_dc_z, - double my_dx, - double my_dy, - double my_dz, - PyHocObject* my_alpha, - PyHocObject* my_permeability, - int, - double, - double); + PyHocObject* my_states, + int my_num_states_x, + int my_num_states_y, + int my_num_states_z, + double my_dc_x, + double my_dc_y, + double my_dc_z, + double my_dx, + double my_dy, + double my_dz, + PyHocObject* my_alpha, + PyHocObject* my_permeability, + int, + double, + double); Grid_node* ICS_make_Grid(PyHocObject* my_states, long num_nodes, @@ -442,61 +442,65 @@ Grid_node* ICS_make_Grid(PyHocObject* my_states, // Insert an ICS_Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids extern "C" NB_EXPORT int ICS_insert(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas); + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas); extern "C" NB_EXPORT int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas); + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas); // Set the diffusion coefficients for a given grid_id extern "C" NB_EXPORT int set_diffusion(int, int, double*, int); -extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability); -extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha); +extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, + int grid_id, + PyHocObject* my_permeability); +extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, + int grid_id, + PyHocObject* my_alpha); extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, - int index_in_list, - int64_t* nodes_per_seg, - int64_t* nodes_per_seg_start_indices, - PyObject* neuron_pointers); + int index_in_list, + int64_t* nodes_per_seg, + int64_t* nodes_per_seg_start_indices, + PyObject* neuron_pointers); extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* neuron_pointers, - double* scale_factors); + int index_in_list, + PyObject* neuron_pointers, + double* scale_factors); extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers); + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers); extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers, - PyObject* scale_factors); + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers, + PyObject* scale_factors); extern "C" NB_EXPORT void delete_by_id(int id); // Delete a specific Grid_node "find" from the list "head" int remove(Grid_node** head, Grid_node* find); diff --git a/src/nrnpython/inithoc.hpp b/src/nrnpython/inithoc.hpp index 81345ec9f2..5e9541e2cf 100644 --- a/src/nrnpython/inithoc.hpp +++ b/src/nrnpython/inithoc.hpp @@ -7,4 +7,3 @@ extern "C" NB_EXPORT PyObject* PyInit_hoc(); #if !defined(MINHG) extern "C" NB_EXPORT void modl_reg(); #endif - diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h index c001e00954..0ef934a826 100644 --- a/src/nrnpython/nb_defs.h +++ b/src/nrnpython/nb_defs.h @@ -1,49 +1,49 @@ #pragma once #if defined(_WIN32) -# define NB_EXPORT __declspec(dllexport) -# define NB_IMPORT __declspec(dllimport) -# define NB_INLINE __forceinline -# define NB_NOINLINE __declspec(noinline) -# define NB_INLINE_LAMBDA +#define NB_EXPORT __declspec(dllexport) +#define NB_IMPORT __declspec(dllimport) +#define NB_INLINE __forceinline +#define NB_NOINLINE __declspec(noinline) +#define NB_INLINE_LAMBDA #else -# define NB_EXPORT __attribute__ ((visibility("default"))) -# define NB_IMPORT NB_EXPORT -# define NB_INLINE inline __attribute__((always_inline)) -# define NB_NOINLINE __attribute__((noinline)) -# if defined(__clang__) -# define NB_INLINE_LAMBDA __attribute__((always_inline)) -# else -# define NB_INLINE_LAMBDA -# endif +#define NB_EXPORT __attribute__((visibility("default"))) +#define NB_IMPORT NB_EXPORT +#define NB_INLINE inline __attribute__((always_inline)) +#define NB_NOINLINE __attribute__((noinline)) +#if defined(__clang__) +#define NB_INLINE_LAMBDA __attribute__((always_inline)) +#else +#define NB_INLINE_LAMBDA +#endif #endif #if defined(__GNUC__) && !defined(_WIN32) -# define NB_NAMESPACE nanobind __attribute__((visibility("hidden"))) +#define NB_NAMESPACE nanobind __attribute__((visibility("hidden"))) #else -# define NB_NAMESPACE nanobind +#define NB_NAMESPACE nanobind #endif #if defined(__GNUC__) -# define NB_UNLIKELY(x) __builtin_expect(bool(x), 0) -# define NB_LIKELY(x) __builtin_expect(bool(x), 1) +#define NB_UNLIKELY(x) __builtin_expect(bool(x), 0) +#define NB_LIKELY(x) __builtin_expect(bool(x), 1) #else -# define NB_LIKELY(x) x -# define NB_UNLIKELY(x) x +#define NB_LIKELY(x) x +#define NB_UNLIKELY(x) x #endif #if defined(NB_SHARED) -# if defined(NB_BUILD) -# define NB_CORE NB_EXPORT -# else -# define NB_CORE NB_IMPORT -# endif +#if defined(NB_BUILD) +#define NB_CORE NB_EXPORT +#else +#define NB_CORE NB_IMPORT +#endif #else -# define NB_CORE +#define NB_CORE #endif #if !defined(NB_SHARED) && defined(__GNUC__) && !defined(_WIN32) -# define NB_EXPORT_SHARED __attribute__ ((visibility("hidden"))) +#define NB_EXPORT_SHARED __attribute__((visibility("hidden"))) #else -# define NB_EXPORT_SHARED +#define NB_EXPORT_SHARED #endif diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index 7ecf200f34..3ce1be5625 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -4,10 +4,10 @@ NB_EXPORT PyObject* nrnpy_hoc(); extern "C" NB_EXPORT PyObject* nrn_hocobj_ptr(double*); extern "C" NB_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ); extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, - PyObject* plotshape_plot0, - PyObject* get_mech_object_0, - PyObject* store_savestate, - PyObject* restore_savestate); + PyObject* plotshape_plot0, + PyObject* get_mech_object_0, + PyObject* store_savestate, + PyObject* restore_savestate); extern "C" NB_EXPORT int nrnpy_set_gui_callback(PyObject*); extern "C" NB_EXPORT PyObject* get_plotshape_data(PyObject* sp); extern "C" NB_EXPORT int nrnpy_vec_math_register(PyObject* callback); diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index c4dea01f55..340394491d 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -1130,7 +1130,7 @@ void TaskQueue_exe_tasks(std::size_t thread_index, TaskQueue* q) { } -void set_num_threads(const int n) { +extern "C" void set_num_threads(const int n) { assert(n > 0); assert(NUM_THREADS > 0); // n and NUM_THREADS include the main thread, old_num and new_num refer to @@ -1184,7 +1184,7 @@ void TaskQueue_sync(TaskQueue* q) { q->waiting_cond.wait(lock, [q] { return q->length == 0; }); } -int get_num_threads(void) { +extern "C" int get_num_threads(void) { return NUM_THREADS; } diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 7371bca493..00deb987c6 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -7,7 +7,67 @@ #define SPECIES_ABSENT -1 #define PREFETCH 4 -typedef void (*fptr)(void); +using fptr = void (*)(void); + +extern "C" NB_EXPORT void rxd_set_no_diffusion(); +extern "C" NB_EXPORT void free_curr_ptrs(); +extern "C" NB_EXPORT void free_conc_ptrs(); +extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, + int* curr_index, + double* curr_scale, + PyHocObject** curr_ptrs); +extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, + int* conc_index, + PyHocObject** conc_ptrs); +extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, + int* grid_counts, + int* grids, + long* index, + double* scales, + PyObject** sources); +extern "C" NB_EXPORT void rxd_include_node_flux1D(int n, + long* index, + double* scales, + PyObject** sources); +extern "C" NB_EXPORT void rxd_set_euler_matrix(int nrow, + int nnonzero, + long* nonzero_i, + long* nonzero_j, + double* nonzero_values, + double* c_diagonal); +extern "C" NB_EXPORT void set_setup(const fptr setup_fn); +extern "C" NB_EXPORT void set_initialize(const fptr initialize_fn); +extern "C" NB_EXPORT void set_setup_matrices(fptr setup_matrices); +extern "C" NB_EXPORT void set_setup_units(fptr setup_units); +extern "C" NB_EXPORT void setup_currents(int num_currents, + int num_fluxes, + int* num_species, + int* node_idxs, + double* scales, + PyHocObject** ptrs, + int* mapped, + int* mapped_ecs); +extern "C" NB_EXPORT int rxd_nonvint_block(int method, int size, double* p1, double* p2, int); +extern "C" NB_EXPORT void register_rate(int nspecies, + int nparam, + int nregions, + int nseg, + int* sidx, + int necs, + int necsparam, + int* ecs_ids, + int* ecsidx, + int nmult, + double* mult, + PyHocObject** vptrs, + ReactionRate f); +extern "C" NB_EXPORT void clear_rates(); +extern "C" NB_EXPORT void species_atolscale(int id, double scale, int len, int* idx); +extern "C" NB_EXPORT void remove_species_atolscale(int id); +extern "C" NB_EXPORT void setup_solver(double* my_states, + int my_num_states, + long* zvi, + int num_zvi); // @olupton 2022-09-16: deleted a declaration of OcPtrVector that did not match // the one in ocptrvector.h @@ -81,11 +141,11 @@ typedef struct TaskQueue { struct TaskList* last; } TaskQueue; -extern "C" void set_num_threads(const int); +extern "C" NB_EXPORT void set_num_threads(const int); void _fadvance(void); void _fadvance_fixed_step_3D(void); -extern "C" int get_num_threads(void); +extern "C" NB_EXPORT int get_num_threads(void); void ecs_set_adi_tort(ECS_Grid_node*); void ecs_set_adi_vol(ECS_Grid_node*); void ecs_set_adi_homogeneous(ECS_Grid_node*); @@ -173,7 +233,23 @@ void _ode_reinit(double*); int ode_count(const int); -extern "C" void scatter_concentrations(void); +extern "C" NB_EXPORT void ics_register_reaction(int list_idx, + int num_species, + int num_params, + int* species_id, + uint64_t* mc3d_start_indices, + int mc3d_region_size, + double* mc3d_mults, + ECSReactionRate f); +extern "C" NB_EXPORT void ecs_register_reaction(int list_idx, + int num_species, + int num_params, + int* species_id, + ECSReactionRate f); +extern "C" NB_EXPORT void scatter_concentrations(void); + +extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2); +extern "C" NB_EXPORT double llpipedfromoriginvolume(double* p0, double* p1, double* p2); int find(const int, const int, const int, const int, const int); @@ -209,3 +285,26 @@ void TaskQueue_exe_tasks(std::size_t, TaskQueue*); void TaskQueue_sync(TaskQueue*); void ecs_atolscale(double*); void apply_node_flux3D(Grid_node*, double, double*); + +extern "C" NB_EXPORT int find_triangles(double thresh, + double value0, + double value1, + double value2, + double value3, + double value4, + double value5, + double value6, + double value7, + double x0, + double x1, + double y0, + double y1, + double z0, + double z1, + double* out); + +extern "C" NB_EXPORT double factorial(const double x); +extern "C" NB_EXPORT double degrees(const double radians); +extern "C" NB_EXPORT void radians(const double degrees, double* radians); +extern "C" NB_EXPORT double log1p(const double x); +extern "C" NB_EXPORT double vtrap(const double x, const double y); From 501bb9363a4fe0c52bf5d84b9ac80fd4376847f2 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 00:56:48 +0200 Subject: [PATCH 33/79] one left --- src/nrnpython/rxd.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 00deb987c6..39a3e7ff7c 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -308,3 +308,14 @@ extern "C" NB_EXPORT double degrees(const double radians); extern "C" NB_EXPORT void radians(const double degrees, double* radians); extern "C" NB_EXPORT double log1p(const double x); extern "C" NB_EXPORT double vtrap(const double x, const double y); + +extern "C" NB_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, + int64_t* num_3d_indices_per_grid, + int64_t* hybrid_indices1d, + int64_t* hybrid_indices3d, + int64_t* num_3d_indices_per_1d_seg, + int64_t* hybrid_grid_ids, + double* rates, + double* volumes1d, + double* volumes3d, + double* dxs); From 41ee749776a94238ce8ee42a15d36d7145d546a5 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 10:38:19 +0200 Subject: [PATCH 34/79] Extern in the right place NB_EXPORT the world --- src/nrnpython/rxd.h | 17 ----------------- src/nrnpython/rxd_marching_cubes.cpp | 4 +++- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 39a3e7ff7c..c0ce71b07b 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -286,23 +286,6 @@ void TaskQueue_sync(TaskQueue*); void ecs_atolscale(double*); void apply_node_flux3D(Grid_node*, double, double*); -extern "C" NB_EXPORT int find_triangles(double thresh, - double value0, - double value1, - double value2, - double value3, - double value4, - double value5, - double value6, - double value7, - double x0, - double x1, - double y0, - double y1, - double z0, - double z1, - double* out); - extern "C" NB_EXPORT double factorial(const double x); extern "C" NB_EXPORT double degrees(const double radians); extern "C" NB_EXPORT void radians(const double degrees, double* radians); diff --git a/src/nrnpython/rxd_marching_cubes.cpp b/src/nrnpython/rxd_marching_cubes.cpp index 7c3c7e16c1..0490f9ada9 100644 --- a/src/nrnpython/rxd_marching_cubes.cpp +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -8,6 +8,8 @@ #include #include +#include "nb_defs.h" + const int edgeTable[] = { 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, @@ -333,7 +335,7 @@ void vi(double* p1, double* p2, double v1, double v2, double* out) { out[2] = p1[2] + mu * (p2[2] - p1[2]); } -extern "C" int find_triangles(double thresh, +extern "C" NB_EXPORT int find_triangles(double thresh, double value0, double value1, double value2, From 59b124cd3d1e7f5def55092fbd5c151064d27cdc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 08:39:49 +0000 Subject: [PATCH 35/79] Fix formatting --- src/nrnpython/rxd_marching_cubes.cpp | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/nrnpython/rxd_marching_cubes.cpp b/src/nrnpython/rxd_marching_cubes.cpp index 0490f9ada9..fb19cdafa9 100644 --- a/src/nrnpython/rxd_marching_cubes.cpp +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -336,21 +336,21 @@ void vi(double* p1, double* p2, double v1, double v2, double* out) { } extern "C" NB_EXPORT int find_triangles(double thresh, - double value0, - double value1, - double value2, - double value3, - double value4, - double value5, - double value6, - double value7, - double x0, - double x1, - double y0, - double y1, - double z0, - double z1, - double* out) { + double value0, + double value1, + double value2, + double value3, + double value4, + double value5, + double value6, + double value7, + double x0, + double x1, + double y0, + double y1, + double z0, + double z1, + double* out) { double position[8][3] = {{x0, y0, z0}, {x1, y0, z0}, {x1, y1, z0}, From 26c15adab05af51b6f96af8b4e0945bbe3f94ade Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 11:13:49 +0200 Subject: [PATCH 36/79] Simplify export --- src/nrnpython/grids.cpp | 14 ++--- src/nrnpython/grids.h | 25 -------- src/nrnpython/inithoc.cpp | 6 +- src/nrnpython/inithoc.hpp | 9 --- src/nrnpython/rxd.cpp | 38 ++++++------ src/nrnpython/rxd.h | 94 ----------------------------- src/nrnpython/rxd_extracellular.cpp | 6 +- src/nrnpython/rxd_intracellular.cpp | 2 +- src/nrnpython/rxd_llgramarea.cpp | 6 +- src/nrnpython/rxdmath.cpp | 13 ++-- 10 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 src/nrnpython/inithoc.hpp diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 2872a317f4..24bf852b5c 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -462,7 +462,7 @@ extern "C" int set_diffusion(int grid_list_index, int grid_id, double* dc, int l return 0; } -extern "C" int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { +extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -513,7 +513,7 @@ void ECS_Grid_node::set_tortuosity(PyHocObject* my_permeability) { } } -extern "C" int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { +extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -585,7 +585,7 @@ void ECS_Grid_node::set_diffusion(double* dc, int) { } -extern "C" void ics_set_grid_concentrations(int grid_list_index, +extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, int index_in_list, int64_t* nodes_per_seg, int64_t* nodes_per_seg_start_indices, @@ -610,7 +610,7 @@ extern "C" void ics_set_grid_concentrations(int grid_list_index, } } -extern "C" void ics_set_grid_currents(int grid_list_index, +extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, int index_in_list, PyObject* neuron_pointers, double* scale_factors) { @@ -634,7 +634,7 @@ extern "C" void ics_set_grid_currents(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ -extern "C" void set_grid_concentrations(int grid_list_index, +extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, int index_in_list, PyObject* grid_indices, PyObject* neuron_pointers) { @@ -675,7 +675,7 @@ extern "C" void set_grid_concentrations(int grid_list_index, } /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ -extern "C" void set_grid_currents(int grid_list_index, +extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, int index_in_list, PyObject* grid_indices, PyObject* neuron_pointers, @@ -780,7 +780,7 @@ int remove(Grid_node** head, Grid_node* find) { return 1; } -extern "C" void delete_by_id(int id) { +extern "C" NB_EXPORT void delete_by_id(int id) { Grid_node* grid; int k; for (k = 0, grid = Parallel_grids[0]; grid != NULL; grid = grid->next, k++) { diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index a39b9cff82..de5351d93e 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -477,31 +477,6 @@ extern "C" NB_EXPORT int ICS_insert_inhom(int grid_list_index, // Set the diffusion coefficients for a given grid_id extern "C" NB_EXPORT int set_diffusion(int, int, double*, int); -extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, - int grid_id, - PyHocObject* my_permeability); -extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, - int grid_id, - PyHocObject* my_alpha); -extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, - int index_in_list, - int64_t* nodes_per_seg, - int64_t* nodes_per_seg_start_indices, - PyObject* neuron_pointers); -extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* neuron_pointers, - double* scale_factors); -extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers); -extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers, - PyObject* scale_factors); -extern "C" NB_EXPORT void delete_by_id(int id); // Delete a specific Grid_node "find" from the list "head" int remove(Grid_node** head, Grid_node* find); diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index b84798b30e..0e54ed8dbf 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -1,6 +1,6 @@ #include "../../nrnconf.h" -#include "inithoc.hpp" +#include "nb_defs.h" #include "nrnmpiuse.h" #include @@ -224,7 +224,7 @@ void nrnpython_finalize() { static char* env[] = {0}; -extern "C" PyObject* PyInit_hoc() { +extern "C" NB_EXPORT PyObject* PyInit_hoc() { #if NRN_ENABLE_THREADS main_thread_ = std::this_thread::get_id(); #endif @@ -371,5 +371,5 @@ extern "C" PyObject* PyInit_hoc() { } #if !defined(MINGW) -extern "C" void modl_reg() {} +extern "C" NB_EXPORT void modl_reg() {} #endif // !defined(MINGW) diff --git a/src/nrnpython/inithoc.hpp b/src/nrnpython/inithoc.hpp deleted file mode 100644 index 5e9541e2cf..0000000000 --- a/src/nrnpython/inithoc.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "nb_defs.h" - -struct _object; -using PyObject = struct _object; - -extern "C" NB_EXPORT PyObject* PyInit_hoc(); -#if !defined(MINHG) -extern "C" NB_EXPORT void modl_reg(); -#endif diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 340394491d..212b7a99c0 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -138,7 +138,7 @@ static inline void* allocopy(void* src, size_t size) { return dst; } -extern "C" void rxd_set_no_diffusion() { +extern "C" NB_EXPORT void rxd_set_no_diffusion() { int i; diffusion = FALSE; if (_rxd_a != NULL) { @@ -154,7 +154,7 @@ extern "C" void rxd_set_no_diffusion() { } } -extern "C" void free_curr_ptrs() { +extern "C" NB_EXPORT void free_curr_ptrs() { _curr_count = 0; if (_curr_indices != NULL) free(_curr_indices); @@ -165,7 +165,7 @@ extern "C" void free_curr_ptrs() { _curr_ptrs.clear(); } -extern "C" void free_conc_ptrs() { +extern "C" NB_EXPORT void free_conc_ptrs() { _conc_count = 0; if (_conc_indices != NULL) free(_conc_indices); @@ -174,7 +174,7 @@ extern "C" void free_conc_ptrs() { } -extern "C" void rxd_setup_curr_ptrs(int num_currents, +extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, int* curr_index, double* curr_scale, PyHocObject** curr_ptrs) { @@ -192,7 +192,7 @@ extern "C" void rxd_setup_curr_ptrs(int num_currents, _curr_ptrs[i] = curr_ptrs[i]->u.px_; } -extern "C" void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { +extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { /* info for NEURON concentration - to transfer to legacy */ int i; free_conc_ptrs(); @@ -204,7 +204,7 @@ extern "C" void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject _conc_ptrs[i] = conc_ptrs[i]->u.px_; } -extern "C" void rxd_include_node_flux3D(int grid_count, +extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, int* grid_counts, int* grids, long* index, @@ -288,7 +288,7 @@ extern "C" void rxd_include_node_flux3D(int grid_count, } } -extern "C" void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { +extern "C" NB_EXPORT void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { if (_node_flux_count != 0) { free(_node_flux_idx); free(_node_flux_scale); @@ -348,7 +348,7 @@ static void apply_node_flux1D(double dt, double* states) { apply_node_flux(_node_flux_count, _node_flux_idx, _node_flux_scale, _node_flux_src, dt, states); } -extern "C" void rxd_set_euler_matrix(int nrow, +extern "C" NB_EXPORT void rxd_set_euler_matrix(int nrow, int nnonzero, long* nonzero_i, long* nonzero_j, @@ -470,20 +470,20 @@ static void mul(int nnonzero, } } -extern "C" void set_setup(const fptr setup_fn) { +extern "C" NB_EXPORT void set_setup(const fptr setup_fn) { _setup = setup_fn; } -extern "C" void set_initialize(const fptr initialize_fn) { +extern "C" NB_EXPORT void set_initialize(const fptr initialize_fn) { _initialize = initialize_fn; set_num_threads(NUM_THREADS); } -extern "C" void set_setup_matrices(fptr setup_matrices) { +extern "C" NB_EXPORT void set_setup_matrices(fptr setup_matrices) { _setup_matrices = setup_matrices; } -extern "C" void set_setup_units(fptr setup_units) { +extern "C" NB_EXPORT void set_setup_units(fptr setup_units) { _setup_units = setup_units; } @@ -623,7 +623,7 @@ static void free_currents() { _membrane_flux = FALSE; } -extern "C" void setup_currents(int num_currents, +extern "C" NB_EXPORT void setup_currents(int num_currents, int num_fluxes, int* num_species, int* node_idxs, @@ -766,7 +766,7 @@ static void _currents(double* rhs) { } } -extern "C" int rxd_nonvint_block(int method, int size, double* p1, double* p2, int) { +extern "C" NB_EXPORT int rxd_nonvint_block(int method, int size, double* p1, double* p2, int) { if (initialized) { if (structure_change_cnt != prev_structure_change_cnt) { /*TODO: Exclude irrelevant (non-rxd) structural changes*/ @@ -846,7 +846,7 @@ extern "C" int rxd_nonvint_block(int method, int size, double* p1, double* p2, i *****************************************************************************/ -extern "C" void register_rate(int nspecies, +extern "C" NB_EXPORT void register_rate(int nspecies, int nparam, int nregions, int nseg, @@ -965,7 +965,7 @@ extern "C" void register_rate(int nspecies, } } -extern "C" void clear_rates() { +extern "C" NB_EXPORT void clear_rates() { ICSReactions *react, *prev; int i, j; for (react = _reactions; react != NULL;) { @@ -1003,7 +1003,7 @@ extern "C" void clear_rates() { } -extern "C" void species_atolscale(int id, double scale, int len, int* idx) { +extern "C" NB_EXPORT void species_atolscale(int id, double scale, int len, int* idx) { SpeciesIndexList* list; SpeciesIndexList* prev; if (species_indices != NULL) { @@ -1028,7 +1028,7 @@ extern "C" void species_atolscale(int id, double scale, int len, int* idx) { list->next = NULL; } -extern "C" void remove_species_atolscale(int id) { +extern "C" NB_EXPORT void remove_species_atolscale(int id) { SpeciesIndexList* list; SpeciesIndexList* prev; for (list = species_indices, prev = NULL; list != NULL; prev = list, list = list->next) { @@ -1044,7 +1044,7 @@ extern "C" void remove_species_atolscale(int id) { } } -extern "C" void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { +extern "C" NB_EXPORT void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { free_currents(); states = my_states; num_states = my_num_states; diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index c0ce71b07b..e1cada9ea8 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -9,66 +9,6 @@ using fptr = void (*)(void); -extern "C" NB_EXPORT void rxd_set_no_diffusion(); -extern "C" NB_EXPORT void free_curr_ptrs(); -extern "C" NB_EXPORT void free_conc_ptrs(); -extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, - int* curr_index, - double* curr_scale, - PyHocObject** curr_ptrs); -extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, - int* conc_index, - PyHocObject** conc_ptrs); -extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, - int* grid_counts, - int* grids, - long* index, - double* scales, - PyObject** sources); -extern "C" NB_EXPORT void rxd_include_node_flux1D(int n, - long* index, - double* scales, - PyObject** sources); -extern "C" NB_EXPORT void rxd_set_euler_matrix(int nrow, - int nnonzero, - long* nonzero_i, - long* nonzero_j, - double* nonzero_values, - double* c_diagonal); -extern "C" NB_EXPORT void set_setup(const fptr setup_fn); -extern "C" NB_EXPORT void set_initialize(const fptr initialize_fn); -extern "C" NB_EXPORT void set_setup_matrices(fptr setup_matrices); -extern "C" NB_EXPORT void set_setup_units(fptr setup_units); -extern "C" NB_EXPORT void setup_currents(int num_currents, - int num_fluxes, - int* num_species, - int* node_idxs, - double* scales, - PyHocObject** ptrs, - int* mapped, - int* mapped_ecs); -extern "C" NB_EXPORT int rxd_nonvint_block(int method, int size, double* p1, double* p2, int); -extern "C" NB_EXPORT void register_rate(int nspecies, - int nparam, - int nregions, - int nseg, - int* sidx, - int necs, - int necsparam, - int* ecs_ids, - int* ecsidx, - int nmult, - double* mult, - PyHocObject** vptrs, - ReactionRate f); -extern "C" NB_EXPORT void clear_rates(); -extern "C" NB_EXPORT void species_atolscale(int id, double scale, int len, int* idx); -extern "C" NB_EXPORT void remove_species_atolscale(int id); -extern "C" NB_EXPORT void setup_solver(double* my_states, - int my_num_states, - long* zvi, - int num_zvi); - // @olupton 2022-09-16: deleted a declaration of OcPtrVector that did not match // the one in ocptrvector.h @@ -233,25 +173,8 @@ void _ode_reinit(double*); int ode_count(const int); -extern "C" NB_EXPORT void ics_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - uint64_t* mc3d_start_indices, - int mc3d_region_size, - double* mc3d_mults, - ECSReactionRate f); -extern "C" NB_EXPORT void ecs_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - ECSReactionRate f); extern "C" NB_EXPORT void scatter_concentrations(void); -extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2); -extern "C" NB_EXPORT double llpipedfromoriginvolume(double* p0, double* p1, double* p2); - - int find(const int, const int, const int, const int, const int); void _ics_hybrid_helper(ICS_Grid_node*); @@ -285,20 +208,3 @@ void TaskQueue_exe_tasks(std::size_t, TaskQueue*); void TaskQueue_sync(TaskQueue*); void ecs_atolscale(double*); void apply_node_flux3D(Grid_node*, double, double*); - -extern "C" NB_EXPORT double factorial(const double x); -extern "C" NB_EXPORT double degrees(const double radians); -extern "C" NB_EXPORT void radians(const double degrees, double* radians); -extern "C" NB_EXPORT double log1p(const double x); -extern "C" NB_EXPORT double vtrap(const double x, const double y); - -extern "C" NB_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, - int64_t* num_3d_indices_per_grid, - int64_t* hybrid_indices1d, - int64_t* hybrid_indices3d, - int64_t* num_3d_indices_per_1d_seg, - int64_t* hybrid_grid_ids, - double* rates, - double* volumes1d, - double* volumes3d, - double* dxs); diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index c297b65be8..f5000e8034 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -9,6 +9,8 @@ #include #include +#include "nb_defs.h" + #define loc(x, y, z) ((z) + (y) *grid->size_z + (x) *grid->size_z * grid->size_y) static void ecs_refresh_reactions(int); @@ -163,7 +165,7 @@ Reaction* ecs_create_reaction(int list_idx, * grid_id - the grid id within the linked list - this corresponds to species * ECSReactionRate - the reaction function */ -extern "C" void ics_register_reaction(int list_idx, +extern "C" NB_EXPORT void ics_register_reaction(int list_idx, int num_species, int num_params, int* species_id, @@ -189,7 +191,7 @@ extern "C" void ics_register_reaction(int list_idx, * grid_id - the grid id within the linked list - this corresponds to species * ECSReactionRate - the reaction function */ -extern "C" void ecs_register_reaction(int list_idx, +extern "C" NB_EXPORT void ecs_register_reaction(int list_idx, int num_species, int num_params, int* species_id, diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index d083eeb569..fcda716803 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -19,7 +19,7 @@ const int ICS_PREFETCH = 3; /* * Sets the data to be used by the grids for 1D/3D hybrid models */ -extern "C" void set_hybrid_data(int64_t* num_1d_indices_per_grid, +extern "C" NB_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, int64_t* num_3d_indices_per_grid, int64_t* hybrid_indices1d, int64_t* hybrid_indices3d, diff --git a/src/nrnpython/rxd_llgramarea.cpp b/src/nrnpython/rxd_llgramarea.cpp index c4875f7c54..fb9c992dbb 100644 --- a/src/nrnpython/rxd_llgramarea.cpp +++ b/src/nrnpython/rxd_llgramarea.cpp @@ -1,6 +1,8 @@ #include -extern "C" double llgramarea(double* p0, double* p1, double* p2) { +#include "nb_defs.h" + +extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2) { /* setup the vectors */ double a[] = {p0[0] - p1[0], p0[1] - p1[1], p0[2] - p1[2]}; double b[] = {p0[0] - p2[0], p0[1] - p2[1], p0[2] - p2[2]}; @@ -13,7 +15,7 @@ extern "C" double llgramarea(double* p0, double* p1, double* p2) { } -extern "C" double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { +extern "C" NB_EXPORT double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { /* take the cross-product */ double cpx = p1[1] * p2[2] - p1[2] * p2[1]; double cpy = p1[2] * p2[0] - p1[0] * p2[2]; diff --git a/src/nrnpython/rxdmath.cpp b/src/nrnpython/rxdmath.cpp index 3b3e4a2aed..c918e1214d 100644 --- a/src/nrnpython/rxdmath.cpp +++ b/src/nrnpython/rxdmath.cpp @@ -1,4 +1,7 @@ #include + +#include "nb_defs.h" + #ifndef M_PI #define M_PI (3.14159265358979323846) #endif @@ -7,25 +10,25 @@ * names and arguments match the wrappers used in rxdmath.py */ -extern "C" double factorial(const double x) { +extern "C" NB_EXPORT double factorial(const double x) { return tgamma(x + 1.); } -extern "C" double degrees(const double radians) { +extern "C" NB_EXPORT double degrees(const double radians) { return radians * (180. / M_PI); } -extern "C" void radians(const double degrees, double* radians) { +extern "C" NB_EXPORT void radians(const double degrees, double* radians) { *radians = degrees * (M_PI / 180.); } -extern "C" double log1p(const double x) { +extern "C" NB_EXPORT double log1p(const double x) { return log(x + 1.); } -extern "C" double vtrap(const double x, const double y) { +extern "C" NB_EXPORT double vtrap(const double x, const double y) { if (fabs(x / y) < 1e-6) { return y * (1.0 - x / y / 2.0); } else { From 6d0f99806fb39922038f6000c744eaf113093d46 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 09:17:26 +0000 Subject: [PATCH 37/79] Fix formatting --- src/nrnpython/grids.cpp | 36 +++++++------ src/nrnpython/rxd.cpp | 78 ++++++++++++++++------------- src/nrnpython/rxd_extracellular.cpp | 22 ++++---- src/nrnpython/rxd_intracellular.cpp | 18 +++---- 4 files changed, 83 insertions(+), 71 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 24bf852b5c..bc4d0bb402 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -462,7 +462,9 @@ extern "C" int set_diffusion(int grid_list_index, int grid_id, double* dc, int l return 0; } -extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { +extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, + int grid_id, + PyHocObject* my_permeability) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -513,7 +515,9 @@ void ECS_Grid_node::set_tortuosity(PyHocObject* my_permeability) { } } -extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { +extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, + int grid_id, + PyHocObject* my_alpha) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -586,10 +590,10 @@ void ECS_Grid_node::set_diffusion(double* dc, int) { extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, - int index_in_list, - int64_t* nodes_per_seg, - int64_t* nodes_per_seg_start_indices, - PyObject* neuron_pointers) { + int index_in_list, + int64_t* nodes_per_seg, + int64_t* nodes_per_seg_start_indices, + PyObject* neuron_pointers) { Grid_node* g; ssize_t i; ssize_t n = (ssize_t) PyList_Size(neuron_pointers); // number of segments. @@ -611,9 +615,9 @@ extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, } extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* neuron_pointers, - double* scale_factors) { + int index_in_list, + PyObject* neuron_pointers, + double* scale_factors) { Grid_node* g; ssize_t i; ssize_t n = (ssize_t) PyList_Size(neuron_pointers); @@ -635,9 +639,9 @@ extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers) { + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers) { /* Preconditions: @@ -676,10 +680,10 @@ extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers, - PyObject* scale_factors) { + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers, + PyObject* scale_factors) { /* Preconditions: diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 212b7a99c0..37c188923b 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -175,9 +175,9 @@ extern "C" NB_EXPORT void free_conc_ptrs() { extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, - int* curr_index, - double* curr_scale, - PyHocObject** curr_ptrs) { + int* curr_index, + double* curr_scale, + PyHocObject** curr_ptrs) { free_curr_ptrs(); /* info for NEURON currents - to update states */ _curr_count = num_currents; @@ -192,7 +192,9 @@ extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, _curr_ptrs[i] = curr_ptrs[i]->u.px_; } -extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { +extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, + int* conc_index, + PyHocObject** conc_ptrs) { /* info for NEURON concentration - to transfer to legacy */ int i; free_conc_ptrs(); @@ -205,11 +207,11 @@ extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, int* conc_index, P } extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, - int* grid_counts, - int* grids, - long* index, - double* scales, - PyObject** sources) { + int* grid_counts, + int* grids, + long* index, + double* scales, + PyObject** sources) { Grid_node* g; int i = 0, j, k, n, grid_id; int offset = 0; @@ -288,7 +290,10 @@ extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, } } -extern "C" NB_EXPORT void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { +extern "C" NB_EXPORT void rxd_include_node_flux1D(int n, + long* index, + double* scales, + PyObject** sources) { if (_node_flux_count != 0) { free(_node_flux_idx); free(_node_flux_scale); @@ -349,11 +354,11 @@ static void apply_node_flux1D(double dt, double* states) { } extern "C" NB_EXPORT void rxd_set_euler_matrix(int nrow, - int nnonzero, - long* nonzero_i, - long* nonzero_j, - double* nonzero_values, - double* c_diagonal) { + int nnonzero, + long* nonzero_i, + long* nonzero_j, + double* nonzero_values, + double* c_diagonal) { long i, j, idx; double val; unsigned int k, ps; @@ -624,13 +629,13 @@ static void free_currents() { } extern "C" NB_EXPORT void setup_currents(int num_currents, - int num_fluxes, - int* num_species, - int* node_idxs, - double* scales, - PyHocObject** ptrs, - int* mapped, - int* mapped_ecs) { + int num_fluxes, + int* num_species, + int* node_idxs, + double* scales, + PyHocObject** ptrs, + int* mapped, + int* mapped_ecs) { int i, j, k, id, side, count; int* induced_currents_ecs_idx; int* induced_currents_grid_id; @@ -847,18 +852,18 @@ extern "C" NB_EXPORT int rxd_nonvint_block(int method, int size, double* p1, dou extern "C" NB_EXPORT void register_rate(int nspecies, - int nparam, - int nregions, - int nseg, - int* sidx, - int necs, - int necsparam, - int* ecs_ids, - int* ecsidx, - int nmult, - double* mult, - PyHocObject** vptrs, - ReactionRate f) { + int nparam, + int nregions, + int nseg, + int* sidx, + int necs, + int necsparam, + int* ecs_ids, + int* ecsidx, + int nmult, + double* mult, + PyHocObject** vptrs, + ReactionRate f) { int i, j, k, idx, ecs_id, ecs_index, ecs_offset; unsigned char counted; Grid_node* g; @@ -1044,7 +1049,10 @@ extern "C" NB_EXPORT void remove_species_atolscale(int id) { } } -extern "C" NB_EXPORT void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { +extern "C" NB_EXPORT void setup_solver(double* my_states, + int my_num_states, + long* zvi, + int num_zvi) { free_currents(); states = my_states; num_states = my_num_states; diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index f5000e8034..6ae12b7227 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -166,13 +166,13 @@ Reaction* ecs_create_reaction(int list_idx, * ECSReactionRate - the reaction function */ extern "C" NB_EXPORT void ics_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - uint64_t* mc3d_start_indices, - int mc3d_region_size, - double* mc3d_mults, - ECSReactionRate f) { + int num_species, + int num_params, + int* species_id, + uint64_t* mc3d_start_indices, + int mc3d_region_size, + double* mc3d_mults, + ECSReactionRate f) { ecs_create_reaction(list_idx, num_species, num_params, @@ -192,10 +192,10 @@ extern "C" NB_EXPORT void ics_register_reaction(int list_idx, * ECSReactionRate - the reaction function */ extern "C" NB_EXPORT void ecs_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - ECSReactionRate f) { + int num_species, + int num_params, + int* species_id, + ECSReactionRate f) { ecs_create_reaction(list_idx, num_species, num_params, species_id, f, NULL, NULL, 0, NULL); ecs_refresh_reactions(NUM_THREADS); } diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index fcda716803..27097c3002 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -20,15 +20,15 @@ const int ICS_PREFETCH = 3; * Sets the data to be used by the grids for 1D/3D hybrid models */ extern "C" NB_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, - int64_t* num_3d_indices_per_grid, - int64_t* hybrid_indices1d, - int64_t* hybrid_indices3d, - int64_t* num_3d_indices_per_1d_seg, - int64_t* hybrid_grid_ids, - double* rates, - double* volumes1d, - double* volumes3d, - double* dxs) { + int64_t* num_3d_indices_per_grid, + int64_t* hybrid_indices1d, + int64_t* hybrid_indices3d, + int64_t* num_3d_indices_per_1d_seg, + int64_t* hybrid_grid_ids, + double* rates, + double* volumes1d, + double* volumes3d, + double* dxs) { Grid_node* grid; int i, j, k, id; int grid_id_check = 0; From 8087f23e5b6c0dc62293b1ffbc568eb301305aeb Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 11:35:02 +0200 Subject: [PATCH 38/79] make_time_ptr --- src/nrnpython/grids.cpp | 2 +- src/nrnpython/grids.h | 3 --- src/nrnpython/nb_defs.h | 36 ------------------------------------ 3 files changed, 1 insertion(+), 40 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 24bf852b5c..12b75ab140 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -25,7 +25,7 @@ extern double* _rxd_induced_currents_ecs; extern double* _rxd_induced_currents_scale; // Set dt, t pointers -extern "C" void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr) { +extern "C" NB_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr) { dt_ptr = static_cast(my_dt_ptr->u.px_); t_ptr = static_cast(my_t_ptr->u.px_); } diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index de5351d93e..27659671e4 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -395,9 +395,6 @@ extern Grid_node* Parallel_grids[100]; // Array of Grid_node * lists // Set the global ∆t void make_dt_ptr(PyHocObject* my_dt_ptr); - -extern "C" NB_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr); - // Create a single Grid_node /* Parameters: Python object that includes array of double pointers, size of x, y, and z dimensions diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h index 0ef934a826..11c9cbcda1 100644 --- a/src/nrnpython/nb_defs.h +++ b/src/nrnpython/nb_defs.h @@ -11,39 +11,3 @@ #define NB_IMPORT NB_EXPORT #define NB_INLINE inline __attribute__((always_inline)) #define NB_NOINLINE __attribute__((noinline)) -#if defined(__clang__) -#define NB_INLINE_LAMBDA __attribute__((always_inline)) -#else -#define NB_INLINE_LAMBDA -#endif -#endif - -#if defined(__GNUC__) && !defined(_WIN32) -#define NB_NAMESPACE nanobind __attribute__((visibility("hidden"))) -#else -#define NB_NAMESPACE nanobind -#endif - -#if defined(__GNUC__) -#define NB_UNLIKELY(x) __builtin_expect(bool(x), 0) -#define NB_LIKELY(x) __builtin_expect(bool(x), 1) -#else -#define NB_LIKELY(x) x -#define NB_UNLIKELY(x) x -#endif - -#if defined(NB_SHARED) -#if defined(NB_BUILD) -#define NB_CORE NB_EXPORT -#else -#define NB_CORE NB_IMPORT -#endif -#else -#define NB_CORE -#endif - -#if !defined(NB_SHARED) && defined(__GNUC__) && !defined(_WIN32) -#define NB_EXPORT_SHARED __attribute__((visibility("hidden"))) -#else -#define NB_EXPORT_SHARED -#endif From c912b00d12eb50382d0aca36f89c06deb83d6223 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 11:45:01 +0200 Subject: [PATCH 39/79] Revert "Simplify CI" This reverts commit 0e889f22ba7b76fc14c5c4742a31cc1b9c49a62a. --- .github/workflows/windows.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 62aa54ad86..d77f7ec8ac 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -75,6 +75,10 @@ jobs: # To enable it, you have to: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) + - name: live debug session on failure (manual steps required, check `.github/windows.yml`) + if: failure() + uses: mxschmitt/action-tmate@v3 + - name: Upload build artifact uses: actions/upload-artifact@v4 with: @@ -91,10 +95,6 @@ jobs: shell: cmd working-directory: ${{runner.workspace}}\nrn - - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() - uses: mxschmitt/action-tmate@v3 - - name: Publish Release Installer working-directory: ${{runner.workspace}}\nrn if: inputs.tag != '' From d8eee4376ed1eeb64d90baaf59326bdf43c52164 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 11:45:11 +0200 Subject: [PATCH 40/79] Revert "Debug windows..." This reverts commit 47c3167b2631228e1326c84464b42fb9194cb5b9. --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d77f7ec8ac..985eae0ae0 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -76,7 +76,7 @@ jobs: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() + if: failure() && contains(github.event.pull_request.title, 'live-debug-win') uses: mxschmitt/action-tmate@v3 - name: Upload build artifact From 8201d103050b5ff23d753bfd8a4921e05307860c Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 11:47:20 +0200 Subject: [PATCH 41/79] Miss one endif --- src/nrnpython/nb_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h index 11c9cbcda1..fd39e25614 100644 --- a/src/nrnpython/nb_defs.h +++ b/src/nrnpython/nb_defs.h @@ -11,3 +11,4 @@ #define NB_IMPORT NB_EXPORT #define NB_INLINE inline __attribute__((always_inline)) #define NB_NOINLINE __attribute__((noinline)) +#endif From 8b7200ac8c0485c98e87b4fe261d2a46c4dfceb0 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 14:22:08 +0200 Subject: [PATCH 42/79] shortened nb_defs.h --- src/nrnpython/nb_defs.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h index fd39e25614..f3fa4f8159 100644 --- a/src/nrnpython/nb_defs.h +++ b/src/nrnpython/nb_defs.h @@ -2,13 +2,6 @@ #if defined(_WIN32) #define NB_EXPORT __declspec(dllexport) -#define NB_IMPORT __declspec(dllimport) -#define NB_INLINE __forceinline -#define NB_NOINLINE __declspec(noinline) -#define NB_INLINE_LAMBDA #else #define NB_EXPORT __attribute__((visibility("default"))) -#define NB_IMPORT NB_EXPORT -#define NB_INLINE inline __attribute__((always_inline)) -#define NB_NOINLINE __attribute__((noinline)) #endif From 9832d252790e375b970a4fafe71f68e1a042bb27 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 12:23:46 +0000 Subject: [PATCH 43/79] Fix formatting --- src/nrnpython/nb_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h index f3fa4f8159..0eb3085755 100644 --- a/src/nrnpython/nb_defs.h +++ b/src/nrnpython/nb_defs.h @@ -1,7 +1,7 @@ #pragma once #if defined(_WIN32) -#define NB_EXPORT __declspec(dllexport) +#define NB_EXPORT __declspec(dllexport) #else -#define NB_EXPORT __attribute__((visibility("default"))) +#define NB_EXPORT __attribute__((visibility("default"))) #endif From 430b64d887c958e3aa125c139a6c49a499fbffba Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 14:25:13 +0200 Subject: [PATCH 44/79] Use nanobind nb_defs --- src/nrnpython/grids.h | 2 +- src/nrnpython/nrnpython.h | 2 +- src/nrnpython/rxd_extracellular.cpp | 2 +- src/nrnpython/rxd_llgramarea.cpp | 2 +- src/nrnpython/rxd_marching_cubes.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 27659671e4..05252f93a9 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -4,7 +4,7 @@ Date: 10/28/16 Description: Header File for grids.cpp. Allows access to Grid_node and Flux_pair structs and their respective functions ******************************************************************/ -#include "nb_defs.h" +#include #include #include diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 472411317a..aa7166bc90 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -1,6 +1,6 @@ #pragma once -#include "nb_defs.h" +#include #ifdef _WIN64 #define MS_WIN64 diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index 6ae12b7227..c3b69e1257 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -9,7 +9,7 @@ #include #include -#include "nb_defs.h" +#include #define loc(x, y, z) ((z) + (y) *grid->size_z + (x) *grid->size_z * grid->size_y) diff --git a/src/nrnpython/rxd_llgramarea.cpp b/src/nrnpython/rxd_llgramarea.cpp index fb9c992dbb..335260ec08 100644 --- a/src/nrnpython/rxd_llgramarea.cpp +++ b/src/nrnpython/rxd_llgramarea.cpp @@ -1,6 +1,6 @@ #include -#include "nb_defs.h" +#include extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2) { /* setup the vectors */ diff --git a/src/nrnpython/rxd_marching_cubes.cpp b/src/nrnpython/rxd_marching_cubes.cpp index fb19cdafa9..6804b72792 100644 --- a/src/nrnpython/rxd_marching_cubes.cpp +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -8,7 +8,7 @@ #include #include -#include "nb_defs.h" +#include const int edgeTable[] = { 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, From 2729efc2bd7cc1f983aec7d1c77bbaf82fa3da3a Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 15:07:50 +0200 Subject: [PATCH 45/79] Fix comments from Luc --- cmake/ExternalProjectHelper.cmake | 3 +-- src/nrnpython/rxd_llgramarea.cpp | 2 +- src/nrnpython/rxdmath.cpp | 12 +++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 3701f62ebc..78cc026818 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,8 +29,7 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - # Shallow clone by default. Developers should clone recursivelly - COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init --depth=1 -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) diff --git a/src/nrnpython/rxd_llgramarea.cpp b/src/nrnpython/rxd_llgramarea.cpp index 335260ec08..fb9c992dbb 100644 --- a/src/nrnpython/rxd_llgramarea.cpp +++ b/src/nrnpython/rxd_llgramarea.cpp @@ -1,6 +1,6 @@ #include -#include +#include "nb_defs.h" extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2) { /* setup the vectors */ diff --git a/src/nrnpython/rxdmath.cpp b/src/nrnpython/rxdmath.cpp index c918e1214d..d50af10fdb 100644 --- a/src/nrnpython/rxdmath.cpp +++ b/src/nrnpython/rxdmath.cpp @@ -1,7 +1,5 @@ #include -#include "nb_defs.h" - #ifndef M_PI #define M_PI (3.14159265358979323846) #endif @@ -10,25 +8,25 @@ * names and arguments match the wrappers used in rxdmath.py */ -extern "C" NB_EXPORT double factorial(const double x) { +extern "C" double factorial(const double x) { return tgamma(x + 1.); } -extern "C" NB_EXPORT double degrees(const double radians) { +extern "C" double degrees(const double radians) { return radians * (180. / M_PI); } -extern "C" NB_EXPORT void radians(const double degrees, double* radians) { +extern "C" void radians(const double degrees, double* radians) { *radians = degrees * (M_PI / 180.); } -extern "C" NB_EXPORT double log1p(const double x) { +extern "C" double log1p(const double x) { return log(x + 1.); } -extern "C" NB_EXPORT double vtrap(const double x, const double y) { +extern "C" double vtrap(const double x, const double y) { if (fabs(x / y) < 1e-6) { return y * (1.0 - x / y / 2.0); } else { From 3f537fa78e82cf604326a7121b63cf7979c6978b Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 15:09:12 +0200 Subject: [PATCH 46/79] Don't modify External --- cmake/ExternalProjectHelper.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 78cc026818..3abadf7e58 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,7 +29,7 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) From d01812007ca79858a4438f8a61d5d0e69a4f2f8d Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 15:11:23 +0200 Subject: [PATCH 47/79] Reduce size of modification --- src/nrnpython/nrnpy_hoc.cpp | 16 ++++++++-------- src/nrnpython/nrnpy_hoc.h | 13 ------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index cec83073b1..232e1f1c93 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -922,7 +922,7 @@ PyObject* nrn_hocobj_handle(neuron::container::data_handle d) { return result; } -extern "C" PyObject* nrn_hocobj_ptr(double* pd) { +extern "C" NB_EXPORT PyObject* nrn_hocobj_ptr(double* pd) { return nrn_hocobj_handle(neuron::container::data_handle{pd}); } @@ -2525,7 +2525,7 @@ static IvocVect* nrnpy_vec_from_python(void* v) { } static PyObject* (*vec_as_numpy)(int, double*); -extern "C" int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ) { +extern "C" NB_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ) { vec_as_numpy = p; return 0; } @@ -2579,7 +2579,7 @@ static void nrnpy_restore_savestate_(int64_t size, char* data) { } } -extern "C" int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, +extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, PyObject* plotshape_plot0, PyObject* get_mech_object_0, PyObject* store_savestate, @@ -2595,7 +2595,7 @@ extern "C" int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, } static PyObject* gui_callback = NULL; -extern "C" int nrnpy_set_gui_callback(PyObject* new_gui_callback) { +extern "C" NB_EXPORT int nrnpy_set_gui_callback(PyObject* new_gui_callback) { gui_callback = new_gui_callback; return 0; } @@ -2815,7 +2815,7 @@ static Object* rvp_rxd_to_callable_(Object* obj) { } -extern "C" PyObject* get_plotshape_data(PyObject* sp) { +extern "C" NB_EXPORT PyObject* get_plotshape_data(PyObject* sp) { PyHocObject* pho = (PyHocObject*) sp; ShapePlotInterface* spi; if (!is_obj_type(pho->ho_, "PlotShape")) { @@ -3048,12 +3048,12 @@ static void add2topdict(PyObject* dict) { static PyObject* nrnpy_vec_math = NULL; -extern "C" int nrnpy_vec_math_register(PyObject* callback) { +extern "C" NB_EXPORT int nrnpy_vec_math_register(PyObject* callback) { nrnpy_vec_math = callback; return 0; } -extern "C" int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { +extern "C" NB_EXPORT int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { nrnpy_rvp_pyobj_callback = callback; return 0; } @@ -3286,7 +3286,7 @@ static PyType_Spec obj_spec_from_name(const char* name) { }; } -PyObject* nrnpy_hoc() { +NB_EXPORT PyObject* nrnpy_hoc() { PyObject* m; PyObject* bases; PyTypeObject* pto; diff --git a/src/nrnpython/nrnpy_hoc.h b/src/nrnpython/nrnpy_hoc.h index 3ce1be5625..47a1de6d1f 100644 --- a/src/nrnpython/nrnpy_hoc.h +++ b/src/nrnpython/nrnpy_hoc.h @@ -1,18 +1,5 @@ #include "nrnpython.h" -NB_EXPORT PyObject* nrnpy_hoc(); -extern "C" NB_EXPORT PyObject* nrn_hocobj_ptr(double*); -extern "C" NB_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ); -extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, - PyObject* plotshape_plot0, - PyObject* get_mech_object_0, - PyObject* store_savestate, - PyObject* restore_savestate); -extern "C" NB_EXPORT int nrnpy_set_gui_callback(PyObject*); -extern "C" NB_EXPORT PyObject* get_plotshape_data(PyObject* sp); -extern "C" NB_EXPORT int nrnpy_vec_math_register(PyObject* callback); -extern "C" NB_EXPORT int nrnpy_rvp_pyobj_callback_register(PyObject* callback); - static PyType_Slot nrnpy_HocObjectType_slots[] = { {Py_tp_dealloc, (void*) hocobj_dealloc}, {Py_tp_repr, (void*) hocobj_repr}, From b44c242fde3817d64c1986e994399a1b02d875a8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 13:13:00 +0000 Subject: [PATCH 48/79] Fix formatting --- src/nrnpython/nrnpy_hoc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 232e1f1c93..377fb6a3aa 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -2580,10 +2580,10 @@ static void nrnpy_restore_savestate_(int64_t size, char* data) { } extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, - PyObject* plotshape_plot0, - PyObject* get_mech_object_0, - PyObject* store_savestate, - PyObject* restore_savestate) { + PyObject* plotshape_plot0, + PyObject* get_mech_object_0, + PyObject* store_savestate, + PyObject* restore_savestate) { rvp_plot = rvp_plot0; plotshape_plot = plotshape_plot0; get_mech_object_ = get_mech_object_0; From df0d68497d8d2f6b943fd16b7f9adca6746c40e7 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 15:14:47 +0200 Subject: [PATCH 49/79] More verbose cmake --- cmake/NanoBindMinimal.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index 1434650522..265e77a2c8 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -8,8 +8,13 @@ function(make_nanobind_target TARGET_NAME PYINC) add_library(${TARGET_NAME} STATIC ${NB_DIR}/src/nb_combined.cpp) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${NB_DIR}/include) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) - target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) - target_compile_definitions(${TARGET_NAME} PRIVATE -D_CRT_SECURE_NO_WARNINGS) + if (MSVC) + # Do not complain about vsnprintf + target_compile_definitions(${TARGET_NAME} PRIVATE -D_CRT_SECURE_NO_WARNINGS) + else() + # Generally needed to handle type punning in Python code + target_compile_options(${TARGET_NAME} PRIVATE -fno-strict-aliasing) + 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) From 0ffb5455e1edafc7a69c4b8ddf928efccb762dcf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 13:17:12 +0000 Subject: [PATCH 50/79] Fix formatting --- cmake/NanoBindMinimal.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/NanoBindMinimal.cmake b/cmake/NanoBindMinimal.cmake index 265e77a2c8..f661e7e473 100644 --- a/cmake/NanoBindMinimal.cmake +++ b/cmake/NanoBindMinimal.cmake @@ -8,7 +8,7 @@ function(make_nanobind_target TARGET_NAME PYINC) add_library(${TARGET_NAME} STATIC ${NB_DIR}/src/nb_combined.cpp) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${NB_DIR}/include) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${NB_DIR}/ext/robin_map/include ${PYINC}) - if (MSVC) + if(MSVC) # Do not complain about vsnprintf target_compile_definitions(${TARGET_NAME} PRIVATE -D_CRT_SECURE_NO_WARNINGS) else() From 016fcdc611fee15eb78bdcb808d57cb0043ae61b Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 15:25:48 +0200 Subject: [PATCH 51/79] Need recursive for nanobind --- cmake/ExternalProjectHelper.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 3abadf7e58..78cc026818 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,7 +29,7 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) From b1c80b8edf20f251b8db7f0fa1a049a25537976f Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 16:01:25 +0200 Subject: [PATCH 52/79] export all --- src/nrnpython/CMakeLists.txt | 1 + src/nrnpython/grids.cpp | 48 ++++++------ src/nrnpython/grids.h | 98 ++++++++++++------------ src/nrnpython/inithoc.cpp | 6 +- src/nrnpython/nb_defs.h | 7 -- src/nrnpython/nrnpy_hoc.cpp | 24 +++--- src/nrnpython/nrnpython.h | 4 +- src/nrnpython/rxd.cpp | 110 +++++++++++++-------------- src/nrnpython/rxd.h | 6 +- src/nrnpython/rxd_extracellular.cpp | 28 ++++--- src/nrnpython/rxd_intracellular.cpp | 20 ++--- src/nrnpython/rxd_llgramarea.cpp | 6 +- src/nrnpython/rxd_marching_cubes.cpp | 34 ++++----- 13 files changed, 181 insertions(+), 211 deletions(-) delete mode 100644 src/nrnpython/nb_defs.h diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 2646f95a60..ff2298212d 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -52,6 +52,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) set(nanobind_target "nanobind_py${pyver}") make_nanobind_target(${nanobind_target} ${pyinc}) add_library(nrnpython${pyver} SHARED ${NRNPYTHON_FILES_LIST}) + set_property(TARGET nrnpython${pyver} WINDOWS_EXPORT_ALL_SYMBOLS TRUE) target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) target_link_libraries(nrnpython${pyver} PUBLIC nrniv_lib) target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} ${nanobind_target}) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index fdb7518211..2872a317f4 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -25,7 +25,7 @@ extern double* _rxd_induced_currents_ecs; extern double* _rxd_induced_currents_scale; // Set dt, t pointers -extern "C" NB_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr) { +extern "C" void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr) { dt_ptr = static_cast(my_dt_ptr->u.px_); t_ptr = static_cast(my_t_ptr->u.px_); } @@ -462,9 +462,7 @@ extern "C" int set_diffusion(int grid_list_index, int grid_id, double* dc, int l return 0; } -extern "C" NB_EXPORT int set_tortuosity(int grid_list_index, - int grid_id, - PyHocObject* my_permeability) { +extern "C" int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -515,9 +513,7 @@ void ECS_Grid_node::set_tortuosity(PyHocObject* my_permeability) { } } -extern "C" NB_EXPORT int set_volume_fraction(int grid_list_index, - int grid_id, - PyHocObject* my_alpha) { +extern "C" int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -589,11 +585,11 @@ void ECS_Grid_node::set_diffusion(double* dc, int) { } -extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, - int index_in_list, - int64_t* nodes_per_seg, - int64_t* nodes_per_seg_start_indices, - PyObject* neuron_pointers) { +extern "C" void ics_set_grid_concentrations(int grid_list_index, + int index_in_list, + int64_t* nodes_per_seg, + int64_t* nodes_per_seg_start_indices, + PyObject* neuron_pointers) { Grid_node* g; ssize_t i; ssize_t n = (ssize_t) PyList_Size(neuron_pointers); // number of segments. @@ -614,10 +610,10 @@ extern "C" NB_EXPORT void ics_set_grid_concentrations(int grid_list_index, } } -extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* neuron_pointers, - double* scale_factors) { +extern "C" void ics_set_grid_currents(int grid_list_index, + int index_in_list, + PyObject* neuron_pointers, + double* scale_factors) { Grid_node* g; ssize_t i; ssize_t n = (ssize_t) PyList_Size(neuron_pointers); @@ -638,10 +634,10 @@ extern "C" NB_EXPORT void ics_set_grid_currents(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ -extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers) { +extern "C" void set_grid_concentrations(int grid_list_index, + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers) { /* Preconditions: @@ -679,11 +675,11 @@ extern "C" NB_EXPORT void set_grid_concentrations(int grid_list_index, } /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ -extern "C" NB_EXPORT void set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers, - PyObject* scale_factors) { +extern "C" void set_grid_currents(int grid_list_index, + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers, + PyObject* scale_factors) { /* Preconditions: @@ -784,7 +780,7 @@ int remove(Grid_node** head, Grid_node* find) { return 1; } -extern "C" NB_EXPORT void delete_by_id(int id) { +extern "C" void delete_by_id(int id) { Grid_node* grid; int k; for (k = 0, grid = Parallel_grids[0]; grid != NULL; grid = grid->next, k++) { diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 05252f93a9..51811a42d2 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -4,8 +4,6 @@ Date: 10/28/16 Description: Header File for grids.cpp. Allows access to Grid_node and Flux_pair structs and their respective functions ******************************************************************/ -#include - #include #include #include @@ -405,22 +403,22 @@ void make_dt_ptr(PyHocObject* my_dt_ptr); // void free_Grid(Grid_node *grid); // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids -extern "C" NB_EXPORT int ECS_insert(int grid_list_index, - PyHocObject* my_states, - int my_num_states_x, - int my_num_states_y, - int my_num_states_z, - double my_dc_x, - double my_dc_y, - double my_dc_z, - double my_dx, - double my_dy, - double my_dz, - PyHocObject* my_alpha, - PyHocObject* my_permeability, - int, - double, - double); +extern "C" int ECS_insert(int grid_list_index, + PyHocObject* my_states, + int my_num_states_x, + int my_num_states_y, + int my_num_states_z, + double my_dc_x, + double my_dc_y, + double my_dc_z, + double my_dx, + double my_dy, + double my_dz, + PyHocObject* my_alpha, + PyHocObject* my_permeability, + int, + double, + double); Grid_node* ICS_make_Grid(PyHocObject* my_states, long num_nodes, @@ -438,41 +436,41 @@ Grid_node* ICS_make_Grid(PyHocObject* my_states, double* ics_alphas); // Insert an ICS_Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids -extern "C" NB_EXPORT int ICS_insert(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas); - -extern "C" NB_EXPORT int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas); +extern "C" int ICS_insert(int grid_list_index, + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas); + +extern "C" int ICS_insert_inhom(int grid_list_index, + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas); // Set the diffusion coefficients for a given grid_id -extern "C" NB_EXPORT int set_diffusion(int, int, double*, int); +extern "C" int set_diffusion(int, int, double*, int); // Delete a specific Grid_node "find" from the list "head" int remove(Grid_node** head, Grid_node* find); diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index 0e54ed8dbf..fc930787b8 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -1,7 +1,5 @@ #include "../../nrnconf.h" -#include "nb_defs.h" - #include "nrnmpiuse.h" #include #include @@ -224,7 +222,7 @@ void nrnpython_finalize() { static char* env[] = {0}; -extern "C" NB_EXPORT PyObject* PyInit_hoc() { +extern "C" PyObject* PyInit_hoc() { #if NRN_ENABLE_THREADS main_thread_ = std::this_thread::get_id(); #endif @@ -371,5 +369,5 @@ extern "C" NB_EXPORT PyObject* PyInit_hoc() { } #if !defined(MINGW) -extern "C" NB_EXPORT void modl_reg() {} +extern "C" void modl_reg() {} #endif // !defined(MINGW) diff --git a/src/nrnpython/nb_defs.h b/src/nrnpython/nb_defs.h deleted file mode 100644 index 0eb3085755..0000000000 --- a/src/nrnpython/nb_defs.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#if defined(_WIN32) -#define NB_EXPORT __declspec(dllexport) -#else -#define NB_EXPORT __attribute__((visibility("default"))) -#endif diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 377fb6a3aa..cec83073b1 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -922,7 +922,7 @@ PyObject* nrn_hocobj_handle(neuron::container::data_handle d) { return result; } -extern "C" NB_EXPORT PyObject* nrn_hocobj_ptr(double* pd) { +extern "C" PyObject* nrn_hocobj_ptr(double* pd) { return nrn_hocobj_handle(neuron::container::data_handle{pd}); } @@ -2525,7 +2525,7 @@ static IvocVect* nrnpy_vec_from_python(void* v) { } static PyObject* (*vec_as_numpy)(int, double*); -extern "C" NB_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ) { +extern "C" int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ) { vec_as_numpy = p; return 0; } @@ -2579,11 +2579,11 @@ static void nrnpy_restore_savestate_(int64_t size, char* data) { } } -extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, - PyObject* plotshape_plot0, - PyObject* get_mech_object_0, - PyObject* store_savestate, - PyObject* restore_savestate) { +extern "C" int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, + PyObject* plotshape_plot0, + PyObject* get_mech_object_0, + PyObject* store_savestate, + PyObject* restore_savestate) { rvp_plot = rvp_plot0; plotshape_plot = plotshape_plot0; get_mech_object_ = get_mech_object_0; @@ -2595,7 +2595,7 @@ extern "C" NB_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, } static PyObject* gui_callback = NULL; -extern "C" NB_EXPORT int nrnpy_set_gui_callback(PyObject* new_gui_callback) { +extern "C" int nrnpy_set_gui_callback(PyObject* new_gui_callback) { gui_callback = new_gui_callback; return 0; } @@ -2815,7 +2815,7 @@ static Object* rvp_rxd_to_callable_(Object* obj) { } -extern "C" NB_EXPORT PyObject* get_plotshape_data(PyObject* sp) { +extern "C" PyObject* get_plotshape_data(PyObject* sp) { PyHocObject* pho = (PyHocObject*) sp; ShapePlotInterface* spi; if (!is_obj_type(pho->ho_, "PlotShape")) { @@ -3048,12 +3048,12 @@ static void add2topdict(PyObject* dict) { static PyObject* nrnpy_vec_math = NULL; -extern "C" NB_EXPORT int nrnpy_vec_math_register(PyObject* callback) { +extern "C" int nrnpy_vec_math_register(PyObject* callback) { nrnpy_vec_math = callback; return 0; } -extern "C" NB_EXPORT int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { +extern "C" int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { nrnpy_rvp_pyobj_callback = callback; return 0; } @@ -3286,7 +3286,7 @@ static PyType_Spec obj_spec_from_name(const char* name) { }; } -NB_EXPORT PyObject* nrnpy_hoc() { +PyObject* nrnpy_hoc() { PyObject* m; PyObject* bases; PyTypeObject* pto; diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index aa7166bc90..7d06e6999b 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -1,7 +1,5 @@ #pragma once -#include - #ifdef _WIN64 #define MS_WIN64 #define MS_WIN32 @@ -98,4 +96,4 @@ int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); -extern "C" NB_EXPORT void nrnpython_reg_real(neuron::python::impl_ptrs*); +extern "C" void nrnpython_reg_real(neuron::python::impl_ptrs*); diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 37c188923b..340394491d 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -138,7 +138,7 @@ static inline void* allocopy(void* src, size_t size) { return dst; } -extern "C" NB_EXPORT void rxd_set_no_diffusion() { +extern "C" void rxd_set_no_diffusion() { int i; diffusion = FALSE; if (_rxd_a != NULL) { @@ -154,7 +154,7 @@ extern "C" NB_EXPORT void rxd_set_no_diffusion() { } } -extern "C" NB_EXPORT void free_curr_ptrs() { +extern "C" void free_curr_ptrs() { _curr_count = 0; if (_curr_indices != NULL) free(_curr_indices); @@ -165,7 +165,7 @@ extern "C" NB_EXPORT void free_curr_ptrs() { _curr_ptrs.clear(); } -extern "C" NB_EXPORT void free_conc_ptrs() { +extern "C" void free_conc_ptrs() { _conc_count = 0; if (_conc_indices != NULL) free(_conc_indices); @@ -174,10 +174,10 @@ extern "C" NB_EXPORT void free_conc_ptrs() { } -extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, - int* curr_index, - double* curr_scale, - PyHocObject** curr_ptrs) { +extern "C" void rxd_setup_curr_ptrs(int num_currents, + int* curr_index, + double* curr_scale, + PyHocObject** curr_ptrs) { free_curr_ptrs(); /* info for NEURON currents - to update states */ _curr_count = num_currents; @@ -192,9 +192,7 @@ extern "C" NB_EXPORT void rxd_setup_curr_ptrs(int num_currents, _curr_ptrs[i] = curr_ptrs[i]->u.px_; } -extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, - int* conc_index, - PyHocObject** conc_ptrs) { +extern "C" void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { /* info for NEURON concentration - to transfer to legacy */ int i; free_conc_ptrs(); @@ -206,12 +204,12 @@ extern "C" NB_EXPORT void rxd_setup_conc_ptrs(int conc_count, _conc_ptrs[i] = conc_ptrs[i]->u.px_; } -extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, - int* grid_counts, - int* grids, - long* index, - double* scales, - PyObject** sources) { +extern "C" void rxd_include_node_flux3D(int grid_count, + int* grid_counts, + int* grids, + long* index, + double* scales, + PyObject** sources) { Grid_node* g; int i = 0, j, k, n, grid_id; int offset = 0; @@ -290,10 +288,7 @@ extern "C" NB_EXPORT void rxd_include_node_flux3D(int grid_count, } } -extern "C" NB_EXPORT void rxd_include_node_flux1D(int n, - long* index, - double* scales, - PyObject** sources) { +extern "C" void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { if (_node_flux_count != 0) { free(_node_flux_idx); free(_node_flux_scale); @@ -353,12 +348,12 @@ static void apply_node_flux1D(double dt, double* states) { apply_node_flux(_node_flux_count, _node_flux_idx, _node_flux_scale, _node_flux_src, dt, states); } -extern "C" NB_EXPORT void rxd_set_euler_matrix(int nrow, - int nnonzero, - long* nonzero_i, - long* nonzero_j, - double* nonzero_values, - double* c_diagonal) { +extern "C" void rxd_set_euler_matrix(int nrow, + int nnonzero, + long* nonzero_i, + long* nonzero_j, + double* nonzero_values, + double* c_diagonal) { long i, j, idx; double val; unsigned int k, ps; @@ -475,20 +470,20 @@ static void mul(int nnonzero, } } -extern "C" NB_EXPORT void set_setup(const fptr setup_fn) { +extern "C" void set_setup(const fptr setup_fn) { _setup = setup_fn; } -extern "C" NB_EXPORT void set_initialize(const fptr initialize_fn) { +extern "C" void set_initialize(const fptr initialize_fn) { _initialize = initialize_fn; set_num_threads(NUM_THREADS); } -extern "C" NB_EXPORT void set_setup_matrices(fptr setup_matrices) { +extern "C" void set_setup_matrices(fptr setup_matrices) { _setup_matrices = setup_matrices; } -extern "C" NB_EXPORT void set_setup_units(fptr setup_units) { +extern "C" void set_setup_units(fptr setup_units) { _setup_units = setup_units; } @@ -628,14 +623,14 @@ static void free_currents() { _membrane_flux = FALSE; } -extern "C" NB_EXPORT void setup_currents(int num_currents, - int num_fluxes, - int* num_species, - int* node_idxs, - double* scales, - PyHocObject** ptrs, - int* mapped, - int* mapped_ecs) { +extern "C" void setup_currents(int num_currents, + int num_fluxes, + int* num_species, + int* node_idxs, + double* scales, + PyHocObject** ptrs, + int* mapped, + int* mapped_ecs) { int i, j, k, id, side, count; int* induced_currents_ecs_idx; int* induced_currents_grid_id; @@ -771,7 +766,7 @@ static void _currents(double* rhs) { } } -extern "C" NB_EXPORT int rxd_nonvint_block(int method, int size, double* p1, double* p2, int) { +extern "C" int rxd_nonvint_block(int method, int size, double* p1, double* p2, int) { if (initialized) { if (structure_change_cnt != prev_structure_change_cnt) { /*TODO: Exclude irrelevant (non-rxd) structural changes*/ @@ -851,19 +846,19 @@ extern "C" NB_EXPORT int rxd_nonvint_block(int method, int size, double* p1, dou *****************************************************************************/ -extern "C" NB_EXPORT void register_rate(int nspecies, - int nparam, - int nregions, - int nseg, - int* sidx, - int necs, - int necsparam, - int* ecs_ids, - int* ecsidx, - int nmult, - double* mult, - PyHocObject** vptrs, - ReactionRate f) { +extern "C" void register_rate(int nspecies, + int nparam, + int nregions, + int nseg, + int* sidx, + int necs, + int necsparam, + int* ecs_ids, + int* ecsidx, + int nmult, + double* mult, + PyHocObject** vptrs, + ReactionRate f) { int i, j, k, idx, ecs_id, ecs_index, ecs_offset; unsigned char counted; Grid_node* g; @@ -970,7 +965,7 @@ extern "C" NB_EXPORT void register_rate(int nspecies, } } -extern "C" NB_EXPORT void clear_rates() { +extern "C" void clear_rates() { ICSReactions *react, *prev; int i, j; for (react = _reactions; react != NULL;) { @@ -1008,7 +1003,7 @@ extern "C" NB_EXPORT void clear_rates() { } -extern "C" NB_EXPORT void species_atolscale(int id, double scale, int len, int* idx) { +extern "C" void species_atolscale(int id, double scale, int len, int* idx) { SpeciesIndexList* list; SpeciesIndexList* prev; if (species_indices != NULL) { @@ -1033,7 +1028,7 @@ extern "C" NB_EXPORT void species_atolscale(int id, double scale, int len, int* list->next = NULL; } -extern "C" NB_EXPORT void remove_species_atolscale(int id) { +extern "C" void remove_species_atolscale(int id) { SpeciesIndexList* list; SpeciesIndexList* prev; for (list = species_indices, prev = NULL; list != NULL; prev = list, list = list->next) { @@ -1049,10 +1044,7 @@ extern "C" NB_EXPORT void remove_species_atolscale(int id) { } } -extern "C" NB_EXPORT void setup_solver(double* my_states, - int my_num_states, - long* zvi, - int num_zvi) { +extern "C" void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { free_currents(); states = my_states; num_states = my_num_states; diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index e1cada9ea8..6ca7d5c00a 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -81,11 +81,11 @@ typedef struct TaskQueue { struct TaskList* last; } TaskQueue; -extern "C" NB_EXPORT void set_num_threads(const int); +extern "C" void set_num_threads(const int); void _fadvance(void); void _fadvance_fixed_step_3D(void); -extern "C" NB_EXPORT int get_num_threads(void); +extern "C" int get_num_threads(void); void ecs_set_adi_tort(ECS_Grid_node*); void ecs_set_adi_vol(ECS_Grid_node*); void ecs_set_adi_homogeneous(ECS_Grid_node*); @@ -173,7 +173,7 @@ void _ode_reinit(double*); int ode_count(const int); -extern "C" NB_EXPORT void scatter_concentrations(void); +extern "C" void scatter_concentrations(void); int find(const int, const int, const int, const int, const int); diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index c3b69e1257..c297b65be8 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -9,8 +9,6 @@ #include #include -#include - #define loc(x, y, z) ((z) + (y) *grid->size_z + (x) *grid->size_z * grid->size_y) static void ecs_refresh_reactions(int); @@ -165,14 +163,14 @@ Reaction* ecs_create_reaction(int list_idx, * grid_id - the grid id within the linked list - this corresponds to species * ECSReactionRate - the reaction function */ -extern "C" NB_EXPORT void ics_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - uint64_t* mc3d_start_indices, - int mc3d_region_size, - double* mc3d_mults, - ECSReactionRate f) { +extern "C" void ics_register_reaction(int list_idx, + int num_species, + int num_params, + int* species_id, + uint64_t* mc3d_start_indices, + int mc3d_region_size, + double* mc3d_mults, + ECSReactionRate f) { ecs_create_reaction(list_idx, num_species, num_params, @@ -191,11 +189,11 @@ extern "C" NB_EXPORT void ics_register_reaction(int list_idx, * grid_id - the grid id within the linked list - this corresponds to species * ECSReactionRate - the reaction function */ -extern "C" NB_EXPORT void ecs_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - ECSReactionRate f) { +extern "C" void ecs_register_reaction(int list_idx, + int num_species, + int num_params, + int* species_id, + ECSReactionRate f) { ecs_create_reaction(list_idx, num_species, num_params, species_id, f, NULL, NULL, 0, NULL); ecs_refresh_reactions(NUM_THREADS); } diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index 27097c3002..d083eeb569 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -19,16 +19,16 @@ const int ICS_PREFETCH = 3; /* * Sets the data to be used by the grids for 1D/3D hybrid models */ -extern "C" NB_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, - int64_t* num_3d_indices_per_grid, - int64_t* hybrid_indices1d, - int64_t* hybrid_indices3d, - int64_t* num_3d_indices_per_1d_seg, - int64_t* hybrid_grid_ids, - double* rates, - double* volumes1d, - double* volumes3d, - double* dxs) { +extern "C" void set_hybrid_data(int64_t* num_1d_indices_per_grid, + int64_t* num_3d_indices_per_grid, + int64_t* hybrid_indices1d, + int64_t* hybrid_indices3d, + int64_t* num_3d_indices_per_1d_seg, + int64_t* hybrid_grid_ids, + double* rates, + double* volumes1d, + double* volumes3d, + double* dxs) { Grid_node* grid; int i, j, k, id; int grid_id_check = 0; diff --git a/src/nrnpython/rxd_llgramarea.cpp b/src/nrnpython/rxd_llgramarea.cpp index fb9c992dbb..c4875f7c54 100644 --- a/src/nrnpython/rxd_llgramarea.cpp +++ b/src/nrnpython/rxd_llgramarea.cpp @@ -1,8 +1,6 @@ #include -#include "nb_defs.h" - -extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2) { +extern "C" double llgramarea(double* p0, double* p1, double* p2) { /* setup the vectors */ double a[] = {p0[0] - p1[0], p0[1] - p1[1], p0[2] - p1[2]}; double b[] = {p0[0] - p2[0], p0[1] - p2[1], p0[2] - p2[2]}; @@ -15,7 +13,7 @@ extern "C" NB_EXPORT double llgramarea(double* p0, double* p1, double* p2) { } -extern "C" NB_EXPORT double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { +extern "C" double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { /* take the cross-product */ double cpx = p1[1] * p2[2] - p1[2] * p2[1]; double cpy = p1[2] * p2[0] - p1[0] * p2[2]; diff --git a/src/nrnpython/rxd_marching_cubes.cpp b/src/nrnpython/rxd_marching_cubes.cpp index 6804b72792..7c3c7e16c1 100644 --- a/src/nrnpython/rxd_marching_cubes.cpp +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -8,8 +8,6 @@ #include #include -#include - const int edgeTable[] = { 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, @@ -335,22 +333,22 @@ void vi(double* p1, double* p2, double v1, double v2, double* out) { out[2] = p1[2] + mu * (p2[2] - p1[2]); } -extern "C" NB_EXPORT int find_triangles(double thresh, - double value0, - double value1, - double value2, - double value3, - double value4, - double value5, - double value6, - double value7, - double x0, - double x1, - double y0, - double y1, - double z0, - double z1, - double* out) { +extern "C" int find_triangles(double thresh, + double value0, + double value1, + double value2, + double value3, + double value4, + double value5, + double value6, + double value7, + double x0, + double x1, + double y0, + double y1, + double z0, + double z1, + double* out) { double position[8][3] = {{x0, y0, z0}, {x1, y0, z0}, {x1, y1, z0}, From dd0bfb0aa4d8f58a233969a31522653de01a1327 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 16:04:15 +0200 Subject: [PATCH 53/79] Huge clean --- src/nrnpython/grids.cpp | 30 +++++++++++++++--------------- src/nrnpython/grids.h | 1 + src/nrnpython/inithoc.cpp | 1 - src/nrnpython/nrnpython.h | 5 +---- src/nrnpython/rxd.cpp | 4 ++-- src/nrnpython/rxd.h | 3 ++- src/nrnpython/rxdmath.cpp | 1 - 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 2872a317f4..23040d396d 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -415,21 +415,21 @@ extern "C" int ICS_insert(int grid_list_index, return new_Grid->insert(grid_list_index); } -extern "C" int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas) { +int ICS_insert_inhom(int grid_list_index, + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas) { ICS_Grid_node* new_Grid = new ICS_Grid_node(my_states, num_nodes, neighbors, diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 51811a42d2..1f5e9f1042 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -393,6 +393,7 @@ extern Grid_node* Parallel_grids[100]; // Array of Grid_node * lists // Set the global ∆t void make_dt_ptr(PyHocObject* my_dt_ptr); + // Create a single Grid_node /* Parameters: Python object that includes array of double pointers, size of x, y, and z dimensions diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index fc930787b8..184ccafc00 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -1,5 +1,4 @@ #include "../../nrnconf.h" - #include "nrnmpiuse.h" #include #include diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 7d06e6999b..310d3ff9d2 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -14,8 +14,6 @@ #undef _XOPEN_SOURCE #include "nrnwrap_Python.h" -#include "nrnpy.h" - #endif /*USE_PYTHON*/ #include @@ -92,8 +90,7 @@ struct Symbol; bool nrn_chk_data_handle(const neuron::container::data_handle&); PyObject* nrn_hocobj_handle(neuron::container::data_handle d); +extern "C" PyObject* nrn_hocobj_ptr(double*); int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); - -extern "C" void nrnpython_reg_real(neuron::python::impl_ptrs*); diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 340394491d..c4dea01f55 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -1130,7 +1130,7 @@ void TaskQueue_exe_tasks(std::size_t thread_index, TaskQueue* q) { } -extern "C" void set_num_threads(const int n) { +void set_num_threads(const int n) { assert(n > 0); assert(NUM_THREADS > 0); // n and NUM_THREADS include the main thread, old_num and new_num refer to @@ -1184,7 +1184,7 @@ void TaskQueue_sync(TaskQueue* q) { q->waiting_cond.wait(lock, [q] { return q->length == 0; }); } -extern "C" int get_num_threads(void) { +int get_num_threads(void) { return NUM_THREADS; } diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 6ca7d5c00a..7371bca493 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -7,7 +7,7 @@ #define SPECIES_ABSENT -1 #define PREFETCH 4 -using fptr = void (*)(void); +typedef void (*fptr)(void); // @olupton 2022-09-16: deleted a declaration of OcPtrVector that did not match // the one in ocptrvector.h @@ -175,6 +175,7 @@ int ode_count(const int); extern "C" void scatter_concentrations(void); + int find(const int, const int, const int, const int, const int); void _ics_hybrid_helper(ICS_Grid_node*); diff --git a/src/nrnpython/rxdmath.cpp b/src/nrnpython/rxdmath.cpp index d50af10fdb..3b3e4a2aed 100644 --- a/src/nrnpython/rxdmath.cpp +++ b/src/nrnpython/rxdmath.cpp @@ -1,5 +1,4 @@ #include - #ifndef M_PI #define M_PI (3.14159265358979323846) #endif From 58f43ce90c4554e412c7e6d638908d8ff541c9d7 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 17:20:46 +0200 Subject: [PATCH 54/79] Fix cmake --- src/nrnpython/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index ff2298212d..c0a455bfe3 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -52,7 +52,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) set(nanobind_target "nanobind_py${pyver}") make_nanobind_target(${nanobind_target} ${pyinc}) add_library(nrnpython${pyver} SHARED ${NRNPYTHON_FILES_LIST}) - set_property(TARGET nrnpython${pyver} WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + set_property(TARGET nrnpython${pyver} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) target_link_libraries(nrnpython${pyver} PUBLIC nrniv_lib) target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} ${nanobind_target}) From e936b96617ea8b5951b575ae571bf54f88904402 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 17:49:54 +0200 Subject: [PATCH 55/79] failure --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 985eae0ae0..d77f7ec8ac 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -76,7 +76,7 @@ jobs: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() && contains(github.event.pull_request.title, 'live-debug-win') + if: failure() uses: mxschmitt/action-tmate@v3 - name: Upload build artifact From db6391286080bd0d7aa3c95adb7fb425ceac61b0 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 30 May 2024 18:29:27 +0200 Subject: [PATCH 56/79] Try --- src/nrnpython/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index c0a455bfe3..73b16c8503 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -52,7 +52,10 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) set(nanobind_target "nanobind_py${pyver}") make_nanobind_target(${nanobind_target} ${pyinc}) add_library(nrnpython${pyver} SHARED ${NRNPYTHON_FILES_LIST}) - set_property(TARGET nrnpython${pyver} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) + if(MSVC) + set_property(TARGET nrnpython${pyver} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) + set(CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS 1) + endif() target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) target_link_libraries(nrnpython${pyver} PUBLIC nrniv_lib) target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} ${nanobind_target}) From 4147249ee0ca13d67e897c176603072db677996f Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 31 May 2024 10:28:42 +0200 Subject: [PATCH 57/79] We are compiling with MINGW --- src/nrnpython/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 73b16c8503..bf69935ead 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -52,7 +52,7 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) set(nanobind_target "nanobind_py${pyver}") make_nanobind_target(${nanobind_target} ${pyinc}) add_library(nrnpython${pyver} SHARED ${NRNPYTHON_FILES_LIST}) - if(MSVC) + if(MINGW) set_property(TARGET nrnpython${pyver} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS 1) endif() From b87a9900968a122f992d19a5d12d0fac3582d7d4 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 31 May 2024 12:49:40 +0200 Subject: [PATCH 58/79] Resurce only nanobind --- .gitmodules | 1 + cmake/ExternalProjectHelper.cmake | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 1bbbebe21c..df5c12155f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,4 @@ [submodule "external/nanobind"] path = external/nanobind url = https://github.com/wjakob/nanobind + fetchRecurseSubmodules = true diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 78cc026818..3abadf7e58 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,7 +29,7 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) From 3177806493dfd2e5373e8f97481da7310ab4eed6 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 31 May 2024 13:45:02 +0200 Subject: [PATCH 59/79] Revert "Resurce only nanobind" This reverts commit b87a9900968a122f992d19a5d12d0fac3582d7d4. --- .gitmodules | 1 - cmake/ExternalProjectHelper.cmake | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index df5c12155f..1bbbebe21c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,4 +28,3 @@ [submodule "external/nanobind"] path = external/nanobind url = https://github.com/wjakob/nanobind - fetchRecurseSubmodules = true diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 3abadf7e58..78cc026818 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -29,7 +29,7 @@ function(nrn_initialize_submodule path) endif() message(STATUS "Sub-module : missing ${path} : running git submodule update --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) From dbfab15a7286fb42573e263d93524cf8e7c51eec Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 20 Jun 2024 10:39:56 +0200 Subject: [PATCH 60/79] Try with a def file --- src/nrnpython/CMakeLists.txt | 4 +++ src/nrnpython/nrnpython.def | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/nrnpython/nrnpython.def diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index bf69935ead..0cc8853aa3 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -28,6 +28,10 @@ set(NRNPYTHON_FILES_LIST rxd_marching_cubes.cpp rxd_llgramarea.cpp) +if (MINGW) + list(APPEND NRNPYTHON_FILES_LIST nrnpython.def) +endif() + set(INCLUDE_DIRS .. ../oc diff --git a/src/nrnpython/nrnpython.def b/src/nrnpython/nrnpython.def new file mode 100644 index 0000000000..b27f7fc077 --- /dev/null +++ b/src/nrnpython/nrnpython.def @@ -0,0 +1,62 @@ +LIBRARY NRNPYTHON +EXPORTS +make_time_ptr @1 +ECS_insert @2 +ICS_insert @3 +set_diffusion @4 +set_tortuosity @5 +set_volume_fraction @6 +ics_set_grid_concentrations @7 +ics_set_grid_currents @8 +set_grid_concentrations @9 +set_grid_currents @10 +delete_by_id @11 +ECS_insert @12 +ICS_insert @13 +ICS_insert_inhom @14 +set_diffusion @15 +PyInit_hoc @16 +modl_reg @17 +nrn_hocobj_ptr @18 +nrnpy_set_vec_as_numpy @19 +nrnpy_set_toplevel_callbacks @20 +nrnpy_set_gui_callback @21 +get_plotshape_data @22 +nrnpy_vec_math_register @23 +nrnpy_rvp_pyobj_callback_register @24 +nrnpython_reg_real @25 +nrn_hocobj_ptr @26 +rxd_set_no_diffusion @27 +free_curr_ptrs @28 +free_conc_ptrs @29 +rxd_setup_curr_ptrs @30 +rxd_setup_conc_ptrs @31 +rxd_include_node_flux3D @32 +rxd_include_node_flux1D @33 +rxd_set_euler_matrix @34 +set_setup @35 +set_initialize @36 +set_setup_matrices @37 +set_setup_units @38 +setup_currents @39 +rxd_nonvint_block @40 +register_rate @41 +clear_rates @42 +species_atolscale @43 +remove_species_atolscale @44 +setup_solver @45 +set_num_threads @46 +get_num_threads @47 +scatter_concentrations @48 +ics_register_reaction @49 +ecs_register_reaction @50 +scatter_concentrations @51 +set_hybrid_data @52 +llgramarea @53 +llpipedfromoriginvolume @54 +find_triangles @55 +factorial @56 +degrees @57 +radians @58 +log1p @59 +vtrap @60 From c2d314a9d5aaab2f841d87e9ea27abd18c73ad32 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:29:54 +0000 Subject: [PATCH 61/79] Fix formatting --- src/nrnpython/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 0cc8853aa3..ab88561239 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -28,8 +28,8 @@ set(NRNPYTHON_FILES_LIST rxd_marching_cubes.cpp rxd_llgramarea.cpp) -if (MINGW) - list(APPEND NRNPYTHON_FILES_LIST nrnpython.def) +if(MINGW) + list(APPEND NRNPYTHON_FILES_LIST nrnpython.def) endif() set(INCLUDE_DIRS From d7aa1ac35aff07c494fa3fad9d72aed9102cc679 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Thu, 20 Jun 2024 19:01:59 +0200 Subject: [PATCH 62/79] forgot nrnpy_hoc --- src/nrnpython/nrnpython.def | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nrnpython/nrnpython.def b/src/nrnpython/nrnpython.def index b27f7fc077..ca61c516a8 100644 --- a/src/nrnpython/nrnpython.def +++ b/src/nrnpython/nrnpython.def @@ -60,3 +60,4 @@ degrees @57 radians @58 log1p @59 vtrap @60 +nrnpy_hoc @61 From 500f98cea0eeaba5fe5329287620618d92295e84 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 21 Jun 2024 13:50:30 +0200 Subject: [PATCH 63/79] Fix format? --- src/nrnpython/nrnpython.def | 124 ++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 63 deletions(-) diff --git a/src/nrnpython/nrnpython.def b/src/nrnpython/nrnpython.def index ca61c516a8..5d891c1216 100644 --- a/src/nrnpython/nrnpython.def +++ b/src/nrnpython/nrnpython.def @@ -1,63 +1,61 @@ -LIBRARY NRNPYTHON -EXPORTS -make_time_ptr @1 -ECS_insert @2 -ICS_insert @3 -set_diffusion @4 -set_tortuosity @5 -set_volume_fraction @6 -ics_set_grid_concentrations @7 -ics_set_grid_currents @8 -set_grid_concentrations @9 -set_grid_currents @10 -delete_by_id @11 -ECS_insert @12 -ICS_insert @13 -ICS_insert_inhom @14 -set_diffusion @15 -PyInit_hoc @16 -modl_reg @17 -nrn_hocobj_ptr @18 -nrnpy_set_vec_as_numpy @19 -nrnpy_set_toplevel_callbacks @20 -nrnpy_set_gui_callback @21 -get_plotshape_data @22 -nrnpy_vec_math_register @23 -nrnpy_rvp_pyobj_callback_register @24 -nrnpython_reg_real @25 -nrn_hocobj_ptr @26 -rxd_set_no_diffusion @27 -free_curr_ptrs @28 -free_conc_ptrs @29 -rxd_setup_curr_ptrs @30 -rxd_setup_conc_ptrs @31 -rxd_include_node_flux3D @32 -rxd_include_node_flux1D @33 -rxd_set_euler_matrix @34 -set_setup @35 -set_initialize @36 -set_setup_matrices @37 -set_setup_units @38 -setup_currents @39 -rxd_nonvint_block @40 -register_rate @41 -clear_rates @42 -species_atolscale @43 -remove_species_atolscale @44 -setup_solver @45 -set_num_threads @46 -get_num_threads @47 -scatter_concentrations @48 -ics_register_reaction @49 -ecs_register_reaction @50 -scatter_concentrations @51 -set_hybrid_data @52 -llgramarea @53 -llpipedfromoriginvolume @54 -find_triangles @55 -factorial @56 -degrees @57 -radians @58 -log1p @59 -vtrap @60 -nrnpy_hoc @61 +make_time_ptr +ECS_insert +ICS_insert +set_diffusion +set_tortuosity +set_volume_fraction +ics_set_grid_concentrations +ics_set_grid_currents +set_grid_concentrations +set_grid_currents +delete_by_id +ECS_insert +ICS_insert +ICS_insert_inhom +set_diffusion +PyInit_hoc +modl_reg +nrn_hocobj_ptr +nrnpy_set_vec_as_numpy +nrnpy_set_toplevel_callbacks +nrnpy_set_gui_callback +get_plotshape_data +nrnpy_vec_math_register +nrnpy_rvp_pyobj_callback_register +nrnpython_reg_real +nrn_hocobj_ptr +rxd_set_no_diffusion +free_curr_ptrs +free_conc_ptrs +rxd_setup_curr_ptrs +rxd_setup_conc_ptrs +rxd_include_node_flux3D +rxd_include_node_flux1D +rxd_set_euler_matrix +set_setup +set_initialize +set_setup_matrices +set_setup_units +setup_currents +rxd_nonvint_block +register_rate +clear_rates +species_atolscale +remove_species_atolscale +setup_solver +set_num_threads +get_num_threads +scatter_concentrations +ics_register_reaction +ecs_register_reaction +scatter_concentrations +set_hybrid_data +llgramarea +llpipedfromoriginvolume +find_triangles +factorial +degrees +radians +log1p +vtrap +nrnpy_hoc From 87f833a4c57e4e26a98343c993754539c18cae79 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 24 Jun 2024 13:32:55 +0200 Subject: [PATCH 64/79] revert cmake way for symbol (because bug) --- src/nrnpython/CMakeLists.txt | 4 --- src/nrnpython/grids.cpp | 22 ++++++------- src/nrnpython/inithoc.cpp | 4 +-- src/nrnpython/nrn_export.hpp | 7 +++++ src/nrnpython/nrnpy_hoc.cpp | 14 ++++----- src/nrnpython/nrnpython.def | 61 ------------------------------------ src/nrnpython/nrnpython.h | 4 ++- src/nrnpython/rxd.cpp | 38 +++++++++++----------- 8 files changed, 49 insertions(+), 105 deletions(-) create mode 100644 src/nrnpython/nrn_export.hpp delete mode 100644 src/nrnpython/nrnpython.def diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index ab88561239..5524ee953f 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -56,10 +56,6 @@ if(NRN_ENABLE_PYTHON_DYNAMIC) set(nanobind_target "nanobind_py${pyver}") make_nanobind_target(${nanobind_target} ${pyinc}) add_library(nrnpython${pyver} SHARED ${NRNPYTHON_FILES_LIST}) - if(MINGW) - set_property(TARGET nrnpython${pyver} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) - set(CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS 1) - endif() target_include_directories(nrnpython${pyver} BEFORE PUBLIC ${pyinc} ${INCLUDE_DIRS}) target_link_libraries(nrnpython${pyver} PUBLIC nrniv_lib) target_link_libraries(nrnpython${pyver} PRIVATE ${Readline_LIBRARY} ${nanobind_target}) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 23040d396d..b773cb17f0 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -25,7 +25,7 @@ extern double* _rxd_induced_currents_ecs; extern double* _rxd_induced_currents_scale; // Set dt, t pointers -extern "C" void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr) { +extern "C" NRN_EXPORT void make_time_ptr(PyHocObject* my_dt_ptr, PyHocObject* my_t_ptr) { dt_ptr = static_cast(my_dt_ptr->u.px_); t_ptr = static_cast(my_t_ptr->u.px_); } @@ -194,7 +194,7 @@ ECS_Grid_node::ECS_Grid_node(PyHocObject* my_states, // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids /* returns the grid number TODO: change this to returning the pointer */ -extern "C" int ECS_insert(int grid_list_index, +extern "C" NRN_EXPORT int ECS_insert(int grid_list_index, PyHocObject* my_states, int my_num_states_x, int my_num_states_y, @@ -381,7 +381,7 @@ ICS_Grid_node::ICS_Grid_node(PyHocObject* my_states, // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids /* returns the grid number TODO: change this to returning the pointer */ -extern "C" int ICS_insert(int grid_list_index, +extern "C" NRN_EXPORT int ICS_insert(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, @@ -449,7 +449,7 @@ int ICS_insert_inhom(int grid_list_index, } -extern "C" int set_diffusion(int grid_list_index, int grid_id, double* dc, int length) { +extern "C" NRN_EXPORT int set_diffusion(int grid_list_index, int grid_id, double* dc, int length) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -462,7 +462,7 @@ extern "C" int set_diffusion(int grid_list_index, int grid_id, double* dc, int l return 0; } -extern "C" int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { +extern "C" NRN_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -513,7 +513,7 @@ void ECS_Grid_node::set_tortuosity(PyHocObject* my_permeability) { } } -extern "C" int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { +extern "C" NRN_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -585,7 +585,7 @@ void ECS_Grid_node::set_diffusion(double* dc, int) { } -extern "C" void ics_set_grid_concentrations(int grid_list_index, +extern "C" NRN_EXPORT void ics_set_grid_concentrations(int grid_list_index, int index_in_list, int64_t* nodes_per_seg, int64_t* nodes_per_seg_start_indices, @@ -610,7 +610,7 @@ extern "C" void ics_set_grid_concentrations(int grid_list_index, } } -extern "C" void ics_set_grid_currents(int grid_list_index, +extern "C" NRN_EXPORT void ics_set_grid_currents(int grid_list_index, int index_in_list, PyObject* neuron_pointers, double* scale_factors) { @@ -634,7 +634,7 @@ extern "C" void ics_set_grid_currents(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ -extern "C" void set_grid_concentrations(int grid_list_index, +extern "C" NRN_EXPORT void set_grid_concentrations(int grid_list_index, int index_in_list, PyObject* grid_indices, PyObject* neuron_pointers) { @@ -675,7 +675,7 @@ extern "C" void set_grid_concentrations(int grid_list_index, } /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ -extern "C" void set_grid_currents(int grid_list_index, +extern "C" NRN_EXPORT void set_grid_currents(int grid_list_index, int index_in_list, PyObject* grid_indices, PyObject* neuron_pointers, @@ -780,7 +780,7 @@ int remove(Grid_node** head, Grid_node* find) { return 1; } -extern "C" void delete_by_id(int id) { +extern "C" NRN_EXPORT void delete_by_id(int id) { Grid_node* grid; int k; for (k = 0, grid = Parallel_grids[0]; grid != NULL; grid = grid->next, k++) { diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index 184ccafc00..3b3339190d 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -221,7 +221,7 @@ void nrnpython_finalize() { static char* env[] = {0}; -extern "C" PyObject* PyInit_hoc() { +extern "C" NRN_EXPORT PyObject* PyInit_hoc() { #if NRN_ENABLE_THREADS main_thread_ = std::this_thread::get_id(); #endif @@ -368,5 +368,5 @@ extern "C" PyObject* PyInit_hoc() { } #if !defined(MINGW) -extern "C" void modl_reg() {} +extern "C" NRN_EXPORT void modl_reg() {} #endif // !defined(MINGW) diff --git a/src/nrnpython/nrn_export.hpp b/src/nrnpython/nrn_export.hpp new file mode 100644 index 0000000000..7b62b27a28 --- /dev/null +++ b/src/nrnpython/nrn_export.hpp @@ -0,0 +1,7 @@ +#pragma once + +#if defined(_WIN32) +#define NRN_EXPORT __declspec(dllexport) +#else +#define NRN_EXPORT __attribute__((visibility("default"))) +#endif diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index d4d9ae0b5a..116b938d0d 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -939,7 +939,7 @@ PyObject* nrn_hocobj_handle(neuron::container::data_handle d) { return result; } -extern "C" PyObject* nrn_hocobj_ptr(double* pd) { +extern "C" NRN_EXPORT PyObject* nrn_hocobj_ptr(double* pd) { return nrn_hocobj_handle(neuron::container::data_handle{pd}); } @@ -2567,7 +2567,7 @@ static IvocVect* nrnpy_vec_from_python(void* v) { } static PyObject* (*vec_as_numpy)(int, double*); -extern "C" int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ) { +extern "C" NRN_EXPORT int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*) ) { vec_as_numpy = p; return 0; } @@ -2621,7 +2621,7 @@ static void nrnpy_restore_savestate_(int64_t size, char* data) { } } -extern "C" int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, +extern "C" NRN_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, PyObject* plotshape_plot0, PyObject* get_mech_object_0, PyObject* store_savestate, @@ -2637,7 +2637,7 @@ extern "C" int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, } static PyObject* gui_callback = NULL; -extern "C" int nrnpy_set_gui_callback(PyObject* new_gui_callback) { +extern "C" NRN_EXPORT int nrnpy_set_gui_callback(PyObject* new_gui_callback) { gui_callback = new_gui_callback; return 0; } @@ -2857,7 +2857,7 @@ static Object* rvp_rxd_to_callable_(Object* obj) { } -extern "C" PyObject* get_plotshape_data(PyObject* sp) { +extern "C" NRN_EXPORT PyObject* get_plotshape_data(PyObject* sp) { PyHocObject* pho = (PyHocObject*) sp; ShapePlotInterface* spi; if (!is_obj_type(pho->ho_, "PlotShape")) { @@ -3102,12 +3102,12 @@ static void add2topdict(PyObject* dict) { static PyObject* nrnpy_vec_math = NULL; -extern "C" int nrnpy_vec_math_register(PyObject* callback) { +extern "C" NRN_EXPORT int nrnpy_vec_math_register(PyObject* callback) { nrnpy_vec_math = callback; return 0; } -extern "C" int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { +extern "C" NRN_EXPORT int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { nrnpy_rvp_pyobj_callback = callback; return 0; } diff --git a/src/nrnpython/nrnpython.def b/src/nrnpython/nrnpython.def deleted file mode 100644 index 5d891c1216..0000000000 --- a/src/nrnpython/nrnpython.def +++ /dev/null @@ -1,61 +0,0 @@ -make_time_ptr -ECS_insert -ICS_insert -set_diffusion -set_tortuosity -set_volume_fraction -ics_set_grid_concentrations -ics_set_grid_currents -set_grid_concentrations -set_grid_currents -delete_by_id -ECS_insert -ICS_insert -ICS_insert_inhom -set_diffusion -PyInit_hoc -modl_reg -nrn_hocobj_ptr -nrnpy_set_vec_as_numpy -nrnpy_set_toplevel_callbacks -nrnpy_set_gui_callback -get_plotshape_data -nrnpy_vec_math_register -nrnpy_rvp_pyobj_callback_register -nrnpython_reg_real -nrn_hocobj_ptr -rxd_set_no_diffusion -free_curr_ptrs -free_conc_ptrs -rxd_setup_curr_ptrs -rxd_setup_conc_ptrs -rxd_include_node_flux3D -rxd_include_node_flux1D -rxd_set_euler_matrix -set_setup -set_initialize -set_setup_matrices -set_setup_units -setup_currents -rxd_nonvint_block -register_rate -clear_rates -species_atolscale -remove_species_atolscale -setup_solver -set_num_threads -get_num_threads -scatter_concentrations -ics_register_reaction -ecs_register_reaction -scatter_concentrations -set_hybrid_data -llgramarea -llpipedfromoriginvolume -find_triangles -factorial -degrees -radians -log1p -vtrap -nrnpy_hoc diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 310d3ff9d2..eb98a335b5 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -14,6 +14,8 @@ #undef _XOPEN_SOURCE #include "nrnwrap_Python.h" +#include "nrn_export.hpp" + #endif /*USE_PYTHON*/ #include @@ -90,7 +92,7 @@ struct Symbol; bool nrn_chk_data_handle(const neuron::container::data_handle&); PyObject* nrn_hocobj_handle(neuron::container::data_handle d); -extern "C" PyObject* nrn_hocobj_ptr(double*); +extern "C" NRN_EXPORT PyObject* nrn_hocobj_ptr(double*); int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 04f123e1e2..6eeaf301a9 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -138,7 +138,7 @@ static inline void* allocopy(void* src, size_t size) { return dst; } -extern "C" void rxd_set_no_diffusion() { +extern "C" NRN_EXPORT void rxd_set_no_diffusion() { int i; diffusion = FALSE; if (_rxd_a != NULL) { @@ -154,7 +154,7 @@ extern "C" void rxd_set_no_diffusion() { } } -extern "C" void free_curr_ptrs() { +extern "C" NRN_EXPORT void free_curr_ptrs() { _curr_count = 0; if (_curr_indices != NULL) free(_curr_indices); @@ -165,7 +165,7 @@ extern "C" void free_curr_ptrs() { _curr_ptrs.clear(); } -extern "C" void free_conc_ptrs() { +extern "C" NRN_EXPORT void free_conc_ptrs() { _conc_count = 0; if (_conc_indices != NULL) free(_conc_indices); @@ -174,7 +174,7 @@ extern "C" void free_conc_ptrs() { } -extern "C" void rxd_setup_curr_ptrs(int num_currents, +extern "C" NRN_EXPORT void rxd_setup_curr_ptrs(int num_currents, int* curr_index, double* curr_scale, PyHocObject** curr_ptrs) { @@ -192,7 +192,7 @@ extern "C" void rxd_setup_curr_ptrs(int num_currents, _curr_ptrs[i] = curr_ptrs[i]->u.px_; } -extern "C" void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { +extern "C" NRN_EXPORT void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { /* info for NEURON concentration - to transfer to legacy */ int i; free_conc_ptrs(); @@ -204,7 +204,7 @@ extern "C" void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject _conc_ptrs[i] = conc_ptrs[i]->u.px_; } -extern "C" void rxd_include_node_flux3D(int grid_count, +extern "C" NRN_EXPORT void rxd_include_node_flux3D(int grid_count, int* grid_counts, int* grids, long* index, @@ -288,7 +288,7 @@ extern "C" void rxd_include_node_flux3D(int grid_count, } } -extern "C" void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { +extern "C" NRN_EXPORT void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { if (_node_flux_count != 0) { free(_node_flux_idx); free(_node_flux_scale); @@ -348,7 +348,7 @@ static void apply_node_flux1D(double dt, double* states) { apply_node_flux(_node_flux_count, _node_flux_idx, _node_flux_scale, _node_flux_src, dt, states); } -extern "C" void rxd_set_euler_matrix(int nrow, +extern "C" NRN_EXPORT void rxd_set_euler_matrix(int nrow, int nnonzero, long* nonzero_i, long* nonzero_j, @@ -470,20 +470,20 @@ static void mul(int nnonzero, } } -extern "C" void set_setup(const fptr setup_fn) { +extern "C" NRN_EXPORT void set_setup(const fptr setup_fn) { _setup = setup_fn; } -extern "C" void set_initialize(const fptr initialize_fn) { +extern "C" NRN_EXPORT void set_initialize(const fptr initialize_fn) { _initialize = initialize_fn; set_num_threads(NUM_THREADS); } -extern "C" void set_setup_matrices(fptr setup_matrices) { +extern "C" NRN_EXPORT void set_setup_matrices(fptr setup_matrices) { _setup_matrices = setup_matrices; } -extern "C" void set_setup_units(fptr setup_units) { +extern "C" NRN_EXPORT void set_setup_units(fptr setup_units) { _setup_units = setup_units; } @@ -623,7 +623,7 @@ static void free_currents() { _membrane_flux = FALSE; } -extern "C" void setup_currents(int num_currents, +extern "C" NRN_EXPORT void setup_currents(int num_currents, int num_fluxes, int* num_species, int* node_idxs, @@ -766,7 +766,7 @@ static void _currents(double* rhs) { } } -extern "C" int rxd_nonvint_block(int method, int size, double* p1, double* p2, int) { +extern "C" NRN_EXPORT int rxd_nonvint_block(int method, int size, double* p1, double* p2, int) { if (initialized) { if (structure_change_cnt != prev_structure_change_cnt) { /*TODO: Exclude irrelevant (non-rxd) structural changes*/ @@ -846,7 +846,7 @@ extern "C" int rxd_nonvint_block(int method, int size, double* p1, double* p2, i *****************************************************************************/ -extern "C" void register_rate(int nspecies, +extern "C" NRN_EXPORT void register_rate(int nspecies, int nparam, int nregions, int nseg, @@ -965,7 +965,7 @@ extern "C" void register_rate(int nspecies, } } -extern "C" void clear_rates() { +extern "C" NRN_EXPORT void clear_rates() { ICSReactions *react, *prev; int i, j; for (react = _reactions; react != NULL;) { @@ -1003,7 +1003,7 @@ extern "C" void clear_rates() { } -extern "C" void species_atolscale(int id, double scale, int len, int* idx) { +extern "C" NRN_EXPORT void species_atolscale(int id, double scale, int len, int* idx) { SpeciesIndexList* list; SpeciesIndexList* prev; if (species_indices != NULL) { @@ -1028,7 +1028,7 @@ extern "C" void species_atolscale(int id, double scale, int len, int* idx) { list->next = NULL; } -extern "C" void remove_species_atolscale(int id) { +extern "C" NRN_EXPORT void remove_species_atolscale(int id) { SpeciesIndexList* list; SpeciesIndexList* prev; for (list = species_indices, prev = NULL; list != NULL; prev = list, list = list->next) { @@ -1044,7 +1044,7 @@ extern "C" void remove_species_atolscale(int id) { } } -extern "C" void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { +extern "C" NRN_EXPORT void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { free_currents(); states = my_states; num_states = my_num_states; From f17e86ea532a4e7c00718609c7ea11b504f93fbe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:49:54 +0000 Subject: [PATCH 65/79] Fix formatting --- src/nrnpython/grids.cpp | 94 +++++++++++++++++++------------------ src/nrnpython/nrnpy_hoc.cpp | 8 ++-- src/nrnpython/rxd.cpp | 78 ++++++++++++++++-------------- 3 files changed, 96 insertions(+), 84 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index b773cb17f0..33b56950fa 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -195,21 +195,21 @@ ECS_Grid_node::ECS_Grid_node(PyHocObject* my_states, /* returns the grid number TODO: change this to returning the pointer */ extern "C" NRN_EXPORT int ECS_insert(int grid_list_index, - PyHocObject* my_states, - int my_num_states_x, - int my_num_states_y, - int my_num_states_z, - double my_dc_x, - double my_dc_y, - double my_dc_z, - double my_dx, - double my_dy, - double my_dz, - PyHocObject* my_alpha, - PyHocObject* my_permeability, - int bc, - double bc_value, - double atolscale) { + PyHocObject* my_states, + int my_num_states_x, + int my_num_states_y, + int my_num_states_z, + double my_dc_x, + double my_dc_y, + double my_dc_z, + double my_dx, + double my_dy, + double my_dz, + PyHocObject* my_alpha, + PyHocObject* my_permeability, + int bc, + double bc_value, + double atolscale) { ECS_Grid_node* new_Grid = new ECS_Grid_node(my_states, my_num_states_x, my_num_states_y, @@ -382,20 +382,20 @@ ICS_Grid_node::ICS_Grid_node(PyHocObject* my_states, /* returns the grid number TODO: change this to returning the pointer */ extern "C" NRN_EXPORT int ICS_insert(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas) { + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas) { ICS_Grid_node* new_Grid = new ICS_Grid_node(my_states, num_nodes, neighbors, @@ -462,7 +462,9 @@ extern "C" NRN_EXPORT int set_diffusion(int grid_list_index, int grid_id, double return 0; } -extern "C" NRN_EXPORT int set_tortuosity(int grid_list_index, int grid_id, PyHocObject* my_permeability) { +extern "C" NRN_EXPORT int set_tortuosity(int grid_list_index, + int grid_id, + PyHocObject* my_permeability) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -513,7 +515,9 @@ void ECS_Grid_node::set_tortuosity(PyHocObject* my_permeability) { } } -extern "C" NRN_EXPORT int set_volume_fraction(int grid_list_index, int grid_id, PyHocObject* my_alpha) { +extern "C" NRN_EXPORT int set_volume_fraction(int grid_list_index, + int grid_id, + PyHocObject* my_alpha) { int id = 0; Grid_node* node = Parallel_grids[grid_list_index]; while (id < grid_id) { @@ -586,10 +590,10 @@ void ECS_Grid_node::set_diffusion(double* dc, int) { extern "C" NRN_EXPORT void ics_set_grid_concentrations(int grid_list_index, - int index_in_list, - int64_t* nodes_per_seg, - int64_t* nodes_per_seg_start_indices, - PyObject* neuron_pointers) { + int index_in_list, + int64_t* nodes_per_seg, + int64_t* nodes_per_seg_start_indices, + PyObject* neuron_pointers) { Grid_node* g; ssize_t i; ssize_t n = (ssize_t) PyList_Size(neuron_pointers); // number of segments. @@ -611,9 +615,9 @@ extern "C" NRN_EXPORT void ics_set_grid_concentrations(int grid_list_index, } extern "C" NRN_EXPORT void ics_set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* neuron_pointers, - double* scale_factors) { + int index_in_list, + PyObject* neuron_pointers, + double* scale_factors) { Grid_node* g; ssize_t i; ssize_t n = (ssize_t) PyList_Size(neuron_pointers); @@ -635,9 +639,9 @@ extern "C" NRN_EXPORT void ics_set_grid_currents(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ extern "C" NRN_EXPORT void set_grid_concentrations(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers) { + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers) { /* Preconditions: @@ -676,10 +680,10 @@ extern "C" NRN_EXPORT void set_grid_concentrations(int grid_list_index, /* TODO: make this work with Grid_node ptrs instead of pairs of list indices */ extern "C" NRN_EXPORT void set_grid_currents(int grid_list_index, - int index_in_list, - PyObject* grid_indices, - PyObject* neuron_pointers, - PyObject* scale_factors) { + int index_in_list, + PyObject* grid_indices, + PyObject* neuron_pointers, + PyObject* scale_factors) { /* Preconditions: diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 116b938d0d..bf1b234843 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -2622,10 +2622,10 @@ static void nrnpy_restore_savestate_(int64_t size, char* data) { } extern "C" NRN_EXPORT int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, - PyObject* plotshape_plot0, - PyObject* get_mech_object_0, - PyObject* store_savestate, - PyObject* restore_savestate) { + PyObject* plotshape_plot0, + PyObject* get_mech_object_0, + PyObject* store_savestate, + PyObject* restore_savestate) { rvp_plot = rvp_plot0; plotshape_plot = plotshape_plot0; get_mech_object_ = get_mech_object_0; diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 6eeaf301a9..d420bb47f0 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -175,9 +175,9 @@ extern "C" NRN_EXPORT void free_conc_ptrs() { extern "C" NRN_EXPORT void rxd_setup_curr_ptrs(int num_currents, - int* curr_index, - double* curr_scale, - PyHocObject** curr_ptrs) { + int* curr_index, + double* curr_scale, + PyHocObject** curr_ptrs) { free_curr_ptrs(); /* info for NEURON currents - to update states */ _curr_count = num_currents; @@ -192,7 +192,9 @@ extern "C" NRN_EXPORT void rxd_setup_curr_ptrs(int num_currents, _curr_ptrs[i] = curr_ptrs[i]->u.px_; } -extern "C" NRN_EXPORT void rxd_setup_conc_ptrs(int conc_count, int* conc_index, PyHocObject** conc_ptrs) { +extern "C" NRN_EXPORT void rxd_setup_conc_ptrs(int conc_count, + int* conc_index, + PyHocObject** conc_ptrs) { /* info for NEURON concentration - to transfer to legacy */ int i; free_conc_ptrs(); @@ -205,11 +207,11 @@ extern "C" NRN_EXPORT void rxd_setup_conc_ptrs(int conc_count, int* conc_index, } extern "C" NRN_EXPORT void rxd_include_node_flux3D(int grid_count, - int* grid_counts, - int* grids, - long* index, - double* scales, - PyObject** sources) { + int* grid_counts, + int* grids, + long* index, + double* scales, + PyObject** sources) { Grid_node* g; int i = 0, j, k, n, grid_id; int offset = 0; @@ -288,7 +290,10 @@ extern "C" NRN_EXPORT void rxd_include_node_flux3D(int grid_count, } } -extern "C" NRN_EXPORT void rxd_include_node_flux1D(int n, long* index, double* scales, PyObject** sources) { +extern "C" NRN_EXPORT void rxd_include_node_flux1D(int n, + long* index, + double* scales, + PyObject** sources) { if (_node_flux_count != 0) { free(_node_flux_idx); free(_node_flux_scale); @@ -349,11 +354,11 @@ static void apply_node_flux1D(double dt, double* states) { } extern "C" NRN_EXPORT void rxd_set_euler_matrix(int nrow, - int nnonzero, - long* nonzero_i, - long* nonzero_j, - double* nonzero_values, - double* c_diagonal) { + int nnonzero, + long* nonzero_i, + long* nonzero_j, + double* nonzero_values, + double* c_diagonal) { long i, j, idx; double val; unsigned int k, ps; @@ -624,13 +629,13 @@ static void free_currents() { } extern "C" NRN_EXPORT void setup_currents(int num_currents, - int num_fluxes, - int* num_species, - int* node_idxs, - double* scales, - PyHocObject** ptrs, - int* mapped, - int* mapped_ecs) { + int num_fluxes, + int* num_species, + int* node_idxs, + double* scales, + PyHocObject** ptrs, + int* mapped, + int* mapped_ecs) { int i, j, k, id, side, count; int* induced_currents_ecs_idx; int* induced_currents_grid_id; @@ -847,18 +852,18 @@ extern "C" NRN_EXPORT int rxd_nonvint_block(int method, int size, double* p1, do extern "C" NRN_EXPORT void register_rate(int nspecies, - int nparam, - int nregions, - int nseg, - int* sidx, - int necs, - int necsparam, - int* ecs_ids, - int* ecsidx, - int nmult, - double* mult, - PyHocObject** vptrs, - ReactionRate f) { + int nparam, + int nregions, + int nseg, + int* sidx, + int necs, + int necsparam, + int* ecs_ids, + int* ecsidx, + int nmult, + double* mult, + PyHocObject** vptrs, + ReactionRate f) { int i, j, k, idx, ecs_id, ecs_index, ecs_offset; unsigned char counted; Grid_node* g; @@ -1044,7 +1049,10 @@ extern "C" NRN_EXPORT void remove_species_atolscale(int id) { } } -extern "C" NRN_EXPORT void setup_solver(double* my_states, int my_num_states, long* zvi, int num_zvi) { +extern "C" NRN_EXPORT void setup_solver(double* my_states, + int my_num_states, + long* zvi, + int num_zvi) { free_currents(); states = my_states; num_states = my_num_states; From d0985da406610e04b336340d797305f55d9de967 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 24 Jun 2024 15:22:41 +0200 Subject: [PATCH 66/79] more include --- src/nrnpython/inithoc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index 3b3339190d..849d507e9f 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -10,6 +10,8 @@ #include #include +#include "nrn_export.hpp" + #include #include From d725e9251b14558e5ac8ad4d31fbe553ae377740 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 24 Jun 2024 16:42:56 +0200 Subject: [PATCH 67/79] No more nrnpython.def --- src/nrnpython/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 5524ee953f..2646f95a60 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -28,10 +28,6 @@ set(NRNPYTHON_FILES_LIST rxd_marching_cubes.cpp rxd_llgramarea.cpp) -if(MINGW) - list(APPEND NRNPYTHON_FILES_LIST nrnpython.def) -endif() - set(INCLUDE_DIRS .. ../oc From ad67a76d7369829fa046cfadef9020e77db351c9 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 24 Jun 2024 17:15:13 +0200 Subject: [PATCH 68/79] export nrnpy_hoc --- src/nrnpython/inithoc.cpp | 2 +- src/nrnpython/nrnpy_hoc.cpp | 2 +- src/nrnpython/nrnpython.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index 849d507e9f..9e9c9ef508 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -24,7 +24,7 @@ extern int nrn_main_launch; // int nrn_global_argc; extern char** nrn_global_argv; extern void (*p_nrnpython_finalize)(); -extern PyObject* nrnpy_hoc(); +extern "C" PyObject* nrnpy_hoc(); #if NRNMPI_DYNAMICLOAD extern void nrnmpi_stubs(); diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index bf1b234843..43ac91d75f 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -3340,7 +3340,7 @@ static PyType_Spec obj_spec_from_name(const char* name) { }; } -PyObject* nrnpy_hoc() { +extern "C" NRN_EXPORT PyObject* nrnpy_hoc() { PyObject* m; PyObject* bases; PyTypeObject* pto; diff --git a/src/nrnpython/nrnpython.cpp b/src/nrnpython/nrnpython.cpp index ad78b3d134..1cc4afd638 100644 --- a/src/nrnpython/nrnpython.cpp +++ b/src/nrnpython/nrnpython.cpp @@ -175,7 +175,7 @@ static int nrnmingw_pyrun_interactiveloop() { return 0; } -extern PyObject* nrnpy_hoc(); +extern "C" PyObject* nrnpy_hoc(); extern PyObject* nrnpy_nrn(); /** @brief Start the Python interpreter. From 314c8afcd250ebbbb59a25b6cfdc611287200702 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 24 Jun 2024 17:42:26 +0200 Subject: [PATCH 69/79] add more NRN_EXPORT --- src/nrnpython/nrnpy_p2h.cpp | 2 +- src/nrnpython/rxd.cpp | 2 +- src/nrnpython/rxd_extracellular.cpp | 6 +++--- src/nrnpython/rxd_intracellular.cpp | 2 +- src/nrnpython/rxd_llgramarea.cpp | 6 ++++-- src/nrnpython/rxdmath.cpp | 12 +++++++----- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/nrnpython/nrnpy_p2h.cpp b/src/nrnpython/nrnpy_p2h.cpp index fad022b4b8..03a34a2e0d 100644 --- a/src/nrnpython/nrnpy_p2h.cpp +++ b/src/nrnpython/nrnpy_p2h.cpp @@ -1118,7 +1118,7 @@ void nrnpython_reg_real_nrnpy_hoc_cpp(neuron::python::impl_ptrs* ptrs); * @brief Populate NEURON state with information from a specific Python. * @param ptrs Logically a return value; avoidi */ -extern "C" void nrnpython_reg_real(neuron::python::impl_ptrs* ptrs) { +extern "C" NRN_EXPORT void nrnpython_reg_real(neuron::python::impl_ptrs* ptrs) { assert(ptrs); class2oc("PythonObject", p_cons, p_destruct, p_members, nullptr, nullptr, nullptr); nrnpy_pyobj_sym_ = hoc_lookup("PythonObject"); diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index d420bb47f0..96f7fd3f1f 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -1138,7 +1138,7 @@ void TaskQueue_exe_tasks(std::size_t thread_index, TaskQueue* q) { } -void set_num_threads(const int n) { +extern "C" NRN_EXPORT void set_num_threads(const int n) { assert(n > 0); assert(NUM_THREADS > 0); // n and NUM_THREADS include the main thread, old_num and new_num refer to diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index 6c4e910800..741077a728 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -163,7 +163,7 @@ Reaction* ecs_create_reaction(int list_idx, * grid_id - the grid id within the linked list - this corresponds to species * ECSReactionRate - the reaction function */ -extern "C" void ics_register_reaction(int list_idx, +extern "C" NRN_EXPORT void ics_register_reaction(int list_idx, int num_species, int num_params, int* species_id, @@ -189,7 +189,7 @@ extern "C" void ics_register_reaction(int list_idx, * grid_id - the grid id within the linked list - this corresponds to species * ECSReactionRate - the reaction function */ -extern "C" void ecs_register_reaction(int list_idx, +extern "C" NRN_EXPORT void ecs_register_reaction(int list_idx, int num_species, int num_params, int* species_id, @@ -599,7 +599,7 @@ void _fadvance_fixed_step_3D(void) { scatter_concentrations(); } -extern "C" void scatter_concentrations(void) { +extern "C" NRN_EXPORT void scatter_concentrations(void) { /* transfer concentrations to classic NEURON */ Grid_node* grid; diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index d083eeb569..cd5aab146e 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -19,7 +19,7 @@ const int ICS_PREFETCH = 3; /* * Sets the data to be used by the grids for 1D/3D hybrid models */ -extern "C" void set_hybrid_data(int64_t* num_1d_indices_per_grid, +extern "C" NRN_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, int64_t* num_3d_indices_per_grid, int64_t* hybrid_indices1d, int64_t* hybrid_indices3d, diff --git a/src/nrnpython/rxd_llgramarea.cpp b/src/nrnpython/rxd_llgramarea.cpp index c4875f7c54..04c673e6cc 100644 --- a/src/nrnpython/rxd_llgramarea.cpp +++ b/src/nrnpython/rxd_llgramarea.cpp @@ -1,6 +1,8 @@ #include -extern "C" double llgramarea(double* p0, double* p1, double* p2) { +#include "nrn_export.hpp" + +extern "C" NRN_EXPORT double llgramarea(double* p0, double* p1, double* p2) { /* setup the vectors */ double a[] = {p0[0] - p1[0], p0[1] - p1[1], p0[2] - p1[2]}; double b[] = {p0[0] - p2[0], p0[1] - p2[1], p0[2] - p2[2]}; @@ -13,7 +15,7 @@ extern "C" double llgramarea(double* p0, double* p1, double* p2) { } -extern "C" double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { +extern "C" NRN_EXPORT double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { /* take the cross-product */ double cpx = p1[1] * p2[2] - p1[2] * p2[1]; double cpy = p1[2] * p2[0] - p1[0] * p2[2]; diff --git a/src/nrnpython/rxdmath.cpp b/src/nrnpython/rxdmath.cpp index 3b3e4a2aed..300b24b280 100644 --- a/src/nrnpython/rxdmath.cpp +++ b/src/nrnpython/rxdmath.cpp @@ -3,29 +3,31 @@ #define M_PI (3.14159265358979323846) #endif +#include "nrn_export.hpp" + /*Some functions supported by numpy that aren't included in math.h * names and arguments match the wrappers used in rxdmath.py */ -extern "C" double factorial(const double x) { +extern "C" NRN_EXPORT double factorial(const double x) { return tgamma(x + 1.); } -extern "C" double degrees(const double radians) { +extern "C" NRN_EXPORT double degrees(const double radians) { return radians * (180. / M_PI); } -extern "C" void radians(const double degrees, double* radians) { +extern "C" NRN_EXPORT void radians(const double degrees, double* radians) { *radians = degrees * (M_PI / 180.); } -extern "C" double log1p(const double x) { +extern "C" NRN_EXPORT double log1p(const double x) { return log(x + 1.); } -extern "C" double vtrap(const double x, const double y) { +extern "C" NRN_EXPORT double vtrap(const double x, const double y) { if (fabs(x / y) < 1e-6) { return y * (1.0 - x / y / 2.0); } else { From 93e5b48530173e1aff07e8eab12f7d1ddec5f383 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 15:43:57 +0000 Subject: [PATCH 70/79] Fix formatting --- src/nrnpython/rxd_extracellular.cpp | 22 +++++++++++----------- src/nrnpython/rxd_intracellular.cpp | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index 741077a728..aeb377eed4 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -164,13 +164,13 @@ Reaction* ecs_create_reaction(int list_idx, * ECSReactionRate - the reaction function */ extern "C" NRN_EXPORT void ics_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - uint64_t* mc3d_start_indices, - int mc3d_region_size, - double* mc3d_mults, - ECSReactionRate f) { + int num_species, + int num_params, + int* species_id, + uint64_t* mc3d_start_indices, + int mc3d_region_size, + double* mc3d_mults, + ECSReactionRate f) { ecs_create_reaction(list_idx, num_species, num_params, @@ -190,10 +190,10 @@ extern "C" NRN_EXPORT void ics_register_reaction(int list_idx, * ECSReactionRate - the reaction function */ extern "C" NRN_EXPORT void ecs_register_reaction(int list_idx, - int num_species, - int num_params, - int* species_id, - ECSReactionRate f) { + int num_species, + int num_params, + int* species_id, + ECSReactionRate f) { ecs_create_reaction(list_idx, num_species, num_params, species_id, f, NULL, NULL, 0, NULL); ecs_refresh_reactions(NUM_THREADS); } diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index cd5aab146e..44fbb96c65 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -20,15 +20,15 @@ const int ICS_PREFETCH = 3; * Sets the data to be used by the grids for 1D/3D hybrid models */ extern "C" NRN_EXPORT void set_hybrid_data(int64_t* num_1d_indices_per_grid, - int64_t* num_3d_indices_per_grid, - int64_t* hybrid_indices1d, - int64_t* hybrid_indices3d, - int64_t* num_3d_indices_per_1d_seg, - int64_t* hybrid_grid_ids, - double* rates, - double* volumes1d, - double* volumes3d, - double* dxs) { + int64_t* num_3d_indices_per_grid, + int64_t* hybrid_indices1d, + int64_t* hybrid_indices3d, + int64_t* num_3d_indices_per_1d_seg, + int64_t* hybrid_grid_ids, + double* rates, + double* volumes1d, + double* volumes3d, + double* dxs) { Grid_node* grid; int i, j, k, id; int grid_id_check = 0; From a6465ab76c5172fdd6bc22134bc7078442234d2b Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Mon, 24 Jun 2024 19:50:01 +0200 Subject: [PATCH 71/79] One more --- src/nrnpython/grids.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 33b56950fa..e866be2998 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -415,7 +415,7 @@ extern "C" NRN_EXPORT int ICS_insert(int grid_list_index, return new_Grid->insert(grid_list_index); } -int ICS_insert_inhom(int grid_list_index, +extern "C" NRN_EXPORT int ICS_insert_inhom(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, From 2ffb3183ec65fa14d22fcc8c19ee19732b60ac56 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 17:52:02 +0000 Subject: [PATCH 72/79] Fix formatting --- src/nrnpython/grids.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index e866be2998..a02dd5b221 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -416,20 +416,20 @@ extern "C" NRN_EXPORT int ICS_insert(int grid_list_index, } extern "C" NRN_EXPORT int ICS_insert_inhom(int grid_list_index, - PyHocObject* my_states, - long num_nodes, - long* neighbors, - long* x_line_defs, - long x_lines_length, - long* y_line_defs, - long y_lines_length, - long* z_line_defs, - long z_lines_length, - double* dcs, - double dx, - bool is_diffusable, - double atolscale, - double* ics_alphas) { + PyHocObject* my_states, + long num_nodes, + long* neighbors, + long* x_line_defs, + long x_lines_length, + long* y_line_defs, + long y_lines_length, + long* z_line_defs, + long z_lines_length, + double* dcs, + double dx, + bool is_diffusable, + double atolscale, + double* ics_alphas) { ICS_Grid_node* new_Grid = new ICS_Grid_node(my_states, num_nodes, neighbors, From 6316e866e0a85614bb0ed088597b50b82895f5a7 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 25 Jun 2024 11:22:21 +0200 Subject: [PATCH 73/79] one more --- src/nrnpython/rxd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index 96f7fd3f1f..7cf61f7513 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -1192,7 +1192,7 @@ void TaskQueue_sync(TaskQueue* q) { q->waiting_cond.wait(lock, [q] { return q->length == 0; }); } -int get_num_threads(void) { +extern "C" NRN_EXPORT int get_num_threads(void) { return NUM_THREADS; } From 25b1725f560ab0df19dcc36ac729c72264ab215c Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 25 Jun 2024 11:47:06 +0200 Subject: [PATCH 74/79] one more --- src/nrnpython/nrnpython.h | 2 +- src/nrnpython/rxd_marching_cubes.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index eb98a335b5..b664c6e841 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -92,7 +92,7 @@ struct Symbol; bool nrn_chk_data_handle(const neuron::container::data_handle&); PyObject* nrn_hocobj_handle(neuron::container::data_handle d); -extern "C" NRN_EXPORT PyObject* nrn_hocobj_ptr(double*); +extern "C" PyObject* nrn_hocobj_ptr(double*); int nrn_is_hocobj_ptr(PyObject*, neuron::container::data_handle&); int nrn_pointer_assign(Prop*, Symbol*, PyObject*); neuron::container::generic_data_handle* nrnpy_setpointer_helper(PyObject*, PyObject*); diff --git a/src/nrnpython/rxd_marching_cubes.cpp b/src/nrnpython/rxd_marching_cubes.cpp index 7c3c7e16c1..c4305efa34 100644 --- a/src/nrnpython/rxd_marching_cubes.cpp +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -8,6 +8,8 @@ #include #include +#include "nrn_export.hpp" + const int edgeTable[] = { 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, @@ -333,7 +335,7 @@ void vi(double* p1, double* p2, double v1, double v2, double* out) { out[2] = p1[2] + mu * (p2[2] - p1[2]); } -extern "C" int find_triangles(double thresh, +extern "C" NRN_EXPORT int find_triangles(double thresh, double value0, double value1, double value2, From 15a286ba57c1dfa92dc514aac963829124dfc279 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:48:38 +0000 Subject: [PATCH 75/79] Fix formatting --- src/nrnpython/rxd_marching_cubes.cpp | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/nrnpython/rxd_marching_cubes.cpp b/src/nrnpython/rxd_marching_cubes.cpp index c4305efa34..e8f865c108 100644 --- a/src/nrnpython/rxd_marching_cubes.cpp +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -336,21 +336,21 @@ void vi(double* p1, double* p2, double v1, double v2, double* out) { } extern "C" NRN_EXPORT int find_triangles(double thresh, - double value0, - double value1, - double value2, - double value3, - double value4, - double value5, - double value6, - double value7, - double x0, - double x1, - double y0, - double y1, - double z0, - double z1, - double* out) { + double value0, + double value1, + double value2, + double value3, + double value4, + double value5, + double value6, + double value7, + double x0, + double x1, + double y0, + double y1, + double z0, + double z1, + double* out) { double position[8][3] = {{x0, y0, z0}, {x1, y0, z0}, {x1, y1, z0}, From 49281aa3876731d84d76f63603f0323b2fd52628 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 26 Jun 2024 08:39:34 +0200 Subject: [PATCH 76/79] Revert GHCI changes --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d77f7ec8ac..985eae0ae0 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -76,7 +76,7 @@ jobs: # * add 'live-debug-win' to your PR title # * push something to your PR branch (note that just re-running the pipeline disregards the title update) - name: live debug session on failure (manual steps required, check `.github/windows.yml`) - if: failure() + if: failure() && contains(github.event.pull_request.title, 'live-debug-win') uses: mxschmitt/action-tmate@v3 - name: Upload build artifact From a342e8c8b4677a1f0ce3b7770ac7b26996412b0f Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 26 Jun 2024 08:57:40 +0200 Subject: [PATCH 77/79] Test the new module --- CMakeLists.txt | 2 +- cmake/ExternalProjectHelper.cmake | 24 ++++++++++++++++++++---- src/coreneuron/CMakeLists.txt | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6d340153f..ba948e02a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -433,7 +433,7 @@ if(NRN_ENABLE_PYTHON) # Make sure the USE_PYTHON macro is defined in the C++ code list(APPEND NRN_COMPILE_DEFS USE_PYTHON) # Ensure nanobind is there, but dont import, we don't want its CMake - nrn_add_external_project(nanobind False) + nrn_add_external_project(nanobind DISABLE_ADD RECURSIVE SHALLOW) include(NanoBindMinimal) endif() diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index 78cc026818..cc32b445d1 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -23,13 +23,21 @@ endfunction(nrn_submodule_file_not_found) # initialize submodule with given path function(nrn_initialize_submodule path) + cmake_parse_arguments(PARSE_ARGV 1 opt "RECURSIVE;SHALLOW" "" "") + set(UPDATE_OPTIONS "") + if(opt_RECURSIVE) + list(APPEND UPDATE_OPTIONS --recursive) + endif() + if(opt_SHALLOW) + list(APPEND UPDATE_OPTIONS --depth 1) + endif() if(NOT ${GIT_FOUND}) message( FATAL_ERROR "git not found and ${path} sub-module not cloned (use git clone --recursive)") endif() - message(STATUS "Sub-module : missing ${path} : running git submodule update --init") + message(STATUS "Sub-module : missing ${path} : running git submodule update ${UPDATE_OPTIONS} --init") execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --recursive --init -- ${path} + COMMAND ${GIT_EXECUTABLE} submodule update ${UPDATE_OPTIONS} --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE ret) if(NOT ret EQUAL 0) @@ -39,6 +47,7 @@ endfunction() # check for external project and initialize submodule if it is missing function(nrn_add_external_project name) + cmake_parse_arguments(PARSE_ARGV 1 opt "RECURSIVE;SHALLOW;DISABLE_ADD" "" "") find_path( ${name}_PATH NAMES CMakeLists.txt @@ -46,13 +55,20 @@ function(nrn_add_external_project name) NO_DEFAULT_PATH) if(NOT EXISTS ${${name}_PATH}) nrn_submodule_file_not_found("${THIRD_PARTY_DIRECTORY}/${name}") - nrn_initialize_submodule("${THIRD_PARTY_DIRECTORY}/${name}") + set(OPTIONS "") + if(opt_RECURSIVE) + list(APPEND OPTIONS "RECURSIVE") + endif() + if (opt_SHALLOW) + list (APPEND OPTIONS "SHALLOW") + endif() + nrn_initialize_submodule("${THIRD_PARTY_DIRECTORY}/${name}" ${OPTIONS}) else() message(STATUS "Sub-project : using ${name} from from ${THIRD_PARTY_DIRECTORY}/${name}") endif() # if second argument is passed and if it's OFF then skip add_subdirectory if(${ARGC} GREATER 1) - if(${ARGV2}) + if(NOT opt_DISABLE_ADD) add_subdirectory("${THIRD_PARTY_DIRECTORY}/${name}") endif() else() diff --git a/src/coreneuron/CMakeLists.txt b/src/coreneuron/CMakeLists.txt index 3594329de6..6ec5a82389 100644 --- a/src/coreneuron/CMakeLists.txt +++ b/src/coreneuron/CMakeLists.txt @@ -267,7 +267,7 @@ else() set(NMODL_ENABLE_PYTHON_BINDINGS OFF CACHE BOOL "Enable NMODL python bindings") - nrn_add_external_project(nmodl OFF) + 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) From c218b711553d468457a4ca6c78568df5b7bb029d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:14:40 +0000 Subject: [PATCH 78/79] Fix formatting --- cmake/ExternalProjectHelper.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index cc32b445d1..159a470700 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -35,7 +35,8 @@ function(nrn_initialize_submodule path) message( FATAL_ERROR "git not found and ${path} sub-module not cloned (use git clone --recursive)") endif() - message(STATUS "Sub-module : missing ${path} : running git submodule update ${UPDATE_OPTIONS} --init") + message( + STATUS "Sub-module : missing ${path} : running git submodule update ${UPDATE_OPTIONS} --init") execute_process( COMMAND ${GIT_EXECUTABLE} submodule update ${UPDATE_OPTIONS} --init -- ${path} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} @@ -59,8 +60,8 @@ function(nrn_add_external_project name) if(opt_RECURSIVE) list(APPEND OPTIONS "RECURSIVE") endif() - if (opt_SHALLOW) - list (APPEND OPTIONS "SHALLOW") + if(opt_SHALLOW) + list(APPEND OPTIONS "SHALLOW") endif() nrn_initialize_submodule("${THIRD_PARTY_DIRECTORY}/${name}" ${OPTIONS}) else() From d3007ead84698b4548ac5abde708e8e66acab0e8 Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 26 Jun 2024 13:42:52 +0200 Subject: [PATCH 79/79] simplify disabling of adding modules --- cmake/ExternalProjectHelper.cmake | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmake/ExternalProjectHelper.cmake b/cmake/ExternalProjectHelper.cmake index cc32b445d1..6ea3fbf88d 100644 --- a/cmake/ExternalProjectHelper.cmake +++ b/cmake/ExternalProjectHelper.cmake @@ -66,12 +66,7 @@ function(nrn_add_external_project name) else() message(STATUS "Sub-project : using ${name} from from ${THIRD_PARTY_DIRECTORY}/${name}") endif() - # if second argument is passed and if it's OFF then skip add_subdirectory - if(${ARGC} GREATER 1) - if(NOT opt_DISABLE_ADD) - add_subdirectory("${THIRD_PARTY_DIRECTORY}/${name}") - endif() - else() + if(NOT opt_DISABLE_ADD) add_subdirectory("${THIRD_PARTY_DIRECTORY}/${name}") endif() endfunction()