Skip to content

Commit

Permalink
Python 3.13 removed the old buffer interface
Browse files Browse the repository at this point in the history
for details, see python/cpython#85275
  • Loading branch information
totaam committed Aug 16, 2024
1 parent 96aab3f commit cbaa895
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/wrapper/wrap_cudadrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ namespace
module *module_from_buffer(py::object buffer, py::object py_options,
py::object message_handler)
{
const char *mod_buf;
PYCUDA_BUFFER_SIZE_T len;
if (PyObject_AsCharBuffer(buffer.ptr(), &mod_buf, &len))
Py_buffer py_buf;
if (PyObject_GetBuffer(buffer.ptr(), &py_buf, PyBUF_ANY_CONTIGUOUS))
throw py::error_already_set();
CUmodule mod;

Expand Down Expand Up @@ -387,10 +387,12 @@ namespace

CUDAPP_PRINT_CALL_TRACE("cuModuleLoadDataEx");
CUresult cu_status_code; \
cu_status_code = cuModuleLoadDataEx(&mod, mod_buf, (unsigned int) options.size(),
cu_status_code = cuModuleLoadDataEx(&mod, py_buf.buf, (unsigned int) options.size(),
const_cast<CUjit_option *>(&*options.begin()),
const_cast<void **>(&*option_values.begin()));

PyBuffer_Release(&py_buf);

size_t info_buf_size = size_t(option_values[1]);
size_t error_buf_size = size_t(option_values[3]);

Expand All @@ -407,7 +409,8 @@ namespace
throw pycuda::error("module_from_buffer", CUDA_ERROR_INVALID_VALUE,
"non-empty options argument only supported on CUDA 2.1 and newer");

CUDAPP_CALL_GUARDED(cuModuleLoadData, (&mod, mod_buf));
CUDAPP_CALL_GUARDED(cuModuleLoadData, (&mod, py_buf.buf));
PyBuffer_Release(&py_buf)
#endif

return new module(mod);
Expand Down Expand Up @@ -500,16 +503,16 @@ namespace

void add_data(py::object py_data, CUjitInputType input_type, py::str py_name)
{
const char *data_buf;
Py_buffer py_buf;
PYCUDA_BUFFER_SIZE_T data_buf_len;
if (PyObject_AsCharBuffer(py_data.ptr(), &data_buf, &data_buf_len) != 0) {
if (PyObject_GetBuffer(py_data.ptr(), &py_buf, PyBUF_ANY_CONTIGUOUS)) {
throw py::error_already_set();
}
const char* name = (py_name.ptr() != Py_None)?
py::extract<const char*>(py_name) : NULL;
const CUresult cu_result = cuLinkAddData(m_link_state, input_type,
static_cast<void *>(const_cast<char *>(data_buf)),
data_buf_len, name, 0, NULL, NULL);
const CUresult cu_result = cuLinkAddData(m_link_state, input_type, py_buf.buf,
py_buf.len, name, 0, NULL, NULL);
PyBuffer_Release(&py_buf);
check_cu_result("cuLinkAddData", cu_result);
}

Expand Down

0 comments on commit cbaa895

Please sign in to comment.