From 8bde8a7bcb11e8b63a9a227bd92f61d845744c77 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 13:08:54 +0200 Subject: [PATCH 1/9] Require C++17. --- CMakeLists.txt | 2 +- external/nmodl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7829b3d5..74ab0250f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ math(EXPR CORENEURON_VERSION_COMBINED # ============================================================================= # CMake common project settings # ============================================================================= -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_BUILD_TYPE diff --git a/external/nmodl b/external/nmodl index d38eb74b7..ca370bb54 160000 --- a/external/nmodl +++ b/external/nmodl @@ -1 +1 @@ -Subproject commit d38eb74b71728e9ab3e9dc43c986d662faa3ff9e +Subproject commit ca370bb54cc2447899ad60aea5300c9cf28089e7 From b7983699f42134e532a9983729be05fc1a85dc3c Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 13:39:42 +0200 Subject: [PATCH 2/9] C++17 changes. --- CMake/MakefileBuildOptions.cmake | 5 ++--- CMake/OpenAccHelper.cmake | 2 -- CMakeLists.txt | 10 +++++++--- coreneuron/mechanism/mech/mod2c_core_thread.hpp | 6 ++++-- coreneuron/sim/scopmath/newton_thread.hpp | 9 +++++---- coreneuron/sim/scopmath/sparse_thread.hpp | 14 ++++++++------ coreneuron/utils/memory.cpp | 1 + 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/CMake/MakefileBuildOptions.cmake b/CMake/MakefileBuildOptions.cmake index a22a00bb7..7aef0c549 100644 --- a/CMake/MakefileBuildOptions.cmake +++ b/CMake/MakefileBuildOptions.cmake @@ -75,8 +75,7 @@ endforeach() # ============================================================================= # compile flags : common to all backend # ============================================================================= -# PGI compiler adds --c++14;-A option for C++14, remove ";" -string(REPLACE ";" " " CXX14_STD_FLAGS "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}") +string(JOIN " " CMAKE_CXX17_STANDARD_COMPILE_OPTION_STRING ${CMAKE_CXX17_STANDARD_COMPILE_OPTION}) string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE) list(TRANSFORM CORENRN_COMPILE_DEFS PREPEND -D OUTPUT_VARIABLE CORENRN_COMPILE_DEF_FLAGS) string( @@ -85,7 +84,7 @@ string( CORENRN_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE}} - ${CXX14_STD_FLAGS} + ${CMAKE_CXX17_STANDARD_COMPILE_OPTION_STRING} ${NVHPC_ACC_COMP_FLAGS} ${NVHPC_CXX_INLINE_FLAGS} ${CORENRN_COMPILE_DEF_FLAGS} diff --git a/CMake/OpenAccHelper.cmake b/CMake/OpenAccHelper.cmake index bb09f8966..1c18225b6 100644 --- a/CMake/OpenAccHelper.cmake +++ b/CMake/OpenAccHelper.cmake @@ -85,8 +85,6 @@ if(CORENRN_ENABLE_GPU) else() message(FATAL_ERROR "${CORENRN_ACCELERATOR_OFFLOAD} not supported with NVHPC compilers") endif() - # avoid PGI adding standard compliant "-A" flags - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14) string(APPEND CMAKE_EXE_LINKER_FLAGS " ${NVHPC_ACC_COMP_FLAGS}") # Use `-Mautoinline` option to compile .cpp files generated from .mod files only. This is # especially needed when we compile with -O0 or -O1 optimisation level where we get link errors. diff --git a/CMakeLists.txt b/CMakeLists.txt index 74ab0250f..cb1c96b6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,11 +30,10 @@ set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Empty or one of Debug, Release, RelWithDebInfo") -if(NOT "cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT "cxx_digit_separators" IN_LIST - CMAKE_CXX_COMPILE_FEATURES) +if(NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) message( FATAL_ERROR - "This compiler does not fully support C++14, choose an higher version or an other compiler.") + "This compiler does not fully support C++17, choose a higher version or another compiler.") endif() # ============================================================================= @@ -297,6 +296,11 @@ if(CORENRN_HAVE_NVHPC_COMPILER) # problem. If GPU support is disabled, we define R123_USE_INTRIN_H=0 to avoid the problem. list(APPEND CORENRN_COMPILE_DEFS R123_USE_INTRIN_H=0) endif() + # CMake versions <3.19 used to add -A when using NVHPC/PGI, which makes the compiler excessively + # pedantic. See https://gitlab.kitware.com/cmake/cmake/-/issues/20997. + if(CMAKE_VERSION VERSION_LESS 3.19) + list(REMOVE_ITEM CMAKE_CXX17_STANDARD_COMPILE_OPTION -A) + endif() endif() # ~~~ diff --git a/coreneuron/mechanism/mech/mod2c_core_thread.hpp b/coreneuron/mechanism/mech/mod2c_core_thread.hpp index 85ed348f6..286270cc8 100644 --- a/coreneuron/mechanism/mech/mod2c_core_thread.hpp +++ b/coreneuron/mechanism/mech/mod2c_core_thread.hpp @@ -12,6 +12,8 @@ #include "coreneuron/mechanism/mechanism.hpp" #include "coreneuron/utils/offload.hpp" +#include + namespace coreneuron { #define _STRIDE _cntml_padded + _iml @@ -74,7 +76,7 @@ template int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) { double const dt{_nt->_dt}; /* calculate the derivatives */ - fun(_threadargs_); // std::invoke in C++17 + std::invoke(fun, _threadargs_); /* update dependent variables */ for (int i = 0; i < neqn; i++) { _p[var[i] * _STRIDE] += dt * (_p[der[i] * _STRIDE]); @@ -84,7 +86,7 @@ int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) { template int derivimplicit_thread(int n, int* slist, int* dlist, F fun, _threadargsproto_) { - fun(_threadargs_); // std::invoke in C++17 + std::invoke(fun, _threadargs_); return 0; } diff --git a/coreneuron/sim/scopmath/newton_thread.hpp b/coreneuron/sim/scopmath/newton_thread.hpp index dc70b643a..ce2572a9b 100644 --- a/coreneuron/sim/scopmath/newton_thread.hpp +++ b/coreneuron/sim/scopmath/newton_thread.hpp @@ -16,6 +16,7 @@ #include #include +#include namespace coreneuron { #if defined(scopmath_newton_ix) || defined(scopmath_newton_s) || defined(scopmath_newton_x) @@ -57,11 +58,11 @@ void nrn_buildjacobian_thread(NewtonSpace* ns, for (int j = 0; j < n; j++) { double increment = std::max(std::fabs(0.02 * (scopmath_newton_x(index[j]))), STEP); scopmath_newton_x(index[j]) += increment; - func(_threadargs_); // std::invoke in C++17 + std::invoke(func, _threadargs_); for (int i = 0; i < n; i++) high_value[scopmath_newton_ix(i)] = value[scopmath_newton_ix(i)]; scopmath_newton_x(index[j]) -= 2.0 * increment; - func(_threadargs_); // std::invoke in C++17 + std::invoke(func, _threadargs_); for (int i = 0; i < n; i++) { low_value[scopmath_newton_ix(i)] = value[scopmath_newton_ix(i)]; @@ -75,7 +76,7 @@ void nrn_buildjacobian_thread(NewtonSpace* ns, /* Restore original variable and function values. */ scopmath_newton_x(index[j]) += increment; - func(_threadargs_); // std::invoke in C++17 + std::invoke(func, _threadargs_); } } #undef scopmath_newton_x @@ -160,7 +161,7 @@ inline int nrn_newton_thread(NewtonSpace* ns, } } // Evaulate function values with new solution. - func(_threadargs_); // std::invoke in C++17 + std::invoke(func, _threadargs_); max_dev = 0.0; for (int i = 0; i < n; i++) { value[scopmath_newton_ix(i)] = -value[scopmath_newton_ix(i)]; /* Required correction diff --git a/coreneuron/sim/scopmath/sparse_thread.hpp b/coreneuron/sim/scopmath/sparse_thread.hpp index 6614a0a1b..4daec7ba9 100644 --- a/coreneuron/sim/scopmath/sparse_thread.hpp +++ b/coreneuron/sim/scopmath/sparse_thread.hpp @@ -13,6 +13,8 @@ #include "coreneuron/mechanism/mech/mod2c_core_thread.hpp" #include "coreneuron/sim/scopmath/errcodes.h" +#include + namespace coreneuron { namespace scopmath { namespace sparse { @@ -479,7 +481,7 @@ void create_coef_list(SparseObj* so, int n, SPFUN fun, _threadargsproto_) { initeqn(so, (unsigned) n); so->phase = 1; so->ngetcall[0] = 0; - fun(so, so->rhs, _threadargs_); // std::invoke in C++17 + std::invoke(fun, so, so->rhs, _threadargs_); if (so->coef_list) { free(so->coef_list); } @@ -488,7 +490,7 @@ void create_coef_list(SparseObj* so, int n, SPFUN fun, _threadargsproto_) { spar_minorder(so); so->phase = 2; so->ngetcall[0] = 0; - fun(so, so->rhs, _threadargs_); // std::invoke in C++17 + std::invoke(fun, so, so->rhs, _threadargs_); so->phase = 0; } } // namespace sparse @@ -565,7 +567,7 @@ int sparse_thread(SparseObj* so, } for (err = 1, j = 0; err > CONVERGE; j++) { scopmath::sparse::init_coef_list(so, _iml); - fun(so, so->rhs, _threadargs_); // std::invoke in C++17 + std::invoke(fun, so, so->rhs, _threadargs_); if ((ierr = scopmath::sparse::matsol(so, _iml))) { return ierr; } @@ -583,8 +585,8 @@ int sparse_thread(SparseObj* so, break; } scopmath::sparse::init_coef_list(so, _iml); - fun(so, so->rhs, _threadargs_); // std::invoke in C++17 - for (i = 0; i < n; i++) { /*restore Dstate at t+dt*/ + std::invoke(fun, so, so->rhs, _threadargs_); + for (i = 0; i < n; i++) { /*restore Dstate at t+dt*/ scopmath_sparse_d(i) = (scopmath_sparse_s(i) - scopmath_sparse_d(i)) / dt; } return SUCCESS; @@ -603,7 +605,7 @@ int _cvode_sparse_thread(void** vpr, int n, int* x, SPFUN fun, _threadargsproto_ } scopmath::sparse::create_coef_list(so, n, fun, _threadargs_); /* calls fun twice */ scopmath::sparse::init_coef_list(so, _iml); - fun(so, so->rhs, _threadargs_); // std::invoke in C++17 + std::invoke(fun, so, so->rhs, _threadargs_); int ierr; if ((ierr = scopmath::sparse::matsol(so, _iml))) { return ierr; diff --git a/coreneuron/utils/memory.cpp b/coreneuron/utils/memory.cpp index 70d928b63..739482556 100644 --- a/coreneuron/utils/memory.cpp +++ b/coreneuron/utils/memory.cpp @@ -38,6 +38,7 @@ void* allocate_unified(std::size_t num_bytes) { // Either the build does not have GPU support or --gpu was not passed. // Allocate using standard operator new. // When we have C++17 support then propagate `alignment` here. + // TODO this could be done in this PR return ::operator new(num_bytes); } From a253eae319ab5a0c7d140b2c069d85ec97aafce9 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 14:24:49 +0200 Subject: [PATCH 3/9] alignment-aware allocation --- coreneuron/utils/memory.cpp | 26 +++++++++++++++++++------- coreneuron/utils/memory.h | 12 ++++++++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/coreneuron/utils/memory.cpp b/coreneuron/utils/memory.cpp index 739482556..8bef928df 100644 --- a/coreneuron/utils/memory.cpp +++ b/coreneuron/utils/memory.cpp @@ -23,7 +23,7 @@ bool unified_memory_enabled() { #endif } -void* allocate_unified(std::size_t num_bytes) { +void* allocate_unified(std::size_t num_bytes, std::align_val_t alignment) { #ifdef CORENEURON_ENABLE_GPU // The build supports GPU execution, check if --gpu was passed to actually // enable it. We should not call CUDA APIs in GPU builds if --gpu was not passed. @@ -32,20 +32,24 @@ void* allocate_unified(std::size_t num_bytes) { void* ptr{nullptr}; auto const code = cudaMallocManaged(&ptr, num_bytes); assert(code == cudaSuccess); + assert(is_aligned(ptr, alignment)); return ptr; } #endif // Either the build does not have GPU support or --gpu was not passed. // Allocate using standard operator new. - // When we have C++17 support then propagate `alignment` here. - // TODO this could be done in this PR - return ::operator new(num_bytes); + if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { + return ::operator new(num_bytes, alignment); + } else { + return ::operator new(num_bytes); + } } -void deallocate_unified(void* ptr, std::size_t num_bytes) { +void deallocate_unified(void* ptr, std::size_t num_bytes, std::align_val_t alignment) { // See comments in allocate_unified to understand the different branches. #ifdef CORENEURON_ENABLE_GPU if (corenrn_param.gpu) { + assert(is_aligned(ptr, alignment)); // Deallocate managed/unified memory. auto const code = cudaFree(ptr); assert(code == cudaSuccess); @@ -53,9 +57,17 @@ void deallocate_unified(void* ptr, std::size_t num_bytes) { } #endif #ifdef __cpp_sized_deallocation - ::operator delete(ptr, num_bytes); + if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { + ::operator delete(ptr, num_bytes, alignment); + } else { + ::operator delete(ptr, num_bytes); + } #else - ::operator delete(ptr); + if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { + ::operator delete(ptr, alignment); + } else { + ::operator delete(ptr); + } #endif } } // namespace coreneuron diff --git a/coreneuron/utils/memory.h b/coreneuron/utils/memory.h index 9a2e65645..919a7683c 100644 --- a/coreneuron/utils/memory.h +++ b/coreneuron/utils/memory.h @@ -32,11 +32,14 @@ bool unified_memory_enabled(); /** @brief Allocate unified memory in GPU builds iff GPU enabled, otherwise new */ -void* allocate_unified(std::size_t num_bytes); +void* allocate_unified(std::size_t num_bytes, + std::align_val_t alignment = std::align_val_t{alignof(std::max_align_t)}); /** @brief Deallocate memory allocated by `allocate_unified`. */ -void deallocate_unified(void* ptr, std::size_t num_bytes); +void deallocate_unified(void* ptr, + std::size_t num_bytes, + std::align_val_t alignment = std::align_val_t{alignof(std::max_align_t)}); /** @brief C++ allocator that uses [de]allocate_unified. */ @@ -50,11 +53,12 @@ struct unified_allocator { unified_allocator(unified_allocator const&) noexcept {} value_type* allocate(std::size_t n) { - return static_cast(allocate_unified(n * sizeof(value_type))); + return static_cast( + allocate_unified(n * sizeof(value_type), std::align_val_t{alignof(T)})); } void deallocate(value_type* p, std::size_t n) noexcept { - deallocate_unified(p, n * sizeof(value_type)); + deallocate_unified(p, n * sizeof(value_type), std::align_val_t{alignof(T)}); } }; From 92f8d92cba4c6e851416f28112ab72fcf7fd84cc Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 14:25:06 +0200 Subject: [PATCH 4/9] add TODO --- coreneuron/mpi/nrnmpi.h | 1 + 1 file changed, 1 insertion(+) diff --git a/coreneuron/mpi/nrnmpi.h b/coreneuron/mpi/nrnmpi.h index 04df699ff..5801a556a 100644 --- a/coreneuron/mpi/nrnmpi.h +++ b/coreneuron/mpi/nrnmpi.h @@ -71,6 +71,7 @@ struct mpi_function_base { // This could be done with a simpler // template struct function : function_base { ... }; // pattern in C++17... +// TODO this could be done in this PR template struct mpi_function {}; From 5b68044b08f5623ac7117cb9d3f619017e671cf1 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 14:33:38 +0200 Subject: [PATCH 5/9] Add includes. --- coreneuron/utils/memory.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coreneuron/utils/memory.h b/coreneuron/utils/memory.h index 919a7683c..3e21d66ba 100644 --- a/coreneuron/utils/memory.h +++ b/coreneuron/utils/memory.h @@ -1,6 +1,6 @@ /* # ============================================================================= -# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL +# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL # # See top-level LICENSE file for details. # =============================================================================. @@ -8,9 +8,11 @@ #pragma once +#include #include #include #include +#include #include "coreneuron/utils/nrn_assert.h" #include "coreneuron/nrniv/nrniv_decl.h" From 9c94480b8e98b139506e7f028af6ad9342b48a1b Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 15:21:00 +0200 Subject: [PATCH 6/9] fixups -- maybe this isn't worth it --- coreneuron/utils/memory.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/coreneuron/utils/memory.cpp b/coreneuron/utils/memory.cpp index 8bef928df..aceb89c84 100644 --- a/coreneuron/utils/memory.cpp +++ b/coreneuron/utils/memory.cpp @@ -32,24 +32,25 @@ void* allocate_unified(std::size_t num_bytes, std::align_val_t alignment) { void* ptr{nullptr}; auto const code = cudaMallocManaged(&ptr, num_bytes); assert(code == cudaSuccess); - assert(is_aligned(ptr, alignment)); + assert(is_aligned(ptr, static_cast(alignment))); return ptr; } #endif // Either the build does not have GPU support or --gpu was not passed. // Allocate using standard operator new. +#ifdef __cpp_aligned_new if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { return ::operator new(num_bytes, alignment); - } else { - return ::operator new(num_bytes); } +#endif + return ::operator new(num_bytes); } void deallocate_unified(void* ptr, std::size_t num_bytes, std::align_val_t alignment) { // See comments in allocate_unified to understand the different branches. #ifdef CORENEURON_ENABLE_GPU if (corenrn_param.gpu) { - assert(is_aligned(ptr, alignment)); + assert(is_aligned(ptr, static_cast(alignment))); // Deallocate managed/unified memory. auto const code = cudaFree(ptr); assert(code == cudaSuccess); @@ -57,17 +58,21 @@ void deallocate_unified(void* ptr, std::size_t num_bytes, std::align_val_t align } #endif #ifdef __cpp_sized_deallocation +#ifdef __cpp_aligned_new if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { ::operator delete(ptr, num_bytes, alignment); - } else { - ::operator delete(ptr, num_bytes); + return; } +#endif + ::operator delete(ptr, num_bytes); #else +#ifdef __cpp_aligned_new if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { ::operator delete(ptr, alignment); - } else { - ::operator delete(ptr); + return; } +#endif + ::operator delete(ptr); #endif } } // namespace coreneuron From a9f80b060935fb1245b77c31a0381903300309e7 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Fri, 1 Jul 2022 18:19:57 +0200 Subject: [PATCH 7/9] Drop TODOs that can be deferred. --- coreneuron/mpi/nrnmpi.h | 1 - coreneuron/utils/memory.cpp | 24 +++--------------------- coreneuron/utils/memory.h | 16 +++++----------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/coreneuron/mpi/nrnmpi.h b/coreneuron/mpi/nrnmpi.h index 5801a556a..04df699ff 100644 --- a/coreneuron/mpi/nrnmpi.h +++ b/coreneuron/mpi/nrnmpi.h @@ -71,7 +71,6 @@ struct mpi_function_base { // This could be done with a simpler // template struct function : function_base { ... }; // pattern in C++17... -// TODO this could be done in this PR template struct mpi_function {}; diff --git a/coreneuron/utils/memory.cpp b/coreneuron/utils/memory.cpp index aceb89c84..70d928b63 100644 --- a/coreneuron/utils/memory.cpp +++ b/coreneuron/utils/memory.cpp @@ -23,7 +23,7 @@ bool unified_memory_enabled() { #endif } -void* allocate_unified(std::size_t num_bytes, std::align_val_t alignment) { +void* allocate_unified(std::size_t num_bytes) { #ifdef CORENEURON_ENABLE_GPU // The build supports GPU execution, check if --gpu was passed to actually // enable it. We should not call CUDA APIs in GPU builds if --gpu was not passed. @@ -32,25 +32,19 @@ void* allocate_unified(std::size_t num_bytes, std::align_val_t alignment) { void* ptr{nullptr}; auto const code = cudaMallocManaged(&ptr, num_bytes); assert(code == cudaSuccess); - assert(is_aligned(ptr, static_cast(alignment))); return ptr; } #endif // Either the build does not have GPU support or --gpu was not passed. // Allocate using standard operator new. -#ifdef __cpp_aligned_new - if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - return ::operator new(num_bytes, alignment); - } -#endif + // When we have C++17 support then propagate `alignment` here. return ::operator new(num_bytes); } -void deallocate_unified(void* ptr, std::size_t num_bytes, std::align_val_t alignment) { +void deallocate_unified(void* ptr, std::size_t num_bytes) { // See comments in allocate_unified to understand the different branches. #ifdef CORENEURON_ENABLE_GPU if (corenrn_param.gpu) { - assert(is_aligned(ptr, static_cast(alignment))); // Deallocate managed/unified memory. auto const code = cudaFree(ptr); assert(code == cudaSuccess); @@ -58,20 +52,8 @@ void deallocate_unified(void* ptr, std::size_t num_bytes, std::align_val_t align } #endif #ifdef __cpp_sized_deallocation -#ifdef __cpp_aligned_new - if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - ::operator delete(ptr, num_bytes, alignment); - return; - } -#endif ::operator delete(ptr, num_bytes); #else -#ifdef __cpp_aligned_new - if (static_cast(alignment) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - ::operator delete(ptr, alignment); - return; - } -#endif ::operator delete(ptr); #endif } diff --git a/coreneuron/utils/memory.h b/coreneuron/utils/memory.h index 3e21d66ba..9a2e65645 100644 --- a/coreneuron/utils/memory.h +++ b/coreneuron/utils/memory.h @@ -1,6 +1,6 @@ /* # ============================================================================= -# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL +# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL # # See top-level LICENSE file for details. # =============================================================================. @@ -8,11 +8,9 @@ #pragma once -#include #include #include #include -#include #include "coreneuron/utils/nrn_assert.h" #include "coreneuron/nrniv/nrniv_decl.h" @@ -34,14 +32,11 @@ bool unified_memory_enabled(); /** @brief Allocate unified memory in GPU builds iff GPU enabled, otherwise new */ -void* allocate_unified(std::size_t num_bytes, - std::align_val_t alignment = std::align_val_t{alignof(std::max_align_t)}); +void* allocate_unified(std::size_t num_bytes); /** @brief Deallocate memory allocated by `allocate_unified`. */ -void deallocate_unified(void* ptr, - std::size_t num_bytes, - std::align_val_t alignment = std::align_val_t{alignof(std::max_align_t)}); +void deallocate_unified(void* ptr, std::size_t num_bytes); /** @brief C++ allocator that uses [de]allocate_unified. */ @@ -55,12 +50,11 @@ struct unified_allocator { unified_allocator(unified_allocator const&) noexcept {} value_type* allocate(std::size_t n) { - return static_cast( - allocate_unified(n * sizeof(value_type), std::align_val_t{alignof(T)})); + return static_cast(allocate_unified(n * sizeof(value_type))); } void deallocate(value_type* p, std::size_t n) noexcept { - deallocate_unified(p, n * sizeof(value_type), std::align_val_t{alignof(T)}); + deallocate_unified(p, n * sizeof(value_type)); } }; From 4582adaa3ea6b907d6572d367e48e97d90c83ca5 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Tue, 5 Jul 2022 10:16:11 +0200 Subject: [PATCH 8/9] update nmodl to master --- external/nmodl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/nmodl b/external/nmodl index ca370bb54..58456d101 160000 --- a/external/nmodl +++ b/external/nmodl @@ -1 +1 @@ -Subproject commit ca370bb54cc2447899ad60aea5300c9cf28089e7 +Subproject commit 58456d1018a177691ce4d63ac2ef436d1e535000 From 7b9545128354112b822337e7413e0e592c9464d8 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Tue, 5 Jul 2022 22:55:56 +0200 Subject: [PATCH 9/9] test reverting std::invoke --- coreneuron/mechanism/mech/mod2c_core_thread.hpp | 6 ++---- coreneuron/sim/scopmath/newton_thread.hpp | 9 ++++----- coreneuron/sim/scopmath/sparse_thread.hpp | 14 ++++++-------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/coreneuron/mechanism/mech/mod2c_core_thread.hpp b/coreneuron/mechanism/mech/mod2c_core_thread.hpp index 286270cc8..85ed348f6 100644 --- a/coreneuron/mechanism/mech/mod2c_core_thread.hpp +++ b/coreneuron/mechanism/mech/mod2c_core_thread.hpp @@ -12,8 +12,6 @@ #include "coreneuron/mechanism/mechanism.hpp" #include "coreneuron/utils/offload.hpp" -#include - namespace coreneuron { #define _STRIDE _cntml_padded + _iml @@ -76,7 +74,7 @@ template int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) { double const dt{_nt->_dt}; /* calculate the derivatives */ - std::invoke(fun, _threadargs_); + fun(_threadargs_); // std::invoke in C++17 /* update dependent variables */ for (int i = 0; i < neqn; i++) { _p[var[i] * _STRIDE] += dt * (_p[der[i] * _STRIDE]); @@ -86,7 +84,7 @@ int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) { template int derivimplicit_thread(int n, int* slist, int* dlist, F fun, _threadargsproto_) { - std::invoke(fun, _threadargs_); + fun(_threadargs_); // std::invoke in C++17 return 0; } diff --git a/coreneuron/sim/scopmath/newton_thread.hpp b/coreneuron/sim/scopmath/newton_thread.hpp index ce2572a9b..dc70b643a 100644 --- a/coreneuron/sim/scopmath/newton_thread.hpp +++ b/coreneuron/sim/scopmath/newton_thread.hpp @@ -16,7 +16,6 @@ #include #include -#include namespace coreneuron { #if defined(scopmath_newton_ix) || defined(scopmath_newton_s) || defined(scopmath_newton_x) @@ -58,11 +57,11 @@ void nrn_buildjacobian_thread(NewtonSpace* ns, for (int j = 0; j < n; j++) { double increment = std::max(std::fabs(0.02 * (scopmath_newton_x(index[j]))), STEP); scopmath_newton_x(index[j]) += increment; - std::invoke(func, _threadargs_); + func(_threadargs_); // std::invoke in C++17 for (int i = 0; i < n; i++) high_value[scopmath_newton_ix(i)] = value[scopmath_newton_ix(i)]; scopmath_newton_x(index[j]) -= 2.0 * increment; - std::invoke(func, _threadargs_); + func(_threadargs_); // std::invoke in C++17 for (int i = 0; i < n; i++) { low_value[scopmath_newton_ix(i)] = value[scopmath_newton_ix(i)]; @@ -76,7 +75,7 @@ void nrn_buildjacobian_thread(NewtonSpace* ns, /* Restore original variable and function values. */ scopmath_newton_x(index[j]) += increment; - std::invoke(func, _threadargs_); + func(_threadargs_); // std::invoke in C++17 } } #undef scopmath_newton_x @@ -161,7 +160,7 @@ inline int nrn_newton_thread(NewtonSpace* ns, } } // Evaulate function values with new solution. - std::invoke(func, _threadargs_); + func(_threadargs_); // std::invoke in C++17 max_dev = 0.0; for (int i = 0; i < n; i++) { value[scopmath_newton_ix(i)] = -value[scopmath_newton_ix(i)]; /* Required correction diff --git a/coreneuron/sim/scopmath/sparse_thread.hpp b/coreneuron/sim/scopmath/sparse_thread.hpp index 4daec7ba9..6614a0a1b 100644 --- a/coreneuron/sim/scopmath/sparse_thread.hpp +++ b/coreneuron/sim/scopmath/sparse_thread.hpp @@ -13,8 +13,6 @@ #include "coreneuron/mechanism/mech/mod2c_core_thread.hpp" #include "coreneuron/sim/scopmath/errcodes.h" -#include - namespace coreneuron { namespace scopmath { namespace sparse { @@ -481,7 +479,7 @@ void create_coef_list(SparseObj* so, int n, SPFUN fun, _threadargsproto_) { initeqn(so, (unsigned) n); so->phase = 1; so->ngetcall[0] = 0; - std::invoke(fun, so, so->rhs, _threadargs_); + fun(so, so->rhs, _threadargs_); // std::invoke in C++17 if (so->coef_list) { free(so->coef_list); } @@ -490,7 +488,7 @@ void create_coef_list(SparseObj* so, int n, SPFUN fun, _threadargsproto_) { spar_minorder(so); so->phase = 2; so->ngetcall[0] = 0; - std::invoke(fun, so, so->rhs, _threadargs_); + fun(so, so->rhs, _threadargs_); // std::invoke in C++17 so->phase = 0; } } // namespace sparse @@ -567,7 +565,7 @@ int sparse_thread(SparseObj* so, } for (err = 1, j = 0; err > CONVERGE; j++) { scopmath::sparse::init_coef_list(so, _iml); - std::invoke(fun, so, so->rhs, _threadargs_); + fun(so, so->rhs, _threadargs_); // std::invoke in C++17 if ((ierr = scopmath::sparse::matsol(so, _iml))) { return ierr; } @@ -585,8 +583,8 @@ int sparse_thread(SparseObj* so, break; } scopmath::sparse::init_coef_list(so, _iml); - std::invoke(fun, so, so->rhs, _threadargs_); - for (i = 0; i < n; i++) { /*restore Dstate at t+dt*/ + fun(so, so->rhs, _threadargs_); // std::invoke in C++17 + for (i = 0; i < n; i++) { /*restore Dstate at t+dt*/ scopmath_sparse_d(i) = (scopmath_sparse_s(i) - scopmath_sparse_d(i)) / dt; } return SUCCESS; @@ -605,7 +603,7 @@ int _cvode_sparse_thread(void** vpr, int n, int* x, SPFUN fun, _threadargsproto_ } scopmath::sparse::create_coef_list(so, n, fun, _threadargs_); /* calls fun twice */ scopmath::sparse::init_coef_list(so, _iml); - std::invoke(fun, so, so->rhs, _threadargs_); + fun(so, so->rhs, _threadargs_); // std::invoke in C++17 int ierr; if ((ierr = scopmath::sparse::matsol(so, _iml))) { return ierr;