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

917 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-16 01:23 +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=7a208273ab596a5fc3e4ce5ca2f4cd474a4d3e649aa06b78bc8e5564fe2cebfd 

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 assert view.ndim == 1 

90 except Exception as e: 

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

92 raise ValueError( 

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

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

95 f"buffer, of size {size}" 

96 ) from e 

97 else: 

98 ptr = <intptr_t>view.buf 

99 finally: 

100 if status == 0: 

101 _cyb_cpython.PyBuffer_Release(&view) 

102 return ptr 

103  

104  

105# <<<< END OF PREAMBLE CONTENT >>>> 

106  

107cimport cython # NOQA 

108from libc.stdint cimport intptr_t, uintptr_t 

109from libc.stdlib cimport malloc, free 

110  

111  

112  

113  

114  

115############################################################################### 

116# POD 

117############################################################################### 

118  

119cdef _get_external_memory_handle_desc_dtype_offsets(): 

120 cdef cudlaExternalMemoryHandleDesc_t pod 

121 return _numpy.dtype({ 

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

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

124 'offsets': [ 

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

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

127 ], 

128 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t), 

129 }) 

130  

131external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets() 

132  

133cdef class ExternalMemoryHandleDesc: 

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

135  

136  

137 .. seealso:: `cudlaExternalMemoryHandleDesc_t` 

138 """ 

139 cdef: 

140 cudlaExternalMemoryHandleDesc_t _data 

141 cudlaExternalMemoryHandleDesc_t *_ptr 

142 object _owner 

143 bint _readonly 

144  

145 def __init__(self): 

146 self._ptr = &self._data 1f

147 self._owner = None 1f

148 self._readonly = False 1f

149  

150 def __repr__(self): 

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

152  

153 @property 

154 def ptr(self): 

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

156 return <intptr_t>(self._ptr) 

157  

158 cdef intptr_t _get_ptr(self): 

159 return <intptr_t>(self._ptr) 

160  

161 def __int__(self): 

162 return <intptr_t>(self._ptr) 

163  

164 def __eq__(self, other): 

165 cdef ExternalMemoryHandleDesc other_ 

166 if not isinstance(other, ExternalMemoryHandleDesc): 

167 return False 

168 other_ = other 

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

170  

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

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

173  

174 def __releasebuffer__(self, Py_buffer *buffer): 

175 pass 

176  

177 def __setitem__(self, key, val): 

178 cdef _cyb_Py_buffer view 

179 if key == 0: 

180 if self._readonly: 

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

182 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

183 try: 

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

185 raise ValueError( 

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

187 ) 

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

189 self._ptr = &self._data 

190 self._owner = None 

191 self._readonly = view.readonly != 0 

192 finally: 

193 _cyb_PyBuffer_Release(&view) 

194 else: 

195 setattr(self, key, val) 

196  

197 @property 

198 def ext_buf_object(self): 

199 """int: """ 

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

201  

202 @ext_buf_object.setter 

203 def ext_buf_object(self, val): 

204 if self._readonly: 1f

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

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

207  

208 @property 

209 def size_(self): 

210 """int: """ 

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

212  

213 @size_.setter 

214 def size_(self, val): 

215 if self._readonly: 1f

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

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

218  

219 @staticmethod 

220 def from_buffer(buffer): 

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

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

223  

224 @staticmethod 

225 def from_data(data): 

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

227  

228 Args: 

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

230 """ 

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

232  

233 @staticmethod 

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

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

236  

237 Args: 

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

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

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

241 """ 

242 if ptr == 0: 

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

244 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc) 

245 if owner is None: 

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

247 obj._ptr = &obj._data 

248 obj._owner = None 

249 else: 

250 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr 

251 obj._owner = owner 

252 obj._readonly = readonly 

253 return obj 

254  

255  

256cdef _get_external_semaphore_handle_desc_dtype_offsets(): 

257 cdef cudlaExternalSemaphoreHandleDesc_t pod 

258 return _numpy.dtype({ 

259 'names': ['ext_sync_object'], 

260 'formats': [_numpy.intp], 

261 'offsets': [ 

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

263 ], 

264 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t), 

265 }) 

266  

267external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets() 

268  

269cdef class ExternalSemaphoreHandleDesc: 

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

271  

272  

273 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t` 

274 """ 

275 cdef: 

276 cudlaExternalSemaphoreHandleDesc_t _data 

277 cudlaExternalSemaphoreHandleDesc_t *_ptr 

278 object _owner 

279 bint _readonly 

280  

281 def __init__(self): 

282 self._ptr = &self._data 1l

283 self._owner = None 1l

284 self._readonly = False 1l

285  

286 def __repr__(self): 

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

288  

289 @property 

290 def ptr(self): 

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

292 return <intptr_t>(self._ptr) 

293  

294 cdef intptr_t _get_ptr(self): 

295 return <intptr_t>(self._ptr) 

296  

297 def __int__(self): 

298 return <intptr_t>(self._ptr) 

299  

300 def __eq__(self, other): 

301 cdef ExternalSemaphoreHandleDesc other_ 

302 if not isinstance(other, ExternalSemaphoreHandleDesc): 

303 return False 

304 other_ = other 

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

306  

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

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

309  

310 def __releasebuffer__(self, Py_buffer *buffer): 

311 pass 

312  

313 def __setitem__(self, key, val): 

314 cdef _cyb_Py_buffer view 

315 if key == 0: 

316 if self._readonly: 

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

318 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

319 try: 

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

321 raise ValueError( 

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

323 ) 

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

325 self._ptr = &self._data 

326 self._owner = None 

327 self._readonly = view.readonly != 0 

328 finally: 

329 _cyb_PyBuffer_Release(&view) 

330 else: 

331 setattr(self, key, val) 

332  

333 @property 

334 def ext_sync_object(self): 

335 """int: """ 

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

337  

338 @ext_sync_object.setter 

339 def ext_sync_object(self, val): 

340 if self._readonly: 1l

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

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

343  

344 @staticmethod 

345 def from_buffer(buffer): 

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

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

348  

349 @staticmethod 

350 def from_data(data): 

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

352  

353 Args: 

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

355 """ 

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

357  

358 @staticmethod 

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

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

361  

362 Args: 

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

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

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

366 """ 

367 if ptr == 0: 

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

369 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc) 

370 if owner is None: 

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

372 obj._ptr = &obj._data 

373 obj._owner = None 

374 else: 

375 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr 

376 obj._owner = owner 

377 obj._readonly = readonly 

378 return obj 

379  

380  

381cdef _get_module_tensor_descriptor_dtype_offsets(): 

382 cdef cudlaModuleTensorDescriptor pod 

383 return _numpy.dtype({ 

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

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

386 'offsets': [ 

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

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

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

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

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

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

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

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

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

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

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

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

399 ], 

400 'itemsize': sizeof(cudlaModuleTensorDescriptor), 

401 }) 

402  

403module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets() 

404  

405cdef class ModuleTensorDescriptor: 

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

407  

408  

409 .. seealso:: `cudlaModuleTensorDescriptor` 

410 """ 

411 cdef: 

412 cudlaModuleTensorDescriptor _data 

413 cudlaModuleTensorDescriptor *_ptr 

414 object _owner 

415 bint _readonly 

416  

417 def __init__(self): 

418 self._ptr = &self._data 1epmg

419 self._owner = None 1epmg

420 self._readonly = False 1epmg

421  

422 def __repr__(self): 

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

424  

425 @property 

426 def ptr(self): 

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

428 return <intptr_t>(self._ptr) 

429  

430 cdef intptr_t _get_ptr(self): 

431 return <intptr_t>(self._ptr) 

432  

433 def __int__(self): 

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

435  

436 def __eq__(self, other): 

437 cdef ModuleTensorDescriptor other_ 

438 if not isinstance(other, ModuleTensorDescriptor): 

439 return False 

440 other_ = other 

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

442  

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

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

445  

446 def __releasebuffer__(self, Py_buffer *buffer): 

447 pass 

448  

449 def __setitem__(self, key, val): 

450 cdef _cyb_Py_buffer view 

451 if key == 0: 

452 if self._readonly: 

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

454 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

455 try: 

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

457 raise ValueError( 

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

459 ) 

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

461 self._ptr = &self._data 

462 self._owner = None 

463 self._readonly = view.readonly != 0 

464 finally: 

465 _cyb_PyBuffer_Release(&view) 

466 else: 

467 setattr(self, key, val) 

468  

469 @property 

470 def name(self): 

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

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

473  

474 @name.setter 

475 def name(self, val): 

476 if self._readonly: 

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

478 cdef bytes buf = val.encode() 

479 if len(buf) >= 81: 

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

481 cdef char *ptr = buf 

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

483  

484 @property 

485 def size_(self): 

486 """int: """ 

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

488  

489 @size_.setter 

490 def size_(self, val): 

491 if self._readonly: 

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

493 self._ptr[0].size = val 

494  

495 @property 

496 def n(self): 

497 """int: """ 

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

499  

500 @n.setter 

501 def n(self, val): 

502 if self._readonly: 

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

504 self._ptr[0].n = val 

505  

506 @property 

507 def c(self): 

508 """int: """ 

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

510  

511 @c.setter 

512 def c(self, val): 

513 if self._readonly: 

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

515 self._ptr[0].c = val 

516  

517 @property 

518 def h(self): 

519 """int: """ 

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

521  

522 @h.setter 

523 def h(self, val): 

524 if self._readonly: 

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

526 self._ptr[0].h = val 

527  

528 @property 

529 def w(self): 

530 """int: """ 

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

532  

533 @w.setter 

534 def w(self, val): 

535 if self._readonly: 

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

537 self._ptr[0].w = val 

538  

539 @property 

540 def data_format(self): 

541 """int: """ 

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

543  

544 @data_format.setter 

545 def data_format(self, val): 

546 if self._readonly: 

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

548 self._ptr[0].dataFormat = val 

549  

550 @property 

551 def data_type(self): 

552 """int: """ 

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

554  

555 @data_type.setter 

556 def data_type(self, val): 

557 if self._readonly: 

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

559 self._ptr[0].dataType = val 

560  

561 @property 

562 def data_category(self): 

563 """int: """ 

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

565  

566 @data_category.setter 

567 def data_category(self, val): 

568 if self._readonly: 

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

570 self._ptr[0].dataCategory = val 

571  

572 @property 

573 def pixel_format(self): 

574 """int: """ 

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

576  

577 @pixel_format.setter 

578 def pixel_format(self, val): 

579 if self._readonly: 

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

581 self._ptr[0].pixelFormat = val 

582  

583 @property 

584 def pixel_mapping(self): 

585 """int: """ 

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

587  

588 @pixel_mapping.setter 

589 def pixel_mapping(self, val): 

590 if self._readonly: 

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

592 self._ptr[0].pixelMapping = val 

593  

594 @property 

595 def stride(self): 

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

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

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

599 return _numpy.asarray(arr) 1m

600  

601 @stride.setter 

602 def stride(self, val): 

603 if self._readonly: 

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

605 if len(val) != 8: 

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

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

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

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

610  

611 @staticmethod 

612 def from_buffer(buffer): 

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

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

615  

616 @staticmethod 

617 def from_data(data): 

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

619  

620 Args: 

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

622 """ 

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

624  

625 @staticmethod 

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

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

628  

629 Args: 

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

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

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

633 """ 

634 if ptr == 0: 

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

636 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor) 

637 if owner is None: 

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

639 obj._ptr = &obj._data 

640 obj._owner = None 

641 else: 

642 obj._ptr = <cudlaModuleTensorDescriptor *>ptr 

643 obj._owner = owner 

644 obj._readonly = readonly 

645 return obj 

646  

647  

648cdef _get_fence_dtype_offsets(): 

649 cdef CudlaFence pod 

650 return _numpy.dtype({ 

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

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

653 'offsets': [ 

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

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

656 ], 

657 'itemsize': sizeof(CudlaFence), 

658 }) 

659  

660fence_dtype = _get_fence_dtype_offsets() 

661  

662cdef class Fence: 

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

664  

665  

666 .. seealso:: `CudlaFence` 

667 """ 

668 cdef: 

669 CudlaFence _data 

670 CudlaFence *_ptr 

671 object _owner 

672 bint _readonly 

673  

674 def __init__(self): 

675 self._ptr = &self._data 1h

676 self._owner = None 1h

677 self._readonly = False 1h

678  

679 def __repr__(self): 

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

681  

682 @property 

683 def ptr(self): 

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

685 return <intptr_t>(self._ptr) 

686  

687 cdef intptr_t _get_ptr(self): 

688 return <intptr_t>(self._ptr) 

689  

690 def __int__(self): 

691 return <intptr_t>(self._ptr) 

692  

693 def __eq__(self, other): 

694 cdef Fence other_ 

695 if not isinstance(other, Fence): 

696 return False 

697 other_ = other 

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

699  

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

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

702  

703 def __releasebuffer__(self, Py_buffer *buffer): 

704 pass 

705  

706 def __setitem__(self, key, val): 

707 cdef _cyb_Py_buffer view 

708 if key == 0: 

709 if self._readonly: 

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

711 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

712 try: 

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

714 raise ValueError( 

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

716 ) 

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

718 self._ptr = &self._data 

719 self._owner = None 

720 self._readonly = view.readonly != 0 

721 finally: 

722 _cyb_PyBuffer_Release(&view) 

723 else: 

724 setattr(self, key, val) 

725  

726 @property 

727 def fence(self): 

728 """int: """ 

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

730  

731 @fence.setter 

732 def fence(self, val): 

733 if self._readonly: 1h

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

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

736  

737 @property 

738 def type(self): 

739 """int: """ 

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

741  

742 @type.setter 

743 def type(self, val): 

744 if self._readonly: 1h

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

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

747  

748 @staticmethod 

749 def from_buffer(buffer): 

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

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

752  

753 @staticmethod 

754 def from_data(data): 

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

756  

757 Args: 

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

759 """ 

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

761  

762 @staticmethod 

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

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

765  

766 Args: 

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

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

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

770 """ 

771 if ptr == 0: 

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

773 cdef Fence obj = Fence.__new__(Fence) 

774 if owner is None: 

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

776 obj._ptr = &obj._data 

777 obj._owner = None 

778 else: 

779 obj._ptr = <CudlaFence *>ptr 

780 obj._owner = owner 

781 obj._readonly = readonly 

782 return obj 

783  

784  

785cdef _get_dev_attribute_dtype_offsets(): 

786 cdef cudlaDevAttribute pod 

787 return _numpy.dtype({ 

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

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

790 'offsets': [ 

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

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

793 ], 

794 'itemsize': sizeof(cudlaDevAttribute), 

795 }) 

796  

797dev_attribute_dtype = _get_dev_attribute_dtype_offsets() 

798  

799cdef class DevAttribute: 

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

801  

802  

803 .. seealso:: `cudlaDevAttribute` 

804 """ 

805 cdef: 

806 cudlaDevAttribute _data 

807 cudlaDevAttribute *_ptr 

808 object _owner 

809 bint _readonly 

810  

811 def __init__(self): 

812 self._ptr = &self._data 1i

813 self._owner = None 1i

814 self._readonly = False 1i

815  

816 def __repr__(self): 

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

818  

819 @property 

820 def ptr(self): 

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

822 return <intptr_t>(self._ptr) 

823  

824 cdef intptr_t _get_ptr(self): 

825 return <intptr_t>(self._ptr) 

826  

827 def __int__(self): 

828 return <intptr_t>(self._ptr) 

829  

830 def __eq__(self, other): 

831 cdef DevAttribute other_ 

832 if not isinstance(other, DevAttribute): 

833 return False 

834 other_ = other 

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

836  

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

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

839  

840 def __releasebuffer__(self, Py_buffer *buffer): 

841 pass 

842  

843 def __setitem__(self, key, val): 

844 cdef _cyb_Py_buffer view 

845 if key == 0: 

846 if self._readonly: 

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

848 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

849 try: 

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

851 raise ValueError( 

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

853 ) 

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

855 self._ptr = &self._data 

856 self._owner = None 

857 self._readonly = view.readonly != 0 

858 finally: 

859 _cyb_PyBuffer_Release(&view) 

860 else: 

861 setattr(self, key, val) 

862  

863 @property 

864 def unified_addressing_supported(self): 

865 """int: """ 

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

867  

868 @unified_addressing_supported.setter 

869 def unified_addressing_supported(self, val): 

870 if self._readonly: 1i

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

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

873  

874 @property 

875 def device_version(self): 

876 """int: """ 

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

878  

879 @device_version.setter 

880 def device_version(self, val): 

881 if self._readonly: 1i

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

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

884  

885 @staticmethod 

886 def from_buffer(buffer): 

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

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

889  

890 @staticmethod 

891 def from_data(data): 

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

893  

894 Args: 

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

896 """ 

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

898  

899 @staticmethod 

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

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

902  

903 Args: 

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

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

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

907 """ 

908 if ptr == 0: 

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

910 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute) 

911 if owner is None: 

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

913 obj._ptr = &obj._data 

914 obj._owner = None 

915 else: 

916 obj._ptr = <cudlaDevAttribute *>ptr 

917 obj._owner = owner 

918 obj._readonly = readonly 

919 return obj 

920  

921  

922cdef _get_module_attribute_dtype_offsets(): 

923 cdef cudlaModuleAttribute pod 

924 return _numpy.dtype({ 

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

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

927 'offsets': [ 

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

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

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

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

932 ], 

933 'itemsize': sizeof(cudlaModuleAttribute), 

934 }) 

935  

936module_attribute_dtype = _get_module_attribute_dtype_offsets() 

937  

938cdef class ModuleAttribute: 

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

940  

941  

942 .. seealso:: `cudlaModuleAttribute` 

943 """ 

944 cdef: 

945 cudlaModuleAttribute _data 

946 cudlaModuleAttribute *_ptr 

947 object _owner 

948 bint _readonly 

949  

950 def __init__(self): 

951 self._ptr = &self._data 1j

952 self._owner = None 1j

953 self._readonly = False 1j

954  

955 def __repr__(self): 

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

957  

958 @property 

959 def ptr(self): 

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

961 return <intptr_t>(self._ptr) 

962  

963 cdef intptr_t _get_ptr(self): 

964 return <intptr_t>(self._ptr) 

965  

966 def __int__(self): 

967 return <intptr_t>(self._ptr) 

968  

969 def __eq__(self, other): 

970 cdef ModuleAttribute other_ 

971 if not isinstance(other, ModuleAttribute): 

972 return False 

973 other_ = other 

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

975  

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

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

978  

979 def __releasebuffer__(self, Py_buffer *buffer): 

980 pass 

981  

982 def __setitem__(self, key, val): 

983 cdef _cyb_Py_buffer view 

984 if key == 0: 

985 if self._readonly: 

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

987 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

988 try: 

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

990 raise ValueError( 

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

992 ) 

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

994 self._ptr = &self._data 

995 self._owner = None 

996 self._readonly = view.readonly != 0 

997 finally: 

998 _cyb_PyBuffer_Release(&view) 

999 else: 

1000 setattr(self, key, val) 

1001  

1002 @property 

1003 def num_input_tensors(self): 

1004 """int: """ 

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

1006  

1007 @num_input_tensors.setter 

1008 def num_input_tensors(self, val): 

1009 if self._readonly: 1j

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

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

1012  

1013 @property 

1014 def num_output_tensors(self): 

1015 """int: """ 

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

1017  

1018 @num_output_tensors.setter 

1019 def num_output_tensors(self, val): 

1020 if self._readonly: 1j

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

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

1023  

1024 @property 

1025 def input_tensor_desc(self): 

1026 """int: """ 

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

1028  

1029 @input_tensor_desc.setter 

1030 def input_tensor_desc(self, val): 

1031 if self._readonly: 

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

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

1034  

1035 @property 

1036 def output_tensor_desc(self): 

1037 """int: """ 

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

1039  

1040 @output_tensor_desc.setter 

1041 def output_tensor_desc(self, val): 

1042 if self._readonly: 

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

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

1045  

1046 @staticmethod 

1047 def from_buffer(buffer): 

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

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

1050  

1051 @staticmethod 

1052 def from_data(data): 

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

1054  

1055 Args: 

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

1057 """ 

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

1059  

1060 @staticmethod 

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

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

1063  

1064 Args: 

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

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

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

1068 """ 

1069 if ptr == 0: 

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

1071 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute) 

1072 if owner is None: 

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

1074 obj._ptr = &obj._data 

1075 obj._owner = None 

1076 else: 

1077 obj._ptr = <cudlaModuleAttribute *>ptr 

1078 obj._owner = owner 

1079 obj._readonly = readonly 

1080 return obj 

1081  

1082  

1083cdef _get_wait_events_dtype_offsets(): 

1084 cdef cudlaWaitEvents pod 

1085 return _numpy.dtype({ 

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

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

1088 'offsets': [ 

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

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

1091 ], 

1092 'itemsize': sizeof(cudlaWaitEvents), 

1093 }) 

1094  

1095wait_events_dtype = _get_wait_events_dtype_offsets() 

1096  

1097cdef class WaitEvents: 

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

1099  

1100  

1101 .. seealso:: `cudlaWaitEvents` 

1102 """ 

1103 cdef: 

1104 cudlaWaitEvents _data 

1105 cudlaWaitEvents *_ptr 

1106 object _owner 

1107 bint _readonly 

1108 dict _refs 

1109  

1110 def __init__(self): 

1111 self._ptr = &self._data 1n

1112 self._owner = None 1n

1113 self._readonly = False 1n

1114 self._refs = {} 1n

1115  

1116 def __repr__(self): 

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

1118  

1119 @property 

1120 def ptr(self): 

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

1122 return <intptr_t>(self._ptr) 

1123  

1124 cdef intptr_t _get_ptr(self): 

1125 return <intptr_t>(self._ptr) 

1126  

1127 def __int__(self): 

1128 return <intptr_t>(self._ptr) 

1129  

1130 def __eq__(self, other): 

1131 cdef WaitEvents other_ 

1132 if not isinstance(other, WaitEvents): 

1133 return False 

1134 other_ = other 

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

1136  

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

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

1139  

1140 def __releasebuffer__(self, Py_buffer *buffer): 

1141 pass 

1142  

1143 def __setitem__(self, key, val): 

1144 cdef _cyb_Py_buffer view 

1145 if key == 0: 

1146 if self._readonly: 

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

1148 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

1149 try: 

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

1151 raise ValueError( 

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

1153 ) 

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

1155 self._ptr = &self._data 

1156 self._owner = None 

1157 self._readonly = view.readonly != 0 

1158 finally: 

1159 _cyb_PyBuffer_Release(&view) 

1160 else: 

1161 setattr(self, key, val) 

1162  

1163 @property 

1164 def pre_fences(self): 

1165 """int: """ 

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

1167 return [] 1n

1168 return Fence.from_ptr( 

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

1170 self._ptr[0].numEvents, 

1171 owner=self, 

1172 readonly=self._readonly 

1173 ) 

1174  

1175 @pre_fences.setter 

1176 def pre_fences(self, val): 

1177 if self._readonly: 

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

1179 cdef Fence arr = val 

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

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

1182 self._refs["pre_fences"] = arr 

1183  

1184 @staticmethod 

1185 def from_buffer(buffer): 

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

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

1188  

1189 @staticmethod 

1190 def from_data(data): 

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

1192  

1193 Args: 

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

1195 """ 

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

1197  

1198 @staticmethod 

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

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

1201  

1202 Args: 

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

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

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

1206 """ 

1207 if ptr == 0: 

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

1209 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents) 

1210 if owner is None: 

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

1212 obj._ptr = &obj._data 

1213 obj._owner = None 

1214 else: 

1215 obj._ptr = <cudlaWaitEvents *>ptr 

1216 obj._owner = owner 

1217 obj._readonly = readonly 

1218 obj._refs = {} 

1219 return obj 

1220  

1221  

1222cdef _get_signal_events_dtype_offsets(): 

1223 cdef cudlaSignalEvents pod 

1224 return _numpy.dtype({ 

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

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

1227 'offsets': [ 

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

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

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

1231 ], 

1232 'itemsize': sizeof(cudlaSignalEvents), 

1233 }) 

1234  

1235signal_events_dtype = _get_signal_events_dtype_offsets() 

1236  

1237cdef class SignalEvents: 

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

1239  

1240  

1241 .. seealso:: `cudlaSignalEvents` 

1242 """ 

1243 cdef: 

1244 cudlaSignalEvents _data 

1245 cudlaSignalEvents *_ptr 

1246 object _owner 

1247 bint _readonly 

1248 dict _refs 

1249  

1250 def __init__(self): 

1251 self._ptr = &self._data 1o

1252 self._owner = None 1o

1253 self._readonly = False 1o

1254 self._refs = {} 1o

1255  

1256 def __repr__(self): 

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

1258  

1259 @property 

1260 def ptr(self): 

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

1262 return <intptr_t>(self._ptr) 

1263  

1264 cdef intptr_t _get_ptr(self): 

1265 return <intptr_t>(self._ptr) 

1266  

1267 def __int__(self): 

1268 return <intptr_t>(self._ptr) 

1269  

1270 def __eq__(self, other): 

1271 cdef SignalEvents other_ 

1272 if not isinstance(other, SignalEvents): 

1273 return False 

1274 other_ = other 

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

1276  

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

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

1279  

1280 def __releasebuffer__(self, Py_buffer *buffer): 

1281 pass 

1282  

1283 def __setitem__(self, key, val): 

1284 cdef _cyb_Py_buffer view 

1285 if key == 0: 

1286 if self._readonly: 

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

1288 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

1289 try: 

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

1291 raise ValueError( 

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

1293 ) 

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

1295 self._ptr = &self._data 

1296 self._owner = None 

1297 self._readonly = view.readonly != 0 

1298 finally: 

1299 _cyb_PyBuffer_Release(&view) 

1300 else: 

1301 setattr(self, key, val) 

1302  

1303 @property 

1304 def dev_ptrs(self): 

1305 """int: """ 

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

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

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

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

1310 return arr 

1311  

1312 @dev_ptrs.setter 

1313 def dev_ptrs(self, val): 

1314 if self._readonly: 

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

1316 cdef Py_ssize_t _n = len(val) 

1317 self._ptr[0].numEvents = _n 

1318 if _n == 0: 

1319 return 

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

1321 cdef intptr_t[:] mv = arr 

1322 cdef Py_ssize_t i 

1323 for i in range(_n): 

1324 mv[i] = val[i] 

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

1326 self._refs["dev_ptrs"] = arr 

1327  

1328 @property 

1329 def eof_fences(self): 

1330 """int: """ 

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

1332 return [] 1o

1333 return Fence.from_ptr( 

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

1335 self._ptr[0].numEvents, 

1336 owner=self, 

1337 readonly=self._readonly 

1338 ) 

1339  

1340 @eof_fences.setter 

1341 def eof_fences(self, val): 

1342 if self._readonly: 

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

1344 cdef Fence arr = val 

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

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

1347 self._refs["eof_fences"] = arr 

1348  

1349 @staticmethod 

1350 def from_buffer(buffer): 

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

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

1353  

1354 @staticmethod 

1355 def from_data(data): 

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

1357  

1358 Args: 

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

1360 """ 

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

1362  

1363 @staticmethod 

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

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

1366  

1367 Args: 

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

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

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

1371 """ 

1372 if ptr == 0: 

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

1374 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents) 

1375 if owner is None: 

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

1377 obj._ptr = &obj._data 

1378 obj._owner = None 

1379 else: 

1380 obj._ptr = <cudlaSignalEvents *>ptr 

1381 obj._owner = owner 

1382 obj._readonly = readonly 

1383 obj._refs = {} 

1384 return obj 

1385  

1386  

1387cdef _get_task_dtype_offsets(): 

1388 cdef cudlaTask pod 

1389 return _numpy.dtype({ 

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

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

1392 'offsets': [ 

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

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

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

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

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

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

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

1400 ], 

1401 'itemsize': sizeof(cudlaTask), 

1402 }) 

1403  

1404task_dtype = _get_task_dtype_offsets() 

1405  

1406cdef class Task: 

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

1408  

1409  

1410 .. seealso:: `cudlaTask` 

1411 """ 

1412 cdef: 

1413 cudlaTask _data 

1414 cudlaTask *_ptr 

1415 object _owner 

1416 bint _readonly 

1417 dict _refs 

1418  

1419 def __init__(self): 

1420 self._ptr = &self._data 1gbkcd

1421 self._owner = None 1gbkcd

1422 self._readonly = False 1gbkcd

1423 self._refs = {} 1gbkcd

1424  

1425 def __repr__(self): 

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

1427  

1428 @property 

1429 def ptr(self): 

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

1431 return <intptr_t>(self._ptr) 

1432  

1433 cdef intptr_t _get_ptr(self): 

1434 return <intptr_t>(self._ptr) 

1435  

1436 def __int__(self): 

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

1438  

1439 def __eq__(self, other): 

1440 cdef Task other_ 

1441 if not isinstance(other, Task): 

1442 return False 

1443 other_ = other 

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

1445  

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

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

1448  

1449 def __releasebuffer__(self, Py_buffer *buffer): 

1450 pass 

1451  

1452 def __setitem__(self, key, val): 

1453 cdef _cyb_Py_buffer view 

1454 if key == 0: 

1455 if self._readonly: 

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

1457 _cyb_PyObject_GetBuffer(val, &view, _cyb_PyBUF_SIMPLE) 

1458 try: 

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

1460 raise ValueError( 

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

1462 ) 

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

1464 self._ptr = &self._data 

1465 self._owner = None 

1466 self._readonly = view.readonly != 0 

1467 finally: 

1468 _cyb_PyBuffer_Release(&view) 

1469 else: 

1470 setattr(self, key, val) 

1471  

1472 @property 

1473 def module_handle(self): 

1474 """int: """ 

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

1476  

1477 @module_handle.setter 

1478 def module_handle(self, val): 

1479 if self._readonly: 1bk

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

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

1482  

1483 @property 

1484 def output_tensor(self): 

1485 """int: """ 

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

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

1488 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

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

1490 return arr 1bd

1491  

1492 @output_tensor.setter 

1493 def output_tensor(self, val): 

1494 if self._readonly: 1bd

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

1496 cdef Py_ssize_t _n = len(val) 1bd

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

1498 if _n == 0: 1bd

1499 return 

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

1501 cdef intptr_t[:] mv = arr 1bd

1502 cdef Py_ssize_t i 

1503 for i in range(_n): 1bd

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

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

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

1507  

1508 @property 

1509 def input_tensor(self): 

1510 """int: """ 

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

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

1513 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

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

1515 return arr 1bc

1516  

1517 @input_tensor.setter 

1518 def input_tensor(self, val): 

1519 if self._readonly: 1bc

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

1521 cdef Py_ssize_t _n = len(val) 1bc

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

1523 if _n == 0: 1bc

1524 return 

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

1526 cdef intptr_t[:] mv = arr 1bc

1527 cdef Py_ssize_t i 

1528 for i in range(_n): 1bc

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

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

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

1532  

1533 @property 

1534 def wait_events(self): 

1535 """int: """ 

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

1537  

1538 @wait_events.setter 

1539 def wait_events(self, val): 

1540 if self._readonly: 1b

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

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

1543  

1544 @property 

1545 def signal_events(self): 

1546 """int: """ 

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

1548  

1549 @signal_events.setter 

1550 def signal_events(self, val): 

1551 if self._readonly: 1b

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

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

1554  

1555 @staticmethod 

1556 def from_buffer(buffer): 

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

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

1559  

1560 @staticmethod 

1561 def from_data(data): 

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

1563  

1564 Args: 

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

1566 """ 

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

1568  

1569 @staticmethod 

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

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

1572  

1573 Args: 

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

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

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

1577 """ 

1578 if ptr == 0: 

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

1580 cdef Task obj = Task.__new__(Task) 

1581 if owner is None: 

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

1583 obj._ptr = &obj._data 

1584 obj._owner = None 

1585 else: 

1586 obj._ptr = <cudlaTask *>ptr 

1587 obj._owner = owner 

1588 obj._readonly = readonly 

1589 obj._refs = {} 

1590 return obj 

1591  

1592  

1593############################################################################### 

1594# Enum 

1595############################################################################### 

1596  

1597class Status(_cyb_IntEnum): 

1598 """ 

1599 See `cudlaStatus`. 

1600 """ 

1601 Success = cudlaSuccess 

1602 ErrorInvalidParam = cudlaErrorInvalidParam 

1603 ErrorOutOfResources = cudlaErrorOutOfResources 

1604 ErrorCreationFailed = cudlaErrorCreationFailed 

1605 ErrorInvalidAddress = cudlaErrorInvalidAddress 

1606 ErrorOs = cudlaErrorOs 

1607 ErrorCuda = cudlaErrorCuda 

1608 ErrorUmd = cudlaErrorUmd 

1609 ErrorInvalidDevice = cudlaErrorInvalidDevice 

1610 ErrorInvalidAttribute = cudlaErrorInvalidAttribute 

1611 ErrorIncompatibleDlaSWVersion = cudlaErrorIncompatibleDlaSWVersion 

1612 ErrorMemoryRegistered = cudlaErrorMemoryRegistered 

1613 ErrorInvalidModule = cudlaErrorInvalidModule 

1614 ErrorUnsupportedOperation = cudlaErrorUnsupportedOperation 

1615 ErrorNvSci = cudlaErrorNvSci 

1616 ErrorDriverNotFound = cudlaErrorDriverNotFound 

1617 ErrorDlaErrInvalidInput = cudlaErrorDlaErrInvalidInput 

1618 ErrorDlaErrInvalidPreAction = cudlaErrorDlaErrInvalidPreAction 

1619 ErrorDlaErrNoMem = cudlaErrorDlaErrNoMem 

1620 ErrorDlaErrProcessorBusy = cudlaErrorDlaErrProcessorBusy 

1621 ErrorDlaErrTaskStatusMismatch = cudlaErrorDlaErrTaskStatusMismatch 

1622 ErrorDlaErrEngineTimeout = cudlaErrorDlaErrEngineTimeout 

1623 ErrorDlaErrDataMismatch = cudlaErrorDlaErrDataMismatch 

1624 ErrorUnknown = cudlaErrorUnknown 

1625  

1626class Mode(_cyb_IntEnum): 

1627 """ 

1628 See `cudlaMode`. 

1629 """ 

1630 CUDA_DLA = CUDLA_CUDA_DLA 

1631 STANDALONE = CUDLA_STANDALONE 

1632  

1633class ModuleAttributeType(_cyb_IntEnum): 

1634 """ 

1635 See `cudlaModuleAttributeType`. 

1636 """ 

1637 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS 

1638 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS 

1639 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS 

1640 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS 

1641 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1642 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS 

1643  

1644class FenceType(_cyb_IntEnum): 

1645 """ 

1646 See `cudlaFenceType`. 

1647 """ 

1648 FENCE = CUDLA_NVSCISYNC_FENCE 

1649 NVSCISYNC_FENCE = FENCE # backward-compat alias 

1650 FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF 

1651 NVSCISYNC_FENCE_SOF = FENCE_SOF # backward-compat alias 

1652  

1653class ModuleLoadFlags(_cyb_IntEnum): 

1654 """ 

1655 See `cudlaModuleLoadFlags`. 

1656 """ 

1657 DEFAULT = CUDLA_MODULE_DEFAULT 

1658 MODULE_DEFAULT = DEFAULT # backward-compat alias 

1659 ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS 

1660 MODULE_ENABLE_FAULT_DIAGNOSTICS = ENABLE_FAULT_DIAGNOSTICS # backward-compat alias 

1661  

1662class SubmissionFlags(_cyb_IntEnum): 

1663 """ 

1664 See `cudlaSubmissionFlags`. 

1665 """ 

1666 NOOP = CUDLA_SUBMIT_NOOP 

1667 SUBMIT_NOOP = NOOP # backward-compat alias 

1668 SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE 

1669 SUBMIT_SKIP_LOCK_ACQUIRE = SKIP_LOCK_ACQUIRE # backward-compat alias 

1670 DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK 

1671 SUBMIT_DIAGNOSTICS_TASK = DIAGNOSTICS_TASK # backward-compat alias 

1672  

1673class AccessPermissionFlags(_cyb_IntEnum): 

1674 """ 

1675 See `cudlaAccessPermissionFlags`. 

1676 """ 

1677 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM 

1678 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM 

1679 TASK_STATISTICS = CUDLA_TASK_STATISTICS 

1680  

1681class DevAttributeType(_cyb_IntEnum): 

1682 """ 

1683 See `cudlaDevAttributeType`. 

1684 """ 

1685 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING 

1686 DEVICE_VERSION = CUDLA_DEVICE_VERSION 

1687  

1688class ScratchMemoryConfig(_cyb_IntEnum): 

1689 """ 

1690 See `cudlaScratchMemoryConfig`. 

1691 """ 

1692 DEFAULT = CUDLA_SCRATCH_MEMORY_DEFAULT 

1693 SCRATCH_MEMORY_DEFAULT = DEFAULT # backward-compat alias 

1694 SHARED_STATIC = CUDLA_SCRATCH_MEMORY_SHARED_STATIC 

1695 SCRATCH_MEMORY_SHARED_STATIC = SHARED_STATIC # backward-compat alias 

1696 CONFIG_MAX = CUDLA_SCRATCH_MEMORY_CONFIG_MAX 

1697 MAX = CONFIG_MAX # backward-compat alias 

1698  

1699  

1700############################################################################### 

1701# Error handling 

1702############################################################################### 

1703  

1704class CudlaError(Exception): 

1705  

1706 def __init__(self, status): 

1707 self.status = status 1qr

1708 s = Status(status) 1qr

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

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

1711  

1712 def __reduce__(self): 

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

1714  

1715  

1716@cython.profile(False) 

1717cpdef inline check_status(int status): 

1718 if status != 0: 

1719 raise CudlaError(status) 

1720  

1721  

1722############################################################################### 

1723# Wrapper functions 

1724############################################################################### 

1725  

1726cpdef uint64_t get_version() except? -1: 

1727 cdef uint64_t version 

1728 with nogil: 

1729 __status__ = cudlaGetVersion(&version) 

1730 check_status(__status__) 

1731 return version 

1732  

1733  

1734cpdef uint64_t device_get_count() except? -1: 

1735 cdef uint64_t p_num_devices 

1736 with nogil: 

1737 __status__ = cudlaDeviceGetCount(&p_num_devices) 

1738 check_status(__status__) 

1739 return p_num_devices 

1740  

1741  

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

1743 cdef DevHandle dev_handle 

1744 if flags & CUDLA_STANDALONE: 

1745 raise CudlaError(cudlaErrorUnsupportedOperation) 

1746 with nogil: 

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

1748 check_status(__status__) 

1749 return <intptr_t>dev_handle 

1750  

1751  

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

1753 cdef uint64_t* dev_ptr 

1754 with nogil: 

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

1756 check_status(__status__) 

1757 return <intptr_t>dev_ptr 

1758  

1759  

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

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

1762 cdef Module h_module 

1763 with nogil: 

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

1765 check_status(__status__) 

1766 return <intptr_t>h_module 

1767  

1768  

1769cpdef module_unload(intptr_t h_module, uint32_t flags): 

1770 with nogil: 

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

1772 check_status(__status__) 

1773  

1774  

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

1776 cdef intptr_t _ptr_to_tasks_ptr_ = int(ptr_to_tasks) 

1777 with nogil: 

1778 __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) 

1779 check_status(__status__) 

1780  

1781  

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

1783 cdef DevAttribute p_attribute_py = DevAttribute() 

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

1785 with nogil: 

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

1787 check_status(__status__) 

1788 return p_attribute_py 

1789  

1790  

1791cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr): 

1792 with nogil: 

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

1794 check_status(__status__) 

1795  

1796  

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

1798 cdef int ret 

1799 with nogil: 

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

1801 return ret 

1802  

1803  

1804cpdef destroy_device(intptr_t dev_handle): 

1805 with nogil: 

1806 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle) 

1807 check_status(__status__) 

1808  

1809  

1810cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout): 

1811 with nogil: 

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

1813 check_status(__status__) 

1814  

1815  

1816cpdef module_get_attributes(intptr_t h_module, int attr_type): 

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

1818 based on the requested attribute type. 

1819  

1820 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS, 

1821 NUM_OUTPUT_TASK_STATISTICS), returns an int. 

1822  

1823 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS, 

1824 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS), 

1825 returns a list of ModuleTensorDescriptor objects. 

1826 """ 

1827 cdef int _attr_type = attr_type 

1828 cdef cudlaModuleAttribute count_attr 

1829 cdef cudlaModuleAttribute num_attr 

1830 cdef cudlaModuleAttribute desc_attr 

1831 cdef uint32_t count 

1832 cdef cudlaModuleTensorDescriptor* desc_buf 

1833 cdef uint32_t i 

1834 cdef int num_attr_type 

1835  

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

1837 with nogil: 

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

1839 check_status(__status__) 

1840 return <int>(count_attr.numInputTensors) 

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

1842 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS: 

1843 num_attr_type = CUDLA_NUM_INPUT_TENSORS 

1844 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS: 

1845 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS 

1846 else: 

1847 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1848 with nogil: 

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

1850 check_status(__status__) 

1851 count = num_attr.numInputTensors 

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

1853 if desc_buf == NULL: 

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

1855 try: 

1856 desc_attr.inputTensorDesc = desc_buf 

1857 with nogil: 

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

1859 check_status(__status__) 

1860 result = [] 

1861 for i in range(count): 

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

1863 return result 

1864 finally: 

1865 free(desc_buf) 

1866 else: 

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

1868del _cyb_IntEnum