Coverage for cuda/bindings/_internal/cudla.pyx: 26.50%

200 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=a7e70bc7234821ae1f02306321604d7605aee20e0fde536def5edd52263be5de 

6  

7  

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

9  

10cdef extern from "<dlfcn.h>": 

11 void* _cyb_dlsym "dlsym"(void*, const char*) nogil 

12 const void * _cyb_RTLD_DEFAULT "RTLD_DEFAULT" 

13  

14from libc.stdint cimport intptr_t as _cyb_intptr_t 

15  

16import threading as _cyb_threading 

17  

18cdef bint _cyb___py_cudla_init = False 

19cdef dict _cyb_func_ptrs = None 

20cdef object _cyb_symbol_lock = _cyb_threading.Lock() 

21  

22# <<<< END OF PREAMBLE CONTENT >>>> 

23  

24from libc.stdint cimport uintptr_t 

25  

26from .utils import FunctionNotFoundError, NotSupportedError 

27from cuda.pathfinder import load_nvidia_dynamic_lib 

28  

29  

30############################################################################### 

31# Wrapper init 

32############################################################################### 

33  

34cdef void* __cudlaGetVersion = NULL 

35cdef void* __cudlaDeviceGetCount = NULL 

36cdef void* __cudlaCreateDevice = NULL 

37cdef void* __cudlaMemRegister = NULL 

38cdef void* __cudlaModuleLoadFromMemory = NULL 

39cdef void* __cudlaModuleGetAttributes = NULL 

40cdef void* __cudlaModuleUnload = NULL 

41cdef void* __cudlaSubmitTask = NULL 

42cdef void* __cudlaDeviceGetAttribute = NULL 

43cdef void* __cudlaMemUnregister = NULL 

44cdef void* __cudlaGetLastError = NULL 

45cdef void* __cudlaDestroyDevice = NULL 

46cdef void* __cudlaSetTaskTimeoutInMs = NULL 

47  

48cdef int _init_cudla() except -1 nogil: 

49 global _cyb___py_cudla_init 

50 cdef void* handle = NULL 

51 with gil, _cyb_symbol_lock: 

52 if _cyb___py_cudla_init: return 0 

53  

54 global __cudlaGetVersion 

55 __cudlaGetVersion = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaGetVersion') 

56 if __cudlaGetVersion == NULL: 

57 if handle == NULL: 

58 handle = load_library() 

59 __cudlaGetVersion = _cyb_dlsym(handle, 'cudlaGetVersion') 

60  

61 global __cudlaDeviceGetCount 

62 __cudlaDeviceGetCount = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaDeviceGetCount') 

63 if __cudlaDeviceGetCount == NULL: 

64 if handle == NULL: 

65 handle = load_library() 

66 __cudlaDeviceGetCount = _cyb_dlsym(handle, 'cudlaDeviceGetCount') 

67  

68 global __cudlaCreateDevice 

69 __cudlaCreateDevice = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaCreateDevice') 

70 if __cudlaCreateDevice == NULL: 

71 if handle == NULL: 

72 handle = load_library() 

73 __cudlaCreateDevice = _cyb_dlsym(handle, 'cudlaCreateDevice') 

74  

75 global __cudlaMemRegister 

76 __cudlaMemRegister = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaMemRegister') 

77 if __cudlaMemRegister == NULL: 

78 if handle == NULL: 

79 handle = load_library() 

80 __cudlaMemRegister = _cyb_dlsym(handle, 'cudlaMemRegister') 

81  

82 global __cudlaModuleLoadFromMemory 

83 __cudlaModuleLoadFromMemory = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaModuleLoadFromMemory') 

84 if __cudlaModuleLoadFromMemory == NULL: 

85 if handle == NULL: 

86 handle = load_library() 

87 __cudlaModuleLoadFromMemory = _cyb_dlsym(handle, 'cudlaModuleLoadFromMemory') 

88  

89 global __cudlaModuleGetAttributes 

90 __cudlaModuleGetAttributes = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaModuleGetAttributes') 

91 if __cudlaModuleGetAttributes == NULL: 

92 if handle == NULL: 

93 handle = load_library() 

94 __cudlaModuleGetAttributes = _cyb_dlsym(handle, 'cudlaModuleGetAttributes') 

95  

96 global __cudlaModuleUnload 

97 __cudlaModuleUnload = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaModuleUnload') 

98 if __cudlaModuleUnload == NULL: 

99 if handle == NULL: 

100 handle = load_library() 

101 __cudlaModuleUnload = _cyb_dlsym(handle, 'cudlaModuleUnload') 

102  

103 global __cudlaSubmitTask 

104 __cudlaSubmitTask = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaSubmitTask') 

105 if __cudlaSubmitTask == NULL: 

106 if handle == NULL: 

107 handle = load_library() 

108 __cudlaSubmitTask = _cyb_dlsym(handle, 'cudlaSubmitTask') 

109  

110 global __cudlaDeviceGetAttribute 

111 __cudlaDeviceGetAttribute = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaDeviceGetAttribute') 

112 if __cudlaDeviceGetAttribute == NULL: 

113 if handle == NULL: 

114 handle = load_library() 

115 __cudlaDeviceGetAttribute = _cyb_dlsym(handle, 'cudlaDeviceGetAttribute') 

116  

117 global __cudlaMemUnregister 

118 __cudlaMemUnregister = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaMemUnregister') 

119 if __cudlaMemUnregister == NULL: 

120 if handle == NULL: 

121 handle = load_library() 

122 __cudlaMemUnregister = _cyb_dlsym(handle, 'cudlaMemUnregister') 

123  

124 global __cudlaGetLastError 

125 __cudlaGetLastError = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaGetLastError') 

126 if __cudlaGetLastError == NULL: 

127 if handle == NULL: 

128 handle = load_library() 

129 __cudlaGetLastError = _cyb_dlsym(handle, 'cudlaGetLastError') 

130  

131 global __cudlaDestroyDevice 

132 __cudlaDestroyDevice = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaDestroyDevice') 

133 if __cudlaDestroyDevice == NULL: 

134 if handle == NULL: 

135 handle = load_library() 

136 __cudlaDestroyDevice = _cyb_dlsym(handle, 'cudlaDestroyDevice') 

137  

138 global __cudlaSetTaskTimeoutInMs 

139 __cudlaSetTaskTimeoutInMs = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'cudlaSetTaskTimeoutInMs') 

140 if __cudlaSetTaskTimeoutInMs == NULL: 

141 if handle == NULL: 

142 handle = load_library() 

143 __cudlaSetTaskTimeoutInMs = _cyb_dlsym(handle, 'cudlaSetTaskTimeoutInMs') 

144  

145 _cyb___py_cudla_init = True 

146 return 0 

147  

148cdef inline int _check_or_init_cudla() except -1 nogil: 

149 if _cyb___py_cudla_init: 

150 return 0 

151  

152 return _init_cudla() 

153  

154  

155cpdef dict _inspect_function_pointers(): 

156 global _cyb_func_ptrs 

157 if _cyb_func_ptrs is not None: 

158 return _cyb_func_ptrs 

159  

160 _check_or_init_cudla() 

161 cdef dict data = {} 

162 global __cudlaGetVersion 

163 data["__cudlaGetVersion"] = <_cyb_intptr_t>__cudlaGetVersion 

164  

165 global __cudlaDeviceGetCount 

166 data["__cudlaDeviceGetCount"] = <_cyb_intptr_t>__cudlaDeviceGetCount 

167  

168 global __cudlaCreateDevice 

169 data["__cudlaCreateDevice"] = <_cyb_intptr_t>__cudlaCreateDevice 

170  

171 global __cudlaMemRegister 

172 data["__cudlaMemRegister"] = <_cyb_intptr_t>__cudlaMemRegister 

173  

174 global __cudlaModuleLoadFromMemory 

175 data["__cudlaModuleLoadFromMemory"] = <_cyb_intptr_t>__cudlaModuleLoadFromMemory 

176  

177 global __cudlaModuleGetAttributes 

178 data["__cudlaModuleGetAttributes"] = <_cyb_intptr_t>__cudlaModuleGetAttributes 

179  

180 global __cudlaModuleUnload 

181 data["__cudlaModuleUnload"] = <_cyb_intptr_t>__cudlaModuleUnload 

182  

183 global __cudlaSubmitTask 

184 data["__cudlaSubmitTask"] = <_cyb_intptr_t>__cudlaSubmitTask 

185  

186 global __cudlaDeviceGetAttribute 

187 data["__cudlaDeviceGetAttribute"] = <_cyb_intptr_t>__cudlaDeviceGetAttribute 

188  

189 global __cudlaMemUnregister 

190 data["__cudlaMemUnregister"] = <_cyb_intptr_t>__cudlaMemUnregister 

191  

192 global __cudlaGetLastError 

193 data["__cudlaGetLastError"] = <_cyb_intptr_t>__cudlaGetLastError 

194  

195 global __cudlaDestroyDevice 

196 data["__cudlaDestroyDevice"] = <_cyb_intptr_t>__cudlaDestroyDevice 

197  

198 global __cudlaSetTaskTimeoutInMs 

199 data["__cudlaSetTaskTimeoutInMs"] = <_cyb_intptr_t>__cudlaSetTaskTimeoutInMs 

200 _cyb_func_ptrs = data 

201 return data 

202  

203  

204cpdef _inspect_function_pointer(str name): 

205 global _cyb_func_ptrs 

206 if _cyb_func_ptrs is None: 

207 _cyb_func_ptrs = _inspect_function_pointers() 

208 return _cyb_func_ptrs[name] 

209  

210  

211  

212  

213cdef void* load_library() except* with gil: 

214 cdef uintptr_t handle = load_nvidia_dynamic_lib("cudla")._handle_uint 

215 return <void*>handle 

216  

217  

218############################################################################### 

219# Wrapper functions 

220############################################################################### 

221  

222cdef cudlaStatus _cudlaGetVersion(uint64_t* const version) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

223 global __cudlaGetVersion 

224 _check_or_init_cudla() 

225 if __cudlaGetVersion == NULL: 

226 with gil: 

227 raise FunctionNotFoundError("function cudlaGetVersion is not found") 

228 return (<cudlaStatus (*)(uint64_t* const) noexcept nogil>__cudlaGetVersion)( 

229 version) 

230  

231  

232cdef cudlaStatus _cudlaDeviceGetCount(uint64_t* const pNumDevices) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

233 global __cudlaDeviceGetCount 

234 _check_or_init_cudla() 

235 if __cudlaDeviceGetCount == NULL: 

236 with gil: 

237 raise FunctionNotFoundError("function cudlaDeviceGetCount is not found") 

238 return (<cudlaStatus (*)(uint64_t* const) noexcept nogil>__cudlaDeviceGetCount)( 

239 pNumDevices) 

240  

241  

242cdef cudlaStatus _cudlaCreateDevice(const uint64_t device, cudlaDevHandle* const devHandle, const uint32_t flags) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

243 global __cudlaCreateDevice 

244 _check_or_init_cudla() 

245 if __cudlaCreateDevice == NULL: 

246 with gil: 

247 raise FunctionNotFoundError("function cudlaCreateDevice is not found") 

248 return (<cudlaStatus (*)(const uint64_t, cudlaDevHandle* const, const uint32_t) noexcept nogil>__cudlaCreateDevice)( 

249 device, devHandle, flags) 

250  

251  

252cdef cudlaStatus _cudlaMemRegister(const cudlaDevHandle devHandle, const uint64_t* const ptr, const size_t size, uint64_t** const devPtr, const uint32_t flags) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

253 global __cudlaMemRegister 

254 _check_or_init_cudla() 

255 if __cudlaMemRegister == NULL: 

256 with gil: 

257 raise FunctionNotFoundError("function cudlaMemRegister is not found") 

258 return (<cudlaStatus (*)(const cudlaDevHandle, const uint64_t* const, const size_t, uint64_t** const, const uint32_t) noexcept nogil>__cudlaMemRegister)( 

259 devHandle, ptr, size, devPtr, flags) 

260  

261  

262cdef cudlaStatus _cudlaModuleLoadFromMemory(const cudlaDevHandle devHandle, const uint8_t* const pModule, const size_t moduleSize, cudlaModule* const hModule, const uint32_t flags) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

263 global __cudlaModuleLoadFromMemory 

264 _check_or_init_cudla() 

265 if __cudlaModuleLoadFromMemory == NULL: 

266 with gil: 

267 raise FunctionNotFoundError("function cudlaModuleLoadFromMemory is not found") 

268 return (<cudlaStatus (*)(const cudlaDevHandle, const uint8_t* const, const size_t, cudlaModule* const, const uint32_t) noexcept nogil>__cudlaModuleLoadFromMemory)( 

269 devHandle, pModule, moduleSize, hModule, flags) 

270  

271  

272cdef cudlaStatus _cudlaModuleGetAttributes(const cudlaModule hModule, const cudlaModuleAttributeType attrType, cudlaModuleAttribute* const attribute) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

273 global __cudlaModuleGetAttributes 

274 _check_or_init_cudla() 

275 if __cudlaModuleGetAttributes == NULL: 

276 with gil: 

277 raise FunctionNotFoundError("function cudlaModuleGetAttributes is not found") 

278 return (<cudlaStatus (*)(const cudlaModule, const cudlaModuleAttributeType, cudlaModuleAttribute* const) noexcept nogil>__cudlaModuleGetAttributes)( 

279 hModule, attrType, attribute) 

280  

281  

282cdef cudlaStatus _cudlaModuleUnload(const cudlaModule hModule, const uint32_t flags) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

283 global __cudlaModuleUnload 

284 _check_or_init_cudla() 

285 if __cudlaModuleUnload == NULL: 

286 with gil: 

287 raise FunctionNotFoundError("function cudlaModuleUnload is not found") 

288 return (<cudlaStatus (*)(const cudlaModule, const uint32_t) noexcept nogil>__cudlaModuleUnload)( 

289 hModule, flags) 

290  

291  

292cdef cudlaStatus _cudlaSubmitTask(const cudlaDevHandle devHandle, const cudlaTask* const ptrToTasks, const uint32_t numTasks, void* const stream, const uint32_t flags) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

293 global __cudlaSubmitTask 

294 _check_or_init_cudla() 

295 if __cudlaSubmitTask == NULL: 

296 with gil: 

297 raise FunctionNotFoundError("function cudlaSubmitTask is not found") 

298 return (<cudlaStatus (*)(const cudlaDevHandle, const cudlaTask* const, const uint32_t, void* const, const uint32_t) noexcept nogil>__cudlaSubmitTask)( 

299 devHandle, ptrToTasks, numTasks, stream, flags) 

300  

301  

302cdef cudlaStatus _cudlaDeviceGetAttribute(const cudlaDevHandle devHandle, const cudlaDevAttributeType attrib, cudlaDevAttribute* const pAttribute) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

303 global __cudlaDeviceGetAttribute 

304 _check_or_init_cudla() 

305 if __cudlaDeviceGetAttribute == NULL: 

306 with gil: 

307 raise FunctionNotFoundError("function cudlaDeviceGetAttribute is not found") 

308 return (<cudlaStatus (*)(const cudlaDevHandle, const cudlaDevAttributeType, cudlaDevAttribute* const) noexcept nogil>__cudlaDeviceGetAttribute)( 

309 devHandle, attrib, pAttribute) 

310  

311  

312cdef cudlaStatus _cudlaMemUnregister(const cudlaDevHandle devHandle, const uint64_t* const devPtr) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

313 global __cudlaMemUnregister 

314 _check_or_init_cudla() 

315 if __cudlaMemUnregister == NULL: 

316 with gil: 

317 raise FunctionNotFoundError("function cudlaMemUnregister is not found") 

318 return (<cudlaStatus (*)(const cudlaDevHandle, const uint64_t* const) noexcept nogil>__cudlaMemUnregister)( 

319 devHandle, devPtr) 

320  

321  

322cdef cudlaStatus _cudlaGetLastError(const cudlaDevHandle devHandle) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

323 global __cudlaGetLastError 

324 _check_or_init_cudla() 

325 if __cudlaGetLastError == NULL: 

326 with gil: 

327 raise FunctionNotFoundError("function cudlaGetLastError is not found") 

328 return (<cudlaStatus (*)(const cudlaDevHandle) noexcept nogil>__cudlaGetLastError)( 

329 devHandle) 

330  

331  

332cdef cudlaStatus _cudlaDestroyDevice(const cudlaDevHandle devHandle) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

333 global __cudlaDestroyDevice 

334 _check_or_init_cudla() 

335 if __cudlaDestroyDevice == NULL: 

336 with gil: 

337 raise FunctionNotFoundError("function cudlaDestroyDevice is not found") 

338 return (<cudlaStatus (*)(const cudlaDevHandle) noexcept nogil>__cudlaDestroyDevice)( 

339 devHandle) 

340  

341  

342cdef cudlaStatus _cudlaSetTaskTimeoutInMs(const cudlaDevHandle devHandle, const uint32_t timeout) except?_CUDLASTATUS_INTERNAL_LOADING_ERROR nogil: 

343 global __cudlaSetTaskTimeoutInMs 

344 _check_or_init_cudla() 

345 if __cudlaSetTaskTimeoutInMs == NULL: 

346 with gil: 

347 raise FunctionNotFoundError("function cudlaSetTaskTimeoutInMs is not found") 

348 return (<cudlaStatus (*)(const cudlaDevHandle, const uint32_t) noexcept nogil>__cudlaSetTaskTimeoutInMs)( 

349 devHandle, timeout)