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

918 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-22 01:37 +0000

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

2# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE 

3  

4# This code was automatically generated with version 1.5.0, generator version 0.3.1.dev1465+gc5c5c8652. Do not modify it directly. 

5  

6cimport cython # NOQA 

7from libc.stdint cimport intptr_t, uintptr_t 

8  

9from ._internal.utils cimport get_buffer_pointer 

10  

11from enum import IntEnum as _IntEnum 

12  

13from libc.stdlib cimport calloc, free, malloc 

14from cython cimport view 

15cimport cpython.buffer 

16cimport cpython.memoryview 

17cimport cpython 

18from libc.string cimport memcmp, memcpy 

19import numpy as _numpy 

20  

21  

22cdef __from_data(data, dtype_name, expected_dtype, lowpp_type): 

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

24 if isinstance(data, lowpp_type): 

25 return data 

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

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

28 if data.size != 1: 

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

30 if data.dtype != expected_dtype: 

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

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

33  

34  

35cdef __from_buffer(buffer, size, lowpp_type): 

36 cdef Py_buffer view 

37 if cpython.PyObject_GetBuffer(buffer, &view, cpython.PyBUF_SIMPLE) != 0: 

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

39 try: 

40 if view.itemsize != 1: 

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

42 if view.len != size: 

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

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

45 finally: 

46 cpython.PyBuffer_Release(&view) 

47  

48  

49cdef __getbuffer(object self, cpython.Py_buffer *buffer, void *ptr, int size, bint readonly): 

50 buffer.buf = <char *>ptr 

51 buffer.format = 'b' 

52 buffer.internal = NULL 

53 buffer.itemsize = 1 

54 buffer.len = size 

55 buffer.ndim = 1 

56 buffer.obj = self 

57 buffer.readonly = readonly 

58 buffer.shape = &buffer.len 

59 buffer.strides = &buffer.itemsize 

60 buffer.suboffsets = NULL 

61  

62  

63  

64  

65############################################################################### 

66# POD 

67############################################################################### 

68  

69cdef _get_external_memory_handle_desc_dtype_offsets(): 

70 cdef cudlaExternalMemoryHandleDesc_t pod = cudlaExternalMemoryHandleDesc_t() 

71 return _numpy.dtype({ 

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

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

74 'offsets': [ 

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

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

77 ], 

78 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t), 

79 }) 

80  

81external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets() 

82  

83cdef class ExternalMemoryHandleDesc: 

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

85  

86  

87 .. seealso:: `cudlaExternalMemoryHandleDesc_t` 

88 """ 

89 cdef: 

90 cudlaExternalMemoryHandleDesc_t *_ptr 

91 object _owner 

92 bint _owned 

93 bint _readonly 

94  

95 def __init__(self): 

96 self._ptr = <cudlaExternalMemoryHandleDesc_t *>calloc(1, sizeof(cudlaExternalMemoryHandleDesc_t)) 1g

97 if self._ptr == NULL: 1g

98 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

99 self._owner = None 1g

100 self._owned = True 1g

101 self._readonly = False 1g

102  

103 def __dealloc__(self): 

104 cdef cudlaExternalMemoryHandleDesc_t *ptr 

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

106 ptr = self._ptr 1g

107 self._ptr = NULL 1g

108 free(ptr) 1g

109  

110 def __repr__(self): 

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

112  

113 @property 

114 def ptr(self): 

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

116 return <intptr_t>(self._ptr) 

117  

118 cdef intptr_t _get_ptr(self): 

119 return <intptr_t>(self._ptr) 

120  

121 def __int__(self): 

122 return <intptr_t>(self._ptr) 

123  

124 def __eq__(self, other): 

125 cdef ExternalMemoryHandleDesc other_ 

126 if not isinstance(other, ExternalMemoryHandleDesc): 

127 return False 

128 other_ = other 

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

130  

131 def __getbuffer__(self, Py_buffer *buffer, int flags): 

132 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalMemoryHandleDesc_t), self._readonly) 

133  

134 def __releasebuffer__(self, Py_buffer *buffer): 

135 pass 

136  

137 def __setitem__(self, key, val): 

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

139 self._ptr = <cudlaExternalMemoryHandleDesc_t *>malloc(sizeof(cudlaExternalMemoryHandleDesc_t)) 

140 if self._ptr == NULL: 

141 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

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

143 self._owner = None 

144 self._owned = True 

145 self._readonly = not val.flags.writeable 

146 else: 

147 setattr(self, key, val) 

148  

149 @property 

150 def ext_buf_object(self): 

151 """int: """ 

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

153  

154 @ext_buf_object.setter 

155 def ext_buf_object(self, val): 

156 if self._readonly: 1g

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

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

159  

160 @property 

161 def size_(self): 

162 """int: """ 

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

164  

165 @size_.setter 

166 def size_(self, val): 

167 if self._readonly: 1g

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

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

170  

171 @staticmethod 

172 def from_buffer(buffer): 

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

174 return __from_buffer(buffer, sizeof(cudlaExternalMemoryHandleDesc_t), ExternalMemoryHandleDesc) 

175  

176 @staticmethod 

177 def from_data(data): 

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

179  

180 Args: 

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

182 """ 

183 return __from_data(data, "external_memory_handle_desc_dtype", external_memory_handle_desc_dtype, ExternalMemoryHandleDesc) 

184  

185 @staticmethod 

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

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

188  

189 Args: 

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

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

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

193 """ 

194 if ptr == 0: 

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

196 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc) 

197 if owner is None: 

198 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>malloc(sizeof(cudlaExternalMemoryHandleDesc_t)) 

199 if obj._ptr == NULL: 

200 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

201 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaExternalMemoryHandleDesc_t)) 

202 obj._owner = None 

203 obj._owned = True 

204 else: 

205 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr 

206 obj._owner = owner 

207 obj._owned = False 

208 obj._readonly = readonly 

209 return obj 

210  

211  

212cdef _get_external_semaphore_handle_desc_dtype_offsets(): 

213 cdef cudlaExternalSemaphoreHandleDesc_t pod = cudlaExternalSemaphoreHandleDesc_t() 

214 return _numpy.dtype({ 

215 'names': ['ext_sync_object'], 

216 'formats': [_numpy.intp], 

217 'offsets': [ 

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

219 ], 

220 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t), 

221 }) 

222  

223external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets() 

224  

225cdef class ExternalSemaphoreHandleDesc: 

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

227  

228  

229 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t` 

230 """ 

231 cdef: 

232 cudlaExternalSemaphoreHandleDesc_t *_ptr 

233 object _owner 

234 bint _owned 

235 bint _readonly 

236  

237 def __init__(self): 

238 self._ptr = <cudlaExternalSemaphoreHandleDesc_t *>calloc(1, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 1l

239 if self._ptr == NULL: 1l

240 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

241 self._owner = None 1l

242 self._owned = True 1l

243 self._readonly = False 1l

244  

245 def __dealloc__(self): 

246 cdef cudlaExternalSemaphoreHandleDesc_t *ptr 

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

248 ptr = self._ptr 1l

249 self._ptr = NULL 1l

250 free(ptr) 1l

251  

252 def __repr__(self): 

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

254  

255 @property 

256 def ptr(self): 

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

258 return <intptr_t>(self._ptr) 

259  

260 cdef intptr_t _get_ptr(self): 

261 return <intptr_t>(self._ptr) 

262  

263 def __int__(self): 

264 return <intptr_t>(self._ptr) 

265  

266 def __eq__(self, other): 

267 cdef ExternalSemaphoreHandleDesc other_ 

268 if not isinstance(other, ExternalSemaphoreHandleDesc): 

269 return False 

270 other_ = other 

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

272  

273 def __getbuffer__(self, Py_buffer *buffer, int flags): 

274 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t), self._readonly) 

275  

276 def __releasebuffer__(self, Py_buffer *buffer): 

277 pass 

278  

279 def __setitem__(self, key, val): 

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

281 self._ptr = <cudlaExternalSemaphoreHandleDesc_t *>malloc(sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

282 if self._ptr == NULL: 

283 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

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

285 self._owner = None 

286 self._owned = True 

287 self._readonly = not val.flags.writeable 

288 else: 

289 setattr(self, key, val) 

290  

291 @property 

292 def ext_sync_object(self): 

293 """int: """ 

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

295  

296 @ext_sync_object.setter 

297 def ext_sync_object(self, val): 

298 if self._readonly: 1l

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

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

301  

302 @staticmethod 

303 def from_buffer(buffer): 

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

305 return __from_buffer(buffer, sizeof(cudlaExternalSemaphoreHandleDesc_t), ExternalSemaphoreHandleDesc) 

306  

307 @staticmethod 

308 def from_data(data): 

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

310  

311 Args: 

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

313 """ 

314 return __from_data(data, "external_semaphore_handle_desc_dtype", external_semaphore_handle_desc_dtype, ExternalSemaphoreHandleDesc) 

315  

316 @staticmethod 

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

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

319  

320 Args: 

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

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

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

324 """ 

325 if ptr == 0: 

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

327 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc) 

328 if owner is None: 

329 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>malloc(sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

330 if obj._ptr == NULL: 

331 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

332 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaExternalSemaphoreHandleDesc_t)) 

333 obj._owner = None 

334 obj._owned = True 

335 else: 

336 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr 

337 obj._owner = owner 

338 obj._owned = False 

339 obj._readonly = readonly 

340 return obj 

341  

342  

343cdef _get_module_tensor_descriptor_dtype_offsets(): 

344 cdef cudlaModuleTensorDescriptor pod = cudlaModuleTensorDescriptor() 

345 return _numpy.dtype({ 

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

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

348 'offsets': [ 

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

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

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

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

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

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

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

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

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

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

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

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

361 ], 

362 'itemsize': sizeof(cudlaModuleTensorDescriptor), 

363 }) 

364  

365module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets() 

366  

367cdef class ModuleTensorDescriptor: 

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

369  

370  

371 .. seealso:: `cudlaModuleTensorDescriptor` 

372 """ 

373 cdef: 

374 cudlaModuleTensorDescriptor *_ptr 

375 object _owner 

376 bint _owned 

377 bint _readonly 

378  

379 def __init__(self): 

380 self._ptr = <cudlaModuleTensorDescriptor *>calloc(1, sizeof(cudlaModuleTensorDescriptor)) 1fpme

381 if self._ptr == NULL: 1fpme

382 raise MemoryError("Error allocating ModuleTensorDescriptor") 

383 self._owner = None 1fpme

384 self._owned = True 1fpme

385 self._readonly = False 1fpme

386  

387 def __dealloc__(self): 

388 cdef cudlaModuleTensorDescriptor *ptr 

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

390 ptr = self._ptr 1fpme

391 self._ptr = NULL 1fpme

392 free(ptr) 1fpme

393  

394 def __repr__(self): 

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

396  

397 @property 

398 def ptr(self): 

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

400 return <intptr_t>(self._ptr) 

401  

402 cdef intptr_t _get_ptr(self): 

403 return <intptr_t>(self._ptr) 

404  

405 def __int__(self): 

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

407  

408 def __eq__(self, other): 

409 cdef ModuleTensorDescriptor other_ 

410 if not isinstance(other, ModuleTensorDescriptor): 

411 return False 

412 other_ = other 

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

414  

415 def __getbuffer__(self, Py_buffer *buffer, int flags): 

416 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleTensorDescriptor), self._readonly) 

417  

418 def __releasebuffer__(self, Py_buffer *buffer): 

419 pass 

420  

421 def __setitem__(self, key, val): 

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

423 self._ptr = <cudlaModuleTensorDescriptor *>malloc(sizeof(cudlaModuleTensorDescriptor)) 

424 if self._ptr == NULL: 

425 raise MemoryError("Error allocating ModuleTensorDescriptor") 

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

427 self._owner = None 

428 self._owned = True 

429 self._readonly = not val.flags.writeable 

430 else: 

431 setattr(self, key, val) 

432  

433 @property 

434 def name(self): 

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

436 return cpython.PyUnicode_FromString(self._ptr[0].name) 1p

437  

438 @name.setter 

439 def name(self, val): 

440 if self._readonly: 

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

442 cdef bytes buf = val.encode() 

443 if len(buf) >= 81: 

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

445 cdef char *ptr = buf 

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

447  

448 @property 

449 def size_(self): 

450 """int: """ 

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

452  

453 @size_.setter 

454 def size_(self, val): 

455 if self._readonly: 

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

457 self._ptr[0].size = val 

458  

459 @property 

460 def n(self): 

461 """int: """ 

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

463  

464 @n.setter 

465 def n(self, val): 

466 if self._readonly: 

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

468 self._ptr[0].n = val 

469  

470 @property 

471 def c(self): 

472 """int: """ 

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

474  

475 @c.setter 

476 def c(self, val): 

477 if self._readonly: 

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

479 self._ptr[0].c = val 

480  

481 @property 

482 def h(self): 

483 """int: """ 

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

485  

486 @h.setter 

487 def h(self, val): 

488 if self._readonly: 

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

490 self._ptr[0].h = val 

491  

492 @property 

493 def w(self): 

494 """int: """ 

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

496  

497 @w.setter 

498 def w(self, val): 

499 if self._readonly: 

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

501 self._ptr[0].w = val 

502  

503 @property 

504 def data_format(self): 

505 """int: """ 

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

507  

508 @data_format.setter 

509 def data_format(self, val): 

510 if self._readonly: 

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

512 self._ptr[0].dataFormat = val 

513  

514 @property 

515 def data_type(self): 

516 """int: """ 

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

518  

519 @data_type.setter 

520 def data_type(self, val): 

521 if self._readonly: 

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

523 self._ptr[0].dataType = val 

524  

525 @property 

526 def data_category(self): 

527 """int: """ 

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

529  

530 @data_category.setter 

531 def data_category(self, val): 

532 if self._readonly: 

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

534 self._ptr[0].dataCategory = val 

535  

536 @property 

537 def pixel_format(self): 

538 """int: """ 

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

540  

541 @pixel_format.setter 

542 def pixel_format(self, val): 

543 if self._readonly: 

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

545 self._ptr[0].pixelFormat = val 

546  

547 @property 

548 def pixel_mapping(self): 

549 """int: """ 

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

551  

552 @pixel_mapping.setter 

553 def pixel_mapping(self, val): 

554 if self._readonly: 

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

556 self._ptr[0].pixelMapping = val 

557  

558 @property 

559 def stride(self): 

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

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

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

563 return _numpy.asarray(arr) 1m

564  

565 @stride.setter 

566 def stride(self, val): 

567 if self._readonly: 

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

569 if len(val) != 8: 

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

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

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

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

574  

575 @staticmethod 

576 def from_buffer(buffer): 

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

578 return __from_buffer(buffer, sizeof(cudlaModuleTensorDescriptor), ModuleTensorDescriptor) 

579  

580 @staticmethod 

581 def from_data(data): 

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

583  

584 Args: 

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

586 """ 

587 return __from_data(data, "module_tensor_descriptor_dtype", module_tensor_descriptor_dtype, ModuleTensorDescriptor) 

588  

589 @staticmethod 

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

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

592  

593 Args: 

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

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

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

597 """ 

598 if ptr == 0: 

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

600 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor) 

601 if owner is None: 

602 obj._ptr = <cudlaModuleTensorDescriptor *>malloc(sizeof(cudlaModuleTensorDescriptor)) 

603 if obj._ptr == NULL: 

604 raise MemoryError("Error allocating ModuleTensorDescriptor") 

605 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaModuleTensorDescriptor)) 

606 obj._owner = None 

607 obj._owned = True 

608 else: 

609 obj._ptr = <cudlaModuleTensorDescriptor *>ptr 

610 obj._owner = owner 

611 obj._owned = False 

612 obj._readonly = readonly 

613 return obj 

614  

615  

616cdef _get_fence_dtype_offsets(): 

617 cdef CudlaFence pod = CudlaFence() 

618 return _numpy.dtype({ 

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

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

621 'offsets': [ 

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

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

624 ], 

625 'itemsize': sizeof(CudlaFence), 

626 }) 

627  

628fence_dtype = _get_fence_dtype_offsets() 

629  

630cdef class Fence: 

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

632  

633  

634 .. seealso:: `CudlaFence` 

635 """ 

636 cdef: 

637 CudlaFence *_ptr 

638 object _owner 

639 bint _owned 

640 bint _readonly 

641  

642 def __init__(self): 

643 self._ptr = <CudlaFence *>calloc(1, sizeof(CudlaFence)) 1h

644 if self._ptr == NULL: 1h

645 raise MemoryError("Error allocating Fence") 

646 self._owner = None 1h

647 self._owned = True 1h

648 self._readonly = False 1h

649  

650 def __dealloc__(self): 

651 cdef CudlaFence *ptr 

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

653 ptr = self._ptr 1h

654 self._ptr = NULL 1h

655 free(ptr) 1h

656  

657 def __repr__(self): 

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

659  

660 @property 

661 def ptr(self): 

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

663 return <intptr_t>(self._ptr) 

664  

665 cdef intptr_t _get_ptr(self): 

666 return <intptr_t>(self._ptr) 

667  

668 def __int__(self): 

669 return <intptr_t>(self._ptr) 

670  

671 def __eq__(self, other): 

672 cdef Fence other_ 

673 if not isinstance(other, Fence): 

674 return False 

675 other_ = other 

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

677  

678 def __getbuffer__(self, Py_buffer *buffer, int flags): 

679 __getbuffer(self, buffer, <void *>self._ptr, sizeof(CudlaFence), self._readonly) 

680  

681 def __releasebuffer__(self, Py_buffer *buffer): 

682 pass 

683  

684 def __setitem__(self, key, val): 

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

686 self._ptr = <CudlaFence *>malloc(sizeof(CudlaFence)) 

687 if self._ptr == NULL: 

688 raise MemoryError("Error allocating Fence") 

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

690 self._owner = None 

691 self._owned = True 

692 self._readonly = not val.flags.writeable 

693 else: 

694 setattr(self, key, val) 

695  

696 @property 

697 def fence(self): 

698 """int: """ 

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

700  

701 @fence.setter 

702 def fence(self, val): 

703 if self._readonly: 1h

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

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

706  

707 @property 

708 def type(self): 

709 """int: """ 

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

711  

712 @type.setter 

713 def type(self, val): 

714 if self._readonly: 1h

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

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

717  

718 @staticmethod 

719 def from_buffer(buffer): 

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

721 return __from_buffer(buffer, sizeof(CudlaFence), Fence) 

722  

723 @staticmethod 

724 def from_data(data): 

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

726  

727 Args: 

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

729 """ 

730 return __from_data(data, "fence_dtype", fence_dtype, Fence) 

731  

732 @staticmethod 

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

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

735  

736 Args: 

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

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

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

740 """ 

741 if ptr == 0: 

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

743 cdef Fence obj = Fence.__new__(Fence) 

744 if owner is None: 

745 obj._ptr = <CudlaFence *>malloc(sizeof(CudlaFence)) 

746 if obj._ptr == NULL: 

747 raise MemoryError("Error allocating Fence") 

748 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(CudlaFence)) 

749 obj._owner = None 

750 obj._owned = True 

751 else: 

752 obj._ptr = <CudlaFence *>ptr 

753 obj._owner = owner 

754 obj._owned = False 

755 obj._readonly = readonly 

756 return obj 

757  

758  

759dev_attribute_dtype = _numpy.dtype(( 

760 _numpy.dtype((_numpy.void, sizeof(cudlaDevAttribute))), 

761 { 

762 "unified_addressing_supported": (_numpy.uint8, 0), 

763 "device_version": (_numpy.uint32, 0), 

764 } 

765 )) 

766  

767cdef class DevAttribute: 

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

769  

770  

771 .. seealso:: `cudlaDevAttribute` 

772 """ 

773 cdef: 

774 cudlaDevAttribute *_ptr 

775 object _owner 

776 bint _owned 

777 bint _readonly 

778  

779 def __init__(self): 

780 self._ptr = <cudlaDevAttribute *>calloc(1, sizeof(cudlaDevAttribute)) 1i

781 if self._ptr == NULL: 1i

782 raise MemoryError("Error allocating DevAttribute") 

783 self._owner = None 1i

784 self._owned = True 1i

785 self._readonly = False 1i

786  

787 def __dealloc__(self): 

788 cdef cudlaDevAttribute *ptr 

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

790 ptr = self._ptr 1i

791 self._ptr = NULL 1i

792 free(ptr) 1i

793  

794 def __repr__(self): 

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

796  

797 @property 

798 def ptr(self): 

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

800 return <intptr_t>(self._ptr) 

801  

802 cdef intptr_t _get_ptr(self): 

803 return <intptr_t>(self._ptr) 

804  

805 def __int__(self): 

806 return <intptr_t>(self._ptr) 

807  

808 def __eq__(self, other): 

809 cdef DevAttribute other_ 

810 if not isinstance(other, DevAttribute): 

811 return False 

812 other_ = other 

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

814  

815 def __getbuffer__(self, Py_buffer *buffer, int flags): 

816 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaDevAttribute), self._readonly) 

817  

818 def __releasebuffer__(self, Py_buffer *buffer): 

819 pass 

820  

821 def __setitem__(self, key, val): 

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

823 self._ptr = <cudlaDevAttribute *>malloc(sizeof(cudlaDevAttribute)) 

824 if self._ptr == NULL: 

825 raise MemoryError("Error allocating DevAttribute") 

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

827 self._owner = None 

828 self._owned = True 

829 self._readonly = not val.flags.writeable 

830 else: 

831 setattr(self, key, val) 

832  

833 @property 

834 def unified_addressing_supported(self): 

835 """int: """ 

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

837  

838 @unified_addressing_supported.setter 

839 def unified_addressing_supported(self, val): 

840 if self._readonly: 1i

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

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

843  

844 @property 

845 def device_version(self): 

846 """int: """ 

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

848  

849 @device_version.setter 

850 def device_version(self, val): 

851 if self._readonly: 1i

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

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

854  

855 @staticmethod 

856 def from_buffer(buffer): 

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

858 return __from_buffer(buffer, sizeof(cudlaDevAttribute), DevAttribute) 

859  

860 @staticmethod 

861 def from_data(data): 

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

863  

864 Args: 

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

866 """ 

867 return __from_data(data, "dev_attribute_dtype", dev_attribute_dtype, DevAttribute) 

868  

869 @staticmethod 

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

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

872  

873 Args: 

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

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

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

877 """ 

878 if ptr == 0: 

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

880 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute) 

881 if owner is None: 

882 obj._ptr = <cudlaDevAttribute *>malloc(sizeof(cudlaDevAttribute)) 

883 if obj._ptr == NULL: 

884 raise MemoryError("Error allocating DevAttribute") 

885 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaDevAttribute)) 

886 obj._owner = None 

887 obj._owned = True 

888 else: 

889 obj._ptr = <cudlaDevAttribute *>ptr 

890 obj._owner = owner 

891 obj._owned = False 

892 obj._readonly = readonly 

893 return obj 

894  

895  

896module_attribute_dtype = _numpy.dtype(( 

897 _numpy.dtype((_numpy.void, sizeof(cudlaModuleAttribute))), 

898 { 

899 "num_input_tensors": (_numpy.uint32, 0), 

900 "num_output_tensors": (_numpy.uint32, 0), 

901 "input_tensor_desc": (_numpy.intp, 0), 

902 "output_tensor_desc": (_numpy.intp, 0), 

903 } 

904 )) 

905  

906cdef class ModuleAttribute: 

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

908  

909  

910 .. seealso:: `cudlaModuleAttribute` 

911 """ 

912 cdef: 

913 cudlaModuleAttribute *_ptr 

914 object _owner 

915 bint _owned 

916 bint _readonly 

917  

918 def __init__(self): 

919 self._ptr = <cudlaModuleAttribute *>calloc(1, sizeof(cudlaModuleAttribute)) 1j

920 if self._ptr == NULL: 1j

921 raise MemoryError("Error allocating ModuleAttribute") 

922 self._owner = None 1j

923 self._owned = True 1j

924 self._readonly = False 1j

925  

926 def __dealloc__(self): 

927 cdef cudlaModuleAttribute *ptr 

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

929 ptr = self._ptr 1j

930 self._ptr = NULL 1j

931 free(ptr) 1j

932  

933 def __repr__(self): 

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

935  

936 @property 

937 def ptr(self): 

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

939 return <intptr_t>(self._ptr) 

940  

941 cdef intptr_t _get_ptr(self): 

942 return <intptr_t>(self._ptr) 

943  

944 def __int__(self): 

945 return <intptr_t>(self._ptr) 

946  

947 def __eq__(self, other): 

948 cdef ModuleAttribute other_ 

949 if not isinstance(other, ModuleAttribute): 

950 return False 

951 other_ = other 

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

953  

954 def __getbuffer__(self, Py_buffer *buffer, int flags): 

955 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaModuleAttribute), self._readonly) 

956  

957 def __releasebuffer__(self, Py_buffer *buffer): 

958 pass 

959  

960 def __setitem__(self, key, val): 

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

962 self._ptr = <cudlaModuleAttribute *>malloc(sizeof(cudlaModuleAttribute)) 

963 if self._ptr == NULL: 

964 raise MemoryError("Error allocating ModuleAttribute") 

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

966 self._owner = None 

967 self._owned = True 

968 self._readonly = not val.flags.writeable 

969 else: 

970 setattr(self, key, val) 

971  

972 @property 

973 def num_input_tensors(self): 

974 """int: """ 

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

976  

977 @num_input_tensors.setter 

978 def num_input_tensors(self, val): 

979 if self._readonly: 1j

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

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

982  

983 @property 

984 def num_output_tensors(self): 

985 """int: """ 

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

987  

988 @num_output_tensors.setter 

989 def num_output_tensors(self, val): 

990 if self._readonly: 1j

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

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

993  

994 @property 

995 def input_tensor_desc(self): 

996 """int: """ 

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

998  

999 @input_tensor_desc.setter 

1000 def input_tensor_desc(self, val): 

1001 if self._readonly: 

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

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

1004  

1005 @property 

1006 def output_tensor_desc(self): 

1007 """int: """ 

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

1009  

1010 @output_tensor_desc.setter 

1011 def output_tensor_desc(self, val): 

1012 if self._readonly: 

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

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

1015  

1016 @staticmethod 

1017 def from_buffer(buffer): 

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

1019 return __from_buffer(buffer, sizeof(cudlaModuleAttribute), ModuleAttribute) 

1020  

1021 @staticmethod 

1022 def from_data(data): 

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

1024  

1025 Args: 

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

1027 """ 

1028 return __from_data(data, "module_attribute_dtype", module_attribute_dtype, ModuleAttribute) 

1029  

1030 @staticmethod 

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

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

1033  

1034 Args: 

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

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

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

1038 """ 

1039 if ptr == 0: 

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

1041 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute) 

1042 if owner is None: 

1043 obj._ptr = <cudlaModuleAttribute *>malloc(sizeof(cudlaModuleAttribute)) 

1044 if obj._ptr == NULL: 

1045 raise MemoryError("Error allocating ModuleAttribute") 

1046 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaModuleAttribute)) 

1047 obj._owner = None 

1048 obj._owned = True 

1049 else: 

1050 obj._ptr = <cudlaModuleAttribute *>ptr 

1051 obj._owner = owner 

1052 obj._owned = False 

1053 obj._readonly = readonly 

1054 return obj 

1055  

1056  

1057cdef _get_wait_events_dtype_offsets(): 

1058 cdef cudlaWaitEvents pod = cudlaWaitEvents() 

1059 return _numpy.dtype({ 

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

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

1062 'offsets': [ 

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

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

1065 ], 

1066 'itemsize': sizeof(cudlaWaitEvents), 

1067 }) 

1068  

1069wait_events_dtype = _get_wait_events_dtype_offsets() 

1070  

1071cdef class WaitEvents: 

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

1073  

1074  

1075 .. seealso:: `cudlaWaitEvents` 

1076 """ 

1077 cdef: 

1078 cudlaWaitEvents *_ptr 

1079 object _owner 

1080 bint _owned 

1081 bint _readonly 

1082 dict _refs 

1083  

1084 def __init__(self): 

1085 self._ptr = <cudlaWaitEvents *>calloc(1, sizeof(cudlaWaitEvents)) 1n

1086 if self._ptr == NULL: 1n

1087 raise MemoryError("Error allocating WaitEvents") 

1088 self._owner = None 1n

1089 self._owned = True 1n

1090 self._readonly = False 1n

1091 self._refs = {} 1n

1092  

1093 def __dealloc__(self): 

1094 cdef cudlaWaitEvents *ptr 

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

1096 ptr = self._ptr 1n

1097 self._ptr = NULL 1n

1098 free(ptr) 1n

1099  

1100 def __repr__(self): 

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

1102  

1103 @property 

1104 def ptr(self): 

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

1106 return <intptr_t>(self._ptr) 

1107  

1108 cdef intptr_t _get_ptr(self): 

1109 return <intptr_t>(self._ptr) 

1110  

1111 def __int__(self): 

1112 return <intptr_t>(self._ptr) 

1113  

1114 def __eq__(self, other): 

1115 cdef WaitEvents other_ 

1116 if not isinstance(other, WaitEvents): 

1117 return False 

1118 other_ = other 

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

1120  

1121 def __getbuffer__(self, Py_buffer *buffer, int flags): 

1122 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaWaitEvents), self._readonly) 

1123  

1124 def __releasebuffer__(self, Py_buffer *buffer): 

1125 pass 

1126  

1127 def __setitem__(self, key, val): 

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

1129 self._ptr = <cudlaWaitEvents *>malloc(sizeof(cudlaWaitEvents)) 

1130 if self._ptr == NULL: 

1131 raise MemoryError("Error allocating WaitEvents") 

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

1133 self._owner = None 

1134 self._owned = True 

1135 self._readonly = not val.flags.writeable 

1136 else: 

1137 setattr(self, key, val) 

1138  

1139 @property 

1140 def pre_fences(self): 

1141 """int: """ 

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

1143 return [] 1n

1144 return Fence.from_ptr(<intptr_t>(self._ptr[0].preFences), self._ptr[0].numEvents) 

1145  

1146 @pre_fences.setter 

1147 def pre_fences(self, val): 

1148 if self._readonly: 

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

1150 cdef Fence arr = val 

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

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

1153 self._refs["pre_fences"] = arr 

1154  

1155 @staticmethod 

1156 def from_buffer(buffer): 

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

1158 return __from_buffer(buffer, sizeof(cudlaWaitEvents), WaitEvents) 

1159  

1160 @staticmethod 

1161 def from_data(data): 

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

1163  

1164 Args: 

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

1166 """ 

1167 return __from_data(data, "wait_events_dtype", wait_events_dtype, WaitEvents) 

1168  

1169 @staticmethod 

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

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

1172  

1173 Args: 

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

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

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

1177 """ 

1178 if ptr == 0: 

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

1180 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents) 

1181 if owner is None: 

1182 obj._ptr = <cudlaWaitEvents *>malloc(sizeof(cudlaWaitEvents)) 

1183 if obj._ptr == NULL: 

1184 raise MemoryError("Error allocating WaitEvents") 

1185 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaWaitEvents)) 

1186 obj._owner = None 

1187 obj._owned = True 

1188 else: 

1189 obj._ptr = <cudlaWaitEvents *>ptr 

1190 obj._owner = owner 

1191 obj._owned = False 

1192 obj._readonly = readonly 

1193 obj._refs = {} 

1194 return obj 

1195  

1196  

1197cdef _get_signal_events_dtype_offsets(): 

1198 cdef cudlaSignalEvents pod = cudlaSignalEvents() 

1199 return _numpy.dtype({ 

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

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

1202 'offsets': [ 

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

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

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

1206 ], 

1207 'itemsize': sizeof(cudlaSignalEvents), 

1208 }) 

1209  

1210signal_events_dtype = _get_signal_events_dtype_offsets() 

1211  

1212cdef class SignalEvents: 

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

1214  

1215  

1216 .. seealso:: `cudlaSignalEvents` 

1217 """ 

1218 cdef: 

1219 cudlaSignalEvents *_ptr 

1220 object _owner 

1221 bint _owned 

1222 bint _readonly 

1223 dict _refs 

1224  

1225 def __init__(self): 

1226 self._ptr = <cudlaSignalEvents *>calloc(1, sizeof(cudlaSignalEvents)) 1o

1227 if self._ptr == NULL: 1o

1228 raise MemoryError("Error allocating SignalEvents") 

1229 self._owner = None 1o

1230 self._owned = True 1o

1231 self._readonly = False 1o

1232 self._refs = {} 1o

1233  

1234 def __dealloc__(self): 

1235 cdef cudlaSignalEvents *ptr 

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

1237 ptr = self._ptr 1o

1238 self._ptr = NULL 1o

1239 free(ptr) 1o

1240  

1241 def __repr__(self): 

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

1243  

1244 @property 

1245 def ptr(self): 

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

1247 return <intptr_t>(self._ptr) 

1248  

1249 cdef intptr_t _get_ptr(self): 

1250 return <intptr_t>(self._ptr) 

1251  

1252 def __int__(self): 

1253 return <intptr_t>(self._ptr) 

1254  

1255 def __eq__(self, other): 

1256 cdef SignalEvents other_ 

1257 if not isinstance(other, SignalEvents): 

1258 return False 

1259 other_ = other 

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

1261  

1262 def __getbuffer__(self, Py_buffer *buffer, int flags): 

1263 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaSignalEvents), self._readonly) 

1264  

1265 def __releasebuffer__(self, Py_buffer *buffer): 

1266 pass 

1267  

1268 def __setitem__(self, key, val): 

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

1270 self._ptr = <cudlaSignalEvents *>malloc(sizeof(cudlaSignalEvents)) 

1271 if self._ptr == NULL: 

1272 raise MemoryError("Error allocating SignalEvents") 

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

1274 self._owner = None 

1275 self._owned = True 

1276 self._readonly = not val.flags.writeable 

1277 else: 

1278 setattr(self, key, val) 

1279  

1280 @property 

1281 def dev_ptrs(self): 

1282 """int: """ 

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

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

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

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

1287 return arr 

1288  

1289 @dev_ptrs.setter 

1290 def dev_ptrs(self, val): 

1291 if self._readonly: 

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

1293 cdef Py_ssize_t _n = len(val) 

1294 self._ptr[0].numEvents = _n 

1295 if _n == 0: 

1296 return 

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

1298 cdef intptr_t[:] mv = arr 

1299 cdef Py_ssize_t i 

1300 for i in range(_n): 

1301 mv[i] = val[i] 

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

1303 self._refs["dev_ptrs"] = arr 

1304  

1305 @property 

1306 def eof_fences(self): 

1307 """int: """ 

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

1309 return [] 1o

1310 return Fence.from_ptr(<intptr_t>(self._ptr[0].eofFences), self._ptr[0].numEvents) 

1311  

1312 @eof_fences.setter 

1313 def eof_fences(self, val): 

1314 if self._readonly: 

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

1316 cdef Fence arr = val 

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

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

1319 self._refs["eof_fences"] = arr 

1320  

1321 @staticmethod 

1322 def from_buffer(buffer): 

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

1324 return __from_buffer(buffer, sizeof(cudlaSignalEvents), SignalEvents) 

1325  

1326 @staticmethod 

1327 def from_data(data): 

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

1329  

1330 Args: 

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

1332 """ 

1333 return __from_data(data, "signal_events_dtype", signal_events_dtype, SignalEvents) 

1334  

1335 @staticmethod 

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

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

1338  

1339 Args: 

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

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

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

1343 """ 

1344 if ptr == 0: 

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

1346 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents) 

1347 if owner is None: 

1348 obj._ptr = <cudlaSignalEvents *>malloc(sizeof(cudlaSignalEvents)) 

1349 if obj._ptr == NULL: 

1350 raise MemoryError("Error allocating SignalEvents") 

1351 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaSignalEvents)) 

1352 obj._owner = None 

1353 obj._owned = True 

1354 else: 

1355 obj._ptr = <cudlaSignalEvents *>ptr 

1356 obj._owner = owner 

1357 obj._owned = False 

1358 obj._readonly = readonly 

1359 obj._refs = {} 

1360 return obj 

1361  

1362  

1363cdef _get_task_dtype_offsets(): 

1364 cdef cudlaTask pod = cudlaTask() 

1365 return _numpy.dtype({ 

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

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

1368 'offsets': [ 

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

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

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

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

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

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

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

1376 ], 

1377 'itemsize': sizeof(cudlaTask), 

1378 }) 

1379  

1380task_dtype = _get_task_dtype_offsets() 

1381  

1382cdef class Task: 

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

1384  

1385  

1386 .. seealso:: `cudlaTask` 

1387 """ 

1388 cdef: 

1389 cudlaTask *_ptr 

1390 object _owner 

1391 bint _owned 

1392 bint _readonly 

1393 dict _refs 

1394  

1395 def __init__(self): 

1396 self._ptr = <cudlaTask *>calloc(1, sizeof(cudlaTask)) 1ebkcd

1397 if self._ptr == NULL: 1ebkcd

1398 raise MemoryError("Error allocating Task") 

1399 self._owner = None 1ebkcd

1400 self._owned = True 1ebkcd

1401 self._readonly = False 1ebkcd

1402 self._refs = {} 1ebkcd

1403  

1404 def __dealloc__(self): 

1405 cdef cudlaTask *ptr 

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

1407 ptr = self._ptr 1ebkcd

1408 self._ptr = NULL 1ebkcd

1409 free(ptr) 1ebkcd

1410  

1411 def __repr__(self): 

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

1413  

1414 @property 

1415 def ptr(self): 

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

1417 return <intptr_t>(self._ptr) 

1418  

1419 cdef intptr_t _get_ptr(self): 

1420 return <intptr_t>(self._ptr) 

1421  

1422 def __int__(self): 

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

1424  

1425 def __eq__(self, other): 

1426 cdef Task other_ 

1427 if not isinstance(other, Task): 

1428 return False 

1429 other_ = other 

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

1431  

1432 def __getbuffer__(self, Py_buffer *buffer, int flags): 

1433 __getbuffer(self, buffer, <void *>self._ptr, sizeof(cudlaTask), self._readonly) 

1434  

1435 def __releasebuffer__(self, Py_buffer *buffer): 

1436 pass 

1437  

1438 def __setitem__(self, key, val): 

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

1440 self._ptr = <cudlaTask *>malloc(sizeof(cudlaTask)) 

1441 if self._ptr == NULL: 

1442 raise MemoryError("Error allocating Task") 

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

1444 self._owner = None 

1445 self._owned = True 

1446 self._readonly = not val.flags.writeable 

1447 else: 

1448 setattr(self, key, val) 

1449  

1450 @property 

1451 def module_handle(self): 

1452 """int: """ 

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

1454  

1455 @module_handle.setter 

1456 def module_handle(self, val): 

1457 if self._readonly: 1bk

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

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

1460  

1461 @property 

1462 def output_tensor(self): 

1463 """int: """ 

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

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

1466 cdef view.array arr = view.array(shape=(self._ptr[0].numOutputTensors,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False) 1bd

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

1468 return arr 1bd

1469  

1470 @output_tensor.setter 

1471 def output_tensor(self, val): 

1472 if self._readonly: 1bd

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

1474 cdef Py_ssize_t _n = len(val) 1bd

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

1476 if _n == 0: 1bd

1477 return 

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

1479 cdef intptr_t[:] mv = arr 1bd

1480 cdef Py_ssize_t i 

1481 for i in range(_n): 1bd

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

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

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

1485  

1486 @property 

1487 def input_tensor(self): 

1488 """int: """ 

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

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

1491 cdef view.array arr = view.array(shape=(self._ptr[0].numInputTensors,), itemsize=sizeof(intptr_t), format="q", mode="c", allocate_buffer=False) 1bc

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

1493 return arr 1bc

1494  

1495 @input_tensor.setter 

1496 def input_tensor(self, val): 

1497 if self._readonly: 1bc

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

1499 cdef Py_ssize_t _n = len(val) 1bc

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

1501 if _n == 0: 1bc

1502 return 

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

1504 cdef intptr_t[:] mv = arr 1bc

1505 cdef Py_ssize_t i 

1506 for i in range(_n): 1bc

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

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

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

1510  

1511 @property 

1512 def wait_events(self): 

1513 """int: """ 

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

1515  

1516 @wait_events.setter 

1517 def wait_events(self, val): 

1518 if self._readonly: 1b

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

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

1521  

1522 @property 

1523 def signal_events(self): 

1524 """int: """ 

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

1526  

1527 @signal_events.setter 

1528 def signal_events(self, val): 

1529 if self._readonly: 1b

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

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

1532  

1533 @staticmethod 

1534 def from_buffer(buffer): 

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

1536 return __from_buffer(buffer, sizeof(cudlaTask), Task) 

1537  

1538 @staticmethod 

1539 def from_data(data): 

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

1541  

1542 Args: 

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

1544 """ 

1545 return __from_data(data, "task_dtype", task_dtype, Task) 

1546  

1547 @staticmethod 

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

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

1550  

1551 Args: 

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

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

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

1555 """ 

1556 if ptr == 0: 

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

1558 cdef Task obj = Task.__new__(Task) 

1559 if owner is None: 

1560 obj._ptr = <cudlaTask *>malloc(sizeof(cudlaTask)) 

1561 if obj._ptr == NULL: 

1562 raise MemoryError("Error allocating Task") 

1563 memcpy(<void*>(obj._ptr), <void*>ptr, sizeof(cudlaTask)) 

1564 obj._owner = None 

1565 obj._owned = True 

1566 else: 

1567 obj._ptr = <cudlaTask *>ptr 

1568 obj._owner = owner 

1569 obj._owned = False 

1570 obj._readonly = readonly 

1571 obj._refs = {} 

1572 return obj 

1573  

1574  

1575############################################################################### 

1576# Enum 

1577############################################################################### 

1578  

1579class Status(_IntEnum): 

1580 """ 

1581 See `cudlaStatus`. 

1582 """ 

1583 Success = cudlaSuccess 

1584 ErrorInvalidParam = cudlaErrorInvalidParam 

1585 ErrorOutOfResources = cudlaErrorOutOfResources 

1586 ErrorCreationFailed = cudlaErrorCreationFailed 

1587 ErrorInvalidAddress = cudlaErrorInvalidAddress 

1588 ErrorOs = cudlaErrorOs 

1589 ErrorCuda = cudlaErrorCuda 

1590 ErrorUmd = cudlaErrorUmd 

1591 ErrorInvalidDevice = cudlaErrorInvalidDevice 

1592 ErrorInvalidAttribute = cudlaErrorInvalidAttribute 

1593 ErrorIncompatibleDlaSWVersion = cudlaErrorIncompatibleDlaSWVersion 

1594 ErrorMemoryRegistered = cudlaErrorMemoryRegistered 

1595 ErrorInvalidModule = cudlaErrorInvalidModule 

1596 ErrorUnsupportedOperation = cudlaErrorUnsupportedOperation 

1597 ErrorNvSci = cudlaErrorNvSci 

1598 ErrorDlaErrInvalidInput = cudlaErrorDlaErrInvalidInput 

1599 ErrorDlaErrInvalidPreAction = cudlaErrorDlaErrInvalidPreAction 

1600 ErrorDlaErrNoMem = cudlaErrorDlaErrNoMem 

1601 ErrorDlaErrProcessorBusy = cudlaErrorDlaErrProcessorBusy 

1602 ErrorDlaErrTaskStatusMismatch = cudlaErrorDlaErrTaskStatusMismatch 

1603 ErrorDlaErrEngineTimeout = cudlaErrorDlaErrEngineTimeout 

1604 ErrorDlaErrDataMismatch = cudlaErrorDlaErrDataMismatch 

1605 ErrorUnknown = cudlaErrorUnknown 

1606  

1607class Mode(_IntEnum): 

1608 """ 

1609 See `cudlaMode`. 

1610 """ 

1611 CUDA_DLA = CUDLA_CUDA_DLA 

1612 STANDALONE = CUDLA_STANDALONE 

1613  

1614class ModuleAttributeType(_IntEnum): 

1615 """ 

1616 See `cudlaModuleAttributeType`. 

1617 """ 

1618 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS 

1619 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS 

1620 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS 

1621 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS 

1622 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1623 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS 

1624  

1625class FenceType(_IntEnum): 

1626 """ 

1627 See `cudlaFenceType`. 

1628 """ 

1629 NVSCISYNC_FENCE = CUDLA_NVSCISYNC_FENCE 

1630 NVSCISYNC_FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF 

1631  

1632class ModuleLoadFlags(_IntEnum): 

1633 """ 

1634 See `cudlaModuleLoadFlags`. 

1635 """ 

1636 MODULE_DEFAULT = CUDLA_MODULE_DEFAULT 

1637 MODULE_ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS 

1638  

1639class SubmissionFlags(_IntEnum): 

1640 """ 

1641 See `cudlaSubmissionFlags`. 

1642 """ 

1643 SUBMIT_NOOP = CUDLA_SUBMIT_NOOP 

1644 SUBMIT_SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE 

1645 SUBMIT_DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK 

1646  

1647class AccessPermissionFlags(_IntEnum): 

1648 """ 

1649 See `cudlaAccessPermissionFlags`. 

1650 """ 

1651 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM 

1652 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM 

1653 TASK_STATISTICS = CUDLA_TASK_STATISTICS 

1654  

1655class DevAttributeType(_IntEnum): 

1656 """ 

1657 See `cudlaDevAttributeType`. 

1658 """ 

1659 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING 

1660 DEVICE_VERSION = CUDLA_DEVICE_VERSION 

1661  

1662  

1663############################################################################### 

1664# Error handling 

1665############################################################################### 

1666  

1667class CudlaError(Exception): 

1668  

1669 def __init__(self, status): 

1670 self.status = status 1qr

1671 s = Status(status) 1qr

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

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

1674  

1675 def __reduce__(self): 

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

1677  

1678  

1679@cython.profile(False) 

1680cpdef inline check_status(int status): 

1681 if status != 0: 

1682 raise CudlaError(status) 

1683  

1684  

1685############################################################################### 

1686# Wrapper functions 

1687############################################################################### 

1688  

1689cpdef uint64_t get_version() except? -1: 

1690 cdef uint64_t version 

1691 with nogil: 

1692 __status__ = cudlaGetVersion(&version) 

1693 check_status(__status__) 

1694 return version 

1695  

1696  

1697cpdef uint64_t device_get_count() except? -1: 

1698 cdef uint64_t p_num_devices 

1699 with nogil: 

1700 __status__ = cudlaDeviceGetCount(&p_num_devices) 

1701 check_status(__status__) 

1702 return p_num_devices 

1703  

1704  

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

1706 cdef DevHandle dev_handle 

1707 if flags == CUDLA_STANDALONE: 

1708 raise CudlaError(cudlaErrorUnsupportedOperation) 

1709 with nogil: 

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

1711 check_status(__status__) 

1712 return <intptr_t>dev_handle 

1713  

1714  

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

1716 cdef uint64_t* dev_ptr 

1717 with nogil: 

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

1719 check_status(__status__) 

1720 return <intptr_t>dev_ptr 

1721  

1722  

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

1724 cdef void* _p_module_ = get_buffer_pointer(p_module, module_size, readonly=True) 

1725 cdef Module h_module 

1726 with nogil: 

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

1728 check_status(__status__) 

1729 return <intptr_t>h_module 

1730  

1731  

1732cpdef module_unload(intptr_t h_module, uint32_t flags): 

1733 with nogil: 

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

1735 check_status(__status__) 

1736  

1737  

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

1739 with nogil: 

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

1741 check_status(__status__) 

1742  

1743  

1744cpdef object device_get_attribute(intptr_t dev_handle, int attrib) except *: 

1745 cdef DevAttribute p_attribute_py = DevAttribute() 

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

1747 with nogil: 

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

1749 check_status(__status__) 

1750 return p_attribute_py 

1751  

1752  

1753cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr): 

1754 with nogil: 

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

1756 check_status(__status__) 

1757  

1758  

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

1760 return <int>cudlaGetLastError(<const DevHandle>dev_handle) 

1761  

1762  

1763cpdef destroy_device(intptr_t dev_handle): 

1764 with nogil: 

1765 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle) 

1766 check_status(__status__) 

1767  

1768  

1769cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout): 

1770 with nogil: 

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

1772 check_status(__status__) 

1773  

1774  

1775cpdef module_get_attributes(intptr_t h_module, int attr_type) except *: 

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

1777 based on the requested attribute type. 

1778  

1779 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS, 

1780 NUM_OUTPUT_TASK_STATISTICS), returns an int. 

1781  

1782 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS, 

1783 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS), 

1784 returns a list of ModuleTensorDescriptor objects. 

1785 """ 

1786 cdef int _attr_type = attr_type 

1787 cdef cudlaModuleAttribute count_attr 

1788 cdef cudlaModuleAttribute num_attr 

1789 cdef cudlaModuleAttribute desc_attr 

1790 cdef uint32_t count 

1791 cdef cudlaModuleTensorDescriptor* desc_buf 

1792 cdef uint32_t i 

1793 cdef int num_attr_type 

1794  

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

1796 with nogil: 

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

1798 check_status(__status__) 

1799 return <int>(count_attr.numInputTensors) 

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

1801 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS: 

1802 num_attr_type = CUDLA_NUM_INPUT_TENSORS 

1803 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS: 

1804 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS 

1805 else: 

1806 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1807 with nogil: 

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

1809 check_status(__status__) 

1810 count = num_attr.numInputTensors 

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

1812 if desc_buf == NULL: 

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

1814 try: 

1815 desc_attr.inputTensorDesc = desc_buf 

1816 with nogil: 

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

1818 check_status(__status__) 

1819 result = [] 

1820 for i in range(count): 

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

1822 return result 

1823 finally: 

1824 free(desc_buf) 

1825 else: 

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