From 84fc680e721a31e417880c01fb5107639ef5e301 Mon Sep 17 00:00:00 2001 From: Drew Parsons Date: Sun, 5 Jan 2025 13:17:13 +0100 Subject: [PATCH 1/2] fix 32-bit usage of size_t On 32-bit systems size_t is identical unsigned in, causing redefinition errors in tables (Array_I_S). This patch guards against the 32-bit redefinition and defines Array_I_S = Array_I_U for the python interface if not already defined. Applies debian patch size_t_int32.patch https://salsa.debian.org/science-team/netgen/-/blob/d7ca1c564d90d00ce3d83e0b63c36fbec11cf1ce/debian/patches/size_t_int32.patch Fixes #168 --- libsrc/core/python_ngcore.hpp | 3 +++ libsrc/core/python_ngcore_export.cpp | 4 ++++ libsrc/core/table.hpp | 3 +++ python/pyngcore/__init__.py | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index 2ce844817..605554c7d 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -2,6 +2,7 @@ #define NETGEN_CORE_PYTHON_NGCORE_HPP #include "ngcore_api.hpp" // for operator new +#include #include #include #include @@ -182,10 +183,12 @@ namespace ngcore static std::string GetName() { return "D"; } }; +#if INTPTR_MAX != INT32_MAX template<> struct PyNameTraits { static std::string GetName() { return "S"; } }; +#endif template struct PyNameTraits> { diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index cc9f5a704..7bfb59370 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -1,3 +1,5 @@ +#include + #include "python_ngcore.hpp" #include "bitarray.hpp" #include "taskmanager.hpp" @@ -23,7 +25,9 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT catch(...) {} ExportArray(m); ExportArray(m); +#if INTPTR_MAX != INT32_MAX ExportArray(m); +#endif ExportArray(m); ExportArray(m); ExportArray(m); diff --git a/libsrc/core/table.hpp b/libsrc/core/table.hpp index d2326c266..a51ae3a59 100644 --- a/libsrc/core/table.hpp +++ b/libsrc/core/table.hpp @@ -8,6 +8,7 @@ /**************************************************************************/ #include +#include #include #include @@ -104,8 +105,10 @@ namespace ngcore { return TablePrefixSum32 (FlatArray (entrysize.Size(), (unsigned int*)(int*)(entrysize.Addr(0)))); } NETGEN_INLINE size_t * TablePrefixSum (FlatArray> entrysize) { return TablePrefixSum32 (FlatArray (entrysize.Size(), (unsigned int*)(std::atomic*)entrysize.Addr(0))); } +#if INTPTR_MAX != INT32_MAX NETGEN_INLINE size_t * TablePrefixSum (FlatArray entrysize) { return TablePrefixSum64 (entrysize); } +#endif /** diff --git a/python/pyngcore/__init__.py b/python/pyngcore/__init__.py index 29580174a..6536a898e 100644 --- a/python/pyngcore/__init__.py +++ b/python/pyngcore/__init__.py @@ -1 +1,7 @@ from .pyngcore import * + +# is the same as on 32 bit arches +# in which case Array_I_S is not defined by python_ngcore_export.cpp. +# In this case identify it with Array_I_U. +try: Array_I_S +except NameError: Array_I_S=Array_I_U From bc489e2f0db946ab30b442c8d593f9cb4e8f4053 Mon Sep 17 00:00:00 2001 From: Drew Parsons Date: Sun, 5 Jan 2025 13:28:59 +0100 Subject: [PATCH 2/2] support non-x86 arches missing RDTSC Extends support of non-intel architectures which do not have an RDTSC timer. Applies debian patch support-non-x86.patch https://salsa.debian.org/science-team/netgen/-/blob/d7ca1c564d90d00ce3d83e0b63c36fbec11cf1ce/debian/patches/support-non-x86.patch --- libsrc/core/utils.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index a503d53c4..24b171e25 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -19,7 +19,9 @@ #ifdef NETGEN_ARCH_AMD64 #ifdef WIN32 #include // for __rdtsc() CPU time step counter -#else +#define NGCORE_HAVE_RDTSC +#elif defined __SSE__ +#define NGCORE_HAVE_RDTSC #include // for __rdtsc() CPU time step counter #endif // WIN32 #endif // NETGEN_ARCH_AMD64 @@ -65,7 +67,7 @@ namespace ngcore { #if defined(__APPLE__) && defined(NETGEN_ARCH_ARM64) return mach_absolute_time(); -#elif defined(NETGEN_ARCH_AMD64) +#elif defined(NETGEN_ARCH_AMD64) || defined(NGCORE_HAVE_RDTSC) return __rdtsc(); #elif defined(NETGEN_ARCH_ARM64) && defined(__GNUC__) // __GNUC__ is also defined by CLANG. Use inline asm to read Generic Timer @@ -74,6 +76,8 @@ namespace ngcore return tics; #elif defined(__EMSCRIPTEN__) return std::chrono::high_resolution_clock::now().time_since_epoch().count(); +#elifndef NGCORE_HAVE_RDTSC + return TTimePoint(std::chrono::steady_clock::now().time_since_epoch().count()); #else #warning "Unsupported CPU architecture" return 0;