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

940 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-05 01:11 +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.4.1. Do not modify it directly. 

5# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=92945a025bf01ceb29f21539fb32be8db41c402bec2606a8d92b79e869a0c0ed 

6  

7  

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

9  

10cimport cpython as _cyb_cpython 

11cimport cpython.buffer as _cyb_cpython_buffer 

12from cpython.buffer cimport ( 

13 PyBUF_SIMPLE as _cyb_PyBUF_SIMPLE, 

14 PyBuffer_Release as _cyb_PyBuffer_Release, 

15 PyObject_GetBuffer as _cyb_PyObject_GetBuffer, 

16 Py_buffer as _cyb_Py_buffer, 

17) 

18from cython cimport view as _cyb_view 

19from libc.stdint cimport ( 

20 intptr_t, 

21 uint32_t, 

22 uint64_t, 

23 uint8_t, 

24) 

25from libc.string cimport ( 

26 memcmp as _cyb_memcmp, 

27 memcpy as _cyb_memcpy, 

28 memmove as _cyb_memmove, 

29) 

30  

31from enum import IntEnum as _cyb_IntEnum 

32  

33import numpy as _numpy 

34  

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

36 buffer.buf = <char *>ptr 

37 buffer.format = 'b' 

38 buffer.internal = NULL 

39 buffer.itemsize = 1 

40 buffer.len = size 

41 buffer.ndim = 1 

42 buffer.obj = self 

43 buffer.readonly = readonly 

44 buffer.shape = &buffer.len 

45 buffer.strides = &buffer.itemsize 

46 buffer.suboffsets = NULL 

47  

48cdef _cyb_from_buffer(buffer, size, lowpp_type): 

49 cdef _cyb_cpython.Py_buffer view 

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

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

52 try: 

53 if view.itemsize != 1: 

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

55 if view.len != size: 

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

57 return lowpp_type.from_ptr(<intptr_t><void *>view.buf, view.readonly != 0, buffer) 

58 finally: 

59 _cyb_cpython.PyBuffer_Release(&view) 

60  

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

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

63 if isinstance(data, lowpp_type): 

64 return data 

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

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

67 if data.size != 1: 

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

69 if data.dtype != expected_dtype: 

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

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

72  

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

74 cdef intptr_t ptr 

75 cdef int flags = _cyb_cpython.PyBUF_ANY_CONTIGUOUS 

76 if not readonly: 

77 flags |= _cyb_cpython.PyBUF_WRITABLE 

78 cdef int status = -1 

79 cdef _cyb_cpython.Py_buffer view 

80 if buf is None: 

81 ptr = 0 

82 elif isinstance(buf, int): 

83 ptr = <intptr_t>buf 

84 else: 

85 try: 

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

87 if size != -1: 

88 assert view.len == size 

89 except Exception as e: 

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

91 raise ValueError( 

92 "buf must be None, a Python int representing the pointer " 

93 f"address to a valid buffer, or a contiguous {adj}" 

94 f"buffer (a ctypes object, NumPy array, bytes, ...), of size {size}" 

95 ) from e 

96 else: 

97 ptr = <intptr_t>view.buf 

98 finally: 

99 if status == 0: 

100 _cyb_cpython.PyBuffer_Release(&view) 

101 return ptr 

102  

103  

104# <<<< END OF PREAMBLE CONTENT >>>> 

105  

106cimport cython # NOQA 

107from libc.stdint cimport intptr_t, uintptr_t 

108from libc.stdlib cimport malloc, free 

109  

110  

111  

112  

113  

114############################################################################### 

115# POD 

116############################################################################### 

117  

118cdef _get_external_memory_handle_desc_dtype_offsets(): 

119 cdef cudlaExternalMemoryHandleDesc_t pod 

120 return _numpy.dtype({ 

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

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

123 'offsets': [ 

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

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

126 ], 

127 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t), 

128 }) 

129  

130external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets() 

131  

132cdef class ExternalMemoryHandleDesc: 

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

134  

135  

136 .. seealso:: `cudlaExternalMemoryHandleDesc_t` 

137 """ 

138 cdef: 

139 cudlaExternalMemoryHandleDesc_t _data 

140 cudlaExternalMemoryHandleDesc_t *_ptr 

141 object _owner 

142 bint _readonly 

143  

144 def __init__(self): 

145 self._ptr = &self._data 1f

146 self._owner = None 1f

147 self._readonly = False 1f

148  

149 def __repr__(self): 

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

151  

152 @property 

153 def ptr(self): 

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

155 return <intptr_t>(self._ptr) 

156  

157 cdef intptr_t _get_ptr(self): 

158 return <intptr_t>(self._ptr) 

159  

160 def __int__(self): 

161 return <intptr_t>(self._ptr) 

162  

163 def __eq__(self, other): 

164 cdef ExternalMemoryHandleDesc other_ 

165 if not isinstance(other, ExternalMemoryHandleDesc): 

166 return False 

167 other_ = other 

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

169  

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

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

172  

173 def __releasebuffer__(self, Py_buffer *buffer): 

174 pass 

175  

176 def __setitem__(self, key, val): 

177 cdef _cyb_Py_buffer view 

178 if key == 0: 

179 if self._readonly: 

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

181 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

182 try: 

183 if <size_t>view.len < sizeof(cudlaExternalMemoryHandleDesc_t): 

184 raise ValueError( 

185 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaExternalMemoryHandleDesc_t), view.len) 

186 ) 

187 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaExternalMemoryHandleDesc_t)) 

188 self._ptr = &self._data 

189 self._owner = None 

190 self._readonly = view.readonly != 0 

191 finally: 

192 _cyb_PyBuffer_Release(&view) 

193 else: 

194 setattr(self, key, val) 

195  

196 @property 

197 def ext_buf_object(self): 

198 """int: """ 

199 return <intptr_t>(self._ptr[0].extBufObject) 1f

200  

201 @ext_buf_object.setter 

202 def ext_buf_object(self, val): 

203 if self._readonly: 1f

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

205 self._ptr[0].extBufObject = <void *><intptr_t>val 1f

206  

207 @property 

208 def size_(self): 

209 """int: """ 

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

211  

212 @size_.setter 

213 def size_(self, val): 

214 if self._readonly: 1f

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

216 self._ptr[0].size = val 1f

217  

218 @staticmethod 

219 def from_buffer(buffer): 

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

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

222  

223 @staticmethod 

224 def from_data(data): 

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

226  

227 Args: 

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

229 """ 

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

231  

232 @staticmethod 

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

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

235  

236 Args: 

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

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

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

240 """ 

241 if ptr == 0: 

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

243 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc) 

244 if owner is None: 

245 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaExternalMemoryHandleDesc_t)) 

246 obj._ptr = &obj._data 

247 obj._owner = None 

248 else: 

249 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr 

250 obj._owner = owner 

251 obj._readonly = readonly 

252 return obj 

253  

254  

255cdef _get_external_semaphore_handle_desc_dtype_offsets(): 

256 cdef cudlaExternalSemaphoreHandleDesc_t pod 

257 return _numpy.dtype({ 

258 'names': ['ext_sync_object'], 

259 'formats': [_numpy.intp], 

260 'offsets': [ 

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

262 ], 

263 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t), 

264 }) 

265  

266external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets() 

267  

268cdef class ExternalSemaphoreHandleDesc: 

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

270  

271  

272 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t` 

273 """ 

274 cdef: 

275 cudlaExternalSemaphoreHandleDesc_t _data 

276 cudlaExternalSemaphoreHandleDesc_t *_ptr 

277 object _owner 

278 bint _readonly 

279  

280 def __init__(self): 

281 self._ptr = &self._data 1l

282 self._owner = None 1l

283 self._readonly = False 1l

284  

285 def __repr__(self): 

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

287  

288 @property 

289 def ptr(self): 

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

291 return <intptr_t>(self._ptr) 

292  

293 cdef intptr_t _get_ptr(self): 

294 return <intptr_t>(self._ptr) 

295  

296 def __int__(self): 

297 return <intptr_t>(self._ptr) 

298  

299 def __eq__(self, other): 

300 cdef ExternalSemaphoreHandleDesc other_ 

301 if not isinstance(other, ExternalSemaphoreHandleDesc): 

302 return False 

303 other_ = other 

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

305  

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

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

308  

309 def __releasebuffer__(self, Py_buffer *buffer): 

310 pass 

311  

312 def __setitem__(self, key, val): 

313 cdef _cyb_Py_buffer view 

314 if key == 0: 

315 if self._readonly: 

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

317 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

318 try: 

319 if <size_t>view.len < sizeof(cudlaExternalSemaphoreHandleDesc_t): 

320 raise ValueError( 

321 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaExternalSemaphoreHandleDesc_t), view.len) 

322 ) 

323 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

324 self._ptr = &self._data 

325 self._owner = None 

326 self._readonly = view.readonly != 0 

327 finally: 

328 _cyb_PyBuffer_Release(&view) 

329 else: 

330 setattr(self, key, val) 

331  

332 @property 

333 def ext_sync_object(self): 

334 """int: """ 

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

336  

337 @ext_sync_object.setter 

338 def ext_sync_object(self, val): 

339 if self._readonly: 1l

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

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

342  

343 @staticmethod 

344 def from_buffer(buffer): 

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

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

347  

348 @staticmethod 

349 def from_data(data): 

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

351  

352 Args: 

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

354 """ 

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

356  

357 @staticmethod 

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

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

360  

361 Args: 

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

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

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

365 """ 

366 if ptr == 0: 

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

368 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc) 

369 if owner is None: 

370 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

371 obj._ptr = &obj._data 

372 obj._owner = None 

373 else: 

374 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr 

375 obj._owner = owner 

376 obj._readonly = readonly 

377 return obj 

378  

379  

380cdef _get_module_tensor_descriptor_dtype_offsets(): 

381 cdef cudlaModuleTensorDescriptor pod 

382 return _numpy.dtype({ 

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

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

385 'offsets': [ 

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

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

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

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

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

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

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

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

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

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

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

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

398 ], 

399 'itemsize': sizeof(cudlaModuleTensorDescriptor), 

400 }) 

401  

402module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets() 

403  

404cdef class ModuleTensorDescriptor: 

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

406  

407  

408 .. seealso:: `cudlaModuleTensorDescriptor` 

409 """ 

410 cdef: 

411 cudlaModuleTensorDescriptor _data 

412 cudlaModuleTensorDescriptor *_ptr 

413 object _owner 

414 bint _readonly 

415  

416 def __init__(self): 

417 self._ptr = &self._data 1epmg

418 self._owner = None 1epmg

419 self._readonly = False 1epmg

420  

421 def __repr__(self): 

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

423  

424 @property 

425 def ptr(self): 

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

427 return <intptr_t>(self._ptr) 

428  

429 cdef intptr_t _get_ptr(self): 

430 return <intptr_t>(self._ptr) 

431  

432 def __int__(self): 

433 return <intptr_t>(self._ptr) 1g

434  

435 def __eq__(self, other): 

436 cdef ModuleTensorDescriptor other_ 

437 if not isinstance(other, ModuleTensorDescriptor): 

438 return False 

439 other_ = other 

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

441  

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

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

444  

445 def __releasebuffer__(self, Py_buffer *buffer): 

446 pass 

447  

448 def __setitem__(self, key, val): 

449 cdef _cyb_Py_buffer view 

450 if key == 0: 

451 if self._readonly: 

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

453 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

454 try: 

455 if <size_t>view.len < sizeof(cudlaModuleTensorDescriptor): 

456 raise ValueError( 

457 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaModuleTensorDescriptor), view.len) 

458 ) 

459 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaModuleTensorDescriptor)) 

460 self._ptr = &self._data 

461 self._owner = None 

462 self._readonly = view.readonly != 0 

463 finally: 

464 _cyb_PyBuffer_Release(&view) 

465 else: 

466 setattr(self, key, val) 

467  

468 @property 

469 def name(self): 

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

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

472  

473 @name.setter 

474 def name(self, val): 

475 if self._readonly: 

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

477 cdef bytes buf = val.encode() 

478 if len(buf) >= 81: 

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

480 cdef char *ptr = buf 

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

482  

483 @property 

484 def size_(self): 

485 """int: """ 

486 return self._ptr[0].size 1e

487  

488 @size_.setter 

489 def size_(self, val): 

490 if self._readonly: 

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

492 self._ptr[0].size = val 

493  

494 @property 

495 def n(self): 

496 """int: """ 

497 return self._ptr[0].n 1e

498  

499 @n.setter 

500 def n(self, val): 

501 if self._readonly: 

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

503 self._ptr[0].n = val 

504  

505 @property 

506 def c(self): 

507 """int: """ 

508 return self._ptr[0].c 1e

509  

510 @c.setter 

511 def c(self, val): 

512 if self._readonly: 

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

514 self._ptr[0].c = val 

515  

516 @property 

517 def h(self): 

518 """int: """ 

519 return self._ptr[0].h 1e

520  

521 @h.setter 

522 def h(self, val): 

523 if self._readonly: 

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

525 self._ptr[0].h = val 

526  

527 @property 

528 def w(self): 

529 """int: """ 

530 return self._ptr[0].w 1e

531  

532 @w.setter 

533 def w(self, val): 

534 if self._readonly: 

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

536 self._ptr[0].w = val 

537  

538 @property 

539 def data_format(self): 

540 """int: """ 

541 return self._ptr[0].dataFormat 1e

542  

543 @data_format.setter 

544 def data_format(self, val): 

545 if self._readonly: 

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

547 self._ptr[0].dataFormat = val 

548  

549 @property 

550 def data_type(self): 

551 """int: """ 

552 return self._ptr[0].dataType 1e

553  

554 @data_type.setter 

555 def data_type(self, val): 

556 if self._readonly: 

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

558 self._ptr[0].dataType = val 

559  

560 @property 

561 def data_category(self): 

562 """int: """ 

563 return self._ptr[0].dataCategory 1e

564  

565 @data_category.setter 

566 def data_category(self, val): 

567 if self._readonly: 

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

569 self._ptr[0].dataCategory = val 

570  

571 @property 

572 def pixel_format(self): 

573 """int: """ 

574 return self._ptr[0].pixelFormat 1e

575  

576 @pixel_format.setter 

577 def pixel_format(self, val): 

578 if self._readonly: 

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

580 self._ptr[0].pixelFormat = val 

581  

582 @property 

583 def pixel_mapping(self): 

584 """int: """ 

585 return self._ptr[0].pixelMapping 1e

586  

587 @pixel_mapping.setter 

588 def pixel_mapping(self, val): 

589 if self._readonly: 

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

591 self._ptr[0].pixelMapping = val 

592  

593 @property 

594 def stride(self): 

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

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

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

598 return _numpy.asarray(arr) 1m

599  

600 @stride.setter 

601 def stride(self, val): 

602 if self._readonly: 

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

604 if len(val) != 8: 

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

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

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

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

609  

610 @staticmethod 

611 def from_buffer(buffer): 

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

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

614  

615 @staticmethod 

616 def from_data(data): 

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

618  

619 Args: 

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

621 """ 

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

623  

624 @staticmethod 

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

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

627  

628 Args: 

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

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

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

632 """ 

633 if ptr == 0: 

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

635 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor) 

636 if owner is None: 

637 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaModuleTensorDescriptor)) 

638 obj._ptr = &obj._data 

639 obj._owner = None 

640 else: 

641 obj._ptr = <cudlaModuleTensorDescriptor *>ptr 

642 obj._owner = owner 

643 obj._readonly = readonly 

644 return obj 

645  

646  

647cdef _get_fence_dtype_offsets(): 

648 cdef CudlaFence pod 

649 return _numpy.dtype({ 

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

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

652 'offsets': [ 

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

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

655 ], 

656 'itemsize': sizeof(CudlaFence), 

657 }) 

658  

659fence_dtype = _get_fence_dtype_offsets() 

660  

661cdef class Fence: 

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

663  

664  

665 .. seealso:: `CudlaFence` 

666 """ 

667 cdef: 

668 CudlaFence _data 

669 CudlaFence *_ptr 

670 object _owner 

671 bint _readonly 

672  

673 def __init__(self): 

674 self._ptr = &self._data 1h

675 self._owner = None 1h

676 self._readonly = False 1h

677  

678 def __repr__(self): 

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

680  

681 @property 

682 def ptr(self): 

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

684 return <intptr_t>(self._ptr) 

685  

686 cdef intptr_t _get_ptr(self): 

687 return <intptr_t>(self._ptr) 

688  

689 def __int__(self): 

690 return <intptr_t>(self._ptr) 

691  

692 def __eq__(self, other): 

693 cdef Fence other_ 

694 if not isinstance(other, Fence): 

695 return False 

696 other_ = other 

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

698  

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

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

701  

702 def __releasebuffer__(self, Py_buffer *buffer): 

703 pass 

704  

705 def __setitem__(self, key, val): 

706 cdef _cyb_Py_buffer view 

707 if key == 0: 

708 if self._readonly: 

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

710 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

711 try: 

712 if <size_t>view.len < sizeof(CudlaFence): 

713 raise ValueError( 

714 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(CudlaFence), view.len) 

715 ) 

716 _cyb_memmove(<void*>&self._data, view.buf, sizeof(CudlaFence)) 

717 self._ptr = &self._data 

718 self._owner = None 

719 self._readonly = view.readonly != 0 

720 finally: 

721 _cyb_PyBuffer_Release(&view) 

722 else: 

723 setattr(self, key, val) 

724  

725 @property 

726 def fence(self): 

727 """int: """ 

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

729  

730 @fence.setter 

731 def fence(self, val): 

732 if self._readonly: 1h

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

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

735  

736 @property 

737 def type(self): 

738 """int: """ 

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

740  

741 @type.setter 

742 def type(self, val): 

743 if self._readonly: 1h

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

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

746  

747 @staticmethod 

748 def from_buffer(buffer): 

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

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

751  

752 @staticmethod 

753 def from_data(data): 

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

755  

756 Args: 

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

758 """ 

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

760  

761 @staticmethod 

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

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

764  

765 Args: 

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

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

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

769 """ 

770 if ptr == 0: 

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

772 cdef Fence obj = Fence.__new__(Fence) 

773 if owner is None: 

774 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(CudlaFence)) 

775 obj._ptr = &obj._data 

776 obj._owner = None 

777 else: 

778 obj._ptr = <CudlaFence *>ptr 

779 obj._owner = owner 

780 obj._readonly = readonly 

781 return obj 

782  

783  

784cdef _get_dev_attribute_dtype_offsets(): 

785 cdef cudlaDevAttribute pod 

786 return _numpy.dtype({ 

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

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

789 'offsets': [ 

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

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

792 ], 

793 'itemsize': sizeof(cudlaDevAttribute), 

794 }) 

795  

796dev_attribute_dtype = _get_dev_attribute_dtype_offsets() 

797  

798cdef class DevAttribute: 

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

800  

801  

802 .. seealso:: `cudlaDevAttribute` 

803 """ 

804 cdef: 

805 cudlaDevAttribute _data 

806 cudlaDevAttribute *_ptr 

807 object _owner 

808 bint _readonly 

809  

810 def __init__(self): 

811 self._ptr = &self._data 1i

812 self._owner = None 1i

813 self._readonly = False 1i

814  

815 def __repr__(self): 

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

817  

818 @property 

819 def ptr(self): 

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

821 return <intptr_t>(self._ptr) 

822  

823 cdef intptr_t _get_ptr(self): 

824 return <intptr_t>(self._ptr) 

825  

826 def __int__(self): 

827 return <intptr_t>(self._ptr) 

828  

829 def __eq__(self, other): 

830 cdef DevAttribute other_ 

831 if not isinstance(other, DevAttribute): 

832 return False 

833 other_ = other 

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

835  

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

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

838  

839 def __releasebuffer__(self, Py_buffer *buffer): 

840 pass 

841  

842 def __setitem__(self, key, val): 

843 cdef _cyb_Py_buffer view 

844 if key == 0: 

845 if self._readonly: 

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

847 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

848 try: 

849 if <size_t>view.len < sizeof(cudlaDevAttribute): 

850 raise ValueError( 

851 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaDevAttribute), view.len) 

852 ) 

853 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaDevAttribute)) 

854 self._ptr = &self._data 

855 self._owner = None 

856 self._readonly = view.readonly != 0 

857 finally: 

858 _cyb_PyBuffer_Release(&view) 

859 else: 

860 setattr(self, key, val) 

861  

862 @property 

863 def unified_addressing_supported(self): 

864 """int: """ 

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

866  

867 @unified_addressing_supported.setter 

868 def unified_addressing_supported(self, val): 

869 if self._readonly: 1i

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

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

872  

873 @property 

874 def device_version(self): 

875 """int: """ 

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

877  

878 @device_version.setter 

879 def device_version(self, val): 

880 if self._readonly: 1i

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

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

883  

884 @staticmethod 

885 def from_buffer(buffer): 

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

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

888  

889 @staticmethod 

890 def from_data(data): 

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

892  

893 Args: 

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

895 """ 

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

897  

898 @staticmethod 

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

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

901  

902 Args: 

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

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

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

906 """ 

907 if ptr == 0: 

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

909 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute) 

910 if owner is None: 

911 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaDevAttribute)) 

912 obj._ptr = &obj._data 

913 obj._owner = None 

914 else: 

915 obj._ptr = <cudlaDevAttribute *>ptr 

916 obj._owner = owner 

917 obj._readonly = readonly 

918 return obj 

919  

920  

921cdef _get_module_attribute_dtype_offsets(): 

922 cdef cudlaModuleAttribute pod 

923 return _numpy.dtype({ 

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

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

926 'offsets': [ 

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

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

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

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

931 ], 

932 'itemsize': sizeof(cudlaModuleAttribute), 

933 }) 

934  

935module_attribute_dtype = _get_module_attribute_dtype_offsets() 

936  

937cdef class ModuleAttribute: 

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

939  

940  

941 .. seealso:: `cudlaModuleAttribute` 

942 """ 

943 cdef: 

944 cudlaModuleAttribute _data 

945 cudlaModuleAttribute *_ptr 

946 object _owner 

947 bint _readonly 

948  

949 def __init__(self): 

950 self._ptr = &self._data 1j

951 self._owner = None 1j

952 self._readonly = False 1j

953  

954 def __repr__(self): 

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

956  

957 @property 

958 def ptr(self): 

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

960 return <intptr_t>(self._ptr) 

961  

962 cdef intptr_t _get_ptr(self): 

963 return <intptr_t>(self._ptr) 

964  

965 def __int__(self): 

966 return <intptr_t>(self._ptr) 

967  

968 def __eq__(self, other): 

969 cdef ModuleAttribute other_ 

970 if not isinstance(other, ModuleAttribute): 

971 return False 

972 other_ = other 

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

974  

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

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

977  

978 def __releasebuffer__(self, Py_buffer *buffer): 

979 pass 

980  

981 def __setitem__(self, key, val): 

982 cdef _cyb_Py_buffer view 

983 if key == 0: 

984 if self._readonly: 

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

986 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

987 try: 

988 if <size_t>view.len < sizeof(cudlaModuleAttribute): 

989 raise ValueError( 

990 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaModuleAttribute), view.len) 

991 ) 

992 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaModuleAttribute)) 

993 self._ptr = &self._data 

994 self._owner = None 

995 self._readonly = view.readonly != 0 

996 finally: 

997 _cyb_PyBuffer_Release(&view) 

998 else: 

999 setattr(self, key, val) 

1000  

1001 @property 

1002 def num_input_tensors(self): 

1003 """int: """ 

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

1005  

1006 @num_input_tensors.setter 

1007 def num_input_tensors(self, val): 

1008 if self._readonly: 1j

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

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

1011  

1012 @property 

1013 def num_output_tensors(self): 

1014 """int: """ 

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

1016  

1017 @num_output_tensors.setter 

1018 def num_output_tensors(self, val): 

1019 if self._readonly: 1j

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

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

1022  

1023 @property 

1024 def input_tensor_desc(self): 

1025 """int: """ 

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

1027  

1028 @input_tensor_desc.setter 

1029 def input_tensor_desc(self, val): 

1030 if self._readonly: 

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

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

1033  

1034 @property 

1035 def output_tensor_desc(self): 

1036 """int: """ 

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

1038  

1039 @output_tensor_desc.setter 

1040 def output_tensor_desc(self, val): 

1041 if self._readonly: 

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

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

1044  

1045 @staticmethod 

1046 def from_buffer(buffer): 

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

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

1049  

1050 @staticmethod 

1051 def from_data(data): 

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

1053  

1054 Args: 

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

1056 """ 

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

1058  

1059 @staticmethod 

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

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

1062  

1063 Args: 

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

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

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

1067 """ 

1068 if ptr == 0: 

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

1070 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute) 

1071 if owner is None: 

1072 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaModuleAttribute)) 

1073 obj._ptr = &obj._data 

1074 obj._owner = None 

1075 else: 

1076 obj._ptr = <cudlaModuleAttribute *>ptr 

1077 obj._owner = owner 

1078 obj._readonly = readonly 

1079 return obj 

1080  

1081  

1082cdef _get_wait_events_dtype_offsets(): 

1083 cdef cudlaWaitEvents pod 

1084 return _numpy.dtype({ 

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

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

1087 'offsets': [ 

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

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

1090 ], 

1091 'itemsize': sizeof(cudlaWaitEvents), 

1092 }) 

1093  

1094wait_events_dtype = _get_wait_events_dtype_offsets() 

1095  

1096cdef class WaitEvents: 

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

1098  

1099  

1100 .. seealso:: `cudlaWaitEvents` 

1101 """ 

1102 cdef: 

1103 cudlaWaitEvents _data 

1104 cudlaWaitEvents *_ptr 

1105 object _owner 

1106 bint _readonly 

1107 dict _refs 

1108  

1109 def __init__(self): 

1110 self._ptr = &self._data 1n

1111 self._owner = None 1n

1112 self._readonly = False 1n

1113 self._refs = {} 1n

1114  

1115 def __repr__(self): 

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

1117  

1118 @property 

1119 def ptr(self): 

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

1121 return <intptr_t>(self._ptr) 

1122  

1123 cdef intptr_t _get_ptr(self): 

1124 return <intptr_t>(self._ptr) 

1125  

1126 def __int__(self): 

1127 return <intptr_t>(self._ptr) 

1128  

1129 def __eq__(self, other): 

1130 cdef WaitEvents other_ 

1131 if not isinstance(other, WaitEvents): 

1132 return False 

1133 other_ = other 

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

1135  

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

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

1138  

1139 def __releasebuffer__(self, Py_buffer *buffer): 

1140 pass 

1141  

1142 def __setitem__(self, key, val): 

1143 cdef _cyb_Py_buffer view 

1144 if key == 0: 

1145 if self._readonly: 

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

1147 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

1148 try: 

1149 if <size_t>view.len < sizeof(cudlaWaitEvents): 

1150 raise ValueError( 

1151 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaWaitEvents), view.len) 

1152 ) 

1153 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaWaitEvents)) 

1154 self._ptr = &self._data 

1155 self._owner = None 

1156 self._readonly = view.readonly != 0 

1157 finally: 

1158 _cyb_PyBuffer_Release(&view) 

1159 else: 

1160 setattr(self, key, val) 

1161  

1162 @property 

1163 def pre_fences(self): 

1164 """int: """ 

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

1166 return [] 1n

1167 return Fence.from_ptr( 

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

1169 self._ptr[0].numEvents, 

1170 owner=self, 

1171 readonly=self._readonly 

1172 ) 

1173  

1174 @pre_fences.setter 

1175 def pre_fences(self, val): 

1176 if self._readonly: 

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

1178 cdef Fence arr = val 

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

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

1181 self._refs["pre_fences"] = arr 

1182  

1183 @staticmethod 

1184 def from_buffer(buffer): 

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

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

1187  

1188 @staticmethod 

1189 def from_data(data): 

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

1191  

1192 Args: 

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

1194 """ 

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

1196  

1197 @staticmethod 

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

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

1200  

1201 Args: 

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

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

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

1205 """ 

1206 if ptr == 0: 

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

1208 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents) 

1209 if owner is None: 

1210 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaWaitEvents)) 

1211 obj._ptr = &obj._data 

1212 obj._owner = None 

1213 else: 

1214 obj._ptr = <cudlaWaitEvents *>ptr 

1215 obj._owner = owner 

1216 obj._readonly = readonly 

1217 obj._refs = {} 

1218 return obj 

1219  

1220  

1221cdef _get_signal_events_dtype_offsets(): 

1222 cdef cudlaSignalEvents pod 

1223 return _numpy.dtype({ 

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

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

1226 'offsets': [ 

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

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

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

1230 ], 

1231 'itemsize': sizeof(cudlaSignalEvents), 

1232 }) 

1233  

1234signal_events_dtype = _get_signal_events_dtype_offsets() 

1235  

1236cdef class SignalEvents: 

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

1238  

1239  

1240 .. seealso:: `cudlaSignalEvents` 

1241 """ 

1242 cdef: 

1243 cudlaSignalEvents _data 

1244 cudlaSignalEvents *_ptr 

1245 object _owner 

1246 bint _readonly 

1247 dict _refs 

1248  

1249 def __init__(self): 

1250 self._ptr = &self._data 1o

1251 self._owner = None 1o

1252 self._readonly = False 1o

1253 self._refs = {} 1o

1254  

1255 def __repr__(self): 

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

1257  

1258 @property 

1259 def ptr(self): 

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

1261 return <intptr_t>(self._ptr) 

1262  

1263 cdef intptr_t _get_ptr(self): 

1264 return <intptr_t>(self._ptr) 

1265  

1266 def __int__(self): 

1267 return <intptr_t>(self._ptr) 

1268  

1269 def __eq__(self, other): 

1270 cdef SignalEvents other_ 

1271 if not isinstance(other, SignalEvents): 

1272 return False 

1273 other_ = other 

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

1275  

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

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

1278  

1279 def __releasebuffer__(self, Py_buffer *buffer): 

1280 pass 

1281  

1282 def __setitem__(self, key, val): 

1283 cdef _cyb_Py_buffer view 

1284 if key == 0: 

1285 if self._readonly: 

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

1287 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

1288 try: 

1289 if <size_t>view.len < sizeof(cudlaSignalEvents): 

1290 raise ValueError( 

1291 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaSignalEvents), view.len) 

1292 ) 

1293 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaSignalEvents)) 

1294 self._ptr = &self._data 

1295 self._owner = None 

1296 self._readonly = view.readonly != 0 

1297 finally: 

1298 _cyb_PyBuffer_Release(&view) 

1299 else: 

1300 setattr(self, key, val) 

1301  

1302 @property 

1303 def dev_ptrs(self): 

1304 """int: """ 

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

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

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

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

1309 return arr 

1310  

1311 @dev_ptrs.setter 

1312 def dev_ptrs(self, val): 

1313 if self._readonly: 

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

1315 cdef Py_ssize_t _n = len(val) 

1316 self._ptr[0].numEvents = _n 

1317 if _n == 0: 

1318 return 

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

1320 cdef intptr_t[:] mv = arr 

1321 cdef Py_ssize_t i 

1322 for i in range(_n): 

1323 mv[i] = val[i] 

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

1325 self._refs["dev_ptrs"] = arr 

1326  

1327 @property 

1328 def eof_fences(self): 

1329 """int: """ 

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

1331 return [] 1o

1332 return Fence.from_ptr( 

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

1334 self._ptr[0].numEvents, 

1335 owner=self, 

1336 readonly=self._readonly 

1337 ) 

1338  

1339 @eof_fences.setter 

1340 def eof_fences(self, val): 

1341 if self._readonly: 

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

1343 cdef Fence arr = val 

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

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

1346 self._refs["eof_fences"] = arr 

1347  

1348 @staticmethod 

1349 def from_buffer(buffer): 

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

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

1352  

1353 @staticmethod 

1354 def from_data(data): 

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

1356  

1357 Args: 

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

1359 """ 

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

1361  

1362 @staticmethod 

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

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

1365  

1366 Args: 

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

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

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

1370 """ 

1371 if ptr == 0: 

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

1373 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents) 

1374 if owner is None: 

1375 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaSignalEvents)) 

1376 obj._ptr = &obj._data 

1377 obj._owner = None 

1378 else: 

1379 obj._ptr = <cudlaSignalEvents *>ptr 

1380 obj._owner = owner 

1381 obj._readonly = readonly 

1382 obj._refs = {} 

1383 return obj 

1384  

1385  

1386cdef _get_task_dtype_offsets(): 

1387 cdef cudlaTask pod 

1388 return _numpy.dtype({ 

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

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

1391 'offsets': [ 

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

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

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

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

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

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

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

1399 ], 

1400 'itemsize': sizeof(cudlaTask), 

1401 }) 

1402  

1403task_dtype = _get_task_dtype_offsets() 

1404  

1405cdef class Task: 

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

1407  

1408  

1409 .. seealso:: `cudlaTask` 

1410 """ 

1411 cdef: 

1412 cudlaTask _data 

1413 cudlaTask *_ptr 

1414 object _owner 

1415 bint _readonly 

1416 dict _refs 

1417  

1418 def __init__(self): 

1419 self._ptr = &self._data 1gbkcd

1420 self._owner = None 1gbkcd

1421 self._readonly = False 1gbkcd

1422 self._refs = {} 1gbkcd

1423  

1424 def __repr__(self): 

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

1426  

1427 @property 

1428 def ptr(self): 

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

1430 return <intptr_t>(self._ptr) 

1431  

1432 cdef intptr_t _get_ptr(self): 

1433 return <intptr_t>(self._ptr) 

1434  

1435 def __int__(self): 

1436 return <intptr_t>(self._ptr) 1g

1437  

1438 def __eq__(self, other): 

1439 cdef Task other_ 

1440 if not isinstance(other, Task): 

1441 return False 

1442 other_ = other 

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

1444  

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

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

1447  

1448 def __releasebuffer__(self, Py_buffer *buffer): 

1449 pass 

1450  

1451 def __setitem__(self, key, val): 

1452 cdef _cyb_Py_buffer view 

1453 if key == 0: 

1454 if self._readonly: 

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

1456 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

1457 try: 

1458 if <size_t>view.len < sizeof(cudlaTask): 

1459 raise ValueError( 

1460 "source buffer too small: expected at least %d bytes, got %d" % (sizeof(cudlaTask), view.len) 

1461 ) 

1462 _cyb_memmove(<void*>&self._data, view.buf, sizeof(cudlaTask)) 

1463 self._ptr = &self._data 

1464 self._owner = None 

1465 self._readonly = view.readonly != 0 

1466 finally: 

1467 _cyb_PyBuffer_Release(&view) 

1468 else: 

1469 setattr(self, key, val) 

1470  

1471 @property 

1472 def module_handle(self): 

1473 """int: """ 

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

1475  

1476 @module_handle.setter 

1477 def module_handle(self, val): 

1478 if self._readonly: 1bk

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

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

1481  

1482 @property 

1483 def output_tensor(self): 

1484 """int: """ 

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

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

1487 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

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

1489 return arr 1bd

1490  

1491 @output_tensor.setter 

1492 def output_tensor(self, val): 

1493 if self._readonly: 1bd

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

1495 cdef Py_ssize_t _n = len(val) 1bd

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

1497 if _n == 0: 1bd

1498 return 

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

1500 cdef intptr_t[:] mv = arr 1bd

1501 cdef Py_ssize_t i 

1502 for i in range(_n): 1bd

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

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

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

1506  

1507 @property 

1508 def input_tensor(self): 

1509 """int: """ 

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

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

1512 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

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

1514 return arr 1bc

1515  

1516 @input_tensor.setter 

1517 def input_tensor(self, val): 

1518 if self._readonly: 1bc

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

1520 cdef Py_ssize_t _n = len(val) 1bc

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

1522 if _n == 0: 1bc

1523 return 

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

1525 cdef intptr_t[:] mv = arr 1bc

1526 cdef Py_ssize_t i 

1527 for i in range(_n): 1bc

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

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

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

1531  

1532 @property 

1533 def wait_events(self): 

1534 """int: """ 

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

1536  

1537 @wait_events.setter 

1538 def wait_events(self, val): 

1539 if self._readonly: 1b

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

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

1542  

1543 @property 

1544 def signal_events(self): 

1545 """int: """ 

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

1547  

1548 @signal_events.setter 

1549 def signal_events(self, val): 

1550 if self._readonly: 1b

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

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

1553  

1554 @staticmethod 

1555 def from_buffer(buffer): 

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

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

1558  

1559 @staticmethod 

1560 def from_data(data): 

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

1562  

1563 Args: 

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

1565 """ 

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

1567  

1568 @staticmethod 

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

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

1571  

1572 Args: 

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

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

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

1576 """ 

1577 if ptr == 0: 

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

1579 cdef Task obj = Task.__new__(Task) 

1580 if owner is None: 

1581 _cyb_memcpy(<void*>&obj._data, <void*>ptr, sizeof(cudlaTask)) 

1582 obj._ptr = &obj._data 

1583 obj._owner = None 

1584 else: 

1585 obj._ptr = <cudlaTask *>ptr 

1586 obj._owner = owner 

1587 obj._readonly = readonly 

1588 obj._refs = {} 

1589 return obj 

1590  

1591  

1592############################################################################### 

1593# Enum 

1594############################################################################### 

1595  

1596class Status(_cyb_IntEnum): 

1597 """ 

1598 See `cudlaStatus`. 

1599 """ 

1600 SUCCESS = cudlaSuccess 

1601 Success = SUCCESS # backward-compat alias 

1602 ERROR_INVALID_PARAM = cudlaErrorInvalidParam 

1603 ErrorInvalidParam = ERROR_INVALID_PARAM # backward-compat alias 

1604 ERROR_OUT_OF_RESOURCES = cudlaErrorOutOfResources 

1605 ErrorOutOfResources = ERROR_OUT_OF_RESOURCES # backward-compat alias 

1606 ERROR_CREATION_FAILED = cudlaErrorCreationFailed 

1607 ErrorCreationFailed = ERROR_CREATION_FAILED # backward-compat alias 

1608 ERROR_INVALID_ADDRESS = cudlaErrorInvalidAddress 

1609 ErrorInvalidAddress = ERROR_INVALID_ADDRESS # backward-compat alias 

1610 ERROR_OS = cudlaErrorOs 

1611 ErrorOs = ERROR_OS # backward-compat alias 

1612 ERROR_CUDA = cudlaErrorCuda 

1613 ErrorCuda = ERROR_CUDA # backward-compat alias 

1614 ERROR_UMD = cudlaErrorUmd 

1615 ErrorUmd = ERROR_UMD # backward-compat alias 

1616 ERROR_INVALID_DEVICE = cudlaErrorInvalidDevice 

1617 ErrorInvalidDevice = ERROR_INVALID_DEVICE # backward-compat alias 

1618 ERROR_INVALID_ATTRIBUTE = cudlaErrorInvalidAttribute 

1619 ErrorInvalidAttribute = ERROR_INVALID_ATTRIBUTE # backward-compat alias 

1620 ERROR_INCOMPATIBLE_DLA_SW_VERSION = cudlaErrorIncompatibleDlaSWVersion 

1621 ErrorIncompatibleDlaSWVersion = ERROR_INCOMPATIBLE_DLA_SW_VERSION # backward-compat alias 

1622 ERROR_MEMORY_REGISTERED = cudlaErrorMemoryRegistered 

1623 ErrorMemoryRegistered = ERROR_MEMORY_REGISTERED # backward-compat alias 

1624 ERROR_INVALID_MODULE = cudlaErrorInvalidModule 

1625 ErrorInvalidModule = ERROR_INVALID_MODULE # backward-compat alias 

1626 ERROR_UNSUPPORTED_OPERATION = cudlaErrorUnsupportedOperation 

1627 ErrorUnsupportedOperation = ERROR_UNSUPPORTED_OPERATION # backward-compat alias 

1628 ERROR_NV_SCI = cudlaErrorNvSci 

1629 ErrorNvSci = ERROR_NV_SCI # backward-compat alias 

1630 ERROR_DRIVER_NOT_FOUND = cudlaErrorDriverNotFound 

1631 ErrorDriverNotFound = ERROR_DRIVER_NOT_FOUND # backward-compat alias 

1632 ERROR_DLA_ERR_INVALID_INPUT = cudlaErrorDlaErrInvalidInput 

1633 ErrorDlaErrInvalidInput = ERROR_DLA_ERR_INVALID_INPUT # backward-compat alias 

1634 ERROR_DLA_ERR_INVALID_PRE_ACTION = cudlaErrorDlaErrInvalidPreAction 

1635 ErrorDlaErrInvalidPreAction = ERROR_DLA_ERR_INVALID_PRE_ACTION # backward-compat alias 

1636 ERROR_DLA_ERR_NO_MEM = cudlaErrorDlaErrNoMem 

1637 ErrorDlaErrNoMem = ERROR_DLA_ERR_NO_MEM # backward-compat alias 

1638 ERROR_DLA_ERR_PROCESSOR_BUSY = cudlaErrorDlaErrProcessorBusy 

1639 ErrorDlaErrProcessorBusy = ERROR_DLA_ERR_PROCESSOR_BUSY # backward-compat alias 

1640 ERROR_DLA_ERR_TASK_STATUS_MISMATCH = cudlaErrorDlaErrTaskStatusMismatch 

1641 ErrorDlaErrTaskStatusMismatch = ERROR_DLA_ERR_TASK_STATUS_MISMATCH # backward-compat alias 

1642 ERROR_DLA_ERR_ENGINE_TIMEOUT = cudlaErrorDlaErrEngineTimeout 

1643 ErrorDlaErrEngineTimeout = ERROR_DLA_ERR_ENGINE_TIMEOUT # backward-compat alias 

1644 ERROR_DLA_ERR_DATA_MISMATCH = cudlaErrorDlaErrDataMismatch 

1645 ErrorDlaErrDataMismatch = ERROR_DLA_ERR_DATA_MISMATCH # backward-compat alias 

1646 ERROR_UNKNOWN = cudlaErrorUnknown 

1647 ErrorUnknown = ERROR_UNKNOWN # backward-compat alias 

1648  

1649class Mode(_cyb_IntEnum): 

1650 """ 

1651 See `cudlaMode`. 

1652 """ 

1653 CUDA_DLA = CUDLA_CUDA_DLA 

1654 STANDALONE = CUDLA_STANDALONE 

1655  

1656class ModuleAttributeType(_cyb_IntEnum): 

1657 """ 

1658 See `cudlaModuleAttributeType`. 

1659 """ 

1660 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS 

1661 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS 

1662 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS 

1663 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS 

1664 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1665 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS 

1666  

1667class FenceType(_cyb_IntEnum): 

1668 """ 

1669 See `cudlaFenceType`. 

1670 """ 

1671 FENCE = CUDLA_NVSCISYNC_FENCE 

1672 NVSCISYNC_FENCE = FENCE # backward-compat alias 

1673 FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF 

1674 NVSCISYNC_FENCE_SOF = FENCE_SOF # backward-compat alias 

1675  

1676class ModuleLoadFlags(_cyb_IntEnum): 

1677 """ 

1678 See `cudlaModuleLoadFlags`. 

1679 """ 

1680 DEFAULT = CUDLA_MODULE_DEFAULT 

1681 MODULE_DEFAULT = DEFAULT # backward-compat alias 

1682 ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS 

1683 MODULE_ENABLE_FAULT_DIAGNOSTICS = ENABLE_FAULT_DIAGNOSTICS # backward-compat alias 

1684  

1685class SubmissionFlags(_cyb_IntEnum): 

1686 """ 

1687 See `cudlaSubmissionFlags`. 

1688 """ 

1689 NOOP = CUDLA_SUBMIT_NOOP 

1690 SUBMIT_NOOP = NOOP # backward-compat alias 

1691 SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE 

1692 SUBMIT_SKIP_LOCK_ACQUIRE = SKIP_LOCK_ACQUIRE # backward-compat alias 

1693 DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK 

1694 SUBMIT_DIAGNOSTICS_TASK = DIAGNOSTICS_TASK # backward-compat alias 

1695  

1696class AccessPermissionFlags(_cyb_IntEnum): 

1697 """ 

1698 See `cudlaAccessPermissionFlags`. 

1699 """ 

1700 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM 

1701 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM 

1702 TASK_STATISTICS = CUDLA_TASK_STATISTICS 

1703  

1704class DevAttributeType(_cyb_IntEnum): 

1705 """ 

1706 See `cudlaDevAttributeType`. 

1707 """ 

1708 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING 

1709 DEVICE_VERSION = CUDLA_DEVICE_VERSION 

1710  

1711class ScratchMemoryConfig(_cyb_IntEnum): 

1712 """ 

1713 See `cudlaScratchMemoryConfig`. 

1714 """ 

1715 DEFAULT = CUDLA_SCRATCH_MEMORY_DEFAULT 

1716 SCRATCH_MEMORY_DEFAULT = DEFAULT # backward-compat alias 

1717 SHARED_STATIC = CUDLA_SCRATCH_MEMORY_SHARED_STATIC 

1718 SCRATCH_MEMORY_SHARED_STATIC = SHARED_STATIC # backward-compat alias 

1719 CONFIG_MAX = CUDLA_SCRATCH_MEMORY_CONFIG_MAX 

1720 MAX = CONFIG_MAX # backward-compat alias 

1721  

1722  

1723############################################################################### 

1724# Error handling 

1725############################################################################### 

1726  

1727class CudlaError(Exception): 

1728  

1729 def __init__(self, status): 

1730 self.status = status 1qr

1731 s = Status(status) 1qr

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

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

1734  

1735 def __reduce__(self): 

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

1737  

1738  

1739@cython.profile(False) 

1740cpdef inline check_status(int status): 

1741 if status != 0: 

1742 raise CudlaError(status) 

1743  

1744  

1745############################################################################### 

1746# Wrapper functions 

1747############################################################################### 

1748  

1749cpdef uint64_t get_version() except? -1: 

1750 cdef uint64_t version 

1751 with nogil: 

1752 __status__ = cudlaGetVersion(&version) 

1753 check_status(__status__) 

1754 return version 

1755  

1756  

1757cpdef uint64_t device_get_count() except? -1: 

1758 cdef uint64_t p_num_devices 

1759 with nogil: 

1760 __status__ = cudlaDeviceGetCount(&p_num_devices) 

1761 check_status(__status__) 

1762 return p_num_devices 

1763  

1764  

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

1766 cdef DevHandle dev_handle 

1767 if flags & CUDLA_STANDALONE: 

1768 raise CudlaError(cudlaErrorUnsupportedOperation) 

1769 with nogil: 

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

1771 check_status(__status__) 

1772 return <intptr_t>dev_handle 

1773  

1774  

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

1776 cdef uint64_t* dev_ptr 

1777 with nogil: 

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

1779 check_status(__status__) 

1780 return <intptr_t>dev_ptr 

1781  

1782  

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

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

1785 cdef Module h_module 

1786 with nogil: 

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

1788 check_status(__status__) 

1789 return <intptr_t>h_module 

1790  

1791  

1792cpdef module_unload(intptr_t h_module, uint32_t flags): 

1793 with nogil: 

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

1795 check_status(__status__) 

1796  

1797  

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

1799 cdef intptr_t _ptr_to_tasks_ptr_ = 0 if ptr_to_tasks is None else int(ptr_to_tasks) 

1800 with nogil: 

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

1802 check_status(__status__) 

1803  

1804  

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

1806 cdef DevAttribute p_attribute_py = DevAttribute() 

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

1808 with nogil: 

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

1810 check_status(__status__) 

1811 return p_attribute_py 

1812  

1813  

1814cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr): 

1815 with nogil: 

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

1817 check_status(__status__) 

1818  

1819  

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

1821 cdef int ret 

1822 with nogil: 

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

1824 return ret 

1825  

1826  

1827cpdef destroy_device(intptr_t dev_handle): 

1828 with nogil: 

1829 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle) 

1830 check_status(__status__) 

1831  

1832  

1833cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout): 

1834 with nogil: 

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

1836 check_status(__status__) 

1837  

1838  

1839cpdef module_get_attributes(intptr_t h_module, int attr_type): 

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

1841 based on the requested attribute type. 

1842  

1843 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS, 

1844 NUM_OUTPUT_TASK_STATISTICS), returns an int. 

1845  

1846 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS, 

1847 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS), 

1848 returns a list of ModuleTensorDescriptor objects. 

1849 """ 

1850 cdef int _attr_type = attr_type 

1851 cdef cudlaModuleAttribute count_attr 

1852 cdef cudlaModuleAttribute num_attr 

1853 cdef cudlaModuleAttribute desc_attr 

1854 cdef uint32_t count 

1855 cdef cudlaModuleTensorDescriptor* desc_buf 

1856 cdef uint32_t i 

1857 cdef int num_attr_type 

1858  

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

1860 with nogil: 

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

1862 check_status(__status__) 

1863 return <int>(count_attr.numInputTensors) 

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

1865 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS: 

1866 num_attr_type = CUDLA_NUM_INPUT_TENSORS 

1867 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS: 

1868 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS 

1869 else: 

1870 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1871 with nogil: 

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

1873 check_status(__status__) 

1874 count = num_attr.numInputTensors 

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

1876 if desc_buf == NULL: 

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

1878 try: 

1879 desc_attr.inputTensorDesc = desc_buf 

1880 with nogil: 

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

1882 check_status(__status__) 

1883 result = [] 

1884 for i in range(count): 

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

1886 return result 

1887 finally: 

1888 free(desc_buf) 

1889 else: 

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

1891del _cyb_IntEnum