Coverage for cuda/bindings/cudla.pyx: 39.94%

954 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-03 02:41 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# SPDX-License-Identifier: Apache-2.0 

3  

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=3c177b7a0328c0f6f16067c8c9f4e5a002bd019e8c17c017ba9f77af21da8d75 

6  

7  

8# <<<< PREAMBLE CONTENT >>>> 

9  

10cimport cpython as _cyb_cpython 

11cimport cpython.buffer as _cyb_cpython_buffer 

12from cython cimport view as _cyb_view 

13from libc.stdint cimport ( 

14 intptr_t, 

15 uint32_t, 

16 uint64_t, 

17 uint8_t, 

18) 

19from libc.stdlib cimport ( 

20 calloc as _cyb_calloc, 

21 free as _cyb_free, 

22 malloc as _cyb_malloc, 

23) 

24from libc.string cimport ( 

25 memcmp as _cyb_memcmp, 

26 memcpy as _cyb_memcpy, 

27) 

28  

29from enum import IntEnum as _cyb_IntEnum 

30  

31import numpy as _numpy 

32  

33cdef _cyb___getbuffer(object self, _cyb_cpython.Py_buffer *buffer, void *ptr, int size, bint readonly): 

34 buffer.buf = <char *>ptr 

35 buffer.format = 'b' 

36 buffer.internal = NULL 

37 buffer.itemsize = 1 

38 buffer.len = size 

39 buffer.ndim = 1 

40 buffer.obj = self 

41 buffer.readonly = readonly 

42 buffer.shape = &buffer.len 

43 buffer.strides = &buffer.itemsize 

44 buffer.suboffsets = NULL 

45  

46cdef _cyb_from_buffer(buffer, size, lowpp_type): 

47 cdef _cyb_cpython.Py_buffer view 

48 if _cyb_cpython.PyObject_GetBuffer(buffer, &view, _cyb_cpython_buffer.PyBUF_SIMPLE) != 0: 

49 raise TypeError("buffer argument does not support the buffer protocol") 

50 try: 

51 if view.itemsize != 1: 

52 raise ValueError("buffer itemsize must be 1 byte") 

53 if view.len != size: 

54 raise ValueError(f"buffer length must be {size} bytes") 

55 return lowpp_type.from_ptr(<intptr_t><void *>view.buf, not view.readonly, buffer) 

56 finally: 

57 _cyb_cpython.PyBuffer_Release(&view) 

58  

59cdef _cyb_from_data(data, dtype_name, expected_dtype, lowpp_type): 

60 # _numpy.recarray is a subclass of _numpy.ndarray, so implicitly handled here. 

61 if isinstance(data, lowpp_type): 

62 return data 

63 if not isinstance(data, _numpy.ndarray): 

64 raise TypeError("data argument must be a NumPy ndarray") 

65 if data.size != 1: 

66 raise ValueError("data array must have a size of 1") 

67 if data.dtype != expected_dtype: 

68 raise ValueError(f"data array must be of dtype {dtype_name}") 

69 return lowpp_type.from_ptr(data.ctypes.data, not data.flags.writeable, data) 

70  

71cdef intptr_t _cyb_get_buffer_pointer(buf, Py_ssize_t size, readonly=True) except?-1: 

72 cdef intptr_t ptr 

73 cdef int flags = _cyb_cpython.PyBUF_ANY_CONTIGUOUS 

74 if not readonly: 

75 flags |= _cyb_cpython.PyBUF_WRITABLE 

76 cdef int status = -1 

77 cdef _cyb_cpython.Py_buffer view 

78 if isinstance(buf, int): 

79 ptr = <intptr_t>buf 

80 else: 

81 try: 

82 status = _cyb_cpython.PyObject_GetBuffer(buf, &view, flags) 

83 if size != -1: 

84 assert view.len == size 

85 assert view.ndim == 1 

86 except Exception as e: 

87 adj = "writable " if not readonly else "" 

88 raise ValueError( 

89 "buf must be either a Python int representing the pointer " 

90 f"address to a valid buffer, or a 1D contiguous {adj}" 

91 f"buffer, of size {size}" 

92 ) from e 

93 else: 

94 ptr = <intptr_t>view.buf 

95 finally: 

96 if status == 0: 

97 _cyb_cpython.PyBuffer_Release(&view) 

98 return ptr 

99  

100  

101# <<<< END OF PREAMBLE CONTENT >>>> 

102  

103cimport cython # NOQA 

104from libc.stdint cimport intptr_t, uintptr_t 

105from libc.stdlib cimport malloc, free 

106  

107  

108  

109  

110  

111############################################################################### 

112# POD 

113############################################################################### 

114  

115cdef _get_external_memory_handle_desc_dtype_offsets(): 

116 cdef cudlaExternalMemoryHandleDesc_t pod 

117 return _numpy.dtype({ 

118 'names': ['ext_buf_object', 'size_'], 

119 'formats': [_numpy.intp, _numpy.uint64], 

120 'offsets': [ 

121 (<intptr_t>&(pod.extBufObject)) - (<intptr_t>&pod), 

122 (<intptr_t>&(pod.size)) - (<intptr_t>&pod), 

123 ], 

124 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t), 

125 }) 

126  

127external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets() 

128  

129cdef class ExternalMemoryHandleDesc: 

130 """Empty-initialize an instance of `cudlaExternalMemoryHandleDesc_t`. 

131  

132  

133 .. seealso:: `cudlaExternalMemoryHandleDesc_t` 

134 """ 

135 cdef: 

136 cudlaExternalMemoryHandleDesc_t *_ptr 

137 object _owner 

138 bint _owned 

139 bint _readonly 

140  

141 def __init__(self): 

142 self._ptr = <cudlaExternalMemoryHandleDesc_t *>_cyb_calloc(1, sizeof(cudlaExternalMemoryHandleDesc_t)) 1g

143 if self._ptr == NULL: 1g

144 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

145 self._owner = None 1g

146 self._owned = True 1g

147 self._readonly = False 1g

148  

149 def __dealloc__(self): 

150 cdef cudlaExternalMemoryHandleDesc_t *ptr 

151 if self._owned and self._ptr != NULL: 1g

152 ptr = self._ptr 1g

153 self._ptr = NULL 1g

154 _cyb_free(ptr) 1g

155  

156 def __repr__(self): 

157 return f"<{__name__}.ExternalMemoryHandleDesc object at {hex(id(self))}>" 

158  

159 @property 

160 def ptr(self): 

161 """Get the pointer address to the data as Python :class:`int`.""" 

162 return <intptr_t>(self._ptr) 

163  

164 cdef intptr_t _get_ptr(self): 

165 return <intptr_t>(self._ptr) 

166  

167 def __int__(self): 

168 return <intptr_t>(self._ptr) 

169  

170 def __eq__(self, other): 

171 cdef ExternalMemoryHandleDesc other_ 

172 if not isinstance(other, ExternalMemoryHandleDesc): 

173 return False 

174 other_ = other 

175 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaExternalMemoryHandleDesc_t)) == 0) 

176  

177 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

178 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalMemoryHandleDesc_t), self._readonly) 

179  

180 def __releasebuffer__(self, Py_buffer *buffer): 

181 pass 

182  

183 def __setitem__(self, key, val): 

184 if key == 0 and isinstance(val, _numpy.ndarray): 

185 self._ptr = <cudlaExternalMemoryHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalMemoryHandleDesc_t)) 

186 if self._ptr == NULL: 

187 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

188 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaExternalMemoryHandleDesc_t)) 

189 self._owner = None 

190 self._owned = True 

191 self._readonly = not val.flags.writeable 

192 else: 

193 setattr(self, key, val) 

194  

195 @property 

196 def ext_buf_object(self): 

197 """int: """ 

198 return <intptr_t>(self._ptr[0].extBufObject) 1g

199  

200 @ext_buf_object.setter 

201 def ext_buf_object(self, val): 

202 if self._readonly: 1g

203 raise ValueError("This ExternalMemoryHandleDesc instance is read-only") 

204 self._ptr[0].extBufObject = <void *><intptr_t>val 1g

205  

206 @property 

207 def size_(self): 

208 """int: """ 

209 return self._ptr[0].size 1g

210  

211 @size_.setter 

212 def size_(self, val): 

213 if self._readonly: 1g

214 raise ValueError("This ExternalMemoryHandleDesc instance is read-only") 

215 self._ptr[0].size = val 1g

216  

217 @staticmethod 

218 def from_buffer(buffer): 

219 """Create an ExternalMemoryHandleDesc instance with the memory from the given buffer.""" 

220 return _cyb_from_buffer(buffer, sizeof(cudlaExternalMemoryHandleDesc_t), ExternalMemoryHandleDesc) 

221  

222 @staticmethod 

223 def from_data(data): 

224 """Create an ExternalMemoryHandleDesc instance wrapping the given NumPy array. 

225  

226 Args: 

227 data (_numpy.ndarray): a single-element array of dtype `external_memory_handle_desc_dtype` holding the data. 

228 """ 

229 return _cyb_from_data(data, "external_memory_handle_desc_dtype", external_memory_handle_desc_dtype, ExternalMemoryHandleDesc) 

230  

231 @staticmethod 

232 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

233 """Create an ExternalMemoryHandleDesc instance wrapping the given pointer. 

234  

235 Args: 

236 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

237 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

238 readonly (bool): whether the data is read-only (to the user). default is `False`. 

239 """ 

240 if ptr == 0: 

241 raise ValueError("ptr must not be null (0)") 

242 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc) 

243 if owner is None: 

244 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalMemoryHandleDesc_t)) 

245 if obj._ptr == NULL: 

246 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

247 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaExternalMemoryHandleDesc_t)) 

248 obj._owner = None 

249 obj._owned = True 

250 else: 

251 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr 

252 obj._owner = owner 

253 obj._owned = False 

254 obj._readonly = readonly 

255 return obj 

256  

257  

258cdef _get_external_semaphore_handle_desc_dtype_offsets(): 

259 cdef cudlaExternalSemaphoreHandleDesc_t pod 

260 return _numpy.dtype({ 

261 'names': ['ext_sync_object'], 

262 'formats': [_numpy.intp], 

263 'offsets': [ 

264 (<intptr_t>&(pod.extSyncObject)) - (<intptr_t>&pod), 

265 ], 

266 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t), 

267 }) 

268  

269external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets() 

270  

271cdef class ExternalSemaphoreHandleDesc: 

272 """Empty-initialize an instance of `cudlaExternalSemaphoreHandleDesc_t`. 

273  

274  

275 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t` 

276 """ 

277 cdef: 

278 cudlaExternalSemaphoreHandleDesc_t *_ptr 

279 object _owner 

280 bint _owned 

281 bint _readonly 

282  

283 def __init__(self): 

284 self._ptr = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_calloc(1, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 1l

285 if self._ptr == NULL: 1l

286 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

287 self._owner = None 1l

288 self._owned = True 1l

289 self._readonly = False 1l

290  

291 def __dealloc__(self): 

292 cdef cudlaExternalSemaphoreHandleDesc_t *ptr 

293 if self._owned and self._ptr != NULL: 1l

294 ptr = self._ptr 1l

295 self._ptr = NULL 1l

296 _cyb_free(ptr) 1l

297  

298 def __repr__(self): 

299 return f"<{__name__}.ExternalSemaphoreHandleDesc object at {hex(id(self))}>" 

300  

301 @property 

302 def ptr(self): 

303 """Get the pointer address to the data as Python :class:`int`.""" 

304 return <intptr_t>(self._ptr) 

305  

306 cdef intptr_t _get_ptr(self): 

307 return <intptr_t>(self._ptr) 

308  

309 def __int__(self): 

310 return <intptr_t>(self._ptr) 

311  

312 def __eq__(self, other): 

313 cdef ExternalSemaphoreHandleDesc other_ 

314 if not isinstance(other, ExternalSemaphoreHandleDesc): 

315 return False 

316 other_ = other 

317 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaExternalSemaphoreHandleDesc_t)) == 0) 

318  

319 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

320 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t), self._readonly) 

321  

322 def __releasebuffer__(self, Py_buffer *buffer): 

323 pass 

324  

325 def __setitem__(self, key, val): 

326 if key == 0 and isinstance(val, _numpy.ndarray): 

327 self._ptr = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

328 if self._ptr == NULL: 

329 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

330 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

331 self._owner = None 

332 self._owned = True 

333 self._readonly = not val.flags.writeable 

334 else: 

335 setattr(self, key, val) 

336  

337 @property 

338 def ext_sync_object(self): 

339 """int: """ 

340 return <intptr_t>(self._ptr[0].extSyncObject) 1l

341  

342 @ext_sync_object.setter 

343 def ext_sync_object(self, val): 

344 if self._readonly: 1l

345 raise ValueError("This ExternalSemaphoreHandleDesc instance is read-only") 

346 self._ptr[0].extSyncObject = <void *><intptr_t>val 1l

347  

348 @staticmethod 

349 def from_buffer(buffer): 

350 """Create an ExternalSemaphoreHandleDesc instance with the memory from the given buffer.""" 

351 return _cyb_from_buffer(buffer, sizeof(cudlaExternalSemaphoreHandleDesc_t), ExternalSemaphoreHandleDesc) 

352  

353 @staticmethod 

354 def from_data(data): 

355 """Create an ExternalSemaphoreHandleDesc instance wrapping the given NumPy array. 

356  

357 Args: 

358 data (_numpy.ndarray): a single-element array of dtype `external_semaphore_handle_desc_dtype` holding the data. 

359 """ 

360 return _cyb_from_data(data, "external_semaphore_handle_desc_dtype", external_semaphore_handle_desc_dtype, ExternalSemaphoreHandleDesc) 

361  

362 @staticmethod 

363 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

364 """Create an ExternalSemaphoreHandleDesc instance wrapping the given pointer. 

365  

366 Args: 

367 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

368 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

369 readonly (bool): whether the data is read-only (to the user). default is `False`. 

370 """ 

371 if ptr == 0: 

372 raise ValueError("ptr must not be null (0)") 

373 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc) 

374 if owner is None: 

375 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>_cyb_malloc(sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

376 if obj._ptr == NULL: 

377 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

378 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

379 obj._owner = None 

380 obj._owned = True 

381 else: 

382 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr 

383 obj._owner = owner 

384 obj._owned = False 

385 obj._readonly = readonly 

386 return obj 

387  

388  

389cdef _get_module_tensor_descriptor_dtype_offsets(): 

390 cdef cudlaModuleTensorDescriptor pod 

391 return _numpy.dtype({ 

392 'names': ['name', 'size_', 'n', 'c', 'h', 'w', 'data_format', 'data_type', 'data_category', 'pixel_format', 'pixel_mapping', 'stride'], 

393 '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)], 

394 'offsets': [ 

395 (<intptr_t>&(pod.name)) - (<intptr_t>&pod), 

396 (<intptr_t>&(pod.size)) - (<intptr_t>&pod), 

397 (<intptr_t>&(pod.n)) - (<intptr_t>&pod), 

398 (<intptr_t>&(pod.c)) - (<intptr_t>&pod), 

399 (<intptr_t>&(pod.h)) - (<intptr_t>&pod), 

400 (<intptr_t>&(pod.w)) - (<intptr_t>&pod), 

401 (<intptr_t>&(pod.dataFormat)) - (<intptr_t>&pod), 

402 (<intptr_t>&(pod.dataType)) - (<intptr_t>&pod), 

403 (<intptr_t>&(pod.dataCategory)) - (<intptr_t>&pod), 

404 (<intptr_t>&(pod.pixelFormat)) - (<intptr_t>&pod), 

405 (<intptr_t>&(pod.pixelMapping)) - (<intptr_t>&pod), 

406 (<intptr_t>&(pod.stride)) - (<intptr_t>&pod), 

407 ], 

408 'itemsize': sizeof(cudlaModuleTensorDescriptor), 

409 }) 

410  

411module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets() 

412  

413cdef class ModuleTensorDescriptor: 

414 """Empty-initialize an instance of `cudlaModuleTensorDescriptor`. 

415  

416  

417 .. seealso:: `cudlaModuleTensorDescriptor` 

418 """ 

419 cdef: 

420 cudlaModuleTensorDescriptor *_ptr 

421 object _owner 

422 bint _owned 

423 bint _readonly 

424  

425 def __init__(self): 

426 self._ptr = <cudlaModuleTensorDescriptor *>_cyb_calloc(1, sizeof(cudlaModuleTensorDescriptor)) 1fpme

427 if self._ptr == NULL: 1fpme

428 raise MemoryError("Error allocating ModuleTensorDescriptor") 

429 self._owner = None 1fpme

430 self._owned = True 1fpme

431 self._readonly = False 1fpme

432  

433 def __dealloc__(self): 

434 cdef cudlaModuleTensorDescriptor *ptr 

435 if self._owned and self._ptr != NULL: 1fpme

436 ptr = self._ptr 1fpme

437 self._ptr = NULL 1fpme

438 _cyb_free(ptr) 1fpme

439  

440 def __repr__(self): 

441 return f"<{__name__}.ModuleTensorDescriptor object at {hex(id(self))}>" 

442  

443 @property 

444 def ptr(self): 

445 """Get the pointer address to the data as Python :class:`int`.""" 

446 return <intptr_t>(self._ptr) 

447  

448 cdef intptr_t _get_ptr(self): 

449 return <intptr_t>(self._ptr) 

450  

451 def __int__(self): 

452 return <intptr_t>(self._ptr) 1e

453  

454 def __eq__(self, other): 

455 cdef ModuleTensorDescriptor other_ 

456 if not isinstance(other, ModuleTensorDescriptor): 

457 return False 

458 other_ = other 

459 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaModuleTensorDescriptor)) == 0) 

460  

461 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

462 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleTensorDescriptor), self._readonly) 

463  

464 def __releasebuffer__(self, Py_buffer *buffer): 

465 pass 

466  

467 def __setitem__(self, key, val): 

468 if key == 0 and isinstance(val, _numpy.ndarray): 

469 self._ptr = <cudlaModuleTensorDescriptor *>_cyb_malloc(sizeof(cudlaModuleTensorDescriptor)) 

470 if self._ptr == NULL: 

471 raise MemoryError("Error allocating ModuleTensorDescriptor") 

472 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaModuleTensorDescriptor)) 

473 self._owner = None 

474 self._owned = True 

475 self._readonly = not val.flags.writeable 

476 else: 

477 setattr(self, key, val) 

478  

479 @property 

480 def name(self): 

481 """~_numpy.int8: (array of length 81).""" 

482 return _cyb_cpython.PyUnicode_FromString(self._ptr[0].name) 1p

483  

484 @name.setter 

485 def name(self, val): 

486 if self._readonly: 

487 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

488 cdef bytes buf = val.encode() 

489 if len(buf) >= 81: 

490 raise ValueError("String too long for field name, max length is 80") 

491 cdef char *ptr = buf 

492 _cyb_memcpy(<void *>(self._ptr[0].name), <void *>ptr, 81) 

493  

494 @property 

495 def size_(self): 

496 """int: """ 

497 return self._ptr[0].size 1f

498  

499 @size_.setter 

500 def size_(self, val): 

501 if self._readonly: 

502 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

503 self._ptr[0].size = val 

504  

505 @property 

506 def n(self): 

507 """int: """ 

508 return self._ptr[0].n 1f

509  

510 @n.setter 

511 def n(self, val): 

512 if self._readonly: 

513 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

514 self._ptr[0].n = val 

515  

516 @property 

517 def c(self): 

518 """int: """ 

519 return self._ptr[0].c 1f

520  

521 @c.setter 

522 def c(self, val): 

523 if self._readonly: 

524 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

525 self._ptr[0].c = val 

526  

527 @property 

528 def h(self): 

529 """int: """ 

530 return self._ptr[0].h 1f

531  

532 @h.setter 

533 def h(self, val): 

534 if self._readonly: 

535 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

536 self._ptr[0].h = val 

537  

538 @property 

539 def w(self): 

540 """int: """ 

541 return self._ptr[0].w 1f

542  

543 @w.setter 

544 def w(self, val): 

545 if self._readonly: 

546 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

547 self._ptr[0].w = val 

548  

549 @property 

550 def data_format(self): 

551 """int: """ 

552 return self._ptr[0].dataFormat 1f

553  

554 @data_format.setter 

555 def data_format(self, val): 

556 if self._readonly: 

557 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

558 self._ptr[0].dataFormat = val 

559  

560 @property 

561 def data_type(self): 

562 """int: """ 

563 return self._ptr[0].dataType 1f

564  

565 @data_type.setter 

566 def data_type(self, val): 

567 if self._readonly: 

568 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

569 self._ptr[0].dataType = val 

570  

571 @property 

572 def data_category(self): 

573 """int: """ 

574 return self._ptr[0].dataCategory 1f

575  

576 @data_category.setter 

577 def data_category(self, val): 

578 if self._readonly: 

579 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

580 self._ptr[0].dataCategory = val 

581  

582 @property 

583 def pixel_format(self): 

584 """int: """ 

585 return self._ptr[0].pixelFormat 1f

586  

587 @pixel_format.setter 

588 def pixel_format(self, val): 

589 if self._readonly: 

590 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

591 self._ptr[0].pixelFormat = val 

592  

593 @property 

594 def pixel_mapping(self): 

595 """int: """ 

596 return self._ptr[0].pixelMapping 1f

597  

598 @pixel_mapping.setter 

599 def pixel_mapping(self, val): 

600 if self._readonly: 

601 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

602 self._ptr[0].pixelMapping = val 

603  

604 @property 

605 def stride(self): 

606 """~_numpy.uint32: (array of length 8).""" 

607 cdef _cyb_view.array arr = _cyb_view.array(shape=(8,), itemsize=sizeof(uint32_t), format="I", mode="c", allocate_buffer=False) 1m

608 arr.data = <char *>(&(self._ptr[0].stride)) 1m

609 return _numpy.asarray(arr) 1m

610  

611 @stride.setter 

612 def stride(self, val): 

613 if self._readonly: 

614 raise ValueError("This ModuleTensorDescriptor instance is read-only") 

615 if len(val) != 8: 

616 raise ValueError(f"Expected length { 8 } for field stride, got {len(val)}") 

617 cdef _cyb_view.array arr = _cyb_view.array(shape=(8,), itemsize=sizeof(uint32_t), format="I", mode="c") 

618 arr[:] = _numpy.asarray(val, dtype=_numpy.uint32) 

619 _cyb_memcpy(<void *>(&(self._ptr[0].stride)), <void *>(arr.data), sizeof(uint32_t) * len(val)) 

620  

621 @staticmethod 

622 def from_buffer(buffer): 

623 """Create an ModuleTensorDescriptor instance with the memory from the given buffer.""" 

624 return _cyb_from_buffer(buffer, sizeof(cudlaModuleTensorDescriptor), ModuleTensorDescriptor) 

625  

626 @staticmethod 

627 def from_data(data): 

628 """Create an ModuleTensorDescriptor instance wrapping the given NumPy array. 

629  

630 Args: 

631 data (_numpy.ndarray): a single-element array of dtype `module_tensor_descriptor_dtype` holding the data. 

632 """ 

633 return _cyb_from_data(data, "module_tensor_descriptor_dtype", module_tensor_descriptor_dtype, ModuleTensorDescriptor) 

634  

635 @staticmethod 

636 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

637 """Create an ModuleTensorDescriptor instance wrapping the given pointer. 

638  

639 Args: 

640 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

641 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

642 readonly (bool): whether the data is read-only (to the user). default is `False`. 

643 """ 

644 if ptr == 0: 

645 raise ValueError("ptr must not be null (0)") 

646 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor) 

647 if owner is None: 

648 obj._ptr = <cudlaModuleTensorDescriptor *>_cyb_malloc(sizeof(cudlaModuleTensorDescriptor)) 

649 if obj._ptr == NULL: 

650 raise MemoryError("Error allocating ModuleTensorDescriptor") 

651 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaModuleTensorDescriptor)) 

652 obj._owner = None 

653 obj._owned = True 

654 else: 

655 obj._ptr = <cudlaModuleTensorDescriptor *>ptr 

656 obj._owner = owner 

657 obj._owned = False 

658 obj._readonly = readonly 

659 return obj 

660  

661  

662cdef _get_fence_dtype_offsets(): 

663 cdef CudlaFence pod 

664 return _numpy.dtype({ 

665 'names': ['fence', 'type'], 

666 'formats': [_numpy.intp, _numpy.int32], 

667 'offsets': [ 

668 (<intptr_t>&(pod.fence)) - (<intptr_t>&pod), 

669 (<intptr_t>&(pod.type)) - (<intptr_t>&pod), 

670 ], 

671 'itemsize': sizeof(CudlaFence), 

672 }) 

673  

674fence_dtype = _get_fence_dtype_offsets() 

675  

676cdef class Fence: 

677 """Empty-initialize an instance of `CudlaFence`. 

678  

679  

680 .. seealso:: `CudlaFence` 

681 """ 

682 cdef: 

683 CudlaFence *_ptr 

684 object _owner 

685 bint _owned 

686 bint _readonly 

687  

688 def __init__(self): 

689 self._ptr = <CudlaFence *>_cyb_calloc(1, sizeof(CudlaFence)) 1h

690 if self._ptr == NULL: 1h

691 raise MemoryError("Error allocating Fence") 

692 self._owner = None 1h

693 self._owned = True 1h

694 self._readonly = False 1h

695  

696 def __dealloc__(self): 

697 cdef CudlaFence *ptr 

698 if self._owned and self._ptr != NULL: 1h

699 ptr = self._ptr 1h

700 self._ptr = NULL 1h

701 _cyb_free(ptr) 1h

702  

703 def __repr__(self): 

704 return f"<{__name__}.Fence object at {hex(id(self))}>" 

705  

706 @property 

707 def ptr(self): 

708 """Get the pointer address to the data as Python :class:`int`.""" 

709 return <intptr_t>(self._ptr) 

710  

711 cdef intptr_t _get_ptr(self): 

712 return <intptr_t>(self._ptr) 

713  

714 def __int__(self): 

715 return <intptr_t>(self._ptr) 

716  

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) 

723  

724 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

725 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(CudlaFence), self._readonly) 

726  

727 def __releasebuffer__(self, Py_buffer *buffer): 

728 pass 

729  

730 def __setitem__(self, key, val): 

731 if key == 0 and isinstance(val, _numpy.ndarray): 

732 self._ptr = <CudlaFence *>_cyb_malloc(sizeof(CudlaFence)) 

733 if self._ptr == NULL: 

734 raise MemoryError("Error allocating Fence") 

735 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(CudlaFence)) 

736 self._owner = None 

737 self._owned = True 

738 self._readonly = not val.flags.writeable 

739 else: 

740 setattr(self, key, val) 

741  

742 @property 

743 def fence(self): 

744 """int: """ 

745 return <intptr_t>(self._ptr[0].fence) 1h

746  

747 @fence.setter 

748 def fence(self, val): 

749 if self._readonly: 1h

750 raise ValueError("This Fence instance is read-only") 

751 self._ptr[0].fence = <void *><intptr_t>val 1h

752  

753 @property 

754 def type(self): 

755 """int: """ 

756 return <int>(self._ptr[0].type) 1h

757  

758 @type.setter 

759 def type(self, val): 

760 if self._readonly: 1h

761 raise ValueError("This Fence instance is read-only") 

762 self._ptr[0].type = <cudlaFenceType><int>val 1h

763  

764 @staticmethod 

765 def from_buffer(buffer): 

766 """Create an Fence instance with the memory from the given buffer.""" 

767 return _cyb_from_buffer(buffer, sizeof(CudlaFence), Fence) 

768  

769 @staticmethod 

770 def from_data(data): 

771 """Create an Fence instance wrapping the given NumPy array. 

772  

773 Args: 

774 data (_numpy.ndarray): a single-element array of dtype `fence_dtype` holding the data. 

775 """ 

776 return _cyb_from_data(data, "fence_dtype", fence_dtype, Fence) 

777  

778 @staticmethod 

779 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

780 """Create an Fence instance wrapping the given pointer. 

781  

782 Args: 

783 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

784 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

785 readonly (bool): whether the data is read-only (to the user). default is `False`. 

786 """ 

787 if ptr == 0: 

788 raise ValueError("ptr must not be null (0)") 

789 cdef Fence obj = Fence.__new__(Fence) 

790 if owner is None: 

791 obj._ptr = <CudlaFence *>_cyb_malloc(sizeof(CudlaFence)) 

792 if obj._ptr == NULL: 

793 raise MemoryError("Error allocating Fence") 

794 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CudlaFence)) 

795 obj._owner = None 

796 obj._owned = True 

797 else: 

798 obj._ptr = <CudlaFence *>ptr 

799 obj._owner = owner 

800 obj._owned = False 

801 obj._readonly = readonly 

802 return obj 

803  

804  

805cdef _get_dev_attribute_dtype_offsets(): 

806 cdef cudlaDevAttribute pod 

807 return _numpy.dtype({ 

808 'names': ['unified_addressing_supported', 'device_version'], 

809 'formats': [_numpy.uint8, _numpy.uint32], 

810 'offsets': [ 

811 (<intptr_t>&(pod.unifiedAddressingSupported)) - (<intptr_t>&pod), 

812 (<intptr_t>&(pod.deviceVersion)) - (<intptr_t>&pod), 

813 ], 

814 'itemsize': sizeof(cudlaDevAttribute), 

815 }) 

816  

817dev_attribute_dtype = _get_dev_attribute_dtype_offsets() 

818  

819cdef class DevAttribute: 

820 """Empty-initialize an instance of `cudlaDevAttribute`. 

821  

822  

823 .. seealso:: `cudlaDevAttribute` 

824 """ 

825 cdef: 

826 cudlaDevAttribute *_ptr 

827 object _owner 

828 bint _owned 

829 bint _readonly 

830  

831 def __init__(self): 

832 self._ptr = <cudlaDevAttribute *>_cyb_calloc(1, sizeof(cudlaDevAttribute)) 1i

833 if self._ptr == NULL: 1i

834 raise MemoryError("Error allocating DevAttribute") 

835 self._owner = None 1i

836 self._owned = True 1i

837 self._readonly = False 1i

838  

839 def __dealloc__(self): 

840 cdef cudlaDevAttribute *ptr 

841 if self._owned and self._ptr != NULL: 1i

842 ptr = self._ptr 1i

843 self._ptr = NULL 1i

844 _cyb_free(ptr) 1i

845  

846 def __repr__(self): 

847 return f"<{__name__}.DevAttribute object at {hex(id(self))}>" 

848  

849 @property 

850 def ptr(self): 

851 """Get the pointer address to the data as Python :class:`int`.""" 

852 return <intptr_t>(self._ptr) 

853  

854 cdef intptr_t _get_ptr(self): 

855 return <intptr_t>(self._ptr) 

856  

857 def __int__(self): 

858 return <intptr_t>(self._ptr) 

859  

860 def __eq__(self, other): 

861 cdef DevAttribute other_ 

862 if not isinstance(other, DevAttribute): 

863 return False 

864 other_ = other 

865 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaDevAttribute)) == 0) 

866  

867 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

868 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaDevAttribute), self._readonly) 

869  

870 def __releasebuffer__(self, Py_buffer *buffer): 

871 pass 

872  

873 def __setitem__(self, key, val): 

874 if key == 0 and isinstance(val, _numpy.ndarray): 

875 self._ptr = <cudlaDevAttribute *>_cyb_malloc(sizeof(cudlaDevAttribute)) 

876 if self._ptr == NULL: 

877 raise MemoryError("Error allocating DevAttribute") 

878 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaDevAttribute)) 

879 self._owner = None 

880 self._owned = True 

881 self._readonly = not val.flags.writeable 

882 else: 

883 setattr(self, key, val) 

884  

885 @property 

886 def unified_addressing_supported(self): 

887 """int: """ 

888 return self._ptr[0].unifiedAddressingSupported 1i

889  

890 @unified_addressing_supported.setter 

891 def unified_addressing_supported(self, val): 

892 if self._readonly: 1i

893 raise ValueError("This DevAttribute instance is read-only") 

894 self._ptr[0].unifiedAddressingSupported = val 1i

895  

896 @property 

897 def device_version(self): 

898 """int: """ 

899 return self._ptr[0].deviceVersion 1i

900  

901 @device_version.setter 

902 def device_version(self, val): 

903 if self._readonly: 1i

904 raise ValueError("This DevAttribute instance is read-only") 

905 self._ptr[0].deviceVersion = val 1i

906  

907 @staticmethod 

908 def from_buffer(buffer): 

909 """Create an DevAttribute instance with the memory from the given buffer.""" 

910 return _cyb_from_buffer(buffer, sizeof(cudlaDevAttribute), DevAttribute) 

911  

912 @staticmethod 

913 def from_data(data): 

914 """Create an DevAttribute instance wrapping the given NumPy array. 

915  

916 Args: 

917 data (_numpy.ndarray): a single-element array of dtype `dev_attribute_dtype` holding the data. 

918 """ 

919 return _cyb_from_data(data, "dev_attribute_dtype", dev_attribute_dtype, DevAttribute) 

920  

921 @staticmethod 

922 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

923 """Create an DevAttribute instance wrapping the given pointer. 

924  

925 Args: 

926 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

927 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

928 readonly (bool): whether the data is read-only (to the user). default is `False`. 

929 """ 

930 if ptr == 0: 

931 raise ValueError("ptr must not be null (0)") 

932 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute) 

933 if owner is None: 

934 obj._ptr = <cudlaDevAttribute *>_cyb_malloc(sizeof(cudlaDevAttribute)) 

935 if obj._ptr == NULL: 

936 raise MemoryError("Error allocating DevAttribute") 

937 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaDevAttribute)) 

938 obj._owner = None 

939 obj._owned = True 

940 else: 

941 obj._ptr = <cudlaDevAttribute *>ptr 

942 obj._owner = owner 

943 obj._owned = False 

944 obj._readonly = readonly 

945 return obj 

946  

947  

948cdef _get_module_attribute_dtype_offsets(): 

949 cdef cudlaModuleAttribute pod 

950 return _numpy.dtype({ 

951 'names': ['num_input_tensors', 'num_output_tensors', 'input_tensor_desc', 'output_tensor_desc'], 

952 'formats': [_numpy.uint32, _numpy.uint32, _numpy.intp, _numpy.intp], 

953 'offsets': [ 

954 (<intptr_t>&(pod.numInputTensors)) - (<intptr_t>&pod), 

955 (<intptr_t>&(pod.numOutputTensors)) - (<intptr_t>&pod), 

956 (<intptr_t>&(pod.inputTensorDesc)) - (<intptr_t>&pod), 

957 (<intptr_t>&(pod.outputTensorDesc)) - (<intptr_t>&pod), 

958 ], 

959 'itemsize': sizeof(cudlaModuleAttribute), 

960 }) 

961  

962module_attribute_dtype = _get_module_attribute_dtype_offsets() 

963  

964cdef class ModuleAttribute: 

965 """Empty-initialize an instance of `cudlaModuleAttribute`. 

966  

967  

968 .. seealso:: `cudlaModuleAttribute` 

969 """ 

970 cdef: 

971 cudlaModuleAttribute *_ptr 

972 object _owner 

973 bint _owned 

974 bint _readonly 

975  

976 def __init__(self): 

977 self._ptr = <cudlaModuleAttribute *>_cyb_calloc(1, sizeof(cudlaModuleAttribute)) 1j

978 if self._ptr == NULL: 1j

979 raise MemoryError("Error allocating ModuleAttribute") 

980 self._owner = None 1j

981 self._owned = True 1j

982 self._readonly = False 1j

983  

984 def __dealloc__(self): 

985 cdef cudlaModuleAttribute *ptr 

986 if self._owned and self._ptr != NULL: 1j

987 ptr = self._ptr 1j

988 self._ptr = NULL 1j

989 _cyb_free(ptr) 1j

990  

991 def __repr__(self): 

992 return f"<{__name__}.ModuleAttribute object at {hex(id(self))}>" 

993  

994 @property 

995 def ptr(self): 

996 """Get the pointer address to the data as Python :class:`int`.""" 

997 return <intptr_t>(self._ptr) 

998  

999 cdef intptr_t _get_ptr(self): 

1000 return <intptr_t>(self._ptr) 

1001  

1002 def __int__(self): 

1003 return <intptr_t>(self._ptr) 

1004  

1005 def __eq__(self, other): 

1006 cdef ModuleAttribute other_ 

1007 if not isinstance(other, ModuleAttribute): 

1008 return False 

1009 other_ = other 

1010 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaModuleAttribute)) == 0) 

1011  

1012 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

1013 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleAttribute), self._readonly) 

1014  

1015 def __releasebuffer__(self, Py_buffer *buffer): 

1016 pass 

1017  

1018 def __setitem__(self, key, val): 

1019 if key == 0 and isinstance(val, _numpy.ndarray): 

1020 self._ptr = <cudlaModuleAttribute *>_cyb_malloc(sizeof(cudlaModuleAttribute)) 

1021 if self._ptr == NULL: 

1022 raise MemoryError("Error allocating ModuleAttribute") 

1023 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaModuleAttribute)) 

1024 self._owner = None 

1025 self._owned = True 

1026 self._readonly = not val.flags.writeable 

1027 else: 

1028 setattr(self, key, val) 

1029  

1030 @property 

1031 def num_input_tensors(self): 

1032 """int: """ 

1033 return self._ptr[0].numInputTensors 1j

1034  

1035 @num_input_tensors.setter 

1036 def num_input_tensors(self, val): 

1037 if self._readonly: 1j

1038 raise ValueError("This ModuleAttribute instance is read-only") 

1039 self._ptr[0].numInputTensors = val 1j

1040  

1041 @property 

1042 def num_output_tensors(self): 

1043 """int: """ 

1044 return self._ptr[0].numOutputTensors 1j

1045  

1046 @num_output_tensors.setter 

1047 def num_output_tensors(self, val): 

1048 if self._readonly: 1j

1049 raise ValueError("This ModuleAttribute instance is read-only") 

1050 self._ptr[0].numOutputTensors = val 1j

1051  

1052 @property 

1053 def input_tensor_desc(self): 

1054 """int: """ 

1055 return <intptr_t>(self._ptr[0].inputTensorDesc) 

1056  

1057 @input_tensor_desc.setter 

1058 def input_tensor_desc(self, val): 

1059 if self._readonly: 

1060 raise ValueError("This ModuleAttribute instance is read-only") 

1061 self._ptr[0].inputTensorDesc = <cudlaModuleTensorDescriptor*><intptr_t>val 

1062  

1063 @property 

1064 def output_tensor_desc(self): 

1065 """int: """ 

1066 return <intptr_t>(self._ptr[0].outputTensorDesc) 

1067  

1068 @output_tensor_desc.setter 

1069 def output_tensor_desc(self, val): 

1070 if self._readonly: 

1071 raise ValueError("This ModuleAttribute instance is read-only") 

1072 self._ptr[0].outputTensorDesc = <cudlaModuleTensorDescriptor*><intptr_t>val 

1073  

1074 @staticmethod 

1075 def from_buffer(buffer): 

1076 """Create an ModuleAttribute instance with the memory from the given buffer.""" 

1077 return _cyb_from_buffer(buffer, sizeof(cudlaModuleAttribute), ModuleAttribute) 

1078  

1079 @staticmethod 

1080 def from_data(data): 

1081 """Create an ModuleAttribute instance wrapping the given NumPy array. 

1082  

1083 Args: 

1084 data (_numpy.ndarray): a single-element array of dtype `module_attribute_dtype` holding the data. 

1085 """ 

1086 return _cyb_from_data(data, "module_attribute_dtype", module_attribute_dtype, ModuleAttribute) 

1087  

1088 @staticmethod 

1089 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

1090 """Create an ModuleAttribute instance wrapping the given pointer. 

1091  

1092 Args: 

1093 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

1094 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

1095 readonly (bool): whether the data is read-only (to the user). default is `False`. 

1096 """ 

1097 if ptr == 0: 

1098 raise ValueError("ptr must not be null (0)") 

1099 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute) 

1100 if owner is None: 

1101 obj._ptr = <cudlaModuleAttribute *>_cyb_malloc(sizeof(cudlaModuleAttribute)) 

1102 if obj._ptr == NULL: 

1103 raise MemoryError("Error allocating ModuleAttribute") 

1104 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaModuleAttribute)) 

1105 obj._owner = None 

1106 obj._owned = True 

1107 else: 

1108 obj._ptr = <cudlaModuleAttribute *>ptr 

1109 obj._owner = owner 

1110 obj._owned = False 

1111 obj._readonly = readonly 

1112 return obj 

1113  

1114  

1115cdef _get_wait_events_dtype_offsets(): 

1116 cdef cudlaWaitEvents pod 

1117 return _numpy.dtype({ 

1118 'names': ['pre_fences', 'num_events'], 

1119 'formats': [_numpy.intp, _numpy.uint32], 

1120 'offsets': [ 

1121 (<intptr_t>&(pod.preFences)) - (<intptr_t>&pod), 

1122 (<intptr_t>&(pod.numEvents)) - (<intptr_t>&pod), 

1123 ], 

1124 'itemsize': sizeof(cudlaWaitEvents), 

1125 }) 

1126  

1127wait_events_dtype = _get_wait_events_dtype_offsets() 

1128  

1129cdef class WaitEvents: 

1130 """Empty-initialize an instance of `cudlaWaitEvents`. 

1131  

1132  

1133 .. seealso:: `cudlaWaitEvents` 

1134 """ 

1135 cdef: 

1136 cudlaWaitEvents *_ptr 

1137 object _owner 

1138 bint _owned 

1139 bint _readonly 

1140 dict _refs 

1141  

1142 def __init__(self): 

1143 self._ptr = <cudlaWaitEvents *>_cyb_calloc(1, sizeof(cudlaWaitEvents)) 1n

1144 if self._ptr == NULL: 1n

1145 raise MemoryError("Error allocating WaitEvents") 

1146 self._owner = None 1n

1147 self._owned = True 1n

1148 self._readonly = False 1n

1149 self._refs = {} 1n

1150  

1151 def __dealloc__(self): 

1152 cdef cudlaWaitEvents *ptr 

1153 if self._owned and self._ptr != NULL: 1n

1154 ptr = self._ptr 1n

1155 self._ptr = NULL 1n

1156 _cyb_free(ptr) 1n

1157  

1158 def __repr__(self): 

1159 return f"<{__name__}.WaitEvents object at {hex(id(self))}>" 

1160  

1161 @property 

1162 def ptr(self): 

1163 """Get the pointer address to the data as Python :class:`int`.""" 

1164 return <intptr_t>(self._ptr) 

1165  

1166 cdef intptr_t _get_ptr(self): 

1167 return <intptr_t>(self._ptr) 

1168  

1169 def __int__(self): 

1170 return <intptr_t>(self._ptr) 

1171  

1172 def __eq__(self, other): 

1173 cdef WaitEvents other_ 

1174 if not isinstance(other, WaitEvents): 

1175 return False 

1176 other_ = other 

1177 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaWaitEvents)) == 0) 

1178  

1179 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

1180 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaWaitEvents), self._readonly) 

1181  

1182 def __releasebuffer__(self, Py_buffer *buffer): 

1183 pass 

1184  

1185 def __setitem__(self, key, val): 

1186 if key == 0 and isinstance(val, _numpy.ndarray): 

1187 self._ptr = <cudlaWaitEvents *>_cyb_malloc(sizeof(cudlaWaitEvents)) 

1188 if self._ptr == NULL: 

1189 raise MemoryError("Error allocating WaitEvents") 

1190 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaWaitEvents)) 

1191 self._owner = None 

1192 self._owned = True 

1193 self._readonly = not val.flags.writeable 

1194 else: 

1195 setattr(self, key, val) 

1196  

1197 @property 

1198 def pre_fences(self): 

1199 """int: """ 

1200 if self._ptr[0].preFences == NULL or self._ptr[0].numEvents == 0: 1n

1201 return [] 1n

1202 return Fence.from_ptr( 

1203 <intptr_t>(self._ptr[0].preFences), 

1204 self._ptr[0].numEvents, 

1205 owner=self, 

1206 readonly=self._readonly 

1207 ) 

1208  

1209 @pre_fences.setter 

1210 def pre_fences(self, val): 

1211 if self._readonly: 

1212 raise ValueError("This WaitEvents instance is read-only") 

1213 cdef Fence arr = val 

1214 self._ptr[0].preFences = <CudlaFence*><intptr_t>(arr._get_ptr()) 

1215 self._ptr[0].numEvents = len(arr) 

1216 self._refs["pre_fences"] = arr 

1217  

1218 @staticmethod 

1219 def from_buffer(buffer): 

1220 """Create an WaitEvents instance with the memory from the given buffer.""" 

1221 return _cyb_from_buffer(buffer, sizeof(cudlaWaitEvents), WaitEvents) 

1222  

1223 @staticmethod 

1224 def from_data(data): 

1225 """Create an WaitEvents instance wrapping the given NumPy array. 

1226  

1227 Args: 

1228 data (_numpy.ndarray): a single-element array of dtype `wait_events_dtype` holding the data. 

1229 """ 

1230 return _cyb_from_data(data, "wait_events_dtype", wait_events_dtype, WaitEvents) 

1231  

1232 @staticmethod 

1233 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

1234 """Create an WaitEvents instance wrapping the given pointer. 

1235  

1236 Args: 

1237 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

1238 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

1239 readonly (bool): whether the data is read-only (to the user). default is `False`. 

1240 """ 

1241 if ptr == 0: 

1242 raise ValueError("ptr must not be null (0)") 

1243 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents) 

1244 if owner is None: 

1245 obj._ptr = <cudlaWaitEvents *>_cyb_malloc(sizeof(cudlaWaitEvents)) 

1246 if obj._ptr == NULL: 

1247 raise MemoryError("Error allocating WaitEvents") 

1248 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaWaitEvents)) 

1249 obj._owner = None 

1250 obj._owned = True 

1251 else: 

1252 obj._ptr = <cudlaWaitEvents *>ptr 

1253 obj._owner = owner 

1254 obj._owned = False 

1255 obj._readonly = readonly 

1256 obj._refs = {} 

1257 return obj 

1258  

1259  

1260cdef _get_signal_events_dtype_offsets(): 

1261 cdef cudlaSignalEvents pod 

1262 return _numpy.dtype({ 

1263 'names': ['dev_ptrs', 'eof_fences', 'num_events'], 

1264 'formats': [_numpy.intp, _numpy.intp, _numpy.uint32], 

1265 'offsets': [ 

1266 (<intptr_t>&(pod.devPtrs)) - (<intptr_t>&pod), 

1267 (<intptr_t>&(pod.eofFences)) - (<intptr_t>&pod), 

1268 (<intptr_t>&(pod.numEvents)) - (<intptr_t>&pod), 

1269 ], 

1270 'itemsize': sizeof(cudlaSignalEvents), 

1271 }) 

1272  

1273signal_events_dtype = _get_signal_events_dtype_offsets() 

1274  

1275cdef class SignalEvents: 

1276 """Empty-initialize an instance of `cudlaSignalEvents`. 

1277  

1278  

1279 .. seealso:: `cudlaSignalEvents` 

1280 """ 

1281 cdef: 

1282 cudlaSignalEvents *_ptr 

1283 object _owner 

1284 bint _owned 

1285 bint _readonly 

1286 dict _refs 

1287  

1288 def __init__(self): 

1289 self._ptr = <cudlaSignalEvents *>_cyb_calloc(1, sizeof(cudlaSignalEvents)) 1o

1290 if self._ptr == NULL: 1o

1291 raise MemoryError("Error allocating SignalEvents") 

1292 self._owner = None 1o

1293 self._owned = True 1o

1294 self._readonly = False 1o

1295 self._refs = {} 1o

1296  

1297 def __dealloc__(self): 

1298 cdef cudlaSignalEvents *ptr 

1299 if self._owned and self._ptr != NULL: 1o

1300 ptr = self._ptr 1o

1301 self._ptr = NULL 1o

1302 _cyb_free(ptr) 1o

1303  

1304 def __repr__(self): 

1305 return f"<{__name__}.SignalEvents object at {hex(id(self))}>" 

1306  

1307 @property 

1308 def ptr(self): 

1309 """Get the pointer address to the data as Python :class:`int`.""" 

1310 return <intptr_t>(self._ptr) 

1311  

1312 cdef intptr_t _get_ptr(self): 

1313 return <intptr_t>(self._ptr) 

1314  

1315 def __int__(self): 

1316 return <intptr_t>(self._ptr) 

1317  

1318 def __eq__(self, other): 

1319 cdef SignalEvents other_ 

1320 if not isinstance(other, SignalEvents): 

1321 return False 

1322 other_ = other 

1323 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaSignalEvents)) == 0) 

1324  

1325 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

1326 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaSignalEvents), self._readonly) 

1327  

1328 def __releasebuffer__(self, Py_buffer *buffer): 

1329 pass 

1330  

1331 def __setitem__(self, key, val): 

1332 if key == 0 and isinstance(val, _numpy.ndarray): 

1333 self._ptr = <cudlaSignalEvents *>_cyb_malloc(sizeof(cudlaSignalEvents)) 

1334 if self._ptr == NULL: 

1335 raise MemoryError("Error allocating SignalEvents") 

1336 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaSignalEvents)) 

1337 self._owner = None 

1338 self._owned = True 

1339 self._readonly = not val.flags.writeable 

1340 else: 

1341 setattr(self, key, val) 

1342  

1343 @property 

1344 def dev_ptrs(self): 

1345 """int: """ 

1346 if self._ptr[0].devPtrs == NULL or self._ptr[0].numEvents == 0: 

1347 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0] 

1348 cdef _cyb_view.array arr = _cyb_view.array(shape=(self._ptr[0].numEvents,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False) 

1349 arr.data = <char *>(self._ptr[0].devPtrs) 

1350 return arr 

1351  

1352 @dev_ptrs.setter 

1353 def dev_ptrs(self, val): 

1354 if self._readonly: 

1355 raise ValueError("This SignalEvents instance is read-only") 

1356 cdef Py_ssize_t _n = len(val) 

1357 self._ptr[0].numEvents = _n 

1358 if _n == 0: 

1359 return 

1360 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 

1361 cdef intptr_t[:] mv = arr 

1362 cdef Py_ssize_t i 

1363 for i in range(_n): 

1364 mv[i] = val[i] 

1365 self._ptr[0].devPtrs = <uint64_t**><intptr_t>(arr.data) 

1366 self._refs["dev_ptrs"] = arr 

1367  

1368 @property 

1369 def eof_fences(self): 

1370 """int: """ 

1371 if self._ptr[0].eofFences == NULL or self._ptr[0].numEvents == 0: 1o

1372 return [] 1o

1373 return Fence.from_ptr( 

1374 <intptr_t>(self._ptr[0].eofFences), 

1375 self._ptr[0].numEvents, 

1376 owner=self, 

1377 readonly=self._readonly 

1378 ) 

1379  

1380 @eof_fences.setter 

1381 def eof_fences(self, val): 

1382 if self._readonly: 

1383 raise ValueError("This SignalEvents instance is read-only") 

1384 cdef Fence arr = val 

1385 self._ptr[0].eofFences = <CudlaFence*><intptr_t>(arr._get_ptr()) 

1386 self._ptr[0].numEvents = len(arr) 

1387 self._refs["eof_fences"] = arr 

1388  

1389 @staticmethod 

1390 def from_buffer(buffer): 

1391 """Create an SignalEvents instance with the memory from the given buffer.""" 

1392 return _cyb_from_buffer(buffer, sizeof(cudlaSignalEvents), SignalEvents) 

1393  

1394 @staticmethod 

1395 def from_data(data): 

1396 """Create an SignalEvents instance wrapping the given NumPy array. 

1397  

1398 Args: 

1399 data (_numpy.ndarray): a single-element array of dtype `signal_events_dtype` holding the data. 

1400 """ 

1401 return _cyb_from_data(data, "signal_events_dtype", signal_events_dtype, SignalEvents) 

1402  

1403 @staticmethod 

1404 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

1405 """Create an SignalEvents instance wrapping the given pointer. 

1406  

1407 Args: 

1408 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

1409 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

1410 readonly (bool): whether the data is read-only (to the user). default is `False`. 

1411 """ 

1412 if ptr == 0: 

1413 raise ValueError("ptr must not be null (0)") 

1414 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents) 

1415 if owner is None: 

1416 obj._ptr = <cudlaSignalEvents *>_cyb_malloc(sizeof(cudlaSignalEvents)) 

1417 if obj._ptr == NULL: 

1418 raise MemoryError("Error allocating SignalEvents") 

1419 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaSignalEvents)) 

1420 obj._owner = None 

1421 obj._owned = True 

1422 else: 

1423 obj._ptr = <cudlaSignalEvents *>ptr 

1424 obj._owner = owner 

1425 obj._owned = False 

1426 obj._readonly = readonly 

1427 obj._refs = {} 

1428 return obj 

1429  

1430  

1431cdef _get_task_dtype_offsets(): 

1432 cdef cudlaTask pod 

1433 return _numpy.dtype({ 

1434 'names': ['module_handle', 'output_tensor', 'num_output_tensors', 'num_input_tensors', 'input_tensor', 'wait_events', 'signal_events'], 

1435 'formats': [_numpy.intp, _numpy.intp, _numpy.uint32, _numpy.uint32, _numpy.intp, _numpy.intp, _numpy.intp], 

1436 'offsets': [ 

1437 (<intptr_t>&(pod.moduleHandle)) - (<intptr_t>&pod), 

1438 (<intptr_t>&(pod.outputTensor)) - (<intptr_t>&pod), 

1439 (<intptr_t>&(pod.numOutputTensors)) - (<intptr_t>&pod), 

1440 (<intptr_t>&(pod.numInputTensors)) - (<intptr_t>&pod), 

1441 (<intptr_t>&(pod.inputTensor)) - (<intptr_t>&pod), 

1442 (<intptr_t>&(pod.waitEvents)) - (<intptr_t>&pod), 

1443 (<intptr_t>&(pod.signalEvents)) - (<intptr_t>&pod), 

1444 ], 

1445 'itemsize': sizeof(cudlaTask), 

1446 }) 

1447  

1448task_dtype = _get_task_dtype_offsets() 

1449  

1450cdef class Task: 

1451 """Empty-initialize an instance of `cudlaTask`. 

1452  

1453  

1454 .. seealso:: `cudlaTask` 

1455 """ 

1456 cdef: 

1457 cudlaTask *_ptr 

1458 object _owner 

1459 bint _owned 

1460 bint _readonly 

1461 dict _refs 

1462  

1463 def __init__(self): 

1464 self._ptr = <cudlaTask *>_cyb_calloc(1, sizeof(cudlaTask)) 1ebkcd

1465 if self._ptr == NULL: 1ebkcd

1466 raise MemoryError("Error allocating Task") 

1467 self._owner = None 1ebkcd

1468 self._owned = True 1ebkcd

1469 self._readonly = False 1ebkcd

1470 self._refs = {} 1ebkcd

1471  

1472 def __dealloc__(self): 

1473 cdef cudlaTask *ptr 

1474 if self._owned and self._ptr != NULL: 1ebkcd

1475 ptr = self._ptr 1ebkcd

1476 self._ptr = NULL 1ebkcd

1477 _cyb_free(ptr) 1ebkcd

1478  

1479 def __repr__(self): 

1480 return f"<{__name__}.Task object at {hex(id(self))}>" 

1481  

1482 @property 

1483 def ptr(self): 

1484 """Get the pointer address to the data as Python :class:`int`.""" 

1485 return <intptr_t>(self._ptr) 

1486  

1487 cdef intptr_t _get_ptr(self): 

1488 return <intptr_t>(self._ptr) 

1489  

1490 def __int__(self): 

1491 return <intptr_t>(self._ptr) 1e

1492  

1493 def __eq__(self, other): 

1494 cdef Task other_ 

1495 if not isinstance(other, Task): 

1496 return False 

1497 other_ = other 

1498 return (_cyb_memcmp(<void *><intptr_t>(self._ptr), <void *><intptr_t>(other_._ptr), sizeof(cudlaTask)) == 0) 

1499  

1500 def __getbuffer__(self, _cyb_cpython.Py_buffer *buffer, int flags): 

1501 _cyb___getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaTask), self._readonly) 

1502  

1503 def __releasebuffer__(self, Py_buffer *buffer): 

1504 pass 

1505  

1506 def __setitem__(self, key, val): 

1507 if key == 0 and isinstance(val, _numpy.ndarray): 

1508 self._ptr = <cudlaTask *>_cyb_malloc(sizeof(cudlaTask)) 

1509 if self._ptr == NULL: 

1510 raise MemoryError("Error allocating Task") 

1511 _cyb_memcpy(<void*>self._ptr, <void*><intptr_t>val.ctypes.data, sizeof(cudlaTask)) 

1512 self._owner = None 

1513 self._owned = True 

1514 self._readonly = not val.flags.writeable 

1515 else: 

1516 setattr(self, key, val) 

1517  

1518 @property 

1519 def module_handle(self): 

1520 """int: """ 

1521 return <intptr_t>(self._ptr[0].moduleHandle) 1bk

1522  

1523 @module_handle.setter 

1524 def module_handle(self, val): 

1525 if self._readonly: 1bk

1526 raise ValueError("This Task instance is read-only") 

1527 self._ptr[0].moduleHandle = <cudlaModule><intptr_t>val 1bk

1528  

1529 @property 

1530 def output_tensor(self): 

1531 """int: """ 

1532 if self._ptr[0].outputTensor == NULL or self._ptr[0].numOutputTensors == 0: 1bd

1533 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0] 

1534 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

1535 arr.data = <char *>(self._ptr[0].outputTensor) 1bd

1536 return arr 1bd

1537  

1538 @output_tensor.setter 

1539 def output_tensor(self, val): 

1540 if self._readonly: 1bd

1541 raise ValueError("This Task instance is read-only") 

1542 cdef Py_ssize_t _n = len(val) 1bd

1543 self._ptr[0].numOutputTensors = _n 1bd

1544 if _n == 0: 1bd

1545 return 

1546 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 1bd

1547 cdef intptr_t[:] mv = arr 1bd

1548 cdef Py_ssize_t i 

1549 for i in range(_n): 1bd

1550 mv[i] = val[i] 1bd

1551 self._ptr[0].outputTensor = <uint64_t**><intptr_t>(arr.data) 1bd

1552 self._refs["output_tensor"] = arr 1bd

1553  

1554 @property 

1555 def input_tensor(self): 

1556 """int: """ 

1557 if self._ptr[0].inputTensor == NULL or self._ptr[0].numInputTensors == 0: 1bc

1558 return _cyb_view.array(shape=(1,), itemsize=sizeof(intptr_t), format="q", mode="c")[:0] 

1559 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

1560 arr.data = <char *>(self._ptr[0].inputTensor) 1bc

1561 return arr 1bc

1562  

1563 @input_tensor.setter 

1564 def input_tensor(self, val): 

1565 if self._readonly: 1bc

1566 raise ValueError("This Task instance is read-only") 

1567 cdef Py_ssize_t _n = len(val) 1bc

1568 self._ptr[0].numInputTensors = _n 1bc

1569 if _n == 0: 1bc

1570 return 

1571 cdef _cyb_view.array arr = _cyb_view.array(shape=(_n,), itemsize=sizeof(intptr_t), format="q", mode="c") 1bc

1572 cdef intptr_t[:] mv = arr 1bc

1573 cdef Py_ssize_t i 

1574 for i in range(_n): 1bc

1575 mv[i] = val[i] 1bc

1576 self._ptr[0].inputTensor = <uint64_t**><intptr_t>(arr.data) 1bc

1577 self._refs["input_tensor"] = arr 1bc

1578  

1579 @property 

1580 def wait_events(self): 

1581 """int: """ 

1582 return <intptr_t>(self._ptr[0].waitEvents) 

1583  

1584 @wait_events.setter 

1585 def wait_events(self, val): 

1586 if self._readonly: 1b

1587 raise ValueError("This Task instance is read-only") 

1588 self._ptr[0].waitEvents = <cudlaWaitEvents*><intptr_t>val 1b

1589  

1590 @property 

1591 def signal_events(self): 

1592 """int: """ 

1593 return <intptr_t>(self._ptr[0].signalEvents) 

1594  

1595 @signal_events.setter 

1596 def signal_events(self, val): 

1597 if self._readonly: 1b

1598 raise ValueError("This Task instance is read-only") 

1599 self._ptr[0].signalEvents = <cudlaSignalEvents*><intptr_t>val 1b

1600  

1601 @staticmethod 

1602 def from_buffer(buffer): 

1603 """Create an Task instance with the memory from the given buffer.""" 

1604 return _cyb_from_buffer(buffer, sizeof(cudlaTask), Task) 

1605  

1606 @staticmethod 

1607 def from_data(data): 

1608 """Create an Task instance wrapping the given NumPy array. 

1609  

1610 Args: 

1611 data (_numpy.ndarray): a single-element array of dtype `task_dtype` holding the data. 

1612 """ 

1613 return _cyb_from_data(data, "task_dtype", task_dtype, Task) 

1614  

1615 @staticmethod 

1616 def from_ptr(intptr_t ptr, bint readonly=False, object owner=None): 

1617 """Create an Task instance wrapping the given pointer. 

1618  

1619 Args: 

1620 ptr (intptr_t): pointer address as Python :class:`int` to the data. 

1621 owner (object): The Python object that owns the pointer. If not provided, data will be copied. 

1622 readonly (bool): whether the data is read-only (to the user). default is `False`. 

1623 """ 

1624 if ptr == 0: 

1625 raise ValueError("ptr must not be null (0)") 

1626 cdef Task obj = Task.__new__(Task) 

1627 if owner is None: 

1628 obj._ptr = <cudlaTask *>_cyb_malloc(sizeof(cudlaTask)) 

1629 if obj._ptr == NULL: 

1630 raise MemoryError("Error allocating Task") 

1631 _cyb_memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaTask)) 

1632 obj._owner = None 

1633 obj._owned = True 

1634 else: 

1635 obj._ptr = <cudlaTask *>ptr 

1636 obj._owner = owner 

1637 obj._owned = False 

1638 obj._readonly = readonly 

1639 obj._refs = {} 

1640 return obj 

1641  

1642  

1643############################################################################### 

1644# Enum 

1645############################################################################### 

1646  

1647class Status(_cyb_IntEnum): 

1648 """ 

1649 See `cudlaStatus`. 

1650 """ 

1651 Success = cudlaSuccess 

1652 ErrorInvalidParam = cudlaErrorInvalidParam 

1653 ErrorOutOfResources = cudlaErrorOutOfResources 

1654 ErrorCreationFailed = cudlaErrorCreationFailed 

1655 ErrorInvalidAddress = cudlaErrorInvalidAddress 

1656 ErrorOs = cudlaErrorOs 

1657 ErrorCuda = cudlaErrorCuda 

1658 ErrorUmd = cudlaErrorUmd 

1659 ErrorInvalidDevice = cudlaErrorInvalidDevice 

1660 ErrorInvalidAttribute = cudlaErrorInvalidAttribute 

1661 ErrorIncompatibleDlaSWVersion = cudlaErrorIncompatibleDlaSWVersion 

1662 ErrorMemoryRegistered = cudlaErrorMemoryRegistered 

1663 ErrorInvalidModule = cudlaErrorInvalidModule 

1664 ErrorUnsupportedOperation = cudlaErrorUnsupportedOperation 

1665 ErrorNvSci = cudlaErrorNvSci 

1666 ErrorDriverNotFound = cudlaErrorDriverNotFound 

1667 ErrorDlaErrInvalidInput = cudlaErrorDlaErrInvalidInput 

1668 ErrorDlaErrInvalidPreAction = cudlaErrorDlaErrInvalidPreAction 

1669 ErrorDlaErrNoMem = cudlaErrorDlaErrNoMem 

1670 ErrorDlaErrProcessorBusy = cudlaErrorDlaErrProcessorBusy 

1671 ErrorDlaErrTaskStatusMismatch = cudlaErrorDlaErrTaskStatusMismatch 

1672 ErrorDlaErrEngineTimeout = cudlaErrorDlaErrEngineTimeout 

1673 ErrorDlaErrDataMismatch = cudlaErrorDlaErrDataMismatch 

1674 ErrorUnknown = cudlaErrorUnknown 

1675  

1676class Mode(_cyb_IntEnum): 

1677 """ 

1678 See `cudlaMode`. 

1679 """ 

1680 CUDA_DLA = CUDLA_CUDA_DLA 

1681 STANDALONE = CUDLA_STANDALONE 

1682  

1683class ModuleAttributeType(_cyb_IntEnum): 

1684 """ 

1685 See `cudlaModuleAttributeType`. 

1686 """ 

1687 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS 

1688 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS 

1689 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS 

1690 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS 

1691 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1692 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS 

1693  

1694class FenceType(_cyb_IntEnum): 

1695 """ 

1696 See `cudlaFenceType`. 

1697 """ 

1698 NVSCISYNC_FENCE = CUDLA_NVSCISYNC_FENCE 

1699 NVSCISYNC_FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF 

1700  

1701class ModuleLoadFlags(_cyb_IntEnum): 

1702 """ 

1703 See `cudlaModuleLoadFlags`. 

1704 """ 

1705 MODULE_DEFAULT = CUDLA_MODULE_DEFAULT 

1706 MODULE_ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS 

1707  

1708class SubmissionFlags(_cyb_IntEnum): 

1709 """ 

1710 See `cudlaSubmissionFlags`. 

1711 """ 

1712 SUBMIT_NOOP = CUDLA_SUBMIT_NOOP 

1713 SUBMIT_SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE 

1714 SUBMIT_DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK 

1715  

1716class AccessPermissionFlags(_cyb_IntEnum): 

1717 """ 

1718 See `cudlaAccessPermissionFlags`. 

1719 """ 

1720 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM 

1721 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM 

1722 TASK_STATISTICS = CUDLA_TASK_STATISTICS 

1723  

1724class DevAttributeType(_cyb_IntEnum): 

1725 """ 

1726 See `cudlaDevAttributeType`. 

1727 """ 

1728 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING 

1729 DEVICE_VERSION = CUDLA_DEVICE_VERSION 

1730  

1731  

1732############################################################################### 

1733# Error handling 

1734############################################################################### 

1735  

1736class CudlaError(Exception): 

1737  

1738 def __init__(self, status): 

1739 self.status = status 1qr

1740 s = Status(status) 1qr

1741 cdef str err = f"{s.name} ({s.value})" 1qr

1742 super(CudlaError, self).__init__(err) 1qr

1743  

1744 def __reduce__(self): 

1745 return (type(self), (self.status,)) 

1746  

1747  

1748@cython.profile(False) 

1749cpdef inline check_status(int status): 

1750 if status != 0: 

1751 raise CudlaError(status) 

1752  

1753  

1754############################################################################### 

1755# Wrapper functions 

1756############################################################################### 

1757  

1758cpdef uint64_t get_version() except? -1: 

1759 cdef uint64_t version 

1760 with nogil: 

1761 __status__ = cudlaGetVersion(&version) 

1762 check_status(__status__) 

1763 return version 

1764  

1765  

1766cpdef uint64_t device_get_count() except? -1: 

1767 cdef uint64_t p_num_devices 

1768 with nogil: 

1769 __status__ = cudlaDeviceGetCount(&p_num_devices) 

1770 check_status(__status__) 

1771 return p_num_devices 

1772  

1773  

1774cpdef intptr_t create_device(uint64_t device, uint32_t flags) except *: 

1775 cdef DevHandle dev_handle 

1776 if flags & CUDLA_STANDALONE: 

1777 raise CudlaError(cudlaErrorUnsupportedOperation) 

1778 with nogil: 

1779 __status__ = cudlaCreateDevice(<const uint64_t>device, &dev_handle, <const uint32_t>flags) 

1780 check_status(__status__) 

1781 return <intptr_t>dev_handle 

1782  

1783  

1784cpdef intptr_t mem_register(intptr_t dev_handle, intptr_t ptr, size_t size, uint32_t flags) except *: 

1785 cdef uint64_t* dev_ptr 

1786 with nogil: 

1787 __status__ = cudlaMemRegister(<const DevHandle>dev_handle, <const uint64_t* const>ptr, <const size_t>size, &dev_ptr, <const uint32_t>flags) 

1788 check_status(__status__) 

1789 return <intptr_t>dev_ptr 

1790  

1791  

1792cpdef intptr_t module_load_from_memory(intptr_t dev_handle, p_module, size_t module_size, uint32_t flags) except *: 

1793 cdef void* _p_module_ = <void *>_cyb_get_buffer_pointer(p_module, module_size, readonly=True) 

1794 cdef Module h_module 

1795 with nogil: 

1796 __status__ = cudlaModuleLoadFromMemory(<const DevHandle>dev_handle, <const uint8_t* const>_p_module_, <const size_t>module_size, &h_module, <const uint32_t>flags) 

1797 check_status(__status__) 

1798 return <intptr_t>h_module 

1799  

1800  

1801cpdef module_unload(intptr_t h_module, uint32_t flags): 

1802 with nogil: 

1803 __status__ = cudlaModuleUnload(<const Module>h_module, <const uint32_t>flags) 

1804 check_status(__status__) 

1805  

1806  

1807cpdef submit_task(intptr_t dev_handle, intptr_t ptr_to_tasks, uint32_t num_tasks, intptr_t stream, uint32_t flags): 

1808 with nogil: 

1809 __status__ = cudlaSubmitTask(<const DevHandle>dev_handle, <const cudlaTask* const>ptr_to_tasks, <const uint32_t>num_tasks, <void* const>stream, <const uint32_t>flags) 

1810 check_status(__status__) 

1811  

1812  

1813cpdef object device_get_attribute(intptr_t dev_handle, int attrib): 

1814 cdef DevAttribute p_attribute_py = DevAttribute() 

1815 cdef cudlaDevAttribute *p_attribute = <cudlaDevAttribute *><intptr_t>(p_attribute_py._get_ptr()) 

1816 with nogil: 

1817 __status__ = cudlaDeviceGetAttribute(<const DevHandle>dev_handle, <const _DevAttributeType>attrib, p_attribute) 

1818 check_status(__status__) 

1819 return p_attribute_py 

1820  

1821  

1822cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr): 

1823 with nogil: 

1824 __status__ = cudlaMemUnregister(<const DevHandle>dev_handle, <const uint64_t* const>dev_ptr) 

1825 check_status(__status__) 

1826  

1827  

1828cpdef int get_last_error(intptr_t dev_handle) except? 0: 

1829 cdef int ret 

1830 with nogil: 

1831 ret = <int>cudlaGetLastError(<const DevHandle>dev_handle) 

1832 return ret 

1833  

1834  

1835cpdef destroy_device(intptr_t dev_handle): 

1836 with nogil: 

1837 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle) 

1838 check_status(__status__) 

1839  

1840  

1841cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout): 

1842 with nogil: 

1843 __status__ = cudlaSetTaskTimeoutInMs(<const DevHandle>dev_handle, <const uint32_t>timeout) 

1844 check_status(__status__) 

1845  

1846  

1847cpdef module_get_attributes(intptr_t h_module, int attr_type): 

1848 """Query module attributes, interpreting the cudlaModuleAttribute union 

1849 based on the requested attribute type. 

1850  

1851 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS, 

1852 NUM_OUTPUT_TASK_STATISTICS), returns an int. 

1853  

1854 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS, 

1855 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS), 

1856 returns a list of ModuleTensorDescriptor objects. 

1857 """ 

1858 cdef int _attr_type = attr_type 

1859 cdef cudlaModuleAttribute count_attr 

1860 cdef cudlaModuleAttribute num_attr 

1861 cdef cudlaModuleAttribute desc_attr 

1862 cdef uint32_t count 

1863 cdef cudlaModuleTensorDescriptor* desc_buf 

1864 cdef uint32_t i 

1865 cdef int num_attr_type 

1866  

1867 if _attr_type == CUDLA_NUM_INPUT_TENSORS or _attr_type == CUDLA_NUM_OUTPUT_TENSORS or _attr_type == CUDLA_NUM_OUTPUT_TASK_STATISTICS: 

1868 with nogil: 

1869 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>_attr_type, &count_attr) 

1870 check_status(__status__) 

1871 return <int>(count_attr.numInputTensors) 

1872 elif _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS or _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS or _attr_type == CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS: 

1873 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS: 

1874 num_attr_type = CUDLA_NUM_INPUT_TENSORS 

1875 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS: 

1876 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS 

1877 else: 

1878 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1879 with nogil: 

1880 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>num_attr_type, &num_attr) 

1881 check_status(__status__) 

1882 count = num_attr.numInputTensors 

1883 desc_buf = <cudlaModuleTensorDescriptor*>malloc(count * sizeof(cudlaModuleTensorDescriptor)) 

1884 if desc_buf == NULL: 

1885 raise MemoryError("Failed to allocate descriptor buffer") 

1886 try: 

1887 desc_attr.inputTensorDesc = desc_buf 

1888 with nogil: 

1889 __status__ = cudlaModuleGetAttributes(<const Module>h_module, <const _ModuleAttributeType>_attr_type, &desc_attr) 

1890 check_status(__status__) 

1891 result = [] 

1892 for i in range(count): 

1893 result.append(ModuleTensorDescriptor.from_ptr(<intptr_t>&desc_buf[i], readonly=True)) 

1894 return result 

1895 finally: 

1896 free(desc_buf) 

1897 else: 

1898 raise ValueError(f"Unknown attribute type: {attr_type}") 

1899del _cyb_IntEnum