Coverage for cuda/bindings/cudla.pyx: 40.82%
931 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-29 01:38 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-29 01:38 +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.3.0. Do not modify it directly.
5# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=b793aebd0586162e23d26c82e2bd54c21675584e3c23d6e443f3a83c61a8674c
8# <<<< PREAMBLE CONTENT >>>>
10cimport cpython as _cyb_cpython
11cimport cpython.buffer as _cyb_cpython_buffer
12from cython cimport view as _cyb_view
13from libc.stdlib cimport (
14 calloc as _cyb_calloc,
15 free as _cyb_free,
16 malloc as _cyb_malloc,
17)
18from libc.string cimport (
19 memcmp as _cyb_memcmp,
20 memcpy as _cyb_memcpy,
21)
23from enum import IntEnum as _cyb_IntEnum
25import numpy as _numpy
27cdef _cyb___getbuffer(object self, _cyb_cpython.Py_buffer *buffer, void *ptr, int size, bint readonly):
28 buffer.buf = <char *>ptr
29 buffer.format = 'b'
30 buffer.internal = NULL
31 buffer.itemsize = 1
32 buffer.len = size
33 buffer.ndim = 1
34 buffer.obj = self
35 buffer.readonly = readonly
36 buffer.shape = &buffer.len
37 buffer.strides = &buffer.itemsize
38 buffer.suboffsets = NULL
40cdef _cyb_from_buffer(buffer, size, lowpp_type):
41 cdef _cyb_cpython.Py_buffer view
42 if _cyb_cpython.PyObject_GetBuffer(buffer, &view, _cyb_cpython_buffer.PyBUF_SIMPLE) != 0:
43 raise TypeError("buffer argument does not support the buffer protocol")
44 try:
45 if view.itemsize != 1:
46 raise ValueError("buffer itemsize must be 1 byte")
47 if view.len != size:
48 raise ValueError(f"buffer length must be {size} bytes")
49 return lowpp_type.from_ptr(<intptr_t><void *>view.buf, not view.readonly, buffer)
50 finally:
51 _cyb_cpython.PyBuffer_Release(&view)
53cdef _cyb_from_data(data, dtype_name, expected_dtype, lowpp_type):
54 # _numpy.recarray is a subclass of _numpy.ndarray, so implicitly handled here.
55 if isinstance(data, lowpp_type):
56 return data
57 if not isinstance(data, _numpy.ndarray):
58 raise TypeError("data argument must be a NumPy ndarray")
59 if data.size != 1:
60 raise ValueError("data array must have a size of 1")
61 if data.dtype != expected_dtype:
62 raise ValueError(f"data array must be of dtype {dtype_name}")
63 return lowpp_type.from_ptr(data.ctypes.data, not data.flags.writeable, data)
66# <<<< END OF PREAMBLE CONTENT >>>>
68cimport cython # NOQA
69from libc.stdint cimport intptr_t, uintptr_t
70from libc.stdlib cimport malloc, free
72from ._internal.utils cimport get_buffer_pointer
77###############################################################################
78# POD
79###############################################################################
81cdef _get_external_memory_handle_desc_dtype_offsets():
82 cdef cudlaExternalMemoryHandleDesc_t pod
83 return _numpy.dtype({
84 'names': ['ext_buf_object', 'size_'],
85 'formats': [_numpy.intp, _numpy.uint64],
86 'offsets': [
87 (<intptr_t>&(pod.extBufObject)) - (<intptr_t>&pod),
88 (<intptr_t>&(pod.size)) - (<intptr_t>&pod),
89 ],
90 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t),
91 })
93external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets()
95cdef class ExternalMemoryHandleDesc:
96 """Empty-initialize an instance of `cudlaExternalMemoryHandleDesc_t`.
99 .. seealso:: `cudlaExternalMemoryHandleDesc_t`
100 """
101 cdef:
102 cudlaExternalMemoryHandleDesc_t *_ptr
103 object _owner
104 bint _owned
105 bint _readonly
107 def __init__(self):
108 self._ptr = <cudlaExternalMemoryHandleDesc_t *>_cyb_calloc(1, sizeof(cudlaExternalMemoryHandleDesc_t)) 1g
109 if self._ptr == NULL: 1g
110 raise MemoryError("Error allocating ExternalMemoryHandleDesc")
111 self._owner = None 1g
112 self._owned = True 1g
113 self._readonly = False 1g
115 def __dealloc__(self):
116 cdef cudlaExternalMemoryHandleDesc_t *ptr
117 if self._owned and self._ptr != NULL: 1g
118 ptr = self._ptr 1g
119 self._ptr = NULL 1g
120 _cyb_free(ptr) 1g
122 def __repr__(self):
123 return f"<{__name__}.ExternalMemoryHandleDesc object at {hex(id(self))}>"
125 @property
126 def ptr(self):
127 """Get the pointer address to the data as Python :class:`int`."""
128 return <intptr_t>(self._ptr)
130 cdef intptr_t _get_ptr(self):
131 return <intptr_t>(self._ptr)
133 def __int__(self):
134 return <intptr_t>(self._ptr)
136 def __eq__(self, other):
137 cdef ExternalMemoryHandleDesc other_
138 if not isinstance(other, ExternalMemoryHandleDesc):
139 return False
140 other_ = other
141 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaExternalMemoryHandleDesc_t)) == 0)
143 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
144 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalMemoryHandleDesc_t), self._readonly)
146 def __releasebuffer__(self, Py_buffer *buffer):
147 pass
149 def __setitem__(self, key, val):
150 if key == 0 and isinstance(val, _numpy.ndarray):
151 self._ptr = <cudlaExternalMemoryHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalMemoryHandleDesc_t))
152 if self._ptr == NULL:
153 raise MemoryError("Error allocating ExternalMemoryHandleDesc")
154 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaExternalMemoryHandleDesc_t))
155 self._owner = None
156 self._owned = True
157 self._readonly = not val.flags.writeable
158 else:
159 setattr(self, key, val)
161 @property
162 def ext_buf_object(self):
163 """int: """
164 return <intptr_t>(self._ptr[0].extBufObject) 1g
166 @ext_buf_object.setter
167 def ext_buf_object(self, val):
168 if self._readonly: 1g
169 raise ValueError("This ExternalMemoryHandleDesc instance is read-only")
170 self._ptr[0].extBufObject = <void *><intptr_t>val 1g
172 @property
173 def size_(self):
174 """int: """
175 return self._ptr[0].size 1g
177 @size_.setter
178 def size_(self, val):
179 if self._readonly: 1g
180 raise ValueError("This ExternalMemoryHandleDesc instance is read-only")
181 self._ptr[0].size = val 1g
183 @staticmethod
184 def from_buffer(buffer):
185 """Create an ExternalMemoryHandleDesc instance with the memory from the given buffer."""
186 return _cyb_from_buffer(buffer, sizeof(cudlaExternalMemoryHandleDesc_t), ExternalMemoryHandleDesc)
188 @staticmethod
189 def from_data(data):
190 """Create an ExternalMemoryHandleDesc instance wrapping the given NumPy array.
192 Args:
193 data (_numpy.ndarray): a single-element array of dtype `external_memory_handle_desc_dtype` holding the data.
194 """
195 return _cyb_from_data(data, "external_memory_handle_desc_dtype", external_memory_handle_desc_dtype, ExternalMemoryHandleDesc)
197 @staticmethod
198 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
199 """Create an ExternalMemoryHandleDesc instance wrapping the given pointer.
201 Args:
202 ptr (intptr_t): pointer address as Python :class:`int` to the data.
203 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
204 readonly (bool): whether the data is read-only (to the user). default is `False`.
205 """
206 if ptr == 0:
207 raise ValueError("ptr must not be null (0)")
208 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc)
209 if owner is None:
210 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalMemoryHandleDesc_t))
211 if obj._ptr == NULL:
212 raise MemoryError("Error allocating ExternalMemoryHandleDesc")
213 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaExternalMemoryHandleDesc_t))
214 obj._owner = None
215 obj._owned = True
216 else:
217 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr
218 obj._owner = owner
219 obj._owned = False
220 obj._readonly = readonly
221 return obj
224cdef _get_external_semaphore_handle_desc_dtype_offsets():
225 cdef cudlaExternalSemaphoreHandleDesc_t pod
226 return _numpy.dtype({
227 'names': ['ext_sync_object'],
228 'formats': [_numpy.intp],
229 'offsets': [
230 (<intptr_t>&(pod.extSyncObject)) - (<intptr_t>&pod),
231 ],
232 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t),
233 })
235external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets()
237cdef class ExternalSemaphoreHandleDesc:
238 """Empty-initialize an instance of `cudlaExternalSemaphoreHandleDesc_t`.
241 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t`
242 """
243 cdef:
244 cudlaExternalSemaphoreHandleDesc_t *_ptr
245 object _owner
246 bint _owned
247 bint _readonly
249 def __init__(self):
250 self._ptr = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_calloc(1, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 1l
251 if self._ptr == NULL: 1l
252 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc")
253 self._owner = None 1l
254 self._owned = True 1l
255 self._readonly = False 1l
257 def __dealloc__(self):
258 cdef cudlaExternalSemaphoreHandleDesc_t *ptr
259 if self._owned and self._ptr != NULL: 1l
260 ptr = self._ptr 1l
261 self._ptr = NULL 1l
262 _cyb_free(ptr) 1l
264 def __repr__(self):
265 return f"<{__name__}.ExternalSemaphoreHandleDesc object at {hex(id(self))}>"
267 @property
268 def ptr(self):
269 """Get the pointer address to the data as Python :class:`int`."""
270 return <intptr_t>(self._ptr)
272 cdef intptr_t _get_ptr(self):
273 return <intptr_t>(self._ptr)
275 def __int__(self):
276 return <intptr_t>(self._ptr)
278 def __eq__(self, other):
279 cdef ExternalSemaphoreHandleDesc other_
280 if not isinstance(other, ExternalSemaphoreHandleDesc):
281 return False
282 other_ = other
283 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaExternalSemaphoreHandleDesc_t)) == 0)
285 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
286 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t), self._readonly)
288 def __releasebuffer__(self, Py_buffer *buffer):
289 pass
291 def __setitem__(self, key, val):
292 if key == 0 and isinstance(val, _numpy.ndarray):
293 self._ptr = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalSemaphoreHandleDesc_t))
294 if self._ptr == NULL:
295 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc")
296 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaExternalSemaphoreHandleDesc_t))
297 self._owner = None
298 self._owned = True
299 self._readonly = not val.flags.writeable
300 else:
301 setattr(self, key, val)
303 @property
304 def ext_sync_object(self):
305 """int: """
306 return <intptr_t>(self._ptr[0].extSyncObject) 1l
308 @ext_sync_object.setter
309 def ext_sync_object(self, val):
310 if self._readonly: 1l
311 raise ValueError("This ExternalSemaphoreHandleDesc instance is read-only")
312 self._ptr[0].extSyncObject = <void *><intptr_t>val 1l
314 @staticmethod
315 def from_buffer(buffer):
316 """Create an ExternalSemaphoreHandleDesc instance with the memory from the given buffer."""
317 return _cyb_from_buffer(buffer, sizeof(cudlaExternalSemaphoreHandleDesc_t), ExternalSemaphoreHandleDesc)
319 @staticmethod
320 def from_data(data):
321 """Create an ExternalSemaphoreHandleDesc instance wrapping the given NumPy array.
323 Args:
324 data (_numpy.ndarray): a single-element array of dtype `external_semaphore_handle_desc_dtype` holding the data.
325 """
326 return _cyb_from_data(data, "external_semaphore_handle_desc_dtype", external_semaphore_handle_desc_dtype, ExternalSemaphoreHandleDesc)
328 @staticmethod
329 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
330 """Create an ExternalSemaphoreHandleDesc instance wrapping the given pointer.
332 Args:
333 ptr (intptr_t): pointer address as Python :class:`int` to the data.
334 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
335 readonly (bool): whether the data is read-only (to the user). default is `False`.
336 """
337 if ptr == 0:
338 raise ValueError("ptr must not be null (0)")
339 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc)
340 if owner is None:
341 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalSemaphoreHandleDesc_t))
342 if obj._ptr == NULL:
343 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc")
344 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t))
345 obj._owner = None
346 obj._owned = True
347 else:
348 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr
349 obj._owner = owner
350 obj._owned = False
351 obj._readonly = readonly
352 return obj
355cdef _get_module_tensor_descriptor_dtype_offsets():
356 cdef cudlaModuleTensorDescriptor pod
357 return _numpy.dtype({
358 'names': ['name', 'size_', 'n', 'c', 'h', 'w', 'data_format', 'data_type', 'data_category', 'pixel_format', 'pixel_mapping', 'stride'],
359 '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)],
360 'offsets': [
361 (<intptr_t>&(pod.name)) - (<intptr_t>&pod),
362 (<intptr_t>&(pod.size)) - (<intptr_t>&pod),
363 (<intptr_t>&(pod.n)) - (<intptr_t>&pod),
364 (<intptr_t>&(pod.c)) - (<intptr_t>&pod),
365 (<intptr_t>&(pod.h)) - (<intptr_t>&pod),
366 (<intptr_t>&(pod.w)) - (<intptr_t>&pod),
367 (<intptr_t>&(pod.dataFormat)) - (<intptr_t>&pod),
368 (<intptr_t>&(pod.dataType)) - (<intptr_t>&pod),
369 (<intptr_t>&(pod.dataCategory)) - (<intptr_t>&pod),
370 (<intptr_t>&(pod.pixelFormat)) - (<intptr_t>&pod),
371 (<intptr_t>&(pod.pixelMapping)) - (<intptr_t>&pod),
372 (<intptr_t>&(pod.stride)) - (<intptr_t>&pod),
373 ],
374 'itemsize': sizeof(cudlaModuleTensorDescriptor),
375 })
377module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets()
379cdef class ModuleTensorDescriptor:
380 """Empty-initialize an instance of `cudlaModuleTensorDescriptor`.
383 .. seealso:: `cudlaModuleTensorDescriptor`
384 """
385 cdef:
386 cudlaModuleTensorDescriptor *_ptr
387 object _owner
388 bint _owned
389 bint _readonly
391 def __init__(self):
392 self._ptr = <cudlaModuleTensorDescriptor *>_cyb_calloc(1, sizeof(cudlaModuleTensorDescriptor)) 1fpme
393 if self._ptr == NULL: 1fpme
394 raise MemoryError("Error allocating ModuleTensorDescriptor")
395 self._owner = None 1fpme
396 self._owned = True 1fpme
397 self._readonly = False 1fpme
399 def __dealloc__(self):
400 cdef cudlaModuleTensorDescriptor *ptr
401 if self._owned and self._ptr != NULL: 1fpme
402 ptr = self._ptr 1fpme
403 self._ptr = NULL 1fpme
404 _cyb_free(ptr) 1fpme
406 def __repr__(self):
407 return f"<{__name__}.ModuleTensorDescriptor object at {hex(id(self))}>"
409 @property
410 def ptr(self):
411 """Get the pointer address to the data as Python :class:`int`."""
412 return <intptr_t>(self._ptr)
414 cdef intptr_t _get_ptr(self):
415 return <intptr_t>(self._ptr)
417 def __int__(self):
418 return <intptr_t>(self._ptr) 1e
420 def __eq__(self, other):
421 cdef ModuleTensorDescriptor other_
422 if not isinstance(other, ModuleTensorDescriptor):
423 return False
424 other_ = other
425 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaModuleTensorDescriptor)) == 0)
427 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
428 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleTensorDescriptor), self._readonly)
430 def __releasebuffer__(self, Py_buffer *buffer):
431 pass
433 def __setitem__(self, key, val):
434 if key == 0 and isinstance(val, _numpy.ndarray):
435 self._ptr = <cudlaModuleTensorDescriptor *>_cyb_malloc(sizeof(cudlaModuleTensorDescriptor))
436 if self._ptr == NULL:
437 raise MemoryError("Error allocating ModuleTensorDescriptor")
438 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaModuleTensorDescriptor))
439 self._owner = None
440 self._owned = True
441 self._readonly = not val.flags.writeable
442 else:
443 setattr(self, key, val)
445 @property
446 def name(self):
447 """~_numpy.int8: (array of length 81)."""
448 return _cyb_cpython.PyUnicode_FromString(self._ptr[0].name) 1p
450 @name.setter
451 def name(self, val):
452 if self._readonly:
453 raise ValueError("This ModuleTensorDescriptor instance is read-only")
454 cdef bytes buf = val.encode()
455 if len(buf) >= 81:
456 raise ValueError("String too long for field name, max length is 80")
457 cdef char *ptr = buf
458 _cyb_memcpy(<void *>(self._ptr[0].name), <void *>ptr, 81)
460 @property
461 def size_(self):
462 """int: """
463 return self._ptr[0].size 1f
465 @size_.setter
466 def size_(self, val):
467 if self._readonly:
468 raise ValueError("This ModuleTensorDescriptor instance is read-only")
469 self._ptr[0].size = val
471 @property
472 def n(self):
473 """int: """
474 return self._ptr[0].n 1f
476 @n.setter
477 def n(self, val):
478 if self._readonly:
479 raise ValueError("This ModuleTensorDescriptor instance is read-only")
480 self._ptr[0].n = val
482 @property
483 def c(self):
484 """int: """
485 return self._ptr[0].c 1f
487 @c.setter
488 def c(self, val):
489 if self._readonly:
490 raise ValueError("This ModuleTensorDescriptor instance is read-only")
491 self._ptr[0].c = val
493 @property
494 def h(self):
495 """int: """
496 return self._ptr[0].h 1f
498 @h.setter
499 def h(self, val):
500 if self._readonly:
501 raise ValueError("This ModuleTensorDescriptor instance is read-only")
502 self._ptr[0].h = val
504 @property
505 def w(self):
506 """int: """
507 return self._ptr[0].w 1f
509 @w.setter
510 def w(self, val):
511 if self._readonly:
512 raise ValueError("This ModuleTensorDescriptor instance is read-only")
513 self._ptr[0].w = val
515 @property
516 def data_format(self):
517 """int: """
518 return self._ptr[0].dataFormat 1f
520 @data_format.setter
521 def data_format(self, val):
522 if self._readonly:
523 raise ValueError("This ModuleTensorDescriptor instance is read-only")
524 self._ptr[0].dataFormat = val
526 @property
527 def data_type(self):
528 """int: """
529 return self._ptr[0].dataType 1f
531 @data_type.setter
532 def data_type(self, val):
533 if self._readonly:
534 raise ValueError("This ModuleTensorDescriptor instance is read-only")
535 self._ptr[0].dataType = val
537 @property
538 def data_category(self):
539 """int: """
540 return self._ptr[0].dataCategory 1f
542 @data_category.setter
543 def data_category(self, val):
544 if self._readonly:
545 raise ValueError("This ModuleTensorDescriptor instance is read-only")
546 self._ptr[0].dataCategory = val
548 @property
549 def pixel_format(self):
550 """int: """
551 return self._ptr[0].pixelFormat 1f
553 @pixel_format.setter
554 def pixel_format(self, val):
555 if self._readonly:
556 raise ValueError("This ModuleTensorDescriptor instance is read-only")
557 self._ptr[0].pixelFormat = val
559 @property
560 def pixel_mapping(self):
561 """int: """
562 return self._ptr[0].pixelMapping 1f
564 @pixel_mapping.setter
565 def pixel_mapping(self, val):
566 if self._readonly:
567 raise ValueError("This ModuleTensorDescriptor instance is read-only")
568 self._ptr[0].pixelMapping = val
570 @property
571 def stride(self):
572 """~_numpy.uint32: (array of length 8)."""
573 cdef _cyb_view.array arr = _cyb_view.array(shape=(8,), itemsize=sizeof(uint32_t), format="I", mode="c", allocate_buffer=False) 1m
574 arr.data = <char *>(&(self._ptr[0].stride)) 1m
575 return _numpy.asarray(arr) 1m
577 @stride.setter
578 def stride(self, val):
579 if self._readonly:
580 raise ValueError("This ModuleTensorDescriptor instance is read-only")
581 if len(val) != 8:
582 raise ValueError(f"Expected length { 8 } for field stride, got {len(val)}")
583 cdef _cyb_view.array arr = _cyb_view.array(shape=(8,), itemsize=sizeof(uint32_t), format="I", mode="c")
584 arr[:] = _numpy.asarray(val, dtype=_numpy.uint32)
585 _cyb_memcpy(<void *>(&(self._ptr[0].stride)), <void *>(arr.data), sizeof(uint32_t) * len(val))
587 @staticmethod
588 def from_buffer(buffer):
589 """Create an ModuleTensorDescriptor instance with the memory from the given buffer."""
590 return _cyb_from_buffer(buffer, sizeof(cudlaModuleTensorDescriptor), ModuleTensorDescriptor)
592 @staticmethod
593 def from_data(data):
594 """Create an ModuleTensorDescriptor instance wrapping the given NumPy array.
596 Args:
597 data (_numpy.ndarray): a single-element array of dtype `module_tensor_descriptor_dtype` holding the data.
598 """
599 return _cyb_from_data(data, "module_tensor_descriptor_dtype", module_tensor_descriptor_dtype, ModuleTensorDescriptor)
601 @staticmethod
602 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
603 """Create an ModuleTensorDescriptor instance wrapping the given pointer.
605 Args:
606 ptr (intptr_t): pointer address as Python :class:`int` to the data.
607 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
608 readonly (bool): whether the data is read-only (to the user). default is `False`.
609 """
610 if ptr == 0:
611 raise ValueError("ptr must not be null (0)")
612 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor)
613 if owner is None:
614 obj._ptr = <cudlaModuleTensorDescriptor *>_cyb_malloc(sizeof(cudlaModuleTensorDescriptor))
615 if obj._ptr == NULL:
616 raise MemoryError("Error allocating ModuleTensorDescriptor")
617 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaModuleTensorDescriptor))
618 obj._owner = None
619 obj._owned = True
620 else:
621 obj._ptr = <cudlaModuleTensorDescriptor *>ptr
622 obj._owner = owner
623 obj._owned = False
624 obj._readonly = readonly
625 return obj
628cdef _get_fence_dtype_offsets():
629 cdef CudlaFence pod
630 return _numpy.dtype({
631 'names': ['fence', 'type'],
632 'formats': [_numpy.intp, _numpy.int32],
633 'offsets': [
634 (<intptr_t>&(pod.fence)) - (<intptr_t>&pod),
635 (<intptr_t>&(pod.type)) - (<intptr_t>&pod),
636 ],
637 'itemsize': sizeof(CudlaFence),
638 })
640fence_dtype = _get_fence_dtype_offsets()
642cdef class Fence:
643 """Empty-initialize an instance of `CudlaFence`.
646 .. seealso:: `CudlaFence`
647 """
648 cdef:
649 CudlaFence *_ptr
650 object _owner
651 bint _owned
652 bint _readonly
654 def __init__(self):
655 self._ptr = <CudlaFence *>_cyb_calloc(1, sizeof(CudlaFence)) 1h
656 if self._ptr == NULL: 1h
657 raise MemoryError("Error allocating Fence")
658 self._owner = None 1h
659 self._owned = True 1h
660 self._readonly = False 1h
662 def __dealloc__(self):
663 cdef CudlaFence *ptr
664 if self._owned and self._ptr != NULL: 1h
665 ptr = self._ptr 1h
666 self._ptr = NULL 1h
667 _cyb_free(ptr) 1h
669 def __repr__(self):
670 return f"<{__name__}.Fence object at {hex(id(self))}>"
672 @property
673 def ptr(self):
674 """Get the pointer address to the data as Python :class:`int`."""
675 return <intptr_t>(self._ptr)
677 cdef intptr_t _get_ptr(self):
678 return <intptr_t>(self._ptr)
680 def __int__(self):
681 return <intptr_t>(self._ptr)
683 def __eq__(self, other):
684 cdef Fence other_
685 if not isinstance(other, Fence):
686 return False
687 other_ = other
688 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(CudlaFence)) == 0)
690 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
691 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CudlaFence), self._readonly)
693 def __releasebuffer__(self, Py_buffer *buffer):
694 pass
696 def __setitem__(self, key, val):
697 if key == 0 and isinstance(val, _numpy.ndarray):
698 self._ptr = <CudlaFence *>_cyb_malloc(sizeof(CudlaFence))
699 if self._ptr == NULL:
700 raise MemoryError("Error allocating Fence")
701 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CudlaFence))
702 self._owner = None
703 self._owned = True
704 self._readonly = not val.flags.writeable
705 else:
706 setattr(self, key, val)
708 @property
709 def fence(self):
710 """int: """
711 return <intptr_t>(self._ptr[0].fence) 1h
713 @fence.setter
714 def fence(self, val):
715 if self._readonly: 1h
716 raise ValueError("This Fence instance is read-only")
717 self._ptr[0].fence = <void *><intptr_t>val 1h
719 @property
720 def type(self):
721 """int: """
722 return <int>(self._ptr[0].type) 1h
724 @type.setter
725 def type(self, val):
726 if self._readonly: 1h
727 raise ValueError("This Fence instance is read-only")
728 self._ptr[0].type = <cudlaFenceType><int>val 1h
730 @staticmethod
731 def from_buffer(buffer):
732 """Create an Fence instance with the memory from the given buffer."""
733 return _cyb_from_buffer(buffer, sizeof(CudlaFence), Fence)
735 @staticmethod
736 def from_data(data):
737 """Create an Fence instance wrapping the given NumPy array.
739 Args:
740 data (_numpy.ndarray): a single-element array of dtype `fence_dtype` holding the data.
741 """
742 return _cyb_from_data(data, "fence_dtype", fence_dtype, Fence)
744 @staticmethod
745 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
746 """Create an Fence instance wrapping the given pointer.
748 Args:
749 ptr (intptr_t): pointer address as Python :class:`int` to the data.
750 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
751 readonly (bool): whether the data is read-only (to the user). default is `False`.
752 """
753 if ptr == 0:
754 raise ValueError("ptr must not be null (0)")
755 cdef Fence obj = Fence.__new__(Fence)
756 if owner is None:
757 obj._ptr = <CudlaFence *>_cyb_malloc(sizeof(CudlaFence))
758 if obj._ptr == NULL:
759 raise MemoryError("Error allocating Fence")
760 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CudlaFence))
761 obj._owner = None
762 obj._owned = True
763 else:
764 obj._ptr = <CudlaFence *>ptr
765 obj._owner = owner
766 obj._owned = False
767 obj._readonly = readonly
768 return obj
771cdef _get_dev_attribute_dtype_offsets():
772 cdef cudlaDevAttribute pod
773 return _numpy.dtype({
774 'names': ['unified_addressing_supported', 'device_version'],
775 'formats': [_numpy.uint8, _numpy.uint32],
776 'offsets': [
777 (<intptr_t>&(pod.unifiedAddressingSupported)) - (<intptr_t>&pod),
778 (<intptr_t>&(pod.deviceVersion)) - (<intptr_t>&pod),
779 ],
780 'itemsize': sizeof(cudlaDevAttribute),
781 })
783dev_attribute_dtype = _get_dev_attribute_dtype_offsets()
785cdef class DevAttribute:
786 """Empty-initialize an instance of `cudlaDevAttribute`.
789 .. seealso:: `cudlaDevAttribute`
790 """
791 cdef:
792 cudlaDevAttribute *_ptr
793 object _owner
794 bint _owned
795 bint _readonly
797 def __init__(self):
798 self._ptr = <cudlaDevAttribute *>_cyb_calloc(1, sizeof(cudlaDevAttribute)) 1i
799 if self._ptr == NULL: 1i
800 raise MemoryError("Error allocating DevAttribute")
801 self._owner = None 1i
802 self._owned = True 1i
803 self._readonly = False 1i
805 def __dealloc__(self):
806 cdef cudlaDevAttribute *ptr
807 if self._owned and self._ptr != NULL: 1i
808 ptr = self._ptr 1i
809 self._ptr = NULL 1i
810 _cyb_free(ptr) 1i
812 def __repr__(self):
813 return f"<{__name__}.DevAttribute object at {hex(id(self))}>"
815 @property
816 def ptr(self):
817 """Get the pointer address to the data as Python :class:`int`."""
818 return <intptr_t>(self._ptr)
820 cdef intptr_t _get_ptr(self):
821 return <intptr_t>(self._ptr)
823 def __int__(self):
824 return <intptr_t>(self._ptr)
826 def __eq__(self, other):
827 cdef DevAttribute other_
828 if not isinstance(other, DevAttribute):
829 return False
830 other_ = other
831 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaDevAttribute)) == 0)
833 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
834 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaDevAttribute), self._readonly)
836 def __releasebuffer__(self, Py_buffer *buffer):
837 pass
839 def __setitem__(self, key, val):
840 if key == 0 and isinstance(val, _numpy.ndarray):
841 self._ptr = <cudlaDevAttribute *>_cyb_malloc(sizeof(cudlaDevAttribute))
842 if self._ptr == NULL:
843 raise MemoryError("Error allocating DevAttribute")
844 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaDevAttribute))
845 self._owner = None
846 self._owned = True
847 self._readonly = not val.flags.writeable
848 else:
849 setattr(self, key, val)
851 @property
852 def unified_addressing_supported(self):
853 """int: """
854 return self._ptr[0].unifiedAddressingSupported 1i
856 @unified_addressing_supported.setter
857 def unified_addressing_supported(self, val):
858 if self._readonly: 1i
859 raise ValueError("This DevAttribute instance is read-only")
860 self._ptr[0].unifiedAddressingSupported = val 1i
862 @property
863 def device_version(self):
864 """int: """
865 return self._ptr[0].deviceVersion 1i
867 @device_version.setter
868 def device_version(self, val):
869 if self._readonly: 1i
870 raise ValueError("This DevAttribute instance is read-only")
871 self._ptr[0].deviceVersion = val 1i
873 @staticmethod
874 def from_buffer(buffer):
875 """Create an DevAttribute instance with the memory from the given buffer."""
876 return _cyb_from_buffer(buffer, sizeof(cudlaDevAttribute), DevAttribute)
878 @staticmethod
879 def from_data(data):
880 """Create an DevAttribute instance wrapping the given NumPy array.
882 Args:
883 data (_numpy.ndarray): a single-element array of dtype `dev_attribute_dtype` holding the data.
884 """
885 return _cyb_from_data(data, "dev_attribute_dtype", dev_attribute_dtype, DevAttribute)
887 @staticmethod
888 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
889 """Create an DevAttribute instance wrapping the given pointer.
891 Args:
892 ptr (intptr_t): pointer address as Python :class:`int` to the data.
893 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
894 readonly (bool): whether the data is read-only (to the user). default is `False`.
895 """
896 if ptr == 0:
897 raise ValueError("ptr must not be null (0)")
898 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute)
899 if owner is None:
900 obj._ptr = <cudlaDevAttribute *>_cyb_malloc(sizeof(cudlaDevAttribute))
901 if obj._ptr == NULL:
902 raise MemoryError("Error allocating DevAttribute")
903 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaDevAttribute))
904 obj._owner = None
905 obj._owned = True
906 else:
907 obj._ptr = <cudlaDevAttribute *>ptr
908 obj._owner = owner
909 obj._owned = False
910 obj._readonly = readonly
911 return obj
914cdef _get_module_attribute_dtype_offsets():
915 cdef cudlaModuleAttribute pod
916 return _numpy.dtype({
917 'names': ['num_input_tensors', 'num_output_tensors', 'input_tensor_desc', 'output_tensor_desc'],
918 'formats': [_numpy.uint32, _numpy.uint32, _numpy.intp, _numpy.intp],
919 'offsets': [
920 (<intptr_t>&(pod.numInputTensors)) - (<intptr_t>&pod),
921 (<intptr_t>&(pod.numOutputTensors)) - (<intptr_t>&pod),
922 (<intptr_t>&(pod.inputTensorDesc)) - (<intptr_t>&pod),
923 (<intptr_t>&(pod.outputTensorDesc)) - (<intptr_t>&pod),
924 ],
925 'itemsize': sizeof(cudlaModuleAttribute),
926 })
928module_attribute_dtype = _get_module_attribute_dtype_offsets()
930cdef class ModuleAttribute:
931 """Empty-initialize an instance of `cudlaModuleAttribute`.
934 .. seealso:: `cudlaModuleAttribute`
935 """
936 cdef:
937 cudlaModuleAttribute *_ptr
938 object _owner
939 bint _owned
940 bint _readonly
942 def __init__(self):
943 self._ptr = <cudlaModuleAttribute *>_cyb_calloc(1, sizeof(cudlaModuleAttribute)) 1j
944 if self._ptr == NULL: 1j
945 raise MemoryError("Error allocating ModuleAttribute")
946 self._owner = None 1j
947 self._owned = True 1j
948 self._readonly = False 1j
950 def __dealloc__(self):
951 cdef cudlaModuleAttribute *ptr
952 if self._owned and self._ptr != NULL: 1j
953 ptr = self._ptr 1j
954 self._ptr = NULL 1j
955 _cyb_free(ptr) 1j
957 def __repr__(self):
958 return f"<{__name__}.ModuleAttribute object at {hex(id(self))}>"
960 @property
961 def ptr(self):
962 """Get the pointer address to the data as Python :class:`int`."""
963 return <intptr_t>(self._ptr)
965 cdef intptr_t _get_ptr(self):
966 return <intptr_t>(self._ptr)
968 def __int__(self):
969 return <intptr_t>(self._ptr)
971 def __eq__(self, other):
972 cdef ModuleAttribute other_
973 if not isinstance(other, ModuleAttribute):
974 return False
975 other_ = other
976 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaModuleAttribute)) == 0)
978 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
979 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleAttribute), self._readonly)
981 def __releasebuffer__(self, Py_buffer *buffer):
982 pass
984 def __setitem__(self, key, val):
985 if key == 0 and isinstance(val, _numpy.ndarray):
986 self._ptr = <cudlaModuleAttribute *>_cyb_malloc(sizeof(cudlaModuleAttribute))
987 if self._ptr == NULL:
988 raise MemoryError("Error allocating ModuleAttribute")
989 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaModuleAttribute))
990 self._owner = None
991 self._owned = True
992 self._readonly = not val.flags.writeable
993 else:
994 setattr(self, key, val)
996 @property
997 def num_input_tensors(self):
998 """int: """
999 return self._ptr[0].numInputTensors 1j
1001 @num_input_tensors.setter
1002 def num_input_tensors(self, val):
1003 if self._readonly: 1j
1004 raise ValueError("This ModuleAttribute instance is read-only")
1005 self._ptr[0].numInputTensors = val 1j
1007 @property
1008 def num_output_tensors(self):
1009 """int: """
1010 return self._ptr[0].numOutputTensors 1j
1012 @num_output_tensors.setter
1013 def num_output_tensors(self, val):
1014 if self._readonly: 1j
1015 raise ValueError("This ModuleAttribute instance is read-only")
1016 self._ptr[0].numOutputTensors = val 1j
1018 @property
1019 def input_tensor_desc(self):
1020 """int: """
1021 return <intptr_t>(self._ptr[0].inputTensorDesc)
1023 @input_tensor_desc.setter
1024 def input_tensor_desc(self, val):
1025 if self._readonly:
1026 raise ValueError("This ModuleAttribute instance is read-only")
1027 self._ptr[0].inputTensorDesc = <cudlaModuleTensorDescriptor*><intptr_t>val
1029 @property
1030 def output_tensor_desc(self):
1031 """int: """
1032 return <intptr_t>(self._ptr[0].outputTensorDesc)
1034 @output_tensor_desc.setter
1035 def output_tensor_desc(self, val):
1036 if self._readonly:
1037 raise ValueError("This ModuleAttribute instance is read-only")
1038 self._ptr[0].outputTensorDesc = <cudlaModuleTensorDescriptor*><intptr_t>val
1040 @staticmethod
1041 def from_buffer(buffer):
1042 """Create an ModuleAttribute instance with the memory from the given buffer."""
1043 return _cyb_from_buffer(buffer, sizeof(cudlaModuleAttribute), ModuleAttribute)
1045 @staticmethod
1046 def from_data(data):
1047 """Create an ModuleAttribute instance wrapping the given NumPy array.
1049 Args:
1050 data (_numpy.ndarray): a single-element array of dtype `module_attribute_dtype` holding the data.
1051 """
1052 return _cyb_from_data(data, "module_attribute_dtype", module_attribute_dtype, ModuleAttribute)
1054 @staticmethod
1055 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1056 """Create an ModuleAttribute instance wrapping the given pointer.
1058 Args:
1059 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1060 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1061 readonly (bool): whether the data is read-only (to the user). default is `False`.
1062 """
1063 if ptr == 0:
1064 raise ValueError("ptr must not be null (0)")
1065 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute)
1066 if owner is None:
1067 obj._ptr = <cudlaModuleAttribute *>_cyb_malloc(sizeof(cudlaModuleAttribute))
1068 if obj._ptr == NULL:
1069 raise MemoryError("Error allocating ModuleAttribute")
1070 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaModuleAttribute))
1071 obj._owner = None
1072 obj._owned = True
1073 else:
1074 obj._ptr = <cudlaModuleAttribute *>ptr
1075 obj._owner = owner
1076 obj._owned = False
1077 obj._readonly = readonly
1078 return obj
1081cdef _get_wait_events_dtype_offsets():
1082 cdef cudlaWaitEvents pod
1083 return _numpy.dtype({
1084 'names': ['pre_fences', 'num_events'],
1085 'formats': [_numpy.intp, _numpy.uint32],
1086 'offsets': [
1087 (<intptr_t>&(pod.preFences)) - (<intptr_t>&pod),
1088 (<intptr_t>&(pod.numEvents)) - (<intptr_t>&pod),
1089 ],
1090 'itemsize': sizeof(cudlaWaitEvents),
1091 })
1093wait_events_dtype = _get_wait_events_dtype_offsets()
1095cdef class WaitEvents:
1096 """Empty-initialize an instance of `cudlaWaitEvents`.
1099 .. seealso:: `cudlaWaitEvents`
1100 """
1101 cdef:
1102 cudlaWaitEvents *_ptr
1103 object _owner
1104 bint _owned
1105 bint _readonly
1106 dict _refs
1108 def __init__(self):
1109 self._ptr = <cudlaWaitEvents *>_cyb_calloc(1, sizeof(cudlaWaitEvents)) 1n
1110 if self._ptr == NULL: 1n
1111 raise MemoryError("Error allocating WaitEvents")
1112 self._owner = None 1n
1113 self._owned = True 1n
1114 self._readonly = False 1n
1115 self._refs = {} 1n
1117 def __dealloc__(self):
1118 cdef cudlaWaitEvents *ptr
1119 if self._owned and self._ptr != NULL: 1n
1120 ptr = self._ptr 1n
1121 self._ptr = NULL 1n
1122 _cyb_free(ptr) 1n
1124 def __repr__(self):
1125 return f"<{__name__}.WaitEvents object at {hex(id(self))}>"
1127 @property
1128 def ptr(self):
1129 """Get the pointer address to the data as Python :class:`int`."""
1130 return <intptr_t>(self._ptr)
1132 cdef intptr_t _get_ptr(self):
1133 return <intptr_t>(self._ptr)
1135 def __int__(self):
1136 return <intptr_t>(self._ptr)
1138 def __eq__(self, other):
1139 cdef WaitEvents other_
1140 if not isinstance(other, WaitEvents):
1141 return False
1142 other_ = other
1143 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaWaitEvents)) == 0)
1145 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1146 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaWaitEvents), self._readonly)
1148 def __releasebuffer__(self, Py_buffer *buffer):
1149 pass
1151 def __setitem__(self, key, val):
1152 if key == 0 and isinstance(val, _numpy.ndarray):
1153 self._ptr = <cudlaWaitEvents *>_cyb_malloc(sizeof(cudlaWaitEvents))
1154 if self._ptr == NULL:
1155 raise MemoryError("Error allocating WaitEvents")
1156 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaWaitEvents))
1157 self._owner = None
1158 self._owned = True
1159 self._readonly = not val.flags.writeable
1160 else:
1161 setattr(self, key, val)
1163 @property
1164 def pre_fences(self):
1165 """int: """
1166 if self._ptr[0].preFences == NULL or self._ptr[0].numEvents == 0: 1n
1167 return [] 1n
1168 return Fence.from_ptr(
1169 <intptr_t>(self._ptr[0].preFences),
1170 self._ptr[0].numEvents,
1171 owner=self,
1172 readonly=self._readonly
1173 )
1175 @pre_fences.setter
1176 def pre_fences(self, val):
1177 if self._readonly:
1178 raise ValueError("This WaitEvents instance is read-only")
1179 cdef Fence arr = val
1180 self._ptr[0].preFences = <CudlaFence*><intptr_t>(arr._get_ptr())
1181 self._ptr[0].numEvents = len(arr)
1182 self._refs["pre_fences"] = arr
1184 @staticmethod
1185 def from_buffer(buffer):
1186 """Create an WaitEvents instance with the memory from the given buffer."""
1187 return _cyb_from_buffer(buffer, sizeof(cudlaWaitEvents), WaitEvents)
1189 @staticmethod
1190 def from_data(data):
1191 """Create an WaitEvents instance wrapping the given NumPy array.
1193 Args:
1194 data (_numpy.ndarray): a single-element array of dtype `wait_events_dtype` holding the data.
1195 """
1196 return _cyb_from_data(data, "wait_events_dtype", wait_events_dtype, WaitEvents)
1198 @staticmethod
1199 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1200 """Create an WaitEvents instance wrapping the given pointer.
1202 Args:
1203 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1204 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1205 readonly (bool): whether the data is read-only (to the user). default is `False`.
1206 """
1207 if ptr == 0:
1208 raise ValueError("ptr must not be null (0)")
1209 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents)
1210 if owner is None:
1211 obj._ptr = <cudlaWaitEvents *>_cyb_malloc(sizeof(cudlaWaitEvents))
1212 if obj._ptr == NULL:
1213 raise MemoryError("Error allocating WaitEvents")
1214 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaWaitEvents))
1215 obj._owner = None
1216 obj._owned = True
1217 else:
1218 obj._ptr = <cudlaWaitEvents *>ptr
1219 obj._owner = owner
1220 obj._owned = False
1221 obj._readonly = readonly
1222 obj._refs = {}
1223 return obj
1226cdef _get_signal_events_dtype_offsets():
1227 cdef cudlaSignalEvents pod
1228 return _numpy.dtype({
1229 'names': ['dev_ptrs', 'eof_fences', 'num_events'],
1230 'formats': [_numpy.intp, _numpy.intp, _numpy.uint32],
1231 'offsets': [
1232 (<intptr_t>&(pod.devPtrs)) - (<intptr_t>&pod),
1233 (<intptr_t>&(pod.eofFences)) - (<intptr_t>&pod),
1234 (<intptr_t>&(pod.numEvents)) - (<intptr_t>&pod),
1235 ],
1236 'itemsize': sizeof(cudlaSignalEvents),
1237 })
1239signal_events_dtype = _get_signal_events_dtype_offsets()
1241cdef class SignalEvents:
1242 """Empty-initialize an instance of `cudlaSignalEvents`.
1245 .. seealso:: `cudlaSignalEvents`
1246 """
1247 cdef:
1248 cudlaSignalEvents *_ptr
1249 object _owner
1250 bint _owned
1251 bint _readonly
1252 dict _refs
1254 def __init__(self):
1255 self._ptr = <cudlaSignalEvents *>_cyb_calloc(1, sizeof(cudlaSignalEvents)) 1o
1256 if self._ptr == NULL: 1o
1257 raise MemoryError("Error allocating SignalEvents")
1258 self._owner = None 1o
1259 self._owned = True 1o
1260 self._readonly = False 1o
1261 self._refs = {} 1o
1263 def __dealloc__(self):
1264 cdef cudlaSignalEvents *ptr
1265 if self._owned and self._ptr != NULL: 1o
1266 ptr = self._ptr 1o
1267 self._ptr = NULL 1o
1268 _cyb_free(ptr) 1o
1270 def __repr__(self):
1271 return f"<{__name__}.SignalEvents object at {hex(id(self))}>"
1273 @property
1274 def ptr(self):
1275 """Get the pointer address to the data as Python :class:`int`."""
1276 return <intptr_t>(self._ptr)
1278 cdef intptr_t _get_ptr(self):
1279 return <intptr_t>(self._ptr)
1281 def __int__(self):
1282 return <intptr_t>(self._ptr)
1284 def __eq__(self, other):
1285 cdef SignalEvents other_
1286 if not isinstance(other, SignalEvents):
1287 return False
1288 other_ = other
1289 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaSignalEvents)) == 0)
1291 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1292 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaSignalEvents), self._readonly)
1294 def __releasebuffer__(self, Py_buffer *buffer):
1295 pass
1297 def __setitem__(self, key, val):
1298 if key == 0 and isinstance(val, _numpy.ndarray):
1299 self._ptr = <cudlaSignalEvents *>_cyb_malloc(sizeof(cudlaSignalEvents))
1300 if self._ptr == NULL:
1301 raise MemoryError("Error allocating SignalEvents")
1302 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaSignalEvents))
1303 self._owner = None
1304 self._owned = True
1305 self._readonly = not val.flags.writeable
1306 else:
1307 setattr(self, key, val)
1309 @property
1310 def dev_ptrs(self):
1311 """int: """
1312 if self._ptr[0].devPtrs == NULL or self._ptr[0].numEvents == 0:
1313 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0]
1314 cdef _cyb_view.array arr = _cyb_view.array(shape=(self._ptr[0].numEvents,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False)
1315 arr.data = <char *>(self._ptr[0].devPtrs)
1316 return arr
1318 @dev_ptrs.setter
1319 def dev_ptrs(self, val):
1320 if self._readonly:
1321 raise ValueError("This SignalEvents instance is read-only")
1322 cdef Py_ssize_t _n = len(val)
1323 self._ptr[0].numEvents = _n
1324 if _n == 0:
1325 return
1326 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c")
1327 cdef intptr_t[:] mv = arr
1328 cdef Py_ssize_t i
1329 for i in range(_n):
1330 mv[i] = val[i]
1331 self._ptr[0].devPtrs = <uint64_t**><intptr_t>(arr.data)
1332 self._refs["dev_ptrs"] = arr
1334 @property
1335 def eof_fences(self):
1336 """int: """
1337 if self._ptr[0].eofFences == NULL or self._ptr[0].numEvents == 0: 1o
1338 return [] 1o
1339 return Fence.from_ptr(
1340 <intptr_t>(self._ptr[0].eofFences),
1341 self._ptr[0].numEvents,
1342 owner=self,
1343 readonly=self._readonly
1344 )
1346 @eof_fences.setter
1347 def eof_fences(self, val):
1348 if self._readonly:
1349 raise ValueError("This SignalEvents instance is read-only")
1350 cdef Fence arr = val
1351 self._ptr[0].eofFences = <CudlaFence*><intptr_t>(arr._get_ptr())
1352 self._ptr[0].numEvents = len(arr)
1353 self._refs["eof_fences"] = arr
1355 @staticmethod
1356 def from_buffer(buffer):
1357 """Create an SignalEvents instance with the memory from the given buffer."""
1358 return _cyb_from_buffer(buffer, sizeof(cudlaSignalEvents), SignalEvents)
1360 @staticmethod
1361 def from_data(data):
1362 """Create an SignalEvents instance wrapping the given NumPy array.
1364 Args:
1365 data (_numpy.ndarray): a single-element array of dtype `signal_events_dtype` holding the data.
1366 """
1367 return _cyb_from_data(data, "signal_events_dtype", signal_events_dtype, SignalEvents)
1369 @staticmethod
1370 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1371 """Create an SignalEvents instance wrapping the given pointer.
1373 Args:
1374 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1375 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1376 readonly (bool): whether the data is read-only (to the user). default is `False`.
1377 """
1378 if ptr == 0:
1379 raise ValueError("ptr must not be null (0)")
1380 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents)
1381 if owner is None:
1382 obj._ptr = <cudlaSignalEvents *>_cyb_malloc(sizeof(cudlaSignalEvents))
1383 if obj._ptr == NULL:
1384 raise MemoryError("Error allocating SignalEvents")
1385 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaSignalEvents))
1386 obj._owner = None
1387 obj._owned = True
1388 else:
1389 obj._ptr = <cudlaSignalEvents *>ptr
1390 obj._owner = owner
1391 obj._owned = False
1392 obj._readonly = readonly
1393 obj._refs = {}
1394 return obj
1397cdef _get_task_dtype_offsets():
1398 cdef cudlaTask pod
1399 return _numpy.dtype({
1400 'names': ['module_handle', 'output_tensor', 'num_output_tensors', 'num_input_tensors', 'input_tensor', 'wait_events', 'signal_events'],
1401 'formats': [_numpy.intp, _numpy.intp, _numpy.uint32, _numpy.uint32, _numpy.intp, _numpy.intp, _numpy.intp],
1402 'offsets': [
1403 (<intptr_t>&(pod.moduleHandle)) - (<intptr_t>&pod),
1404 (<intptr_t>&(pod.outputTensor)) - (<intptr_t>&pod),
1405 (<intptr_t>&(pod.numOutputTensors)) - (<intptr_t>&pod),
1406 (<intptr_t>&(pod.numInputTensors)) - (<intptr_t>&pod),
1407 (<intptr_t>&(pod.inputTensor)) - (<intptr_t>&pod),
1408 (<intptr_t>&(pod.waitEvents)) - (<intptr_t>&pod),
1409 (<intptr_t>&(pod.signalEvents)) - (<intptr_t>&pod),
1410 ],
1411 'itemsize': sizeof(cudlaTask),
1412 })
1414task_dtype = _get_task_dtype_offsets()
1416cdef class Task:
1417 """Empty-initialize an instance of `cudlaTask`.
1420 .. seealso:: `cudlaTask`
1421 """
1422 cdef:
1423 cudlaTask *_ptr
1424 object _owner
1425 bint _owned
1426 bint _readonly
1427 dict _refs
1429 def __init__(self):
1430 self._ptr = <cudlaTask *>_cyb_calloc(1, sizeof(cudlaTask)) 1ebkcd
1431 if self._ptr == NULL: 1ebkcd
1432 raise MemoryError("Error allocating Task")
1433 self._owner = None 1ebkcd
1434 self._owned = True 1ebkcd
1435 self._readonly = False 1ebkcd
1436 self._refs = {} 1ebkcd
1438 def __dealloc__(self):
1439 cdef cudlaTask *ptr
1440 if self._owned and self._ptr != NULL: 1ebkcd
1441 ptr = self._ptr 1ebkcd
1442 self._ptr = NULL 1ebkcd
1443 _cyb_free(ptr) 1ebkcd
1445 def __repr__(self):
1446 return f"<{__name__}.Task object at {hex(id(self))}>"
1448 @property
1449 def ptr(self):
1450 """Get the pointer address to the data as Python :class:`int`."""
1451 return <intptr_t>(self._ptr)
1453 cdef intptr_t _get_ptr(self):
1454 return <intptr_t>(self._ptr)
1456 def __int__(self):
1457 return <intptr_t>(self._ptr) 1e
1459 def __eq__(self, other):
1460 cdef Task other_
1461 if not isinstance(other, Task):
1462 return False
1463 other_ = other
1464 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaTask)) == 0)
1466 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags):
1467 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaTask), self._readonly)
1469 def __releasebuffer__(self, Py_buffer *buffer):
1470 pass
1472 def __setitem__(self, key, val):
1473 if key == 0 and isinstance(val, _numpy.ndarray):
1474 self._ptr = <cudlaTask *>_cyb_malloc(sizeof(cudlaTask))
1475 if self._ptr == NULL:
1476 raise MemoryError("Error allocating Task")
1477 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaTask))
1478 self._owner = None
1479 self._owned = True
1480 self._readonly = not val.flags.writeable
1481 else:
1482 setattr(self, key, val)
1484 @property
1485 def module_handle(self):
1486 """int: """
1487 return <intptr_t>(self._ptr[0].moduleHandle) 1bk
1489 @module_handle.setter
1490 def module_handle(self, val):
1491 if self._readonly: 1bk
1492 raise ValueError("This Task instance is read-only")
1493 self._ptr[0].moduleHandle = <cudlaModule><intptr_t>val 1bk
1495 @property
1496 def output_tensor(self):
1497 """int: """
1498 if self._ptr[0].outputTensor == NULL or self._ptr[0].numOutputTensors == 0: 1bd
1499 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0]
1500 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
1501 arr.data = <char *>(self._ptr[0].outputTensor) 1bd
1502 return arr 1bd
1504 @output_tensor.setter
1505 def output_tensor(self, val):
1506 if self._readonly: 1bd
1507 raise ValueError("This Task instance is read-only")
1508 cdef Py_ssize_t _n = len(val) 1bd
1509 self._ptr[0].numOutputTensors = _n 1bd
1510 if _n == 0: 1bd
1511 return
1512 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 1bd
1513 cdef intptr_t[:] mv = arr 1bd
1514 cdef Py_ssize_t i
1515 for i in range(_n): 1bd
1516 mv[i] = val[i] 1bd
1517 self._ptr[0].outputTensor = <uint64_t**><intptr_t>(arr.data) 1bd
1518 self._refs["output_tensor"] = arr 1bd
1520 @property
1521 def input_tensor(self):
1522 """int: """
1523 if self._ptr[0].inputTensor == NULL or self._ptr[0].numInputTensors == 0: 1bc
1524 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0]
1525 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
1526 arr.data = <char *>(self._ptr[0].inputTensor) 1bc
1527 return arr 1bc
1529 @input_tensor.setter
1530 def input_tensor(self, val):
1531 if self._readonly: 1bc
1532 raise ValueError("This Task instance is read-only")
1533 cdef Py_ssize_t _n = len(val) 1bc
1534 self._ptr[0].numInputTensors = _n 1bc
1535 if _n == 0: 1bc
1536 return
1537 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 1bc
1538 cdef intptr_t[:] mv = arr 1bc
1539 cdef Py_ssize_t i
1540 for i in range(_n): 1bc
1541 mv[i] = val[i] 1bc
1542 self._ptr[0].inputTensor = <uint64_t**><intptr_t>(arr.data) 1bc
1543 self._refs["input_tensor"] = arr 1bc
1545 @property
1546 def wait_events(self):
1547 """int: """
1548 return <intptr_t>(self._ptr[0].waitEvents)
1550 @wait_events.setter
1551 def wait_events(self, val):
1552 if self._readonly: 1b
1553 raise ValueError("This Task instance is read-only")
1554 self._ptr[0].waitEvents = <cudlaWaitEvents*><intptr_t>val 1b
1556 @property
1557 def signal_events(self):
1558 """int: """
1559 return <intptr_t>(self._ptr[0].signalEvents)
1561 @signal_events.setter
1562 def signal_events(self, val):
1563 if self._readonly: 1b
1564 raise ValueError("This Task instance is read-only")
1565 self._ptr[0].signalEvents = <cudlaSignalEvents*><intptr_t>val 1b
1567 @staticmethod
1568 def from_buffer(buffer):
1569 """Create an Task instance with the memory from the given buffer."""
1570 return _cyb_from_buffer(buffer, sizeof(cudlaTask), Task)
1572 @staticmethod
1573 def from_data(data):
1574 """Create an Task instance wrapping the given NumPy array.
1576 Args:
1577 data (_numpy.ndarray): a single-element array of dtype `task_dtype` holding the data.
1578 """
1579 return _cyb_from_data(data, "task_dtype", task_dtype, Task)
1581 @staticmethod
1582 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None):
1583 """Create an Task instance wrapping the given pointer.
1585 Args:
1586 ptr (intptr_t): pointer address as Python :class:`int` to the data.
1587 owner (object): The Python object that owns the pointer. If not provided, data will be copied.
1588 readonly (bool): whether the data is read-only (to the user). default is `False`.
1589 """
1590 if ptr == 0:
1591 raise ValueError("ptr must not be null (0)")
1592 cdef Task obj = Task.__new__(Task)
1593 if owner is None:
1594 obj._ptr = <cudlaTask *>_cyb_malloc(sizeof(cudlaTask))
1595 if obj._ptr == NULL:
1596 raise MemoryError("Error allocating Task")
1597 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaTask))
1598 obj._owner = None
1599 obj._owned = True
1600 else:
1601 obj._ptr = <cudlaTask *>ptr
1602 obj._owner = owner
1603 obj._owned = False
1604 obj._readonly = readonly
1605 obj._refs = {}
1606 return obj
1609###############################################################################
1610# Enum
1611###############################################################################
1613class Status(_cyb_IntEnum):
1614 """
1615 See `cudlaStatus`.
1616 """
1617 Success = cudlaSuccess
1618 ErrorInvalidParam = cudlaErrorInvalidParam
1619 ErrorOutOfResources = cudlaErrorOutOfResources
1620 ErrorCreationFailed = cudlaErrorCreationFailed
1621 ErrorInvalidAddress = cudlaErrorInvalidAddress
1622 ErrorOs = cudlaErrorOs
1623 ErrorCuda = cudlaErrorCuda
1624 ErrorUmd = cudlaErrorUmd
1625 ErrorInvalidDevice = cudlaErrorInvalidDevice
1626 ErrorInvalidAttribute = cudlaErrorInvalidAttribute
1627 ErrorIncompatibleDlaSWVersion = cudlaErrorIncompatibleDlaSWVersion
1628 ErrorMemoryRegistered = cudlaErrorMemoryRegistered
1629 ErrorInvalidModule = cudlaErrorInvalidModule
1630 ErrorUnsupportedOperation = cudlaErrorUnsupportedOperation
1631 ErrorNvSci = cudlaErrorNvSci
1632 ErrorDriverNotFound = cudlaErrorDriverNotFound
1633 ErrorDlaErrInvalidInput = cudlaErrorDlaErrInvalidInput
1634 ErrorDlaErrInvalidPreAction = cudlaErrorDlaErrInvalidPreAction
1635 ErrorDlaErrNoMem = cudlaErrorDlaErrNoMem
1636 ErrorDlaErrProcessorBusy = cudlaErrorDlaErrProcessorBusy
1637 ErrorDlaErrTaskStatusMismatch = cudlaErrorDlaErrTaskStatusMismatch
1638 ErrorDlaErrEngineTimeout = cudlaErrorDlaErrEngineTimeout
1639 ErrorDlaErrDataMismatch = cudlaErrorDlaErrDataMismatch
1640 ErrorUnknown = cudlaErrorUnknown
1642class Mode(_cyb_IntEnum):
1643 """
1644 See `cudlaMode`.
1645 """
1646 CUDA_DLA = CUDLA_CUDA_DLA
1647 STANDALONE = CUDLA_STANDALONE
1649class ModuleAttributeType(_cyb_IntEnum):
1650 """
1651 See `cudlaModuleAttributeType`.
1652 """
1653 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS
1654 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS
1655 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS
1656 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS
1657 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS
1658 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS
1660class FenceType(_cyb_IntEnum):
1661 """
1662 See `cudlaFenceType`.
1663 """
1664 NVSCISYNC_FENCE = CUDLA_NVSCISYNC_FENCE
1665 NVSCISYNC_FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF
1667class ModuleLoadFlags(_cyb_IntEnum):
1668 """
1669 See `cudlaModuleLoadFlags`.
1670 """
1671 MODULE_DEFAULT = CUDLA_MODULE_DEFAULT
1672 MODULE_ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS
1674class SubmissionFlags(_cyb_IntEnum):
1675 """
1676 See `cudlaSubmissionFlags`.
1677 """
1678 SUBMIT_NOOP = CUDLA_SUBMIT_NOOP
1679 SUBMIT_SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE
1680 SUBMIT_DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK
1682class AccessPermissionFlags(_cyb_IntEnum):
1683 """
1684 See `cudlaAccessPermissionFlags`.
1685 """
1686 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM
1687 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM
1688 TASK_STATISTICS = CUDLA_TASK_STATISTICS
1690class DevAttributeType(_cyb_IntEnum):
1691 """
1692 See `cudlaDevAttributeType`.
1693 """
1694 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING
1695 DEVICE_VERSION = CUDLA_DEVICE_VERSION
1698###############################################################################
1699# Error handling
1700###############################################################################
1702class CudlaError(Exception):
1704 def __init__(self, status):
1705 self.status = status 1qr
1706 s = Status(status) 1qr
1707 cdef str err = f"{s.name} ({s.value})" 1qr
1708 super(CudlaError, self).__init__(err) 1qr
1710 def __reduce__(self):
1711 return (type(self), (self.status,))
1714@cython.profile(False)
1715cpdef inline check_status(int status):
1716 if status != 0:
1717 raise CudlaError(status)
1720###############################################################################
1721# Wrapper functions
1722###############################################################################
1724cpdef uint64_t get_version() except? -1:
1725 cdef uint64_t version
1726 with nogil:
1727 __status__ = cudlaGetVersion(&version)
1728 check_status(__status__)
1729 return version
1732cpdef uint64_t device_get_count() except? -1:
1733 cdef uint64_t p_num_devices
1734 with nogil:
1735 __status__ = cudlaDeviceGetCount(&p_num_devices)
1736 check_status(__status__)
1737 return p_num_devices
1740cpdef intptr_t create_device(uint64_t device, uint32_t flags) except *:
1741 cdef DevHandle dev_handle
1742 if flags == CUDLA_STANDALONE:
1743 raise CudlaError(cudlaErrorUnsupportedOperation)
1744 with nogil:
1745 __status__ = cudlaCreateDevice(<const uint64_t>device, &dev_handle, <const uint32_t>flags)
1746 check_status(__status__)
1747 return <intptr_t>dev_handle
1750cpdef intptr_t mem_register(intptr_t dev_handle, intptr_t ptr, size_t size, uint32_t flags) except *:
1751 cdef uint64_t* dev_ptr
1752 with nogil:
1753 __status__ = cudlaMemRegister(<const DevHandle>dev_handle, <const uint64_t* const>ptr, <const size_t>size, &dev_ptr, <const uint32_t>flags)
1754 check_status(__status__)
1755 return <intptr_t>dev_ptr
1758cpdef intptr_t module_load_from_memory(intptr_t dev_handle, p_module, size_t module_size, uint32_t flags) except *:
1759 cdef void* _p_module_ = get_buffer_pointer(p_module, module_size, readonly=True)
1760 cdef Module h_module
1761 with nogil:
1762 __status__ = cudlaModuleLoadFromMemory(<const DevHandle>dev_handle, <const uint8_t* const>_p_module_, <const size_t>module_size, &h_module, <const uint32_t>flags)
1763 check_status(__status__)
1764 return <intptr_t>h_module
1767cpdef module_unload(intptr_t h_module, uint32_t flags):
1768 with nogil:
1769 __status__ = cudlaModuleUnload(<const Module>h_module, <const uint32_t>flags)
1770 check_status(__status__)
1773cpdef submit_task(intptr_t dev_handle, intptr_t ptr_to_tasks, uint32_t num_tasks, intptr_t stream, uint32_t flags):
1774 with nogil:
1775 __status__ = cudlaSubmitTask(<const DevHandle>dev_handle, <const cudlaTask* const>ptr_to_tasks, <const uint32_t>num_tasks, <void* const>stream, <const uint32_t>flags)
1776 check_status(__status__)
1779cpdef object device_get_attribute(intptr_t dev_handle, int attrib) except *:
1780 cdef DevAttribute p_attribute_py = DevAttribute()
1781 cdef cudlaDevAttribute *p_attribute = <cudlaDevAttribute *><intptr_t>(p_attribute_py._get_ptr())
1782 with nogil:
1783 __status__ = cudlaDeviceGetAttribute(<const DevHandle>dev_handle, <const _DevAttributeType>attrib, p_attribute)
1784 check_status(__status__)
1785 return p_attribute_py
1788cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr):
1789 with nogil:
1790 __status__ = cudlaMemUnregister(<const DevHandle>dev_handle, <const uint64_t* const>dev_ptr)
1791 check_status(__status__)
1794cpdef int get_last_error(intptr_t dev_handle) except? 0:
1795 cdef int ret
1796 with nogil:
1797 ret = <int>cudlaGetLastError(<const DevHandle>dev_handle)
1798 return ret
1801cpdef destroy_device(intptr_t dev_handle):
1802 with nogil:
1803 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle)
1804 check_status(__status__)
1807cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout):
1808 with nogil:
1809 __status__ = cudlaSetTaskTimeoutInMs(<const DevHandle>dev_handle, <const uint32_t>timeout)
1810 check_status(__status__)
1813cpdef module_get_attributes(intptr_t h_module, int attr_type) except *:
1814 """Query module attributes, interpreting the cudlaModuleAttribute union
1815 based on the requested attribute type.
1817 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS,
1818 NUM_OUTPUT_TASK_STATISTICS), returns an int.
1820 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS,
1821 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS),
1822 returns a list of ModuleTensorDescriptor objects.
1823 """
1824 cdef int _attr_type = attr_type
1825 cdef cudlaModuleAttribute count_attr
1826 cdef cudlaModuleAttribute num_attr
1827 cdef cudlaModuleAttribute desc_attr
1828 cdef uint32_t count
1829 cdef cudlaModuleTensorDescriptor* desc_buf
1830 cdef uint32_t i
1831 cdef int num_attr_type
1833 if _attr_type == CUDLA_NUM_INPUT_TENSORS or _attr_type == CUDLA_NUM_OUTPUT_TENSORS or _attr_type == CUDLA_NUM_OUTPUT_TASK_STATISTICS:
1834 with nogil:
1835 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>_attr_type, &count_attr)
1836 check_status(__status__)
1837 return <int>(count_attr.numInputTensors)
1838 elif _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS or _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS or _attr_type == CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS:
1839 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS:
1840 num_attr_type = CUDLA_NUM_INPUT_TENSORS
1841 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS:
1842 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS
1843 else:
1844 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS
1845 with nogil:
1846 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>num_attr_type, &num_attr)
1847 check_status(__status__)
1848 count = num_attr.numInputTensors
1849 desc_buf = <cudlaModuleTensorDescriptor*>malloc(count * sizeof(cudlaModuleTensorDescriptor))
1850 if desc_buf == NULL:
1851 raise MemoryError("Failed to allocate descriptor buffer")
1852 try:
1853 desc_attr.inputTensorDesc = desc_buf
1854 with nogil:
1855 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>_attr_type, &desc_attr)
1856 check_status(__status__)
1857 result = []
1858 for i in range(count):
1859 result.append(ModuleTensorDescriptor.from_ptr(<intptr_t>&desc_buf[i], readonly=True))
1860 return result
1861 finally:
1862 free(desc_buf)
1863 else:
1864 raise ValueError(f"Unknown attribute type: {attr_type}")
1865del _cyb_IntEnum