Merge bc489e2f0db946ab30b442c8d593f9cb4e8f4053 into 0a1fd5a2e295b68815ac3daffd73886f52dd7d2a

This commit is contained in:
Drew Parsons 2025-01-07 16:55:08 +01:00 committed by GitHub
commit 696819d207
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#define NETGEN_CORE_PYTHON_NGCORE_HPP #define NETGEN_CORE_PYTHON_NGCORE_HPP
#include "ngcore_api.hpp" // for operator new #include "ngcore_api.hpp" // for operator new
#include <cstdint>
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include <pybind11/operators.h> #include <pybind11/operators.h>
#include <pybind11/numpy.h> #include <pybind11/numpy.h>
@ -182,10 +183,12 @@ namespace ngcore
static std::string GetName() { return "D"; } static std::string GetName() { return "D"; }
}; };
#if INTPTR_MAX != INT32_MAX
template<> template<>
struct PyNameTraits<size_t> { struct PyNameTraits<size_t> {
static std::string GetName() { return "S"; } static std::string GetName() { return "S"; }
}; };
#endif
template<typename T> template<typename T>
struct PyNameTraits<std::shared_ptr<T>> { struct PyNameTraits<std::shared_ptr<T>> {

View File

@ -1,3 +1,5 @@
#include <cstdint>
#include "python_ngcore.hpp" #include "python_ngcore.hpp"
#include "bitarray.hpp" #include "bitarray.hpp"
#include "taskmanager.hpp" #include "taskmanager.hpp"
@ -23,7 +25,9 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
catch(...) {} catch(...) {}
ExportArray<int>(m); ExportArray<int>(m);
ExportArray<unsigned>(m); ExportArray<unsigned>(m);
#if INTPTR_MAX != INT32_MAX
ExportArray<size_t>(m); ExportArray<size_t>(m);
#endif
ExportArray<double>(m); ExportArray<double>(m);
ExportArray<float>(m); ExportArray<float>(m);
ExportArray<signed short>(m); ExportArray<signed short>(m);

View File

@ -8,6 +8,7 @@
/**************************************************************************/ /**************************************************************************/
#include <atomic> #include <atomic>
#include <cstdint>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
@ -104,8 +105,10 @@ namespace ngcore
{ return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(int*)(entrysize.Addr(0)))); } { return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(int*)(entrysize.Addr(0)))); }
NETGEN_INLINE size_t * TablePrefixSum (FlatArray<std::atomic<int>> entrysize) NETGEN_INLINE size_t * TablePrefixSum (FlatArray<std::atomic<int>> entrysize)
{ return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(std::atomic<int>*)entrysize.Addr(0))); } { return TablePrefixSum32 (FlatArray<unsigned> (entrysize.Size(), (unsigned int*)(std::atomic<int>*)entrysize.Addr(0))); }
#if INTPTR_MAX != INT32_MAX
NETGEN_INLINE size_t * TablePrefixSum (FlatArray<size_t> entrysize) NETGEN_INLINE size_t * TablePrefixSum (FlatArray<size_t> entrysize)
{ return TablePrefixSum64 (entrysize); } { return TablePrefixSum64 (entrysize); }
#endif
/** /**

View File

@ -19,7 +19,9 @@
#ifdef NETGEN_ARCH_AMD64 #ifdef NETGEN_ARCH_AMD64
#ifdef WIN32 #ifdef WIN32
#include <intrin.h> // for __rdtsc() CPU time step counter #include <intrin.h> // for __rdtsc() CPU time step counter
#else #define NGCORE_HAVE_RDTSC
#elif defined __SSE__
#define NGCORE_HAVE_RDTSC
#include <x86intrin.h> // for __rdtsc() CPU time step counter #include <x86intrin.h> // for __rdtsc() CPU time step counter
#endif // WIN32 #endif // WIN32
#endif // NETGEN_ARCH_AMD64 #endif // NETGEN_ARCH_AMD64
@ -65,7 +67,7 @@ namespace ngcore
{ {
#if defined(__APPLE__) && defined(NETGEN_ARCH_ARM64) #if defined(__APPLE__) && defined(NETGEN_ARCH_ARM64)
return mach_absolute_time(); return mach_absolute_time();
#elif defined(NETGEN_ARCH_AMD64) #elif defined(NETGEN_ARCH_AMD64) || defined(NGCORE_HAVE_RDTSC)
return __rdtsc(); return __rdtsc();
#elif defined(NETGEN_ARCH_ARM64) && defined(__GNUC__) #elif defined(NETGEN_ARCH_ARM64) && defined(__GNUC__)
// __GNUC__ is also defined by CLANG. Use inline asm to read Generic Timer // __GNUC__ is also defined by CLANG. Use inline asm to read Generic Timer
@ -74,6 +76,8 @@ namespace ngcore
return tics; return tics;
#elif defined(__EMSCRIPTEN__) #elif defined(__EMSCRIPTEN__)
return std::chrono::high_resolution_clock::now().time_since_epoch().count(); 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 #else
#warning "Unsupported CPU architecture" #warning "Unsupported CPU architecture"
return 0; return 0;

View File

@ -1 +1,7 @@
from .pyngcore import * from .pyngcore import *
# <size_t> is the same as <unsigned int> 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