diff --git a/src/cpp/cuda.cpp b/src/cpp/cuda.cpp index 4bceb78fb07c50ba21866b40cad97ca4df322458..00c7072c71a5a67e57cc9be53347559640ad7d68 100644 --- a/src/cpp/cuda.cpp +++ b/src/cpp/cuda.cpp @@ -1,3 +1,6 @@ +#define NO_IMPORT_ARRAY +#define PY_ARRAY_UNIQUE_SYMBOL pycuda_ARRAY_API + #include "cuda.hpp" boost::thread_specific_ptr pycuda::context_stack_ptr; diff --git a/src/wrapper/_pvt_struct_v2.cpp b/src/wrapper/_pvt_struct_v2.cpp index dac348468efe85bc7fb4e3edca4c861a5db7beee..aab88150ecb627754f123bdfe9558e22f17ac472 100644 --- a/src/wrapper/_pvt_struct_v2.cpp +++ b/src/wrapper/_pvt_struct_v2.cpp @@ -7,13 +7,15 @@ * for packing complex values and only supports native packing. * (the minimum that's needed for PyOpenCL/PyCUDA.) */ +#define PY_ARRAY_UNIQUE_SYMBOL pycuda_pvt_struct_v2_ARRAY_API + #define PY_SSIZE_T_CLEAN #include "Python.h" +#include #include "structseq.h" #include "structmember.h" #include -#include "numpy_init.hpp" // static PyTypeObject PyStructType; @@ -1570,6 +1572,8 @@ The variable struct.error is an exception raised on errors.\n"); PyMODINIT_FUNC init_pvt_struct(void) { + import_array(); + PyObject *ver, *m; ver = PyString_FromString("0.2"); diff --git a/src/wrapper/_pvt_struct_v3.cpp b/src/wrapper/_pvt_struct_v3.cpp index 316062f1e72f118ee69b1af766d5345f397a78b9..15f7b18e132ef60f4b7a3ba5d3c79d7ed22d51c8 100644 --- a/src/wrapper/_pvt_struct_v3.cpp +++ b/src/wrapper/_pvt_struct_v3.cpp @@ -3,12 +3,14 @@ /* New version supporting byte order, alignment and size options, character strings, and unsigned numbers */ +#define PY_ARRAY_UNIQUE_SYMBOL pycuda_pvt_struct_v2_ARRAY_API + #define PY_SSIZE_T_CLEAN #include "Python.h" +#include #include "structmember.h" #include -#include "numpy_init.hpp" namespace { extern PyTypeObject PyStructType; @@ -1720,6 +1722,8 @@ extern "C" PyMODINIT_FUNC PyInit__pvt_struct(void) { + import_array(); + PyObject *m; m = PyModule_Create(&_structmodule); diff --git a/src/wrapper/mempool.cpp b/src/wrapper/mempool.cpp index 7734a6a2a14ed1822010c5d9d6b517cd9e964cf0..918d3d0d5ca9e166ef04937c9963fd512d1e5bfa 100644 --- a/src/wrapper/mempool.cpp +++ b/src/wrapper/mempool.cpp @@ -1,3 +1,6 @@ +#define NO_IMPORT_ARRAY +#define PY_ARRAY_UNIQUE_SYMBOL pycuda_ARRAY_API + #include #include "tools.hpp" #include "wrap_helpers.hpp" diff --git a/src/wrapper/numpy_init.hpp b/src/wrapper/numpy_init.hpp deleted file mode 100644 index a07198593bc63e03e0377e080af7dc1b2adeaba0..0000000000000000000000000000000000000000 --- a/src/wrapper/numpy_init.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _FAYHVVAAA_PYCUDA_HEADER_SEEN_NUMPY_INIT_HPP - - - - -#include -#include - - - - -namespace -{ - static struct pyublas_array_importer - { - static bool do_import_array() - { - import_array1(false); - return true; - } - - pyublas_array_importer() - { - if (!do_import_array()) - throw std::runtime_error("numpy failed to initialize"); - } - } _array_importer; -} - - - - -#endif diff --git a/src/wrapper/tools.hpp b/src/wrapper/tools.hpp index f0fd57180a6b06e74c97a314a9bb98d56b8c47c8..98a7d8c3714d4069a3db8c5449937869654fa45d 100644 --- a/src/wrapper/tools.hpp +++ b/src/wrapper/tools.hpp @@ -7,7 +7,7 @@ #include #include #include -#include "numpy_init.hpp" +#include diff --git a/src/wrapper/wrap_cudadrv.cpp b/src/wrapper/wrap_cudadrv.cpp index f50f12b4316213de8f4ad9503dd96433306a2050..dfa3d1cda929f86a186fb6788bd0e438128a0f6f 100644 --- a/src/wrapper/wrap_cudadrv.cpp +++ b/src/wrapper/wrap_cudadrv.cpp @@ -1,3 +1,5 @@ +#define PY_ARRAY_UNIQUE_SYMBOL pycuda_ARRAY_API + #include #include @@ -656,8 +658,18 @@ void pycuda_expose_curand(); +static bool import_numpy_helper() +{ + import_array1(false); + return true; +} + + BOOST_PYTHON_MODULE(_driver) { + if (!import_numpy_helper()) + throw py::error_already_set(); + py::def("get_version", cuda_version); #if CUDAPP_CUDA_VERSION >= 2020 py::def("get_driver_version", pycuda::get_driver_version);