Repository navigation
Updates for the array/size argument changes #3561
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # This code was automatically generated across versions from 12.4.1 to 13.5.0. Do not modify it directly. | ||
| # CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=5017cbd422315ed05d8c8d89fcf7ee2efa806dbccab0e7cc58a646a037f8053a | ||
| # CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=93a3aa883e727ee9fb62ffe1decd27a9c8f56eb75312e1c3c8ab5457a880c10c | ||
|
|
||
|
|
||
| # <<<< PREAMBLE CONTENT >>>> | ||
|
|
@@ -17,35 +17,53 @@ from libc.stdint cimport intptr_t | |
|
|
||
| from cuda.bindings._internal._fast_enum import FastEnum as _cyb_FastEnum | ||
|
|
||
| cdef intptr_t _cyb_get_buffer_pointer(buf, Py_ssize_t size, readonly=True) except?-1: | ||
| cdef intptr_t ptr | ||
| cdef int flags = _cyb_cpython.PyBUF_ANY_CONTIGUOUS | ||
| if not readonly: | ||
| flags |= _cyb_cpython.PyBUF_WRITABLE | ||
| cdef int status = -1 | ||
| cdef _cyb_cpython.Py_buffer view | ||
| if buf is None: | ||
| ptr = 0 | ||
| elif isinstance(buf, int): | ||
| ptr = <intptr_t>buf | ||
| else: | ||
| cdef class _cyb_BufferGuard: | ||
| """Holds an export of a buffer for as long as it lives. | ||
|
|
||
| `buf` is `None` (NULL), a Python `int` (an address, which is not held), or a contiguous buffer. | ||
| With `wrap_errors`, any failure to get the buffer (or its size, if `size` is not -1) is a `ValueError`. | ||
| """ | ||
| cdef _cyb_cpython.Py_buffer _view | ||
| cdef bint _held | ||
| cdef void* ptr | ||
| cdef Py_ssize_t nbytes | ||
|
|
||
| def __cinit__(self, buf, Py_ssize_t size, bint readonly, bint wrap_errors): | ||
|
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. Keep oversized explicit counts on the
Declare the guard's count as |
||
| cdef int flags = _cyb_cpython.PyBUF_ANY_CONTIGUOUS | ||
| self._held = False | ||
| self.ptr = NULL | ||
| self.nbytes = 0 | ||
| if buf is None: | ||
| return | ||
| if isinstance(buf, int): | ||
| self.ptr = <void*><intptr_t>buf | ||
| return | ||
| if not readonly: | ||
| flags |= _cyb_cpython.PyBUF_WRITABLE | ||
| adj = "writable " if not readonly else "" | ||
| try: | ||
| status = _cyb_cpython.PyObject_GetBuffer(buf, &view, flags) | ||
| _cyb_cpython.PyObject_GetBuffer(buf, &self._view, flags) | ||
| self._held = True | ||
| if size != -1: | ||
| assert view.len == size | ||
| assert self._view.len == size | ||
|
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. important: Keep the buffer length check active under optimized Python. Cython omits this check when assertions are disabled. A buffer with a mismatched byte count then reaches the native call with the caller's original |
||
| except Exception as e: | ||
| adj = "writable " if not readonly else "" | ||
| if wrap_errors: | ||
| raise ValueError( | ||
| "buf must be None, a Python int representing the pointer " | ||
| f"address to a valid buffer, or a contiguous {adj}" | ||
| f"buffer (a ctypes object, NumPy array, bytes, ...), of size {size}" | ||
| ) from e | ||
| if not isinstance(e, BufferError): | ||
| raise | ||
| raise ValueError( | ||
| "buf must be None, a Python int representing the pointer " | ||
| f"address to a valid buffer, or a contiguous {adj}" | ||
| f"buffer (a ctypes object, NumPy array, bytes, ...), of size {size}" | ||
| f"buf must be a contiguous {adj}buffer (a ctypes object, NumPy array, bytes, ...)" | ||
| ) from e | ||
| else: | ||
| ptr = <intptr_t>view.buf | ||
| finally: | ||
| if status == 0: | ||
| _cyb_cpython.PyBuffer_Release(&view) | ||
| return ptr | ||
| self.ptr = self._view.buf | ||
| self.nbytes = self._view.len | ||
|
|
||
| def __dealloc__(self): | ||
| if self._held: | ||
| _cyb_cpython.PyBuffer_Release(&self._view) | ||
|
|
||
|
|
||
| # <<<< END OF PREAMBLE CONTENT >>>> | ||
|
|
@@ -192,7 +210,8 @@ cpdef add_ptx(intptr_t handle, code, size_t size, arch, identifier, options_cmd_ | |
|
|
||
| .. seealso:: `nvFatbinAddPTX` | ||
| """ | ||
| cdef void* _code_ = <void *>_cyb_get_buffer_pointer(code, size, readonly=True) | ||
| cdef _cyb_BufferGuard _code_guard_ = _cyb_BufferGuard(code, size, True, True) | ||
| cdef void* _code_ = _code_guard_.ptr | ||
| if not isinstance(arch, str): | ||
| raise TypeError("arch must be a Python str") | ||
| cdef bytes _temp_arch_ = (<str>arch).encode() | ||
|
|
@@ -224,7 +243,8 @@ cpdef add_cubin(intptr_t handle, code, size_t size, arch, identifier): | |
|
|
||
| .. seealso:: `nvFatbinAddCubin` | ||
| """ | ||
| cdef void* _code_ = <void *>_cyb_get_buffer_pointer(code, size, readonly=True) | ||
| cdef _cyb_BufferGuard _code_guard_ = _cyb_BufferGuard(code, size, True, True) | ||
| cdef void* _code_ = _code_guard_.ptr | ||
| if not isinstance(arch, str): | ||
| raise TypeError("arch must be a Python str") | ||
| cdef bytes _temp_arch_ = (<str>arch).encode() | ||
|
|
@@ -253,7 +273,8 @@ cpdef add_ltoir(intptr_t handle, code, size_t size, arch, identifier, options_cm | |
|
|
||
| .. seealso:: `nvFatbinAddLTOIR` | ||
| """ | ||
| cdef void* _code_ = <void *>_cyb_get_buffer_pointer(code, size, readonly=True) | ||
| cdef _cyb_BufferGuard _code_guard_ = _cyb_BufferGuard(code, size, True, True) | ||
| cdef void* _code_ = _code_guard_.ptr | ||
| if not isinstance(arch, str): | ||
| raise TypeError("arch must be a Python str") | ||
| cdef bytes _temp_arch_ = (<str>arch).encode() | ||
|
|
@@ -298,7 +319,8 @@ cpdef get(intptr_t handle, buffer): | |
|
|
||
| .. seealso:: `nvFatbinGet` | ||
| """ | ||
| cdef void* _buffer_ = <void *>_cyb_get_buffer_pointer(buffer, -1, readonly=False) | ||
| cdef _cyb_BufferGuard _buffer_guard_ = _cyb_BufferGuard(buffer, -1, False, True) | ||
| cdef void* _buffer_ = _buffer_guard_.ptr | ||
| with nogil: | ||
| __status__ = nvFatbinGet(<Handle>handle, <void*>_buffer_) | ||
| check_status(__status__) | ||
|
|
@@ -334,7 +356,8 @@ cpdef add_index(intptr_t handle, code, size_t size, identifier): | |
|
|
||
| .. seealso:: `nvFatbinAddIndex` | ||
| """ | ||
| cdef void* _code_ = <void *>_cyb_get_buffer_pointer(code, size, readonly=True) | ||
| cdef _cyb_BufferGuard _code_guard_ = _cyb_BufferGuard(code, size, True, True) | ||
| cdef void* _code_ = _code_guard_.ptr | ||
| if not isinstance(identifier, str): | ||
| raise TypeError("identifier must be a Python str") | ||
| cdef bytes _temp_identifier_ = (<str>identifier).encode() | ||
|
|
@@ -354,7 +377,8 @@ cpdef add_reloc(intptr_t handle, code, size_t size): | |
|
|
||
| .. seealso:: `nvFatbinAddReloc` | ||
| """ | ||
| cdef void* _code_ = <void *>_cyb_get_buffer_pointer(code, size, readonly=True) | ||
| cdef _cyb_BufferGuard _code_guard_ = _cyb_BufferGuard(code, size, True, True) | ||
| cdef void* _code_ = _code_guard_.ptr | ||
| with nogil: | ||
| __status__ = nvFatbinAddReloc(<Handle>handle, <const void*>_code_, size) | ||
| check_status(__status__) | ||
|
|
@@ -373,7 +397,8 @@ cpdef add_tile_ir(intptr_t handle, code, size_t size, identifier, options_cmd_li | |
|
|
||
| .. seealso:: `nvFatbinAddTileIR` | ||
| """ | ||
| cdef void* _code_ = <void *>_cyb_get_buffer_pointer(code, size, readonly=True) | ||
| cdef _cyb_BufferGuard _code_guard_ = _cyb_BufferGuard(code, size, True, True) | ||
| cdef void* _code_ = _code_guard_.ptr | ||
| if not isinstance(identifier, str): | ||
| raise TypeError("identifier must be a Python str") | ||
| cdef bytes _temp_identifier_ = (<str>identifier).encode() | ||
|
|
||
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.
important: Record the generation inputs and command in the PR.
The PR description identifies a generator update, but it does not identify the generator revision, the toolkit inputs for each root, or the regeneration command. A seal verifies file content, not how the file was generated. Add those details so reviewers can reproduce the artifacts. As per coding guidelines, “record the generator revision, toolkit inputs, and command in the pull request.” (github.com)
Source: Coding guidelines