Skip to content

Commit

Permalink
Fix numpy initialization. Closes inducergh-214
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Aug 9, 2019
1 parent 9c024f3 commit ea7d1fa
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
3 changes: 3 additions & 0 deletions src/cpp/cuda.cpp
Original file line number Diff line number Diff line change
@@ -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> pycuda::context_stack_ptr;
6 changes: 5 additions & 1 deletion src/wrapper/_pvt_struct_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <numpy/arrayobject.h>
#include "structseq.h"
#include "structmember.h"
#include <ctype.h>
#include "numpy_init.hpp"

// static PyTypeObject PyStructType;

Expand Down Expand Up @@ -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");
Expand Down
6 changes: 5 additions & 1 deletion src/wrapper/_pvt_struct_v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <numpy/arrayobject.h>
#include "structmember.h"
#include <ctype.h>
#include "numpy_init.hpp"

namespace {
extern PyTypeObject PyStructType;
Expand Down Expand Up @@ -1720,6 +1722,8 @@ extern "C"
PyMODINIT_FUNC
PyInit__pvt_struct(void)
{
import_array();

PyObject *m;

m = PyModule_Create(&_structmodule);
Expand Down
3 changes: 3 additions & 0 deletions src/wrapper/mempool.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define NO_IMPORT_ARRAY
#define PY_ARRAY_UNIQUE_SYMBOL pycuda_ARRAY_API

#include <vector>
#include "tools.hpp"
#include "wrap_helpers.hpp"
Expand Down
33 changes: 0 additions & 33 deletions src/wrapper/numpy_init.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/wrapper/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <cuda.hpp>
#include <boost/python.hpp>
#include <numeric>
#include "numpy_init.hpp"
#include <numpy/arrayobject.h>



Expand Down
12 changes: 12 additions & 0 deletions src/wrapper/wrap_cudadrv.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define PY_ARRAY_UNIQUE_SYMBOL pycuda_ARRAY_API

#include <cuda.hpp>

#include <utility>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ea7d1fa

Please sign in to comment.