Coverage for cuda/bindings/cudla.pyx: 39.80%
985 statements
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 01:06 +0000
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 01:06 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2# SPDX-License-Identifier: Apache-2.0
4# This code was automatically generated across versions from 1.5.0 to 13.5.0. Do not modify it directly.
5# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=2ddc08b7839e06f87dbb946eab7b3db85897fa051767efd3b966d681dbde4550
8# <<<< PREAMBLE CONTENT >>>>
10cimport cpython as _cyb_cpython
11cimport cpython.buffer as _cyb_cpython_buffer
12from cpython.buffer cimport (
13 PyBUF_SIMPLE as _cyb_PyBUF_SIMPLE,
14 PyBuffer_Release as _cyb_PyBuffer_Release,
15 PyObject_GetBuffer as _cyb_PyObject_GetBuffer,
16 Py_buffer as _cyb_Py_buffer,
17)
18cimport cython as _cyb_cython
19from cython cimport view as _cyb_view
20from libc.stdint cimport (
21 intptr_t,
22 uint32_t,
23 uint64_t,
24 uint8_t,
25)
26from libc.stdlib cimport (
27 calloc as _cyb_calloc,
28 free as _cyb_free,
29)
30from libc.string cimport (
31 memcmp as _cyb_memcmp,
32 memcpy as _cyb_memcpy,
33 memmove as _cyb_memmove,
34)
36from cuda.bindings._internal._fast_enum import FastEnum as _cyb_FastEnum
38import numpy as _numpy
40cdef _cyb___getbuffer(object self, _cyb_cpython.Py_buffer *buffer, void *ptr, int size, bint readonly):
41 buffer.buf = <char *>ptr
42 buffer.format = 'b'
43 buffer.internal = NULL
44 buffer.itemsize = 1
45 buffer.len = size
46 buffer.ndim = 1
47 buffer.obj = self
48 buffer.readonly = readonly
49 buffer.shape = &buffer.len
50 buffer.strides = &buffer.itemsize
51 buffer.suboffsets = NULL
53cdef _cyb_from_buffer(buffer, size, lowpp_type):
54 cdef _cyb_cpython.Py_buffer view
55 if _cyb_cpython.PyObject_GetBuffer(buffer, &view, _cyb_cpython_buffer.PyBUF_SIMPLE) != 0:
56 raise TypeError("buffer argument does not support the buffer protocol")
57 try:
58 if view.itemsize != 1:
59 raise ValueError("buffer itemsize must be 1 byte")
60 if view.len != size:
61 raise ValueError(f"buffer length must be {size} bytes")
62 return lowpp_type.from_ptr(<intptr_t><void *>view.buf, view.readonly != 0, buffer)
63 finally:
64 _cyb_cpython.PyBuffer_Release(&view)
66cdef _cyb_from_data(data, dtype_name, expected_dtype, lowpp_type):
67 # _numpy.recarray is a subclass of _numpy.ndarray, so implicitly handled here.
68 if isinstance(data, lowpp_type):
69 return data
70 if not isinstance(data, _numpy.ndarray):
71 raise TypeError("data argument must be a NumPy ndarray")
72 if data.size != 1:
73 raise ValueError("data array must have a size of 1")
74 if data.dtype != expected_dtype:
75 raise ValueError(f"data array must be of dtype {dtype_name}")
76 return lowpp_type.from_ptr(data.ctypes.data, not data.flags.writeable, data)
78cdef intptr_t _cyb_get_buffer_pointer(buf, Py_ssize_t size, readonly=True) except?-1:
79 cdef intptr_t ptr
80 cdef int flags = _cyb_cpython.PyBUF_ANY_CONTIGUOUS
81 if not readonly:
82 flags |= _cyb_cpython.PyBUF_WRITABLE
83 cdef int status = -1
84 cdef _cyb_cpython.Py_buffer view
85 if buf is None:
86 ptr = 0
87 elif isinstance(buf, int):
88 ptr = <intptr_t>buf
89 else:
90 try:
91 status = _cyb_cpython.PyObject_GetBuffer(buf, &view, flags)
92 if size != -1:
93 assert view.len == size
94 except Exception as e:
95 adj = "writable " if not readonly else ""
96 raise ValueError(
97 "buf must be None, a Python int representing the pointer "
98 f"address to a valid buffer, or a contiguous {adj}"
99 f"buffer (a ctypes object, NumPy array, bytes, ...), of size {size}"
100 ) from e
101 else:
102 ptr = <intptr_t>view.buf
103 finally:
104 if status == 0:
105 _cyb_cpython.PyBuffer_Release(&view)
106 return ptr
109# <<<< END OF PREAMBLE CONTENT >>>>
111cimport cython # NOQA
112from libc.stdint cimport intptr_t, uintptr_t
113from libc.stdlib cimport malloc, free
119###############################################################################
120# POD
121###############################################################################
123cdef _get_external_memory_handle_desc_dtype_offsets():
124 cdef cudlaExternalMemoryHandleDesc_t *pod = <cudlaExternalMemoryHandleDesc_t *>_cyb_calloc(1, sizeof(cudlaExternalMemoryHandleDesc_t))
125 if pod == NULL:
126 raise MemoryError("Error allocating cudlaExternalMemoryHandleDesc_t")
127 try:
128 return _numpy.dtype({
129 'names': ['ext_buf_object', 'size_'],
130 'formats': [_numpy.intp, _numpy.uint64],
131 'offsets': [
132 (<intptr_t>&(pod.extBufObject)) - (<intptr_t>pod),
133 (<intptr_t>&(pod.size)) - (<intptr_t>pod),
134 ],
135 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t),
136 })
137 finally:
138 _cyb_free(pod)
140external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets()
142cdef class ExternalMemoryHandleDesc:
143 """Empty-initialize an instance of `cudlaExternalMemoryHandleDesc_t`.
146 .. seealso:: `cudlaExternalMemoryHandleDesc_t`
147 """
148 cdef:
149 cudlaExternalMemoryHandleDesc_t _data
150 cudlaExternalMemoryHandleDesc_t *_ptr
151 object _owner
152 bint _readonly
154 def __init__(self):
155 self._ptr = &self._data 1f
156 self._owner = None 1f
157 self._readonly = False 1f
159 def __repr__(self):
160 return f"<{__name__}.ExternalMemoryHandleDesc object at {hex(id(self))}>"
162 @property
163 def ptr(self):
164 """Get the pointer address to the data as Python :class:`int`."""
165 return <intptr_t>(self._ptr)
167 cdef intptr_t _get_ptr(self):
168 return <intptr_t>(self._ptr)
170 def __int__(self):
171 return <intptr_t>(self._ptr)
173 def __eq__(self, other):
174 cdef ExternalMemoryHandleDesc other_
175 if not isinstance(other, ExternalMemoryHandleDesc):
176 return False
177 other_ = other
178 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaExternalMemoryHandleDesc_t)) == 0)
180 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
181 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalMemoryHandleDesc_t), self._readonly)
183 def __releasebuffer__(self, Py_buffer *buffer):
184 pass
186 def __setitem__(self, key, val):
187 cdef _cyb_Py_buffer view
188 if key == 0:
189 if self._readonly:
190 raise ValueError("This ExternalMemoryHandleDesc instance is read-only")
191 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
192 try:
193 if <size_t>view.len < sizeof(cudlaExternalMemoryHandleDesc_t):
194 raise ValueError(
195 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaExternalMemoryHandleDesc_t), view.len)
196 )
197 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaExternalMemoryHandleDesc_t))
198 self._ptr = &self._data
199 self._owner = None
200 self._readonly = view.readonly != 0
201 finally:
202 _cyb_PyBuffer_Release(&view)
203 else:
204 setattr(self, key, val)
206 @property
207 def ext_buf_object(self):
208 """int: """
209 return <intptr_t>(self._ptr[0].extBufObject) 1f
211 @ext_buf_object.setter
212 def ext_buf_object(self, val):
213 if self._readonly: 1f
214 raise ValueError("This ExternalMemoryHandleDesc instance is read-only")
215 self._ptr[0].extBufObject = <void *><intptr_t>val 1f
217 @property
218 def size_(self):
219 """int: """
220 return self._ptr[0].size 1f
222 @size_.setter
223 def size_(self, val):
224 if self._readonly: 1f
225 raise ValueError("This ExternalMemoryHandleDesc instance is read-only")
226 self._ptr[0].size = val 1f
228 @staticmethod
229 def from_buffer(buffer):
230 """Create an ExternalMemoryHandleDesc instance with the memory from the given buffer."""
231 return _cyb_from_buffer(buffer, sizeof(cudlaExternalMemoryHandleDesc_t), ExternalMemoryHandleDesc)
233 @staticmethod
234 def from_data(data):
235 """Create an ExternalMemoryHandleDesc instance wrapping the given NumPy array.
237 Args:
238 data (_numpy.ndarray): a single-element array of dtype `external_memory_handle_desc_dtype` holding the data.
239 """
240 return _cyb_from_data(data, "external_memory_handle_desc_dtype", external_memory_handle_desc_dtype, ExternalMemoryHandleDesc)
242 @staticmethod
243 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
244 """Create an ExternalMemoryHandleDesc instance wrapping the given pointer.
246 Args:
247 ptr (intptr_t): pointer address as Python :class:`int` to the data.
248 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
249 readonly (bool): whether the data is read-only (to the user). default is `False`.
250 """
251 if ptr == 0:
252 raise ValueError("ptr must not be null (0)")
253 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc)
254 if owner is None:
255 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaExternalMemoryHandleDesc_t))
256 obj._ptr = &obj._data
257 obj._owner = None
258 else:
259 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr
260 obj._owner = owner
261 obj._readonly = readonly
262 return obj
265cdef _get_external_semaphore_handle_desc_dtype_offsets():
266 cdef cudlaExternalSemaphoreHandleDesc_t *pod = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_calloc(1, sizeof(cudlaExternalSemaphoreHandleDesc_t))
267 if pod == NULL:
268 raise MemoryError("Error allocating cudlaExternalSemaphoreHandleDesc_t")
269 try:
270 return _numpy.dtype({
271 'names': ['ext_sync_object'],
272 'formats': [_numpy.intp],
273 'offsets': [
274 (<intptr_t>&(pod.extSyncObject)) - (<intptr_t>pod),
275 ],
276 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t),
277 })
278 finally:
279 _cyb_free(pod)
281external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets()
283cdef class ExternalSemaphoreHandleDesc:
284 """Empty-initialize an instance of `cudlaExternalSemaphoreHandleDesc_t`.
287 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t`
288 """
289 cdef:
290 cudlaExternalSemaphoreHandleDesc_t _data
291 cudlaExternalSemaphoreHandleDesc_t *_ptr
292 object _owner
293 bint _readonly
295 def __init__(self):
296 self._ptr = &self._data 1l
297 self._owner = None 1l
298 self._readonly = False 1l
300 def __repr__(self):
301 return f"<{__name__}.ExternalSemaphoreHandleDesc object at {hex(id(self))}>"
303 @property
304 def ptr(self):
305 """Get the pointer address to the data as Python :class:`int`."""
306 return <intptr_t>(self._ptr)
308 cdef intptr_t _get_ptr(self):
309 return <intptr_t>(self._ptr)
311 def __int__(self):
312 return <intptr_t>(self._ptr)
314 def __eq__(self, other):
315 cdef ExternalSemaphoreHandleDesc other_
316 if not isinstance(other, ExternalSemaphoreHandleDesc):
317 return False
318 other_ = other
319 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaExternalSemaphoreHandleDesc_t)) == 0)
321 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
322 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t), self._readonly)
324 def __releasebuffer__(self, Py_buffer *buffer):
325 pass
327 def __setitem__(self, key, val):
328 cdef _cyb_Py_buffer view
329 if key == 0:
330 if self._readonly:
331 raise ValueError("This ExternalSemaphoreHandleDesc instance is read-only")
332 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
333 try:
334 if <size_t>view.len < sizeof(cudlaExternalSemaphoreHandleDesc_t):
335 raise ValueError(
336 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaExternalSemaphoreHandleDesc_t), view.len)
337 )
338 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaExternalSemaphoreHandleDesc_t))
339 self._ptr = &self._data
340 self._owner = None
341 self._readonly = view.readonly != 0
342 finally:
343 _cyb_PyBuffer_Release(&view)
344 else:
345 setattr(self, key, val)
347 @property
348 def ext_sync_object(self):
349 """int: """
350 return <intptr_t>(self._ptr[0].extSyncObject) 1l
352 @ext_sync_object.setter
353 def ext_sync_object(self, val):
354 if self._readonly: 1l
355 raise ValueError("This ExternalSemaphoreHandleDesc instance is read-only")
356 self._ptr[0].extSyncObject = <void *><intptr_t>val 1l
358 @staticmethod
359 def from_buffer(buffer):
360 """Create an ExternalSemaphoreHandleDesc instance with the memory from the given buffer."""
361 return _cyb_from_buffer(buffer, sizeof(cudlaExternalSemaphoreHandleDesc_t), ExternalSemaphoreHandleDesc)
363 @staticmethod
364 def from_data(data):
365 """Create an ExternalSemaphoreHandleDesc instance wrapping the given NumPy array.
367 Args:
368 data (_numpy.ndarray): a single-element array of dtype `external_semaphore_handle_desc_dtype` holding the data.
369 """
370 return _cyb_from_data(data, "external_semaphore_handle_desc_dtype", external_semaphore_handle_desc_dtype, ExternalSemaphoreHandleDesc)
372 @staticmethod
373 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
374 """Create an ExternalSemaphoreHandleDesc instance wrapping the given pointer.
376 Args:
377 ptr (intptr_t): pointer address as Python :class:`int` to the data.
378 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
379 readonly (bool): whether the data is read-only (to the user). default is `False`.
380 """
381 if ptr == 0:
382 raise ValueError("ptr must not be null (0)")
383 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc)
384 if owner is None:
385 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t))
386 obj._ptr = &obj._data
387 obj._owner = None
388 else:
389 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr
390 obj._owner = owner
391 obj._readonly = readonly
392 return obj
395cdef _get_module_tensor_descriptor_dtype_offsets():
396 cdef cudlaModuleTensorDescriptor *pod = <cudlaModuleTensorDescriptor *>_cyb_calloc(1, sizeof(cudlaModuleTensorDescriptor))
397 if pod == NULL:
398 raise MemoryError("Error allocating cudlaModuleTensorDescriptor")
399 try:
400 return _numpy.dtype({
401 'names': ['name', 'size_', 'n', 'c', 'h', 'w', 'data_format', 'data_type', 'data_category', 'pixel_format', 'pixel_mapping', 'stride'],
402 'formats': [(_numpy.int8, 81), _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint8, _numpy.uint8, _numpy.uint8, _numpy.uint8, _numpy.uint8, (_numpy.uint32, 8)],
403 'offsets': [
404 (<intptr_t>&(pod.name)) - (<intptr_t>pod),
405 (<intptr_t>&(pod.size)) - (<intptr_t>pod),
406 (<intptr_t>&(pod.n)) - (<intptr_t>pod),
407 (<intptr_t>&(pod.c)) - (<intptr_t>pod),
408 (<intptr_t>&(pod.h)) - (<intptr_t>pod),
409 (<intptr_t>&(pod.w)) - (<intptr_t>pod),
410 (<intptr_t>&(pod.dataFormat)) - (<intptr_t>pod),
411 (<intptr_t>&(pod.dataType)) - (<intptr_t>pod),
412 (<intptr_t>&(pod.dataCategory)) - (<intptr_t>pod),
413 (<intptr_t>&(pod.pixelFormat)) - (<intptr_t>pod),
414 (<intptr_t>&(pod.pixelMapping)) - (<intptr_t>pod),
415 (<intptr_t>&(pod.stride)) - (<intptr_t>pod),
416 ],
417 'itemsize': sizeof(cudlaModuleTensorDescriptor),
418 })
419 finally:
420 _cyb_free(pod)
422module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets()
424cdef class ModuleTensorDescriptor:
425 """Empty-initialize an instance of `cudlaModuleTensorDescriptor`.
428 .. seealso:: `cudlaModuleTensorDescriptor`
429 """
430 cdef:
431 cudlaModuleTensorDescriptor _data
432 cudlaModuleTensorDescriptor *_ptr
433 object _owner
434 bint _readonly
436 def __init__(self):
437 self._ptr = &self._data 1epmg
438 self._owner = None 1epmg
439 self._readonly = False 1epmg
441 def __repr__(self):
442 return f"<{__name__}.ModuleTensorDescriptor object at {hex(id(self))}>"
444 @property
445 def ptr(self):
446 """Get the pointer address to the data as Python :class:`int`."""
447 return <intptr_t>(self._ptr)
449 cdef intptr_t _get_ptr(self):
450 return <intptr_t>(self._ptr)
452 def __int__(self):
453 return <intptr_t>(self._ptr) 1g
455 def __eq__(self, other):
456 cdef ModuleTensorDescriptor other_
457 if not isinstance(other, ModuleTensorDescriptor):
458 return False
459 other_ = other
460 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaModuleTensorDescriptor)) == 0)
462 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
463 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleTensorDescriptor), self._readonly)
465 def __releasebuffer__(self, Py_buffer *buffer):
466 pass
468 def __setitem__(self, key, val):
469 cdef _cyb_Py_buffer view
470 if key == 0:
471 if self._readonly:
472 raise ValueError("This ModuleTensorDescriptor instance is read-only")
473 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
474 try:
475 if <size_t>view.len < sizeof(cudlaModuleTensorDescriptor):
476 raise ValueError(
477 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaModuleTensorDescriptor), view.len)
478 )
479 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaModuleTensorDescriptor))
480 self._ptr = &self._data
481 self._owner = None
482 self._readonly = view.readonly != 0
483 finally:
484 _cyb_PyBuffer_Release(&view)
485 else:
486 setattr(self, key, val)
488 @property
489 def name(self):
490 """~_numpy.int8: (array of length 81)."""
491 return _cyb_cpython.PyUnicode_FromString(self._ptr[0].name) 1p
493 @name.setter
494 def name(self, val):
495 if self._readonly:
496 raise ValueError("This ModuleTensorDescriptor instance is read-only")
497 cdef bytes buf = val.encode()
498 if len(buf) >= 81:
499 raise ValueError("String too long for field name, max length is 80")
500 cdef char *ptr = buf
501 _cyb_memcpy(<void *>(self._ptr[0].name), <void *>ptr, 81)
503 @property
504 def size_(self):
505 """int: """
506 return self._ptr[0].size 1e
508 @size_.setter
509 def size_(self, val):
510 if self._readonly:
511 raise ValueError("This ModuleTensorDescriptor instance is read-only")
512 self._ptr[0].size = val
514 @property
515 def n(self):
516 """int: """
517 return self._ptr[0].n 1e
519 @n.setter
520 def n(self, val):
521 if self._readonly:
522 raise ValueError("This ModuleTensorDescriptor instance is read-only")
523 self._ptr[0].n = val
525 @property
526 def c(self):
527 """int: """
528 return self._ptr[0].c 1e
530 @c.setter
531 def c(self, val):
532 if self._readonly:
533 raise ValueError("This ModuleTensorDescriptor instance is read-only")
534 self._ptr[0].c = val
536 @property
537 def h(self):
538 """int: """
539 return self._ptr[0].h 1e
541 @h.setter
542 def h(self, val):
543 if self._readonly:
544 raise ValueError("This ModuleTensorDescriptor instance is read-only")
545 self._ptr[0].h = val
547 @property
548 def w(self):
549 """int: """
550 return self._ptr[0].w 1e
552 @w.setter
553 def w(self, val):
554 if self._readonly:
555 raise ValueError("This ModuleTensorDescriptor instance is read-only")
556 self._ptr[0].w = val
558 @property
559 def data_format(self):
560 """int: """
561 return self._ptr[0].dataFormat 1e
563 @data_format.setter
564 def data_format(self, val):
565 if self._readonly:
566 raise ValueError("This ModuleTensorDescriptor instance is read-only")
567 self._ptr[0].dataFormat = val
569 @property
570 def data_type(self):
571 """int: """
572 return self._ptr[0].dataType 1e
574 @data_type.setter
575 def data_type(self, val):
576 if self._readonly:
577 raise ValueError("This ModuleTensorDescriptor instance is read-only")
578 self._ptr[0].dataType = val
580 @property
581 def data_category(self):
582 """int: """
583 return self._ptr[0].dataCategory 1e
585 @data_category.setter
586 def data_category(self, val):
587 if self._readonly:
588 raise ValueError("This ModuleTensorDescriptor instance is read-only")
589 self._ptr[0].dataCategory = val
591 @property
592 def pixel_format(self):
593 """int: """
594 return self._ptr[0].pixelFormat 1e
596 @pixel_format.setter
597 def pixel_format(self, val):
598 if self._readonly:
599 raise ValueError("This ModuleTensorDescriptor instance is read-only")
600 self._ptr[0].pixelFormat = val
602 @property
603 def pixel_mapping(self):
604 """int: """
605 return self._ptr[0].pixelMapping 1e
607 @pixel_mapping.setter
608 def pixel_mapping(self, val):
609 if self._readonly:
610 raise ValueError("This ModuleTensorDescriptor instance is read-only")
611 self._ptr[0].pixelMapping = val
613 @property
614 def stride(self):
615 """~_numpy.uint32: (array of length 8)."""
616 cdef _cyb_view.array arr = _cyb_view.array(shape=(8,), itemsize=sizeof(uint32_t), format="I", mode="c", allocate_buffer=False) 1m
617 arr.data = <char *>(&(self._ptr[0].stride)) 1m
618 return _numpy.asarray(arr) 1m
620 @stride.setter
621 def stride(self, val):
622 if self._readonly:
623 raise ValueError("This ModuleTensorDescriptor instance is read-only")
624 if len(val) != 8:
625 raise ValueError(f"Expected length { 8 } for field stride, got {len(val)}")
626 cdef _cyb_view.array arr = _cyb_view.array(shape=(8,), itemsize=sizeof(uint32_t), format="I", mode="c")
627 arr[:] = _numpy.asarray(val, dtype=_numpy.uint32)
628 _cyb_memcpy(<void *>(&(self._ptr[0].stride)), <void *>(arr.data), sizeof(uint32_t) * len(val))
630 @staticmethod
631 def from_buffer(buffer):
632 """Create an ModuleTensorDescriptor instance with the memory from the given buffer."""
633 return _cyb_from_buffer(buffer, sizeof(cudlaModuleTensorDescriptor), ModuleTensorDescriptor)
635 @staticmethod
636 def from_data(data):
637 """Create an ModuleTensorDescriptor instance wrapping the given NumPy array.
639 Args:
640 data (_numpy.ndarray): a single-element array of dtype `module_tensor_descriptor_dtype` holding the data.
641 """
642 return _cyb_from_data(data, "module_tensor_descriptor_dtype", module_tensor_descriptor_dtype, ModuleTensorDescriptor)
644 @staticmethod
645 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
646 """Create an ModuleTensorDescriptor instance wrapping the given pointer.
648 Args:
649 ptr (intptr_t): pointer address as Python :class:`int` to the data.
650 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
651 readonly (bool): whether the data is read-only (to the user). default is `False`.
652 """
653 if ptr == 0:
654 raise ValueError("ptr must not be null (0)")
655 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor)
656 if owner is None:
657 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaModuleTensorDescriptor))
658 obj._ptr = &obj._data
659 obj._owner = None
660 else:
661 obj._ptr = <cudlaModuleTensorDescriptor *>ptr
662 obj._owner = owner
663 obj._readonly = readonly
664 return obj
667cdef _get_fence_dtype_offsets():
668 cdef CudlaFence *pod = <CudlaFence *>_cyb_calloc(1, sizeof(CudlaFence))
669 if pod == NULL:
670 raise MemoryError("Error allocating CudlaFence")
671 try:
672 return _numpy.dtype({
673 'names': ['fence', 'type'],
674 'formats': [_numpy.intp, _numpy.int32],
675 'offsets': [
676 (<intptr_t>&(pod.fence)) - (<intptr_t>pod),
677 (<intptr_t>&(pod.type)) - (<intptr_t>pod),
678 ],
679 'itemsize': sizeof(CudlaFence),
680 })
681 finally:
682 _cyb_free(pod)
684fence_dtype = _get_fence_dtype_offsets()
686cdef class Fence:
687 """Empty-initialize an instance of `CudlaFence`.
690 .. seealso:: `CudlaFence`
691 """
692 cdef:
693 CudlaFence _data
694 CudlaFence *_ptr
695 object _owner
696 bint _readonly
698 def __init__(self):
699 self._ptr = &self._data 1h
700 self._owner = None 1h
701 self._readonly = False 1h
703 def __repr__(self):
704 return f"<{__name__}.Fence object at {hex(id(self))}>"
706 @property
707 def ptr(self):
708 """Get the pointer address to the data as Python :class:`int`."""
709 return <intptr_t>(self._ptr)
711 cdef intptr_t _get_ptr(self):
712 return <intptr_t>(self._ptr)
714 def __int__(self):
715 return <intptr_t>(self._ptr)
717 def __eq__(self, other):
718 cdef Fence other_
719 if not isinstance(other, Fence):
720 return False
721 other_ = other
722 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CudlaFence)) == 0)
724 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
725 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CudlaFence), self._readonly)
727 def __releasebuffer__(self, Py_buffer *buffer):
728 pass
730 def __setitem__(self, key, val):
731 cdef _cyb_Py_buffer view
732 if key == 0:
733 if self._readonly:
734 raise ValueError("This Fence instance is read-only")
735 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
736 try:
737 if <size_t>view.len < sizeof(CudlaFence):
738 raise ValueError(
739 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(CudlaFence), view.len)
740 )
741 _cyb_memmove(<void*>&self._data, view.buf, sizeof(CudlaFence))
742 self._ptr = &self._data
743 self._owner = None
744 self._readonly = view.readonly != 0
745 finally:
746 _cyb_PyBuffer_Release(&view)
747 else:
748 setattr(self, key, val)
750 @property
751 def fence(self):
752 """int: """
753 return <intptr_t>(self._ptr[0].fence) 1h
755 @fence.setter
756 def fence(self, val):
757 if self._readonly: 1h
758 raise ValueError("This Fence instance is read-only")
759 self._ptr[0].fence = <void *><intptr_t>val 1h
761 @property
762 def type(self):
763 """int: """
764 return <int>(self._ptr[0].type) 1h
766 @type.setter
767 def type(self, val):
768 if self._readonly: 1h
769 raise ValueError("This Fence instance is read-only")
770 self._ptr[0].type = <cudlaFenceType><int>val 1h
772 @staticmethod
773 def from_buffer(buffer):
774 """Create an Fence instance with the memory from the given buffer."""
775 return _cyb_from_buffer(buffer, sizeof(CudlaFence), Fence)
777 @staticmethod
778 def from_data(data):
779 """Create an Fence instance wrapping the given NumPy array.
781 Args:
782 data (_numpy.ndarray): a single-element array of dtype `fence_dtype` holding the data.
783 """
784 return _cyb_from_data(data, "fence_dtype", fence_dtype, Fence)
786 @staticmethod
787 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
788 """Create an Fence instance wrapping the given pointer.
790 Args:
791 ptr (intptr_t): pointer address as Python :class:`int` to the data.
792 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
793 readonly (bool): whether the data is read-only (to the user). default is `False`.
794 """
795 if ptr == 0:
796 raise ValueError("ptr must not be null (0)")
797 cdef Fence obj = Fence.__new__(Fence)
798 if owner is None:
799 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(CudlaFence))
800 obj._ptr = &obj._data
801 obj._owner = None
802 else:
803 obj._ptr = <CudlaFence *>ptr
804 obj._owner = owner
805 obj._readonly = readonly
806 return obj
809cdef _get_dev_attribute_dtype_offsets():
810 cdef cudlaDevAttribute *pod = <cudlaDevAttribute *>_cyb_calloc(1, sizeof(cudlaDevAttribute))
811 if pod == NULL:
812 raise MemoryError("Error allocating cudlaDevAttribute")
813 try:
814 return _numpy.dtype({
815 'names': ['unified_addressing_supported', 'device_version'],
816 'formats': [_numpy.uint8, _numpy.uint32],
817 'offsets': [
818 (<intptr_t>&(pod.unifiedAddressingSupported)) - (<intptr_t>pod),
819 (<intptr_t>&(pod.deviceVersion)) - (<intptr_t>pod),
820 ],
821 'itemsize': sizeof(cudlaDevAttribute),
822 })
823 finally:
824 _cyb_free(pod)
826dev_attribute_dtype = _get_dev_attribute_dtype_offsets()
828cdef class DevAttribute:
829 """Empty-initialize an instance of `cudlaDevAttribute`.
832 .. seealso:: `cudlaDevAttribute`
833 """
834 cdef:
835 cudlaDevAttribute _data
836 cudlaDevAttribute *_ptr
837 object _owner
838 bint _readonly
840 def __init__(self):
841 self._ptr = &self._data 1i
842 self._owner = None 1i
843 self._readonly = False 1i
845 def __repr__(self):
846 return f"<{__name__}.DevAttribute object at {hex(id(self))}>"
848 @property
849 def ptr(self):
850 """Get the pointer address to the data as Python :class:`int`."""
851 return <intptr_t>(self._ptr)
853 cdef intptr_t _get_ptr(self):
854 return <intptr_t>(self._ptr)
856 def __int__(self):
857 return <intptr_t>(self._ptr)
859 def __eq__(self, other):
860 cdef DevAttribute other_
861 if not isinstance(other, DevAttribute):
862 return False
863 other_ = other
864 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaDevAttribute)) == 0)
866 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
867 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaDevAttribute), self._readonly)
869 def __releasebuffer__(self, Py_buffer *buffer):
870 pass
872 def __setitem__(self, key, val):
873 cdef _cyb_Py_buffer view
874 if key == 0:
875 if self._readonly:
876 raise ValueError("This DevAttribute instance is read-only")
877 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
878 try:
879 if <size_t>view.len < sizeof(cudlaDevAttribute):
880 raise ValueError(
881 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaDevAttribute), view.len)
882 )
883 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaDevAttribute))
884 self._ptr = &self._data
885 self._owner = None
886 self._readonly = view.readonly != 0
887 finally:
888 _cyb_PyBuffer_Release(&view)
889 else:
890 setattr(self, key, val)
892 @property
893 def unified_addressing_supported(self):
894 """int: """
895 return self._ptr[0].unifiedAddressingSupported 1i
897 @unified_addressing_supported.setter
898 def unified_addressing_supported(self, val):
899 if self._readonly: 1i
900 raise ValueError("This DevAttribute instance is read-only")
901 self._ptr[0].unifiedAddressingSupported = val 1i
903 @property
904 def device_version(self):
905 """int: """
906 return self._ptr[0].deviceVersion 1i
908 @device_version.setter
909 def device_version(self, val):
910 if self._readonly: 1i
911 raise ValueError("This DevAttribute instance is read-only")
912 self._ptr[0].deviceVersion = val 1i
914 @staticmethod
915 def from_buffer(buffer):
916 """Create an DevAttribute instance with the memory from the given buffer."""
917 return _cyb_from_buffer(buffer, sizeof(cudlaDevAttribute), DevAttribute)
919 @staticmethod
920 def from_data(data):
921 """Create an DevAttribute instance wrapping the given NumPy array.
923 Args:
924 data (_numpy.ndarray): a single-element array of dtype `dev_attribute_dtype` holding the data.
925 """
926 return _cyb_from_data(data, "dev_attribute_dtype", dev_attribute_dtype, DevAttribute)
928 @staticmethod
929 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
930 """Create an DevAttribute instance wrapping the given pointer.
932 Args:
933 ptr (intptr_t): pointer address as Python :class:`int` to the data.
934 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
935 readonly (bool): whether the data is read-only (to the user). default is `False`.
936 """
937 if ptr == 0:
938 raise ValueError("ptr must not be null (0)")
939 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute)
940 if owner is None:
941 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaDevAttribute))
942 obj._ptr = &obj._data
943 obj._owner = None
944 else:
945 obj._ptr = <cudlaDevAttribute *>ptr
946 obj._owner = owner
947 obj._readonly = readonly
948 return obj
951cdef _get_module_attribute_dtype_offsets():
952 cdef cudlaModuleAttribute *pod = <cudlaModuleAttribute *>_cyb_calloc(1, sizeof(cudlaModuleAttribute))
953 if pod == NULL:
954 raise MemoryError("Error allocating cudlaModuleAttribute")
955 try:
956 return _numpy.dtype({
957 'names': ['num_input_tensors', 'num_output_tensors', 'input_tensor_desc', 'output_tensor_desc'],
958 'formats': [_numpy.uint32, _numpy.uint32, _numpy.intp, _numpy.intp],
959 'offsets': [
960 (<intptr_t>&(pod.numInputTensors)) - (<intptr_t>pod),
961 (<intptr_t>&(pod.numOutputTensors)) - (<intptr_t>pod),
962 (<intptr_t>&(pod.inputTensorDesc)) - (<intptr_t>pod),
963 (<intptr_t>&(pod.outputTensorDesc)) - (<intptr_t>pod),
964 ],
965 'itemsize': sizeof(cudlaModuleAttribute),
966 })
967 finally:
968 _cyb_free(pod)
970module_attribute_dtype = _get_module_attribute_dtype_offsets()
972cdef class ModuleAttribute:
973 """Empty-initialize an instance of `cudlaModuleAttribute`.
976 .. seealso:: `cudlaModuleAttribute`
977 """
978 cdef:
979 cudlaModuleAttribute _data
980 cudlaModuleAttribute *_ptr
981 object _owner
982 bint _readonly
984 def __init__(self):
985 self._ptr = &self._data 1j
986 self._owner = None 1j
987 self._readonly = False 1j
989 def __repr__(self):
990 return f"<{__name__}.ModuleAttribute object at {hex(id(self))}>"
992 @property
993 def ptr(self):
994 """Get the pointer address to the data as Python :class:`int`."""
995 return <intptr_t>(self._ptr)
997 cdef intptr_t _get_ptr(self):
998 return <intptr_t>(self._ptr)
1000 def __int__(self):
1001 return <intptr_t>(self._ptr)
1003 def __eq__(self, other):
1004 cdef ModuleAttribute other_
1005 if not isinstance(other, ModuleAttribute):
1006 return False
1007 other_ = other
1008 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaModuleAttribute)) == 0)
1010 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1011 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleAttribute), self._readonly)
1013 def __releasebuffer__(self, Py_buffer *buffer):
1014 pass
1016 def __setitem__(self, key, val):
1017 cdef _cyb_Py_buffer view
1018 if key == 0:
1019 if self._readonly:
1020 raise ValueError("This ModuleAttribute instance is read-only")
1021 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
1022 try:
1023 if <size_t>view.len < sizeof(cudlaModuleAttribute):
1024 raise ValueError(
1025 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaModuleAttribute), view.len)
1026 )
1027 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaModuleAttribute))
1028 self._ptr = &self._data
1029 self._owner = None
1030 self._readonly = view.readonly != 0
1031 finally:
1032 _cyb_PyBuffer_Release(&view)
1033 else:
1034 setattr(self, key, val)
1036 @property
1037 def num_input_tensors(self):
1038 """int: """
1039 return self._ptr[0].numInputTensors 1j
1041 @num_input_tensors.setter
1042 def num_input_tensors(self, val):
1043 if self._readonly: 1j
1044 raise ValueError("This ModuleAttribute instance is read-only")
1045 self._ptr[0].numInputTensors = val 1j
1047 @property
1048 def num_output_tensors(self):
1049 """int: """
1050 return self._ptr[0].numOutputTensors 1j
1052 @num_output_tensors.setter
1053 def num_output_tensors(self, val):
1054 if self._readonly: 1j
1055 raise ValueError("This ModuleAttribute instance is read-only")
1056 self._ptr[0].numOutputTensors = val 1j
1058 @property
1059 def input_tensor_desc(self):
1060 """int: """
1061 return <intptr_t>(self._ptr[0].inputTensorDesc)
1063 @input_tensor_desc.setter
1064 def input_tensor_desc(self, val):
1065 if self._readonly:
1066 raise ValueError("This ModuleAttribute instance is read-only")
1067 self._ptr[0].inputTensorDesc = <cudlaModuleTensorDescriptor*><intptr_t>val
1069 @property
1070 def output_tensor_desc(self):
1071 """int: """
1072 return <intptr_t>(self._ptr[0].outputTensorDesc)
1074 @output_tensor_desc.setter
1075 def output_tensor_desc(self, val):
1076 if self._readonly:
1077 raise ValueError("This ModuleAttribute instance is read-only")
1078 self._ptr[0].outputTensorDesc = <cudlaModuleTensorDescriptor*><intptr_t>val
1080 @staticmethod
1081 def from_buffer(buffer):
1082 """Create an ModuleAttribute instance with the memory from the given buffer."""
1083 return _cyb_from_buffer(buffer, sizeof(cudlaModuleAttribute), ModuleAttribute)
1085 @staticmethod
1086 def from_data(data):
1087 """Create an ModuleAttribute instance wrapping the given NumPy array.
1089 Args:
1090 data (_numpy.ndarray): a single-element array of dtype `module_attribute_dtype` holding the data.
1091 """
1092 return _cyb_from_data(data, "module_attribute_dtype", module_attribute_dtype, ModuleAttribute)
1094 @staticmethod
1095 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1096 """Create an ModuleAttribute instance wrapping the given pointer.
1098 Args:
1099 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1100 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1101 readonly (bool): whether the data is read-only (to the user). default is `False`.
1102 """
1103 if ptr == 0:
1104 raise ValueError("ptr must not be null (0)")
1105 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute)
1106 if owner is None:
1107 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaModuleAttribute))
1108 obj._ptr = &obj._data
1109 obj._owner = None
1110 else:
1111 obj._ptr = <cudlaModuleAttribute *>ptr
1112 obj._owner = owner
1113 obj._readonly = readonly
1114 return obj
1117cdef _get_wait_events_dtype_offsets():
1118 cdef cudlaWaitEvents *pod = <cudlaWaitEvents *>_cyb_calloc(1, sizeof(cudlaWaitEvents))
1119 if pod == NULL:
1120 raise MemoryError("Error allocating cudlaWaitEvents")
1121 try:
1122 return _numpy.dtype({
1123 'names': ['pre_fences', 'num_events'],
1124 'formats': [_numpy.intp, _numpy.uint32],
1125 'offsets': [
1126 (<intptr_t>&(pod.preFences)) - (<intptr_t>pod),
1127 (<intptr_t>&(pod.numEvents)) - (<intptr_t>pod),
1128 ],
1129 'itemsize': sizeof(cudlaWaitEvents),
1130 })
1131 finally:
1132 _cyb_free(pod)
1134wait_events_dtype = _get_wait_events_dtype_offsets()
1136cdef class WaitEvents:
1137 """Empty-initialize an instance of `cudlaWaitEvents`.
1140 .. seealso:: `cudlaWaitEvents`
1141 """
1142 cdef:
1143 cudlaWaitEvents _data
1144 cudlaWaitEvents *_ptr
1145 object _owner
1146 bint _readonly
1147 dict _refs
1149 def __init__(self):
1150 self._ptr = &self._data 1n
1151 self._owner = None 1n
1152 self._readonly = False 1n
1153 self._refs = {} 1n
1155 def __repr__(self):
1156 return f"<{__name__}.WaitEvents object at {hex(id(self))}>"
1158 @property
1159 def ptr(self):
1160 """Get the pointer address to the data as Python :class:`int`."""
1161 return <intptr_t>(self._ptr)
1163 cdef intptr_t _get_ptr(self):
1164 return <intptr_t>(self._ptr)
1166 def __int__(self):
1167 return <intptr_t>(self._ptr)
1169 def __eq__(self, other):
1170 cdef WaitEvents other_
1171 if not isinstance(other, WaitEvents):
1172 return False
1173 other_ = other
1174 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaWaitEvents)) == 0)
1176 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1177 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaWaitEvents), self._readonly)
1179 def __releasebuffer__(self, Py_buffer *buffer):
1180 pass
1182 def __setitem__(self, key, val):
1183 cdef _cyb_Py_buffer view
1184 if key == 0:
1185 if self._readonly:
1186 raise ValueError("This WaitEvents instance is read-only")
1187 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
1188 try:
1189 if <size_t>view.len < sizeof(cudlaWaitEvents):
1190 raise ValueError(
1191 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaWaitEvents), view.len)
1192 )
1193 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaWaitEvents))
1194 self._ptr = &self._data
1195 self._owner = None
1196 self._readonly = view.readonly != 0
1197 finally:
1198 _cyb_PyBuffer_Release(&view)
1199 else:
1200 setattr(self, key, val)
1202 @property
1203 def pre_fences(self):
1204 """int: """
1205 if self._ptr[0].preFences == NULL or self._ptr[0].numEvents == 0: 1n
1206 return [] 1n
1207 return Fence.from_ptr(
1208 <intptr_t>(self._ptr[0].preFences),
1209 self._ptr[0].numEvents,
1210 owner=self,
1211 readonly=self._readonly
1212 )
1214 @pre_fences.setter
1215 def pre_fences(self, val):
1216 if self._readonly:
1217 raise ValueError("This WaitEvents instance is read-only")
1218 cdef Fence arr = val
1219 self._ptr[0].preFences = <CudlaFence*><intptr_t>(arr._get_ptr())
1220 self._ptr[0].numEvents = len(arr)
1221 self._refs["pre_fences"] = arr
1223 @staticmethod
1224 def from_buffer(buffer):
1225 """Create an WaitEvents instance with the memory from the given buffer."""
1226 return _cyb_from_buffer(buffer, sizeof(cudlaWaitEvents), WaitEvents)
1228 @staticmethod
1229 def from_data(data):
1230 """Create an WaitEvents instance wrapping the given NumPy array.
1232 Args:
1233 data (_numpy.ndarray): a single-element array of dtype `wait_events_dtype` holding the data.
1234 """
1235 return _cyb_from_data(data, "wait_events_dtype", wait_events_dtype, WaitEvents)
1237 @staticmethod
1238 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1239 """Create an WaitEvents instance wrapping the given pointer.
1241 Args:
1242 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1243 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1244 readonly (bool): whether the data is read-only (to the user). default is `False`.
1245 """
1246 if ptr == 0:
1247 raise ValueError("ptr must not be null (0)")
1248 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents)
1249 if owner is None:
1250 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaWaitEvents))
1251 obj._ptr = &obj._data
1252 obj._owner = None
1253 else:
1254 obj._ptr = <cudlaWaitEvents *>ptr
1255 obj._owner = owner
1256 obj._readonly = readonly
1257 obj._refs = {}
1258 return obj
1261cdef _get_signal_events_dtype_offsets():
1262 cdef cudlaSignalEvents *pod = <cudlaSignalEvents *>_cyb_calloc(1, sizeof(cudlaSignalEvents))
1263 if pod == NULL:
1264 raise MemoryError("Error allocating cudlaSignalEvents")
1265 try:
1266 return _numpy.dtype({
1267 'names': ['dev_ptrs', 'eof_fences', 'num_events'],
1268 'formats': [_numpy.intp, _numpy.intp, _numpy.uint32],
1269 'offsets': [
1270 (<intptr_t>&(pod.devPtrs)) - (<intptr_t>pod),
1271 (<intptr_t>&(pod.eofFences)) - (<intptr_t>pod),
1272 (<intptr_t>&(pod.numEvents)) - (<intptr_t>pod),
1273 ],
1274 'itemsize': sizeof(cudlaSignalEvents),
1275 })
1276 finally:
1277 _cyb_free(pod)
1279signal_events_dtype = _get_signal_events_dtype_offsets()
1281cdef class SignalEvents:
1282 """Empty-initialize an instance of `cudlaSignalEvents`.
1285 .. seealso:: `cudlaSignalEvents`
1286 """
1287 cdef:
1288 cudlaSignalEvents _data
1289 cudlaSignalEvents *_ptr
1290 object _owner
1291 bint _readonly
1292 dict _refs
1294 def __init__(self):
1295 self._ptr = &self._data 1o
1296 self._owner = None 1o
1297 self._readonly = False 1o
1298 self._refs = {} 1o
1300 def __repr__(self):
1301 return f"<{__name__}.SignalEvents object at {hex(id(self))}>"
1303 @property
1304 def ptr(self):
1305 """Get the pointer address to the data as Python :class:`int`."""
1306 return <intptr_t>(self._ptr)
1308 cdef intptr_t _get_ptr(self):
1309 return <intptr_t>(self._ptr)
1311 def __int__(self):
1312 return <intptr_t>(self._ptr)
1314 def __eq__(self, other):
1315 cdef SignalEvents other_
1316 if not isinstance(other, SignalEvents):
1317 return False
1318 other_ = other
1319 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaSignalEvents)) == 0)
1321 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1322 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaSignalEvents), self._readonly)
1324 def __releasebuffer__(self, Py_buffer *buffer):
1325 pass
1327 def __setitem__(self, key, val):
1328 cdef _cyb_Py_buffer view
1329 if key == 0:
1330 if self._readonly:
1331 raise ValueError("This SignalEvents instance is read-only")
1332 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
1333 try:
1334 if <size_t>view.len < sizeof(cudlaSignalEvents):
1335 raise ValueError(
1336 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaSignalEvents), view.len)
1337 )
1338 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaSignalEvents))
1339 self._ptr = &self._data
1340 self._owner = None
1341 self._readonly = view.readonly != 0
1342 finally:
1343 _cyb_PyBuffer_Release(&view)
1344 else:
1345 setattr(self, key, val)
1347 @property
1348 def dev_ptrs(self):
1349 """int: """
1350 if self._ptr[0].devPtrs == NULL or self._ptr[0].numEvents == 0:
1351 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0]
1352 cdef _cyb_view.array arr = _cyb_view.array(shape=(self._ptr[0].numEvents,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False)
1353 arr.data = <char *>(self._ptr[0].devPtrs)
1354 return arr
1356 @dev_ptrs.setter
1357 def dev_ptrs(self, val):
1358 if self._readonly:
1359 raise ValueError("This SignalEvents instance is read-only")
1360 cdef Py_ssize_t _n = len(val)
1361 self._ptr[0].numEvents = _n
1362 if _n == 0:
1363 return
1364 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c")
1365 cdef intptr_t[:] mv = arr
1366 cdef Py_ssize_t i
1367 with _cyb_cython.boundscheck(False), _cyb_cython.wraparound(False):
1368 for i in range(_n):
1369 mv[i] = val[i]
1370 self._ptr[0].devPtrs = <uint64_t**><intptr_t>(arr.data)
1371 self._refs["dev_ptrs"] = arr
1373 @property
1374 def eof_fences(self):
1375 """int: """
1376 if self._ptr[0].eofFences == NULL or self._ptr[0].numEvents == 0: 1o
1377 return [] 1o
1378 return Fence.from_ptr(
1379 <intptr_t>(self._ptr[0].eofFences),
1380 self._ptr[0].numEvents,
1381 owner=self,
1382 readonly=self._readonly
1383 )
1385 @eof_fences.setter
1386 def eof_fences(self, val):
1387 if self._readonly:
1388 raise ValueError("This SignalEvents instance is read-only")
1389 cdef Fence arr = val
1390 self._ptr[0].eofFences = <CudlaFence*><intptr_t>(arr._get_ptr())
1391 self._ptr[0].numEvents = len(arr)
1392 self._refs["eof_fences"] = arr
1394 @staticmethod
1395 def from_buffer(buffer):
1396 """Create an SignalEvents instance with the memory from the given buffer."""
1397 return _cyb_from_buffer(buffer, sizeof(cudlaSignalEvents), SignalEvents)
1399 @staticmethod
1400 def from_data(data):
1401 """Create an SignalEvents instance wrapping the given NumPy array.
1403 Args:
1404 data (_numpy.ndarray): a single-element array of dtype `signal_events_dtype` holding the data.
1405 """
1406 return _cyb_from_data(data, "signal_events_dtype", signal_events_dtype, SignalEvents)
1408 @staticmethod
1409 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1410 """Create an SignalEvents instance wrapping the given pointer.
1412 Args:
1413 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1414 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1415 readonly (bool): whether the data is read-only (to the user). default is `False`.
1416 """
1417 if ptr == 0:
1418 raise ValueError("ptr must not be null (0)")
1419 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents)
1420 if owner is None:
1421 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaSignalEvents))
1422 obj._ptr = &obj._data
1423 obj._owner = None
1424 else:
1425 obj._ptr = <cudlaSignalEvents *>ptr
1426 obj._owner = owner
1427 obj._readonly = readonly
1428 obj._refs = {}
1429 return obj
1432cdef _get_task_dtype_offsets():
1433 cdef cudlaTask *pod = <cudlaTask *>_cyb_calloc(1, sizeof(cudlaTask))
1434 if pod == NULL:
1435 raise MemoryError("Error allocating cudlaTask")
1436 try:
1437 return _numpy.dtype({
1438 'names': ['module_handle', 'output_tensor', 'num_output_tensors', 'num_input_tensors', 'input_tensor', 'wait_events', 'signal_events'],
1439 'formats': [_numpy.intp, _numpy.intp, _numpy.uint32, _numpy.uint32, _numpy.intp, _numpy.intp, _numpy.intp],
1440 'offsets': [
1441 (<intptr_t>&(pod.moduleHandle)) - (<intptr_t>pod),
1442 (<intptr_t>&(pod.outputTensor)) - (<intptr_t>pod),
1443 (<intptr_t>&(pod.numOutputTensors)) - (<intptr_t>pod),
1444 (<intptr_t>&(pod.numInputTensors)) - (<intptr_t>pod),
1445 (<intptr_t>&(pod.inputTensor)) - (<intptr_t>pod),
1446 (<intptr_t>&(pod.waitEvents)) - (<intptr_t>pod),
1447 (<intptr_t>&(pod.signalEvents)) - (<intptr_t>pod),
1448 ],
1449 'itemsize': sizeof(cudlaTask),
1450 })
1451 finally:
1452 _cyb_free(pod)
1454task_dtype = _get_task_dtype_offsets()
1456cdef class Task:
1457 """Empty-initialize an instance of `cudlaTask`.
1460 .. seealso:: `cudlaTask`
1461 """
1462 cdef:
1463 cudlaTask _data
1464 cudlaTask *_ptr
1465 object _owner
1466 bint _readonly
1467 dict _refs
1469 def __init__(self):
1470 self._ptr = &self._data 1gbkcd
1471 self._owner = None 1gbkcd
1472 self._readonly = False 1gbkcd
1473 self._refs = {} 1gbkcd
1475 def __repr__(self):
1476 return f"<{__name__}.Task object at {hex(id(self))}>"
1478 @property
1479 def ptr(self):
1480 """Get the pointer address to the data as Python :class:`int`."""
1481 return <intptr_t>(self._ptr)
1483 cdef intptr_t _get_ptr(self):
1484 return <intptr_t>(self._ptr)
1486 def __int__(self):
1487 return <intptr_t>(self._ptr) 1g
1489 def __eq__(self, other):
1490 cdef Task other_
1491 if not isinstance(other, Task):
1492 return False
1493 other_ = other
1494 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaTask)) == 0)
1496 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1497 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaTask), self._readonly)
1499 def __releasebuffer__(self, Py_buffer *buffer):
1500 pass
1502 def __setitem__(self, key, val):
1503 cdef _cyb_Py_buffer view
1504 if key == 0:
1505 if self._readonly:
1506 raise ValueError("This Task instance is read-only")
1507 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE)
1508 try:
1509 if <size_t>view.len < sizeof(cudlaTask):
1510 raise ValueError(
1511 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaTask), view.len)
1512 )
1513 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaTask))
1514 self._ptr = &self._data
1515 self._owner = None
1516 self._readonly = view.readonly != 0
1517 finally:
1518 _cyb_PyBuffer_Release(&view)
1519 else:
1520 setattr(self, key, val)
1522 @property
1523 def module_handle(self):
1524 """int: """
1525 return <intptr_t>(self._ptr[0].moduleHandle) 1bk
1527 @module_handle.setter
1528 def module_handle(self, val):
1529 if self._readonly: 1bk
1530 raise ValueError("This Task instance is read-only")
1531 self._ptr[0].moduleHandle = <cudlaModule><intptr_t>val 1bk
1533 @property
1534 def output_tensor(self):
1535 """int: """
1536 if self._ptr[0].outputTensor == NULL or self._ptr[0].numOutputTensors == 0: 1bd
1537 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0]
1538 cdef _cyb_view.array arr = _cyb_view.array(shape=(self._ptr[0].numOutputTensors,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False) 1bd
1539 arr.data = <char *>(self._ptr[0].outputTensor) 1bd
1540 return arr 1bd
1542 @output_tensor.setter
1543 def output_tensor(self, val):
1544 if self._readonly: 1bd
1545 raise ValueError("This Task instance is read-only")
1546 cdef Py_ssize_t _n = len(val) 1bd
1547 self._ptr[0].numOutputTensors = _n 1bd
1548 if _n == 0: 1bd
1549 return
1550 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 1bd
1551 cdef intptr_t[:] mv = arr 1bd
1552 cdef Py_ssize_t i
1553 with _cyb_cython.boundscheck(False), _cyb_cython.wraparound(False):
1554 for i in range(_n): 1bd
1555 mv[i] = val[i] 1bd
1556 self._ptr[0].outputTensor = <uint64_t**><intptr_t>(arr.data) 1bd
1557 self._refs["output_tensor"] = arr 1bd
1559 @property
1560 def input_tensor(self):
1561 """int: """
1562 if self._ptr[0].inputTensor == NULL or self._ptr[0].numInputTensors == 0: 1bc
1563 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0]
1564 cdef _cyb_view.array arr = _cyb_view.array(shape=(self._ptr[0].numInputTensors,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False) 1bc
1565 arr.data = <char *>(self._ptr[0].inputTensor) 1bc
1566 return arr 1bc
1568 @input_tensor.setter
1569 def input_tensor(self, val):
1570 if self._readonly: 1bc
1571 raise ValueError("This Task instance is read-only")
1572 cdef Py_ssize_t _n = len(val) 1bc
1573 self._ptr[0].numInputTensors = _n 1bc
1574 if _n == 0: 1bc
1575 return
1576 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 1bc
1577 cdef intptr_t[:] mv = arr 1bc
1578 cdef Py_ssize_t i
1579 with _cyb_cython.boundscheck(False), _cyb_cython.wraparound(False):
1580 for i in range(_n): 1bc
1581 mv[i] = val[i] 1bc
1582 self._ptr[0].inputTensor = <uint64_t**><intptr_t>(arr.data) 1bc
1583 self._refs["input_tensor"] = arr 1bc
1585 @property
1586 def wait_events(self):
1587 """int: """
1588 return <intptr_t>(self._ptr[0].waitEvents)
1590 @wait_events.setter
1591 def wait_events(self, val):
1592 if self._readonly: 1b
1593 raise ValueError("This Task instance is read-only")
1594 self._ptr[0].waitEvents = <cudlaWaitEvents*><intptr_t>val 1b
1596 @property
1597 def signal_events(self):
1598 """int: """
1599 return <intptr_t>(self._ptr[0].signalEvents)
1601 @signal_events.setter
1602 def signal_events(self, val):
1603 if self._readonly: 1b
1604 raise ValueError("This Task instance is read-only")
1605 self._ptr[0].signalEvents = <cudlaSignalEvents*><intptr_t>val 1b
1607 @staticmethod
1608 def from_buffer(buffer):
1609 """Create an Task instance with the memory from the given buffer."""
1610 return _cyb_from_buffer(buffer, sizeof(cudlaTask), Task)
1612 @staticmethod
1613 def from_data(data):
1614 """Create an Task instance wrapping the given NumPy array.
1616 Args:
1617 data (_numpy.ndarray): a single-element array of dtype `task_dtype` holding the data.
1618 """
1619 return _cyb_from_data(data, "task_dtype", task_dtype, Task)
1621 @staticmethod
1622 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1623 """Create an Task instance wrapping the given pointer.
1625 Args:
1626 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1627 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1628 readonly (bool): whether the data is read-only (to the user). default is `False`.
1629 """
1630 if ptr == 0:
1631 raise ValueError("ptr must not be null (0)")
1632 cdef Task obj = Task.__new__(Task)
1633 if owner is None:
1634 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaTask))
1635 obj._ptr = &obj._data
1636 obj._owner = None
1637 else:
1638 obj._ptr = <cudlaTask *>ptr
1639 obj._owner = owner
1640 obj._readonly = readonly
1641 obj._refs = {}
1642 return obj
1645###############################################################################
1646# Enum
1647###############################################################################
1649class Status(_cyb_FastEnum):
1650 """
1651 See `cudlaStatus`.
1652 """
1653 SUCCESS = cudlaSuccess
1654 Success = SUCCESS # backward-compat alias
1655 ERROR_INVALID_PARAM = cudlaErrorInvalidParam
1656 ErrorInvalidParam = ERROR_INVALID_PARAM # backward-compat alias
1657 ERROR_OUT_OF_RESOURCES = cudlaErrorOutOfResources
1658 ErrorOutOfResources = ERROR_OUT_OF_RESOURCES # backward-compat alias
1659 ERROR_CREATION_FAILED = cudlaErrorCreationFailed
1660 ErrorCreationFailed = ERROR_CREATION_FAILED # backward-compat alias
1661 ERROR_INVALID_ADDRESS = cudlaErrorInvalidAddress
1662 ErrorInvalidAddress = ERROR_INVALID_ADDRESS # backward-compat alias
1663 ERROR_OS = cudlaErrorOs
1664 ErrorOs = ERROR_OS # backward-compat alias
1665 ERROR_CUDA = cudlaErrorCuda
1666 ErrorCuda = ERROR_CUDA # backward-compat alias
1667 ERROR_UMD = cudlaErrorUmd
1668 ErrorUmd = ERROR_UMD # backward-compat alias
1669 ERROR_INVALID_DEVICE = cudlaErrorInvalidDevice
1670 ErrorInvalidDevice = ERROR_INVALID_DEVICE # backward-compat alias
1671 ERROR_INVALID_ATTRIBUTE = cudlaErrorInvalidAttribute
1672 ErrorInvalidAttribute = ERROR_INVALID_ATTRIBUTE # backward-compat alias
1673 ERROR_INCOMPATIBLE_DLA_SW_VERSION = cudlaErrorIncompatibleDlaSWVersion
1674 ErrorIncompatibleDlaSWVersion = ERROR_INCOMPATIBLE_DLA_SW_VERSION # backward-compat alias
1675 ERROR_MEMORY_REGISTERED = cudlaErrorMemoryRegistered
1676 ErrorMemoryRegistered = ERROR_MEMORY_REGISTERED # backward-compat alias
1677 ERROR_INVALID_MODULE = cudlaErrorInvalidModule
1678 ErrorInvalidModule = ERROR_INVALID_MODULE # backward-compat alias
1679 ERROR_UNSUPPORTED_OPERATION = cudlaErrorUnsupportedOperation
1680 ErrorUnsupportedOperation = ERROR_UNSUPPORTED_OPERATION # backward-compat alias
1681 ERROR_NV_SCI = cudlaErrorNvSci
1682 ErrorNvSci = ERROR_NV_SCI # backward-compat alias
1683 ERROR_DRIVER_NOT_FOUND = cudlaErrorDriverNotFound
1684 ErrorDriverNotFound = ERROR_DRIVER_NOT_FOUND # backward-compat alias
1685 ERROR_DLA_ERR_INVALID_INPUT = cudlaErrorDlaErrInvalidInput
1686 ErrorDlaErrInvalidInput = ERROR_DLA_ERR_INVALID_INPUT # backward-compat alias
1687 ERROR_DLA_ERR_INVALID_PRE_ACTION = cudlaErrorDlaErrInvalidPreAction
1688 ErrorDlaErrInvalidPreAction = ERROR_DLA_ERR_INVALID_PRE_ACTION # backward-compat alias
1689 ERROR_DLA_ERR_NO_MEM = cudlaErrorDlaErrNoMem
1690 ErrorDlaErrNoMem = ERROR_DLA_ERR_NO_MEM # backward-compat alias
1691 ERROR_DLA_ERR_PROCESSOR_BUSY = cudlaErrorDlaErrProcessorBusy
1692 ErrorDlaErrProcessorBusy = ERROR_DLA_ERR_PROCESSOR_BUSY # backward-compat alias
1693 ERROR_DLA_ERR_TASK_STATUS_MISMATCH = cudlaErrorDlaErrTaskStatusMismatch
1694 ErrorDlaErrTaskStatusMismatch = ERROR_DLA_ERR_TASK_STATUS_MISMATCH # backward-compat alias
1695 ERROR_DLA_ERR_ENGINE_TIMEOUT = cudlaErrorDlaErrEngineTimeout
1696 ErrorDlaErrEngineTimeout = ERROR_DLA_ERR_ENGINE_TIMEOUT # backward-compat alias
1697 ERROR_DLA_ERR_DATA_MISMATCH = cudlaErrorDlaErrDataMismatch
1698 ErrorDlaErrDataMismatch = ERROR_DLA_ERR_DATA_MISMATCH # backward-compat alias
1699 ERROR_UNKNOWN = cudlaErrorUnknown
1700 ErrorUnknown = ERROR_UNKNOWN # backward-compat alias
1702class Mode(_cyb_FastEnum):
1703 """
1704 See `cudlaMode`.
1705 """
1706 CUDA_DLA = CUDLA_CUDA_DLA
1707 STANDALONE = CUDLA_STANDALONE
1709class ModuleAttributeType(_cyb_FastEnum):
1710 """
1711 See `cudlaModuleAttributeType`.
1712 """
1713 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS
1714 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS
1715 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS
1716 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS
1717 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS
1718 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS
1720class FenceType(_cyb_FastEnum):
1721 """
1722 See `cudlaFenceType`.
1723 """
1724 FENCE = CUDLA_NVSCISYNC_FENCE
1725 NVSCISYNC_FENCE = FENCE # backward-compat alias
1726 FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF
1727 NVSCISYNC_FENCE_SOF = FENCE_SOF # backward-compat alias
1729class ModuleLoadFlags(_cyb_FastEnum):
1730 """
1731 See `cudlaModuleLoadFlags`.
1732 """
1733 DEFAULT = CUDLA_MODULE_DEFAULT
1734 MODULE_DEFAULT = DEFAULT # backward-compat alias
1735 ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS
1736 MODULE_ENABLE_FAULT_DIAGNOSTICS = ENABLE_FAULT_DIAGNOSTICS # backward-compat alias
1738class SubmissionFlags(_cyb_FastEnum):
1739 """
1740 See `cudlaSubmissionFlags`.
1741 """
1742 NOOP = CUDLA_SUBMIT_NOOP
1743 SUBMIT_NOOP = NOOP # backward-compat alias
1744 SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE
1745 SUBMIT_SKIP_LOCK_ACQUIRE = SKIP_LOCK_ACQUIRE # backward-compat alias
1746 DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK
1747 SUBMIT_DIAGNOSTICS_TASK = DIAGNOSTICS_TASK # backward-compat alias
1749class AccessPermissionFlags(_cyb_FastEnum):
1750 """
1751 See `cudlaAccessPermissionFlags`.
1752 """
1753 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM
1754 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM
1755 TASK_STATISTICS = CUDLA_TASK_STATISTICS
1757class DevAttributeType(_cyb_FastEnum):
1758 """
1759 See `cudlaDevAttributeType`.
1760 """
1761 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING
1762 DEVICE_VERSION = CUDLA_DEVICE_VERSION
1764class ScratchMemoryConfig(_cyb_FastEnum):
1765 """
1766 See `cudlaScratchMemoryConfig`.
1767 """
1768 DEFAULT = CUDLA_SCRATCH_MEMORY_DEFAULT
1769 SCRATCH_MEMORY_DEFAULT = DEFAULT # backward-compat alias
1770 SHARED_STATIC = CUDLA_SCRATCH_MEMORY_SHARED_STATIC
1771 SCRATCH_MEMORY_SHARED_STATIC = SHARED_STATIC # backward-compat alias
1772 CONFIG_MAX = CUDLA_SCRATCH_MEMORY_CONFIG_MAX
1773 MAX = CONFIG_MAX # backward-compat alias
1776###############################################################################
1777# Error handling
1778###############################################################################
1780class CudlaError(Exception):
1782 def __init__(self, status):
1783 self.status = status 1qr
1784 s = Status(status) 1qr
1785 cdef str err = f"{s.name} ({s.value})" 1qr
1786 super(CudlaError, self).__init__(err) 1qr
1788 def __reduce__(self):
1789 return (type(self), (self.status,))
1792@cython.profile(False)
1793cpdef inline check_status(int status):
1794 if status != 0:
1795 raise CudlaError(status)
1798###############################################################################
1799# Wrapper functions
1800###############################################################################
1802cpdef uint64_t get_version() except? -1:
1803 cdef uint64_t version
1804 with nogil:
1805 __status__ = cudlaGetVersion(&version)
1806 check_status(__status__)
1807 return version
1810cpdef uint64_t device_get_count() except? -1:
1811 cdef uint64_t p_num_devices
1812 with nogil:
1813 __status__ = cudlaDeviceGetCount(&p_num_devices)
1814 check_status(__status__)
1815 return p_num_devices
1818cpdef intptr_t create_device(uint64_t device, uint32_t flags) except *:
1819 cdef DevHandle dev_handle
1820 if flags & CUDLA_STANDALONE:
1821 raise CudlaError(cudlaErrorUnsupportedOperation)
1822 with nogil:
1823 __status__ = cudlaCreateDevice(<const uint64_t>device, &dev_handle, <const uint32_t>flags)
1824 check_status(__status__)
1825 return <intptr_t>dev_handle
1828cpdef intptr_t mem_register(intptr_t dev_handle, intptr_t ptr, size_t size, uint32_t flags) except *:
1829 cdef uint64_t* dev_ptr
1830 with nogil:
1831 __status__ = cudlaMemRegister(<const DevHandle>dev_handle, <const uint64_t* const>ptr, <const size_t>size, &dev_ptr, <const uint32_t>flags)
1832 check_status(__status__)
1833 return <intptr_t>dev_ptr
1836cpdef intptr_t module_load_from_memory(intptr_t dev_handle, p_module, size_t module_size, uint32_t flags) except *:
1837 cdef void* _p_module_ = <void *>_cyb_get_buffer_pointer(p_module, module_size, readonly=True)
1838 cdef Module h_module
1839 with nogil:
1840 __status__ = cudlaModuleLoadFromMemory(<const DevHandle>dev_handle, <const uint8_t* const>_p_module_, <const size_t>module_size, &h_module, <const uint32_t>flags)
1841 check_status(__status__)
1842 return <intptr_t>h_module
1845cpdef module_unload(intptr_t h_module, uint32_t flags):
1846 with nogil:
1847 __status__ = cudlaModuleUnload(<const Module>h_module, <const uint32_t>flags)
1848 check_status(__status__)
1851cpdef submit_task(intptr_t dev_handle, ptr_to_tasks, uint32_t num_tasks, intptr_t stream, uint32_t flags):
1852 cdef intptr_t _ptr_to_tasks_ptr_ = 0 if ptr_to_tasks is None else int(ptr_to_tasks)
1853 with nogil:
1854 __status__ = cudlaSubmitTask(<const DevHandle>dev_handle, <const cudlaTask* const>_ptr_to_tasks_ptr_, <const uint32_t>num_tasks, <void* const>stream, <const uint32_t>flags)
1855 check_status(__status__)
1858cpdef object device_get_attribute(intptr_t dev_handle, int attrib):
1859 cdef DevAttribute p_attribute_py = DevAttribute()
1860 cdef cudlaDevAttribute *p_attribute = <cudlaDevAttribute *><intptr_t>(p_attribute_py._get_ptr())
1861 with nogil:
1862 __status__ = cudlaDeviceGetAttribute(<const DevHandle>dev_handle, <const _DevAttributeType>attrib, p_attribute)
1863 check_status(__status__)
1864 return p_attribute_py
1867cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr):
1868 with nogil:
1869 __status__ = cudlaMemUnregister(<const DevHandle>dev_handle, <const uint64_t* const>dev_ptr)
1870 check_status(__status__)
1873cpdef int get_last_error(intptr_t dev_handle) except? 0:
1874 cdef int ret
1875 with nogil:
1876 ret = <int>cudlaGetLastError(<const DevHandle>dev_handle)
1877 return ret
1880cpdef destroy_device(intptr_t dev_handle):
1881 with nogil:
1882 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle)
1883 check_status(__status__)
1886cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout):
1887 with nogil:
1888 __status__ = cudlaSetTaskTimeoutInMs(<const DevHandle>dev_handle, <const uint32_t>timeout)
1889 check_status(__status__)
1892cpdef module_get_attributes(intptr_t h_module, int attr_type):
1893 """Query module attributes, interpreting the cudlaModuleAttribute union
1894 based on the requested attribute type.
1896 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS,
1897 NUM_OUTPUT_TASK_STATISTICS), returns an int.
1899 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS,
1900 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS),
1901 returns a list of ModuleTensorDescriptor objects.
1902 """
1903 cdef int _attr_type = attr_type
1904 cdef cudlaModuleAttribute count_attr
1905 cdef cudlaModuleAttribute num_attr
1906 cdef cudlaModuleAttribute desc_attr
1907 cdef uint32_t count
1908 cdef cudlaModuleTensorDescriptor* desc_buf
1909 cdef uint32_t i
1910 cdef int num_attr_type
1912 if _attr_type == CUDLA_NUM_INPUT_TENSORS or _attr_type == CUDLA_NUM_OUTPUT_TENSORS or _attr_type == CUDLA_NUM_OUTPUT_TASK_STATISTICS:
1913 with nogil:
1914 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>_attr_type, &count_attr)
1915 check_status(__status__)
1916 return <int>(count_attr.numInputTensors)
1917 elif _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS or _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS or _attr_type == CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS:
1918 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS:
1919 num_attr_type = CUDLA_NUM_INPUT_TENSORS
1920 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS:
1921 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS
1922 else:
1923 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS
1924 with nogil:
1925 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>num_attr_type, &num_attr)
1926 check_status(__status__)
1927 count = num_attr.numInputTensors
1928 desc_buf = <cudlaModuleTensorDescriptor*>malloc(count * sizeof(cudlaModuleTensorDescriptor))
1929 if desc_buf == NULL:
1930 raise MemoryError("Failed to allocate descriptor buffer")
1931 try:
1932 desc_attr.inputTensorDesc = desc_buf
1933 with nogil:
1934 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>_attr_type, &desc_attr)
1935 check_status(__status__)
1936 result = []
1937 for i in range(count):
1938 result.append(ModuleTensorDescriptor.from_ptr(<intptr_t>&desc_buf[i], readonly=True))
1939 return result
1940 finally:
1941 free(desc_buf)
1942 else:
1943 raise ValueError(f"Unknown attribute type: {attr_type}")
1944del _cyb_FastEnum