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

915 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-19 01:12 +0000

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

2# SPDX-License-Identifier: Apache-2.0 

3  

4# This code was automatically generated across versions from 1.5.0 to 13.3.0. Do not modify it directly. 

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

6  

7  

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

9  

10cimport cpython as _cyb_cpython 

11cimport cpython.buffer as _cyb_cpython_buffer 

12from cython cimport view as _cyb_view 

13from libc.stdlib cimport ( 

14 calloc as _cyb_calloc, 

15 free as _cyb_free, 

16 malloc as _cyb_malloc, 

17) 

18from libc.string cimport ( 

19 memcmp as _cyb_memcmp, 

20 memcpy as _cyb_memcpy, 

21) 

22  

23from enum import IntEnum as _cyb_IntEnum 

24  

25import numpy as _numpy 

26  

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

28 buffer.buf = <char *>ptr 

29 buffer.format = 'b' 

30 buffer.internal = NULL 

31 buffer.itemsize = 1 

32 buffer.len = size 

33 buffer.ndim = 1 

34 buffer.obj = self 

35 buffer.readonly = readonly 

36 buffer.shape = &buffer.len 

37 buffer.strides = &buffer.itemsize 

38 buffer.suboffsets = NULL 

39  

40cdef _cyb_from_buffer(buffer, size, lowpp_type): 

41 cdef _cyb_cpython.Py_buffer view 

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

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

44 try: 

45 if view.itemsize != 1: 

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

47 if view.len != size: 

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

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

50 finally: 

51 _cyb_cpython.PyBuffer_Release(&view) 

52  

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

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

55 if isinstance(data, lowpp_type): 

56 return data 

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

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

59 if data.size != 1: 

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

61 if data.dtype != expected_dtype: 

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

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

64  

65  

66# <<<< END OF PREAMBLE CONTENT >>>> 

67  

68cimport cython # NOQA 

69from libc.stdint cimport intptr_t, uintptr_t 

70from libc.stdlib cimport malloc, free 

71  

72from ._internal.utils cimport get_buffer_pointer 

73  

74  

75  

76  

77############################################################################### 

78# POD 

79############################################################################### 

80  

81cdef _get_external_memory_handle_desc_dtype_offsets(): 

82 cdef cudlaExternalMemoryHandleDesc_t pod 

83 return _numpy.dtype({ 

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

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

86 'offsets': [ 

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

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

89 ], 

90 'itemsize': sizeof(cudlaExternalMemoryHandleDesc_t), 

91 }) 

92  

93external_memory_handle_desc_dtype = _get_external_memory_handle_desc_dtype_offsets() 

94  

95cdef class ExternalMemoryHandleDesc: 

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

97  

98  

99 .. seealso:: `cudlaExternalMemoryHandleDesc_t` 

100 """ 

101 cdef: 

102 cudlaExternalMemoryHandleDesc_t *_ptr 

103 object _owner 

104 bint _owned 

105 bint _readonly 

106  

107 def __init__(self): 

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

109 if self._ptr == NULL: 1g

110 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

111 self._owner = None 1g

112 self._owned = True 1g

113 self._readonly = False 1g

114  

115 def __dealloc__(self): 

116 cdef cudlaExternalMemoryHandleDesc_t *ptr 

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

118 ptr = self._ptr 1g

119 self._ptr = NULL 1g

120 _cyb_free(ptr) 1g

121  

122 def __repr__(self): 

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

124  

125 @property 

126 def ptr(self): 

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

128 return <intptr_t>(self._ptr) 

129  

130 cdef intptr_t _get_ptr(self): 

131 return <intptr_t>(self._ptr) 

132  

133 def __int__(self): 

134 return <intptr_t>(self._ptr) 

135  

136 def __eq__(self, other): 

137 cdef ExternalMemoryHandleDesc other_ 

138 if not isinstance(other, ExternalMemoryHandleDesc): 

139 return False 

140 other_ = other 

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

142  

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

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

145  

146 def __releasebuffer__(self, Py_buffer *buffer): 

147 pass 

148  

149 def __setitem__(self, key, val): 

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

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

152 if self._ptr == NULL: 

153 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

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

155 self._owner = None 

156 self._owned = True 

157 self._readonly = not val.flags.writeable 

158 else: 

159 setattr(self, key, val) 

160  

161 @property 

162 def ext_buf_object(self): 

163 """int: """ 

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

165  

166 @ext_buf_object.setter 

167 def ext_buf_object(self, val): 

168 if self._readonly: 1g

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

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

171  

172 @property 

173 def size_(self): 

174 """int: """ 

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

176  

177 @size_.setter 

178 def size_(self, val): 

179 if self._readonly: 1g

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

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

182  

183 @staticmethod 

184 def from_buffer(buffer): 

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

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

187  

188 @staticmethod 

189 def from_data(data): 

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

191  

192 Args: 

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

194 """ 

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

196  

197 @staticmethod 

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

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

200  

201 Args: 

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

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

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

205 """ 

206 if ptr == 0: 

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

208 cdef ExternalMemoryHandleDesc obj = ExternalMemoryHandleDesc.__new__(ExternalMemoryHandleDesc) 

209 if owner is None: 

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

211 if obj._ptr == NULL: 

212 raise MemoryError("Error allocating ExternalMemoryHandleDesc") 

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

214 obj._owner = None 

215 obj._owned = True 

216 else: 

217 obj._ptr = <cudlaExternalMemoryHandleDesc_t *>ptr 

218 obj._owner = owner 

219 obj._owned = False 

220 obj._readonly = readonly 

221 return obj 

222  

223  

224cdef _get_external_semaphore_handle_desc_dtype_offsets(): 

225 cdef cudlaExternalSemaphoreHandleDesc_t pod 

226 return _numpy.dtype({ 

227 'names': ['ext_sync_object'], 

228 'formats': [_numpy.intp], 

229 'offsets': [ 

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

231 ], 

232 'itemsize': sizeof(cudlaExternalSemaphoreHandleDesc_t), 

233 }) 

234  

235external_semaphore_handle_desc_dtype = _get_external_semaphore_handle_desc_dtype_offsets() 

236  

237cdef class ExternalSemaphoreHandleDesc: 

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

239  

240  

241 .. seealso:: `cudlaExternalSemaphoreHandleDesc_t` 

242 """ 

243 cdef: 

244 cudlaExternalSemaphoreHandleDesc_t *_ptr 

245 object _owner 

246 bint _owned 

247 bint _readonly 

248  

249 def __init__(self): 

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

251 if self._ptr == NULL: 1l

252 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

253 self._owner = None 1l

254 self._owned = True 1l

255 self._readonly = False 1l

256  

257 def __dealloc__(self): 

258 cdef cudlaExternalSemaphoreHandleDesc_t *ptr 

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

260 ptr = self._ptr 1l

261 self._ptr = NULL 1l

262 _cyb_free(ptr) 1l

263  

264 def __repr__(self): 

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

266  

267 @property 

268 def ptr(self): 

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

270 return <intptr_t>(self._ptr) 

271  

272 cdef intptr_t _get_ptr(self): 

273 return <intptr_t>(self._ptr) 

274  

275 def __int__(self): 

276 return <intptr_t>(self._ptr) 

277  

278 def __eq__(self, other): 

279 cdef ExternalSemaphoreHandleDesc other_ 

280 if not isinstance(other, ExternalSemaphoreHandleDesc): 

281 return False 

282 other_ = other 

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

284  

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

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

287  

288 def __releasebuffer__(self, Py_buffer *buffer): 

289 pass 

290  

291 def __setitem__(self, key, val): 

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

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

294 if self._ptr == NULL: 

295 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

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

297 self._owner = None 

298 self._owned = True 

299 self._readonly = not val.flags.writeable 

300 else: 

301 setattr(self, key, val) 

302  

303 @property 

304 def ext_sync_object(self): 

305 """int: """ 

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

307  

308 @ext_sync_object.setter 

309 def ext_sync_object(self, val): 

310 if self._readonly: 1l

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

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

313  

314 @staticmethod 

315 def from_buffer(buffer): 

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

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

318  

319 @staticmethod 

320 def from_data(data): 

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

322  

323 Args: 

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

325 """ 

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

327  

328 @staticmethod 

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

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

331  

332 Args: 

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

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

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

336 """ 

337 if ptr == 0: 

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

339 cdef ExternalSemaphoreHandleDesc obj = ExternalSemaphoreHandleDesc.__new__(ExternalSemaphoreHandleDesc) 

340 if owner is None: 

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

342 if obj._ptr == NULL: 

343 raise MemoryError("Error allocating ExternalSemaphoreHandleDesc") 

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

345 obj._owner = None 

346 obj._owned = True 

347 else: 

348 obj._ptr = <cudlaExternalSemaphoreHandleDesc_t *>ptr 

349 obj._owner = owner 

350 obj._owned = False 

351 obj._readonly = readonly 

352 return obj 

353  

354  

355cdef _get_module_tensor_descriptor_dtype_offsets(): 

356 cdef cudlaModuleTensorDescriptor pod 

357 return _numpy.dtype({ 

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

359 'formats': [(_numpy.int8, 81), _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint64, _numpy.uint8, _numpy.uint8, _numpy.uint8, _numpy.uint8, _numpy.uint8, (_numpy.uint32, 8)], 

360 'offsets': [ 

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

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

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

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

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

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

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

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

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

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

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

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

373 ], 

374 'itemsize': sizeof(cudlaModuleTensorDescriptor), 

375 }) 

376  

377module_tensor_descriptor_dtype = _get_module_tensor_descriptor_dtype_offsets() 

378  

379cdef class ModuleTensorDescriptor: 

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

381  

382  

383 .. seealso:: `cudlaModuleTensorDescriptor` 

384 """ 

385 cdef: 

386 cudlaModuleTensorDescriptor *_ptr 

387 object _owner 

388 bint _owned 

389 bint _readonly 

390  

391 def __init__(self): 

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

393 if self._ptr == NULL: 1fpme

394 raise MemoryError("Error allocating ModuleTensorDescriptor") 

395 self._owner = None 1fpme

396 self._owned = True 1fpme

397 self._readonly = False 1fpme

398  

399 def __dealloc__(self): 

400 cdef cudlaModuleTensorDescriptor *ptr 

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

402 ptr = self._ptr 1fpme

403 self._ptr = NULL 1fpme

404 _cyb_free(ptr) 1fpme

405  

406 def __repr__(self): 

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

408  

409 @property 

410 def ptr(self): 

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

412 return <intptr_t>(self._ptr) 

413  

414 cdef intptr_t _get_ptr(self): 

415 return <intptr_t>(self._ptr) 

416  

417 def __int__(self): 

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

419  

420 def __eq__(self, other): 

421 cdef ModuleTensorDescriptor other_ 

422 if not isinstance(other, ModuleTensorDescriptor): 

423 return False 

424 other_ = other 

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

426  

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

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

429  

430 def __releasebuffer__(self, Py_buffer *buffer): 

431 pass 

432  

433 def __setitem__(self, key, val): 

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

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

436 if self._ptr == NULL: 

437 raise MemoryError("Error allocating ModuleTensorDescriptor") 

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

439 self._owner = None 

440 self._owned = True 

441 self._readonly = not val.flags.writeable 

442 else: 

443 setattr(self, key, val) 

444  

445 @property 

446 def name(self): 

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

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

449  

450 @name.setter 

451 def name(self, val): 

452 if self._readonly: 

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

454 cdef bytes buf = val.encode() 

455 if len(buf) >= 81: 

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

457 cdef char *ptr = buf 

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

459  

460 @property 

461 def size_(self): 

462 """int: """ 

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

464  

465 @size_.setter 

466 def size_(self, val): 

467 if self._readonly: 

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

469 self._ptr[0].size = val 

470  

471 @property 

472 def n(self): 

473 """int: """ 

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

475  

476 @n.setter 

477 def n(self, val): 

478 if self._readonly: 

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

480 self._ptr[0].n = val 

481  

482 @property 

483 def c(self): 

484 """int: """ 

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

486  

487 @c.setter 

488 def c(self, val): 

489 if self._readonly: 

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

491 self._ptr[0].c = val 

492  

493 @property 

494 def h(self): 

495 """int: """ 

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

497  

498 @h.setter 

499 def h(self, val): 

500 if self._readonly: 

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

502 self._ptr[0].h = val 

503  

504 @property 

505 def w(self): 

506 """int: """ 

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

508  

509 @w.setter 

510 def w(self, val): 

511 if self._readonly: 

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

513 self._ptr[0].w = val 

514  

515 @property 

516 def data_format(self): 

517 """int: """ 

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

519  

520 @data_format.setter 

521 def data_format(self, val): 

522 if self._readonly: 

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

524 self._ptr[0].dataFormat = val 

525  

526 @property 

527 def data_type(self): 

528 """int: """ 

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

530  

531 @data_type.setter 

532 def data_type(self, val): 

533 if self._readonly: 

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

535 self._ptr[0].dataType = val 

536  

537 @property 

538 def data_category(self): 

539 """int: """ 

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

541  

542 @data_category.setter 

543 def data_category(self, val): 

544 if self._readonly: 

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

546 self._ptr[0].dataCategory = val 

547  

548 @property 

549 def pixel_format(self): 

550 """int: """ 

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

552  

553 @pixel_format.setter 

554 def pixel_format(self, val): 

555 if self._readonly: 

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

557 self._ptr[0].pixelFormat = val 

558  

559 @property 

560 def pixel_mapping(self): 

561 """int: """ 

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

563  

564 @pixel_mapping.setter 

565 def pixel_mapping(self, val): 

566 if self._readonly: 

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

568 self._ptr[0].pixelMapping = val 

569  

570 @property 

571 def stride(self): 

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

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

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

575 return _numpy.asarray(arr) 1m

576  

577 @stride.setter 

578 def stride(self, val): 

579 if self._readonly: 

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

581 if len(val) != 8: 

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

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

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

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

586  

587 @staticmethod 

588 def from_buffer(buffer): 

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

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

591  

592 @staticmethod 

593 def from_data(data): 

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

595  

596 Args: 

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

598 """ 

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

600  

601 @staticmethod 

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

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

604  

605 Args: 

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

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

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

609 """ 

610 if ptr == 0: 

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

612 cdef ModuleTensorDescriptor obj = ModuleTensorDescriptor.__new__(ModuleTensorDescriptor) 

613 if owner is None: 

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

615 if obj._ptr == NULL: 

616 raise MemoryError("Error allocating ModuleTensorDescriptor") 

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

618 obj._owner = None 

619 obj._owned = True 

620 else: 

621 obj._ptr = <cudlaModuleTensorDescriptor *>ptr 

622 obj._owner = owner 

623 obj._owned = False 

624 obj._readonly = readonly 

625 return obj 

626  

627  

628cdef _get_fence_dtype_offsets(): 

629 cdef CudlaFence pod 

630 return _numpy.dtype({ 

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

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

633 'offsets': [ 

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

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

636 ], 

637 'itemsize': sizeof(CudlaFence), 

638 }) 

639  

640fence_dtype = _get_fence_dtype_offsets() 

641  

642cdef class Fence: 

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

644  

645  

646 .. seealso:: `CudlaFence` 

647 """ 

648 cdef: 

649 CudlaFence *_ptr 

650 object _owner 

651 bint _owned 

652 bint _readonly 

653  

654 def __init__(self): 

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

656 if self._ptr == NULL: 1h

657 raise MemoryError("Error allocating Fence") 

658 self._owner = None 1h

659 self._owned = True 1h

660 self._readonly = False 1h

661  

662 def __dealloc__(self): 

663 cdef CudlaFence *ptr 

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

665 ptr = self._ptr 1h

666 self._ptr = NULL 1h

667 _cyb_free(ptr) 1h

668  

669 def __repr__(self): 

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

671  

672 @property 

673 def ptr(self): 

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

675 return <intptr_t>(self._ptr) 

676  

677 cdef intptr_t _get_ptr(self): 

678 return <intptr_t>(self._ptr) 

679  

680 def __int__(self): 

681 return <intptr_t>(self._ptr) 

682  

683 def __eq__(self, other): 

684 cdef Fence other_ 

685 if not isinstance(other, Fence): 

686 return False 

687 other_ = other 

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

689  

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

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

692  

693 def __releasebuffer__(self, Py_buffer *buffer): 

694 pass 

695  

696 def __setitem__(self, key, val): 

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

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

699 if self._ptr == NULL: 

700 raise MemoryError("Error allocating Fence") 

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

702 self._owner = None 

703 self._owned = True 

704 self._readonly = not val.flags.writeable 

705 else: 

706 setattr(self, key, val) 

707  

708 @property 

709 def fence(self): 

710 """int: """ 

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

712  

713 @fence.setter 

714 def fence(self, val): 

715 if self._readonly: 1h

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

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

718  

719 @property 

720 def type(self): 

721 """int: """ 

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

723  

724 @type.setter 

725 def type(self, val): 

726 if self._readonly: 1h

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

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

729  

730 @staticmethod 

731 def from_buffer(buffer): 

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

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

734  

735 @staticmethod 

736 def from_data(data): 

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

738  

739 Args: 

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

741 """ 

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

743  

744 @staticmethod 

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

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

747  

748 Args: 

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

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

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

752 """ 

753 if ptr == 0: 

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

755 cdef Fence obj = Fence.__new__(Fence) 

756 if owner is None: 

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

758 if obj._ptr == NULL: 

759 raise MemoryError("Error allocating Fence") 

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

761 obj._owner = None 

762 obj._owned = True 

763 else: 

764 obj._ptr = <CudlaFence *>ptr 

765 obj._owner = owner 

766 obj._owned = False 

767 obj._readonly = readonly 

768 return obj 

769  

770  

771dev_attribute_dtype = _numpy.dtype(( 

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

773 { 

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

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

776 } 

777 )) 

778  

779cdef class DevAttribute: 

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

781  

782  

783 .. seealso:: `cudlaDevAttribute` 

784 """ 

785 cdef: 

786 cudlaDevAttribute *_ptr 

787 object _owner 

788 bint _owned 

789 bint _readonly 

790  

791 def __init__(self): 

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

793 if self._ptr == NULL: 1i

794 raise MemoryError("Error allocating DevAttribute") 

795 self._owner = None 1i

796 self._owned = True 1i

797 self._readonly = False 1i

798  

799 def __dealloc__(self): 

800 cdef cudlaDevAttribute *ptr 

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

802 ptr = self._ptr 1i

803 self._ptr = NULL 1i

804 _cyb_free(ptr) 1i

805  

806 def __repr__(self): 

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

808  

809 @property 

810 def ptr(self): 

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

812 return <intptr_t>(self._ptr) 

813  

814 cdef intptr_t _get_ptr(self): 

815 return <intptr_t>(self._ptr) 

816  

817 def __int__(self): 

818 return <intptr_t>(self._ptr) 

819  

820 def __eq__(self, other): 

821 cdef DevAttribute other_ 

822 if not isinstance(other, DevAttribute): 

823 return False 

824 other_ = other 

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

826  

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

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

829  

830 def __releasebuffer__(self, Py_buffer *buffer): 

831 pass 

832  

833 def __setitem__(self, key, val): 

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

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

836 if self._ptr == NULL: 

837 raise MemoryError("Error allocating DevAttribute") 

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

839 self._owner = None 

840 self._owned = True 

841 self._readonly = not val.flags.writeable 

842 else: 

843 setattr(self, key, val) 

844  

845 @property 

846 def unified_addressing_supported(self): 

847 """int: """ 

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

849  

850 @unified_addressing_supported.setter 

851 def unified_addressing_supported(self, val): 

852 if self._readonly: 1i

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

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

855  

856 @property 

857 def device_version(self): 

858 """int: """ 

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

860  

861 @device_version.setter 

862 def device_version(self, val): 

863 if self._readonly: 1i

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

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

866  

867 @staticmethod 

868 def from_buffer(buffer): 

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

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

871  

872 @staticmethod 

873 def from_data(data): 

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

875  

876 Args: 

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

878 """ 

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

880  

881 @staticmethod 

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

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

884  

885 Args: 

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

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

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

889 """ 

890 if ptr == 0: 

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

892 cdef DevAttribute obj = DevAttribute.__new__(DevAttribute) 

893 if owner is None: 

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

895 if obj._ptr == NULL: 

896 raise MemoryError("Error allocating DevAttribute") 

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

898 obj._owner = None 

899 obj._owned = True 

900 else: 

901 obj._ptr = <cudlaDevAttribute *>ptr 

902 obj._owner = owner 

903 obj._owned = False 

904 obj._readonly = readonly 

905 return obj 

906  

907  

908module_attribute_dtype = _numpy.dtype(( 

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

910 { 

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

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

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

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

915 } 

916 )) 

917  

918cdef class ModuleAttribute: 

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

920  

921  

922 .. seealso:: `cudlaModuleAttribute` 

923 """ 

924 cdef: 

925 cudlaModuleAttribute *_ptr 

926 object _owner 

927 bint _owned 

928 bint _readonly 

929  

930 def __init__(self): 

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

932 if self._ptr == NULL: 1j

933 raise MemoryError("Error allocating ModuleAttribute") 

934 self._owner = None 1j

935 self._owned = True 1j

936 self._readonly = False 1j

937  

938 def __dealloc__(self): 

939 cdef cudlaModuleAttribute *ptr 

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

941 ptr = self._ptr 1j

942 self._ptr = NULL 1j

943 _cyb_free(ptr) 1j

944  

945 def __repr__(self): 

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

947  

948 @property 

949 def ptr(self): 

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

951 return <intptr_t>(self._ptr) 

952  

953 cdef intptr_t _get_ptr(self): 

954 return <intptr_t>(self._ptr) 

955  

956 def __int__(self): 

957 return <intptr_t>(self._ptr) 

958  

959 def __eq__(self, other): 

960 cdef ModuleAttribute other_ 

961 if not isinstance(other, ModuleAttribute): 

962 return False 

963 other_ = other 

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

965  

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

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

968  

969 def __releasebuffer__(self, Py_buffer *buffer): 

970 pass 

971  

972 def __setitem__(self, key, val): 

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

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

975 if self._ptr == NULL: 

976 raise MemoryError("Error allocating ModuleAttribute") 

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

978 self._owner = None 

979 self._owned = True 

980 self._readonly = not val.flags.writeable 

981 else: 

982 setattr(self, key, val) 

983  

984 @property 

985 def num_input_tensors(self): 

986 """int: """ 

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

988  

989 @num_input_tensors.setter 

990 def num_input_tensors(self, val): 

991 if self._readonly: 1j

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

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

994  

995 @property 

996 def num_output_tensors(self): 

997 """int: """ 

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

999  

1000 @num_output_tensors.setter 

1001 def num_output_tensors(self, val): 

1002 if self._readonly: 1j

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

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

1005  

1006 @property 

1007 def input_tensor_desc(self): 

1008 """int: """ 

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

1010  

1011 @input_tensor_desc.setter 

1012 def input_tensor_desc(self, val): 

1013 if self._readonly: 

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

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

1016  

1017 @property 

1018 def output_tensor_desc(self): 

1019 """int: """ 

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

1021  

1022 @output_tensor_desc.setter 

1023 def output_tensor_desc(self, val): 

1024 if self._readonly: 

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

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

1027  

1028 @staticmethod 

1029 def from_buffer(buffer): 

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

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

1032  

1033 @staticmethod 

1034 def from_data(data): 

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

1036  

1037 Args: 

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

1039 """ 

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

1041  

1042 @staticmethod 

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

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

1045  

1046 Args: 

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

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

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

1050 """ 

1051 if ptr == 0: 

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

1053 cdef ModuleAttribute obj = ModuleAttribute.__new__(ModuleAttribute) 

1054 if owner is None: 

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

1056 if obj._ptr == NULL: 

1057 raise MemoryError("Error allocating ModuleAttribute") 

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

1059 obj._owner = None 

1060 obj._owned = True 

1061 else: 

1062 obj._ptr = <cudlaModuleAttribute *>ptr 

1063 obj._owner = owner 

1064 obj._owned = False 

1065 obj._readonly = readonly 

1066 return obj 

1067  

1068  

1069cdef _get_wait_events_dtype_offsets(): 

1070 cdef cudlaWaitEvents pod 

1071 return _numpy.dtype({ 

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

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

1074 'offsets': [ 

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

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

1077 ], 

1078 'itemsize': sizeof(cudlaWaitEvents), 

1079 }) 

1080  

1081wait_events_dtype = _get_wait_events_dtype_offsets() 

1082  

1083cdef class WaitEvents: 

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

1085  

1086  

1087 .. seealso:: `cudlaWaitEvents` 

1088 """ 

1089 cdef: 

1090 cudlaWaitEvents *_ptr 

1091 object _owner 

1092 bint _owned 

1093 bint _readonly 

1094 dict _refs 

1095  

1096 def __init__(self): 

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

1098 if self._ptr == NULL: 1n

1099 raise MemoryError("Error allocating WaitEvents") 

1100 self._owner = None 1n

1101 self._owned = True 1n

1102 self._readonly = False 1n

1103 self._refs = {} 1n

1104  

1105 def __dealloc__(self): 

1106 cdef cudlaWaitEvents *ptr 

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

1108 ptr = self._ptr 1n

1109 self._ptr = NULL 1n

1110 _cyb_free(ptr) 1n

1111  

1112 def __repr__(self): 

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

1114  

1115 @property 

1116 def ptr(self): 

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

1118 return <intptr_t>(self._ptr) 

1119  

1120 cdef intptr_t _get_ptr(self): 

1121 return <intptr_t>(self._ptr) 

1122  

1123 def __int__(self): 

1124 return <intptr_t>(self._ptr) 

1125  

1126 def __eq__(self, other): 

1127 cdef WaitEvents other_ 

1128 if not isinstance(other, WaitEvents): 

1129 return False 

1130 other_ = other 

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

1132  

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

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

1135  

1136 def __releasebuffer__(self, Py_buffer *buffer): 

1137 pass 

1138  

1139 def __setitem__(self, key, val): 

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

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

1142 if self._ptr == NULL: 

1143 raise MemoryError("Error allocating WaitEvents") 

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

1145 self._owner = None 

1146 self._owned = True 

1147 self._readonly = not val.flags.writeable 

1148 else: 

1149 setattr(self, key, val) 

1150  

1151 @property 

1152 def pre_fences(self): 

1153 """int: """ 

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

1155 return [] 1n

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

1157  

1158 @pre_fences.setter 

1159 def pre_fences(self, val): 

1160 if self._readonly: 

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

1162 cdef Fence arr = val 

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

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

1165 self._refs["pre_fences"] = arr 

1166  

1167 @staticmethod 

1168 def from_buffer(buffer): 

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

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

1171  

1172 @staticmethod 

1173 def from_data(data): 

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

1175  

1176 Args: 

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

1178 """ 

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

1180  

1181 @staticmethod 

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

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

1184  

1185 Args: 

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

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

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

1189 """ 

1190 if ptr == 0: 

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

1192 cdef WaitEvents obj = WaitEvents.__new__(WaitEvents) 

1193 if owner is None: 

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

1195 if obj._ptr == NULL: 

1196 raise MemoryError("Error allocating WaitEvents") 

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

1198 obj._owner = None 

1199 obj._owned = True 

1200 else: 

1201 obj._ptr = <cudlaWaitEvents *>ptr 

1202 obj._owner = owner 

1203 obj._owned = False 

1204 obj._readonly = readonly 

1205 obj._refs = {} 

1206 return obj 

1207  

1208  

1209cdef _get_signal_events_dtype_offsets(): 

1210 cdef cudlaSignalEvents pod 

1211 return _numpy.dtype({ 

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

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

1214 'offsets': [ 

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

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

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

1218 ], 

1219 'itemsize': sizeof(cudlaSignalEvents), 

1220 }) 

1221  

1222signal_events_dtype = _get_signal_events_dtype_offsets() 

1223  

1224cdef class SignalEvents: 

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

1226  

1227  

1228 .. seealso:: `cudlaSignalEvents` 

1229 """ 

1230 cdef: 

1231 cudlaSignalEvents *_ptr 

1232 object _owner 

1233 bint _owned 

1234 bint _readonly 

1235 dict _refs 

1236  

1237 def __init__(self): 

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

1239 if self._ptr == NULL: 1o

1240 raise MemoryError("Error allocating SignalEvents") 

1241 self._owner = None 1o

1242 self._owned = True 1o

1243 self._readonly = False 1o

1244 self._refs = {} 1o

1245  

1246 def __dealloc__(self): 

1247 cdef cudlaSignalEvents *ptr 

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

1249 ptr = self._ptr 1o

1250 self._ptr = NULL 1o

1251 _cyb_free(ptr) 1o

1252  

1253 def __repr__(self): 

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

1255  

1256 @property 

1257 def ptr(self): 

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

1259 return <intptr_t>(self._ptr) 

1260  

1261 cdef intptr_t _get_ptr(self): 

1262 return <intptr_t>(self._ptr) 

1263  

1264 def __int__(self): 

1265 return <intptr_t>(self._ptr) 

1266  

1267 def __eq__(self, other): 

1268 cdef SignalEvents other_ 

1269 if not isinstance(other, SignalEvents): 

1270 return False 

1271 other_ = other 

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

1273  

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

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

1276  

1277 def __releasebuffer__(self, Py_buffer *buffer): 

1278 pass 

1279  

1280 def __setitem__(self, key, val): 

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

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

1283 if self._ptr == NULL: 

1284 raise MemoryError("Error allocating SignalEvents") 

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

1286 self._owner = None 

1287 self._owned = True 

1288 self._readonly = not val.flags.writeable 

1289 else: 

1290 setattr(self, key, val) 

1291  

1292 @property 

1293 def dev_ptrs(self): 

1294 """int: """ 

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

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

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

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

1299 return arr 

1300  

1301 @dev_ptrs.setter 

1302 def dev_ptrs(self, val): 

1303 if self._readonly: 

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

1305 cdef Py_ssize_t _n = len(val) 

1306 self._ptr[0].numEvents = _n 

1307 if _n == 0: 

1308 return 

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

1310 cdef intptr_t[:] mv = arr 

1311 cdef Py_ssize_t i 

1312 for i in range(_n): 

1313 mv[i] = val[i] 

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

1315 self._refs["dev_ptrs"] = arr 

1316  

1317 @property 

1318 def eof_fences(self): 

1319 """int: """ 

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

1321 return [] 1o

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

1323  

1324 @eof_fences.setter 

1325 def eof_fences(self, val): 

1326 if self._readonly: 

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

1328 cdef Fence arr = val 

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

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

1331 self._refs["eof_fences"] = arr 

1332  

1333 @staticmethod 

1334 def from_buffer(buffer): 

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

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

1337  

1338 @staticmethod 

1339 def from_data(data): 

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

1341  

1342 Args: 

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

1344 """ 

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

1346  

1347 @staticmethod 

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

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

1350  

1351 Args: 

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

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

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

1355 """ 

1356 if ptr == 0: 

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

1358 cdef SignalEvents obj = SignalEvents.__new__(SignalEvents) 

1359 if owner is None: 

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

1361 if obj._ptr == NULL: 

1362 raise MemoryError("Error allocating SignalEvents") 

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

1364 obj._owner = None 

1365 obj._owned = True 

1366 else: 

1367 obj._ptr = <cudlaSignalEvents *>ptr 

1368 obj._owner = owner 

1369 obj._owned = False 

1370 obj._readonly = readonly 

1371 obj._refs = {} 

1372 return obj 

1373  

1374  

1375cdef _get_task_dtype_offsets(): 

1376 cdef cudlaTask pod 

1377 return _numpy.dtype({ 

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

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

1380 'offsets': [ 

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

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

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

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

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

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

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

1388 ], 

1389 'itemsize': sizeof(cudlaTask), 

1390 }) 

1391  

1392task_dtype = _get_task_dtype_offsets() 

1393  

1394cdef class Task: 

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

1396  

1397  

1398 .. seealso:: `cudlaTask` 

1399 """ 

1400 cdef: 

1401 cudlaTask *_ptr 

1402 object _owner 

1403 bint _owned 

1404 bint _readonly 

1405 dict _refs 

1406  

1407 def __init__(self): 

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

1409 if self._ptr == NULL: 1ebkcd

1410 raise MemoryError("Error allocating Task") 

1411 self._owner = None 1ebkcd

1412 self._owned = True 1ebkcd

1413 self._readonly = False 1ebkcd

1414 self._refs = {} 1ebkcd

1415  

1416 def __dealloc__(self): 

1417 cdef cudlaTask *ptr 

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

1419 ptr = self._ptr 1ebkcd

1420 self._ptr = NULL 1ebkcd

1421 _cyb_free(ptr) 1ebkcd

1422  

1423 def __repr__(self): 

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

1425  

1426 @property 

1427 def ptr(self): 

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

1429 return <intptr_t>(self._ptr) 

1430  

1431 cdef intptr_t _get_ptr(self): 

1432 return <intptr_t>(self._ptr) 

1433  

1434 def __int__(self): 

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

1436  

1437 def __eq__(self, other): 

1438 cdef Task other_ 

1439 if not isinstance(other, Task): 

1440 return False 

1441 other_ = other 

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

1443  

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

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

1446  

1447 def __releasebuffer__(self, Py_buffer *buffer): 

1448 pass 

1449  

1450 def __setitem__(self, key, val): 

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

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

1453 if self._ptr == NULL: 

1454 raise MemoryError("Error allocating Task") 

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

1456 self._owner = None 

1457 self._owned = True 

1458 self._readonly = not val.flags.writeable 

1459 else: 

1460 setattr(self, key, val) 

1461  

1462 @property 

1463 def module_handle(self): 

1464 """int: """ 

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

1466  

1467 @module_handle.setter 

1468 def module_handle(self, val): 

1469 if self._readonly: 1bk

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

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

1472  

1473 @property 

1474 def output_tensor(self): 

1475 """int: """ 

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

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

1478 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

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

1480 return arr 1bd

1481  

1482 @output_tensor.setter 

1483 def output_tensor(self, val): 

1484 if self._readonly: 1bd

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

1486 cdef Py_ssize_t _n = len(val) 1bd

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

1488 if _n == 0: 1bd

1489 return 

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

1491 cdef intptr_t[:] mv = arr 1bd

1492 cdef Py_ssize_t i 

1493 for i in range(_n): 1bd

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

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

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

1497  

1498 @property 

1499 def input_tensor(self): 

1500 """int: """ 

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

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

1503 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

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

1505 return arr 1bc

1506  

1507 @input_tensor.setter 

1508 def input_tensor(self, val): 

1509 if self._readonly: 1bc

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

1511 cdef Py_ssize_t _n = len(val) 1bc

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

1513 if _n == 0: 1bc

1514 return 

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

1516 cdef intptr_t[:] mv = arr 1bc

1517 cdef Py_ssize_t i 

1518 for i in range(_n): 1bc

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

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

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

1522  

1523 @property 

1524 def wait_events(self): 

1525 """int: """ 

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

1527  

1528 @wait_events.setter 

1529 def wait_events(self, val): 

1530 if self._readonly: 1b

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

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

1533  

1534 @property 

1535 def signal_events(self): 

1536 """int: """ 

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

1538  

1539 @signal_events.setter 

1540 def signal_events(self, val): 

1541 if self._readonly: 1b

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

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

1544  

1545 @staticmethod 

1546 def from_buffer(buffer): 

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

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

1549  

1550 @staticmethod 

1551 def from_data(data): 

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

1553  

1554 Args: 

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

1556 """ 

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

1558  

1559 @staticmethod 

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

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

1562  

1563 Args: 

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

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

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

1567 """ 

1568 if ptr == 0: 

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

1570 cdef Task obj = Task.__new__(Task) 

1571 if owner is None: 

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

1573 if obj._ptr == NULL: 

1574 raise MemoryError("Error allocating Task") 

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

1576 obj._owner = None 

1577 obj._owned = True 

1578 else: 

1579 obj._ptr = <cudlaTask *>ptr 

1580 obj._owner = owner 

1581 obj._owned = False 

1582 obj._readonly = readonly 

1583 obj._refs = {} 

1584 return obj 

1585  

1586  

1587############################################################################### 

1588# Enum 

1589############################################################################### 

1590  

1591class Status(_cyb_IntEnum): 

1592 """ 

1593 See `cudlaStatus`. 

1594 """ 

1595 Success = cudlaSuccess 

1596 ErrorInvalidParam = cudlaErrorInvalidParam 

1597 ErrorOutOfResources = cudlaErrorOutOfResources 

1598 ErrorCreationFailed = cudlaErrorCreationFailed 

1599 ErrorInvalidAddress = cudlaErrorInvalidAddress 

1600 ErrorOs = cudlaErrorOs 

1601 ErrorCuda = cudlaErrorCuda 

1602 ErrorUmd = cudlaErrorUmd 

1603 ErrorInvalidDevice = cudlaErrorInvalidDevice 

1604 ErrorInvalidAttribute = cudlaErrorInvalidAttribute 

1605 ErrorIncompatibleDlaSWVersion = cudlaErrorIncompatibleDlaSWVersion 

1606 ErrorMemoryRegistered = cudlaErrorMemoryRegistered 

1607 ErrorInvalidModule = cudlaErrorInvalidModule 

1608 ErrorUnsupportedOperation = cudlaErrorUnsupportedOperation 

1609 ErrorNvSci = cudlaErrorNvSci 

1610 ErrorDriverNotFound = cudlaErrorDriverNotFound 

1611 ErrorDlaErrInvalidInput = cudlaErrorDlaErrInvalidInput 

1612 ErrorDlaErrInvalidPreAction = cudlaErrorDlaErrInvalidPreAction 

1613 ErrorDlaErrNoMem = cudlaErrorDlaErrNoMem 

1614 ErrorDlaErrProcessorBusy = cudlaErrorDlaErrProcessorBusy 

1615 ErrorDlaErrTaskStatusMismatch = cudlaErrorDlaErrTaskStatusMismatch 

1616 ErrorDlaErrEngineTimeout = cudlaErrorDlaErrEngineTimeout 

1617 ErrorDlaErrDataMismatch = cudlaErrorDlaErrDataMismatch 

1618 ErrorUnknown = cudlaErrorUnknown 

1619  

1620class Mode(_cyb_IntEnum): 

1621 """ 

1622 See `cudlaMode`. 

1623 """ 

1624 CUDA_DLA = CUDLA_CUDA_DLA 

1625 STANDALONE = CUDLA_STANDALONE 

1626  

1627class ModuleAttributeType(_cyb_IntEnum): 

1628 """ 

1629 See `cudlaModuleAttributeType`. 

1630 """ 

1631 NUM_INPUT_TENSORS = CUDLA_NUM_INPUT_TENSORS 

1632 NUM_OUTPUT_TENSORS = CUDLA_NUM_OUTPUT_TENSORS 

1633 INPUT_TENSOR_DESCRIPTORS = CUDLA_INPUT_TENSOR_DESCRIPTORS 

1634 OUTPUT_TENSOR_DESCRIPTORS = CUDLA_OUTPUT_TENSOR_DESCRIPTORS 

1635 NUM_OUTPUT_TASK_STATISTICS = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1636 OUTPUT_TASK_STATISTICS_DESCRIPTORS = CUDLA_OUTPUT_TASK_STATISTICS_DESCRIPTORS 

1637  

1638class FenceType(_cyb_IntEnum): 

1639 """ 

1640 See `cudlaFenceType`. 

1641 """ 

1642 NVSCISYNC_FENCE = CUDLA_NVSCISYNC_FENCE 

1643 NVSCISYNC_FENCE_SOF = CUDLA_NVSCISYNC_FENCE_SOF 

1644  

1645class ModuleLoadFlags(_cyb_IntEnum): 

1646 """ 

1647 See `cudlaModuleLoadFlags`. 

1648 """ 

1649 MODULE_DEFAULT = CUDLA_MODULE_DEFAULT 

1650 MODULE_ENABLE_FAULT_DIAGNOSTICS = CUDLA_MODULE_ENABLE_FAULT_DIAGNOSTICS 

1651  

1652class SubmissionFlags(_cyb_IntEnum): 

1653 """ 

1654 See `cudlaSubmissionFlags`. 

1655 """ 

1656 SUBMIT_NOOP = CUDLA_SUBMIT_NOOP 

1657 SUBMIT_SKIP_LOCK_ACQUIRE = CUDLA_SUBMIT_SKIP_LOCK_ACQUIRE 

1658 SUBMIT_DIAGNOSTICS_TASK = CUDLA_SUBMIT_DIAGNOSTICS_TASK 

1659  

1660class AccessPermissionFlags(_cyb_IntEnum): 

1661 """ 

1662 See `cudlaAccessPermissionFlags`. 

1663 """ 

1664 READ_WRITE_PERM = CUDLA_READ_WRITE_PERM 

1665 READ_ONLY_PERM = CUDLA_READ_ONLY_PERM 

1666 TASK_STATISTICS = CUDLA_TASK_STATISTICS 

1667  

1668class DevAttributeType(_cyb_IntEnum): 

1669 """ 

1670 See `cudlaDevAttributeType`. 

1671 """ 

1672 UNIFIED_ADDRESSING = CUDLA_UNIFIED_ADDRESSING 

1673 DEVICE_VERSION = CUDLA_DEVICE_VERSION 

1674  

1675  

1676############################################################################### 

1677# Error handling 

1678############################################################################### 

1679  

1680class CudlaError(Exception): 

1681  

1682 def __init__(self, status): 

1683 self.status = status 1qr

1684 s = Status(status) 1qr

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

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

1687  

1688 def __reduce__(self): 

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

1690  

1691  

1692@cython.profile(False) 

1693cpdef inline check_status(int status): 

1694 if status != 0: 

1695 raise CudlaError(status) 

1696  

1697  

1698############################################################################### 

1699# Wrapper functions 

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

1701  

1702cpdef uint64_t get_version() except? -1: 

1703 cdef uint64_t version 

1704 with nogil: 

1705 __status__ = cudlaGetVersion(&version) 

1706 check_status(__status__) 

1707 return version 

1708  

1709  

1710cpdef uint64_t device_get_count() except? -1: 

1711 cdef uint64_t p_num_devices 

1712 with nogil: 

1713 __status__ = cudlaDeviceGetCount(&p_num_devices) 

1714 check_status(__status__) 

1715 return p_num_devices 

1716  

1717  

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

1719 cdef DevHandle dev_handle 

1720 if flags == CUDLA_STANDALONE: 

1721 raise CudlaError(cudlaErrorUnsupportedOperation) 

1722 with nogil: 

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

1724 check_status(__status__) 

1725 return <intptr_t>dev_handle 

1726  

1727  

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

1729 cdef uint64_t* dev_ptr 

1730 with nogil: 

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

1732 check_status(__status__) 

1733 return <intptr_t>dev_ptr 

1734  

1735  

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

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

1738 cdef Module h_module 

1739 with nogil: 

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

1741 check_status(__status__) 

1742 return <intptr_t>h_module 

1743  

1744  

1745cpdef module_unload(intptr_t h_module, uint32_t flags): 

1746 with nogil: 

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

1748 check_status(__status__) 

1749  

1750  

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

1752 with nogil: 

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

1754 check_status(__status__) 

1755  

1756  

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

1758 cdef DevAttribute p_attribute_py = DevAttribute() 

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

1760 with nogil: 

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

1762 check_status(__status__) 

1763 return p_attribute_py 

1764  

1765  

1766cpdef mem_unregister(intptr_t dev_handle, intptr_t dev_ptr): 

1767 with nogil: 

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

1769 check_status(__status__) 

1770  

1771  

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

1773 cdef int ret 

1774 with nogil: 

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

1776 return ret 

1777  

1778  

1779cpdef destroy_device(intptr_t dev_handle): 

1780 with nogil: 

1781 __status__ = cudlaDestroyDevice(<const DevHandle>dev_handle) 

1782 check_status(__status__) 

1783  

1784  

1785cpdef set_task_timeout_in_ms(intptr_t dev_handle, uint32_t timeout): 

1786 with nogil: 

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

1788 check_status(__status__) 

1789  

1790  

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

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

1793 based on the requested attribute type. 

1794  

1795 For count attributes (NUM_INPUT_TENSORS, NUM_OUTPUT_TENSORS, 

1796 NUM_OUTPUT_TASK_STATISTICS), returns an int. 

1797  

1798 For descriptor attributes (INPUT_TENSOR_DESCRIPTORS, 

1799 OUTPUT_TENSOR_DESCRIPTORS, OUTPUT_TASK_STATISTICS_DESCRIPTORS), 

1800 returns a list of ModuleTensorDescriptor objects. 

1801 """ 

1802 cdef int _attr_type = attr_type 

1803 cdef cudlaModuleAttribute count_attr 

1804 cdef cudlaModuleAttribute num_attr 

1805 cdef cudlaModuleAttribute desc_attr 

1806 cdef uint32_t count 

1807 cdef cudlaModuleTensorDescriptor* desc_buf 

1808 cdef uint32_t i 

1809 cdef int num_attr_type 

1810  

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

1812 with nogil: 

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

1814 check_status(__status__) 

1815 return <int>(count_attr.numInputTensors) 

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

1817 if _attr_type == CUDLA_INPUT_TENSOR_DESCRIPTORS: 

1818 num_attr_type = CUDLA_NUM_INPUT_TENSORS 

1819 elif _attr_type == CUDLA_OUTPUT_TENSOR_DESCRIPTORS: 

1820 num_attr_type = CUDLA_NUM_OUTPUT_TENSORS 

1821 else: 

1822 num_attr_type = CUDLA_NUM_OUTPUT_TASK_STATISTICS 

1823 with nogil: 

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

1825 check_status(__status__) 

1826 count = num_attr.numInputTensors 

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

1828 if desc_buf == NULL: 

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

1830 try: 

1831 desc_attr.inputTensorDesc = desc_buf 

1832 with nogil: 

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

1834 check_status(__status__) 

1835 result = [] 

1836 for i in range(count): 

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

1838 return result 

1839 finally: 

1840 free(desc_buf) 

1841 else: 

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

1843del _cyb_IntEnum