Skip to content

Commit

Permalink
Move SVM constructor to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Oct 8, 2024
1 parent 7f51e24 commit 1dfcd6f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 0 additions & 10 deletions pyopencl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,15 +1323,6 @@ def svmptr_as_buffer(self, ctx: Context, *, flags: Optional[int] = None,

# }}}

if get_cl_header_version() >= (2, 0):
svm_old_init = SVM.__init__

def svm_init(self, mem):
if get_cl_header_version() >= (2, 0):
svm_old_init(self, mem)

self.mem = mem

def svm_map(self, queue, flags, is_blocking=True, wait_for=None):
"""
:arg is_blocking: If *False*, subsequent code must wait on
Expand Down Expand Up @@ -1368,7 +1359,6 @@ def svm__enqueue_unmap(self, queue, wait_for=None):
return _cl._enqueue_svm_unmap(queue, self, wait_for)

if get_cl_header_version() >= (2, 0):
SVM.__init__ = svm_init
SVM.map = svm_map
SVM.map_ro = svm_map_ro
SVM.map_rw = svm_map_rw
Expand Down
9 changes: 8 additions & 1 deletion src/wrap_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ namespace pyopencl
}
};


// }}}


inline
py::tuple get_cl_header_version()
{
Expand Down Expand Up @@ -3663,9 +3663,11 @@ namespace pyopencl
void *m_ptr;
PYOPENCL_BUFFER_SIZE_T m_size;
std::unique_ptr<py_buffer_wrapper> ward;
py::object m_mem;

public:
svm_arg_wrapper(py::object holder)
: m_mem(holder)
{
ward = std::unique_ptr<py_buffer_wrapper>(new py_buffer_wrapper);
#ifdef PYPY_VERSION
Expand All @@ -3688,6 +3690,11 @@ namespace pyopencl
{
return m_size;
}

py::object mem() const
{
return m_mem;
}
};

// }}}
Expand Down
1 change: 1 addition & 0 deletions src/wrap_cl_part_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ void pyopencl_expose_part_2(py::module_ &m)
typedef svm_arg_wrapper cls;
py::class_<cls, svm_pointer>(m, "SVM", py::dynamic_attr())
.def(py::init<py::object>())
.def_prop_ro("mem", &cls::mem)
;
}

Expand Down

0 comments on commit 1dfcd6f

Please sign in to comment.