-
Notifications
You must be signed in to change notification settings - Fork 248
[PERF]: Faster void * conversion #1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
143b128
2350e36
a992e59
0462a0d
e9a6c3e
0baf1fa
467f108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,31 +128,32 @@ cdef class _HelperKernelParams: | |
|
|
||
| cdef class _HelperInputVoidPtr: | ||
| def __cinit__(self, ptr): | ||
| self._pyobj_acquired = False | ||
| self._cptr = _helper_input_void_ptr(ptr, &self._helper) | ||
|
|
||
| def __dealloc__(self): | ||
| _helper_input_void_ptr_free(&self._helper) | ||
|
|
||
| @property | ||
| def cptr(self): | ||
| return <void_ptr>self._cptr | ||
|
|
||
|
|
||
| cdef void * _helper_input_void_ptr(ptr, _HelperInputVoidPtrStruct *helper): | ||
| helper[0]._pybuffer.buf = NULL | ||
| try: | ||
| return <void *><void_ptr>ptr | ||
| except: | ||
| if ptr is None: | ||
| self._cptr = NULL | ||
| elif isinstance(ptr, (int)): | ||
| # Easy run, user gave us an already configured void** address | ||
| self._cptr = <void*><void_ptr>ptr | ||
| elif isinstance(ptr, (_driver["CUdeviceptr"])): | ||
| self._cptr = <void*><void_ptr>int(ptr) | ||
|
Comment on lines
-137
to
-138
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: This path seems to be gone?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep -- it is now redundant with calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I mean it's handled by this line, with the implicit conversion to int: |
||
| return NULL | ||
| elif PyObject_CheckBuffer(ptr): | ||
| # Easy run, get address from Python Buffer Protocol | ||
| err_buffer = PyObject_GetBuffer(ptr, &self._pybuffer, PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS) | ||
| err_buffer = PyObject_GetBuffer(ptr, &helper[0]._pybuffer, PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS) | ||
| if err_buffer == -1: | ||
| raise RuntimeError("Failed to retrieve buffer through Buffer Protocol") | ||
| self._pyobj_acquired = True | ||
| self._cptr = <void*><void_ptr>self._pybuffer.buf | ||
| return <void*><void_ptr>(helper[0]._pybuffer.buf) | ||
| else: | ||
| raise TypeError("Provided argument is of type {} but expected Type {}, {} or object with Buffer Protocol".format(type(ptr), type(None), type(int))) | ||
|
|
||
| def __dealloc__(self): | ||
| if self._pyobj_acquired is True: | ||
| PyBuffer_Release(&self._pybuffer) | ||
|
|
||
| @property | ||
| def cptr(self): | ||
| return <void_ptr>self._cptr | ||
|
|
||
| {{if 'CUmemPool_attribute_enum' in found_types}} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Should we check first if
helperis NULL?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but since this internal code only ever called from generated code, I think it's safe to skip it. Since
_helperis stack-allocated, there is nomallocfailing to check for.