Coverage for cuda/bindings/_internal/nvfatbin.pyx: 66.31%

187 statements  

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

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

2# 

3# SPDX-License-Identifier: Apache-2.0 

4# 

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

6# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=8a025fac12ad4fa9dc651c68c1ab7948f78cbb4b9450935db8f930c9d44988f4 

7  

8  

9# <<<< PREAMBLE CONTENT >>>> 

10  

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

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

13 const void * _cyb_RTLD_DEFAULT "RTLD_DEFAULT" 

14  

15from libc.stdint cimport intptr_t as _cyb_intptr_t 

16  

17import threading as _cyb_threading 

18  

19cdef bint _cyb___py_nvfatbin_init = False 

20cdef dict _cyb_func_ptrs = None 

21cdef object _cyb_symbol_lock = _cyb_threading.Lock() 

22  

23# <<<< END OF PREAMBLE CONTENT >>>> 

24  

25from libc.stdint cimport uintptr_t 

26  

27from .utils import FunctionNotFoundError, NotSupportedError 

28from cuda.pathfinder import load_nvidia_dynamic_lib 

29  

30  

31############################################################################### 

32# Wrapper init 

33############################################################################### 

34  

35cdef void* __nvFatbinGetErrorString = NULL 

36cdef void* __nvFatbinCreate = NULL 

37cdef void* __nvFatbinDestroy = NULL 

38cdef void* __nvFatbinAddPTX = NULL 

39cdef void* __nvFatbinAddCubin = NULL 

40cdef void* __nvFatbinAddLTOIR = NULL 

41cdef void* __nvFatbinSize = NULL 

42cdef void* __nvFatbinGet = NULL 

43cdef void* __nvFatbinVersion = NULL 

44cdef void* __nvFatbinAddIndex = NULL 

45cdef void* __nvFatbinAddReloc = NULL 

46cdef void* __nvFatbinAddTileIR = NULL 

47  

48cdef int _init_nvfatbin() except -1 nogil: 

49 global _cyb___py_nvfatbin_init 

50 cdef void* handle = NULL 

51 with gil, _cyb_symbol_lock: 

52 if _cyb___py_nvfatbin_init: return 0 

53  

54 global __nvFatbinGetErrorString 

55 __nvFatbinGetErrorString = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinGetErrorString') 

56 if __nvFatbinGetErrorString == NULL: 

57 if handle == NULL: 

58 handle = load_library() 

59 __nvFatbinGetErrorString = _cyb_dlsym(handle, 'nvFatbinGetErrorString') 

60  

61 global __nvFatbinCreate 

62 __nvFatbinCreate = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinCreate') 

63 if __nvFatbinCreate == NULL: 

64 if handle == NULL: 

65 handle = load_library() 

66 __nvFatbinCreate = _cyb_dlsym(handle, 'nvFatbinCreate') 

67  

68 global __nvFatbinDestroy 

69 __nvFatbinDestroy = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinDestroy') 

70 if __nvFatbinDestroy == NULL: 

71 if handle == NULL: 

72 handle = load_library() 

73 __nvFatbinDestroy = _cyb_dlsym(handle, 'nvFatbinDestroy') 

74  

75 global __nvFatbinAddPTX 

76 __nvFatbinAddPTX = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddPTX') 

77 if __nvFatbinAddPTX == NULL: 

78 if handle == NULL: 

79 handle = load_library() 

80 __nvFatbinAddPTX = _cyb_dlsym(handle, 'nvFatbinAddPTX') 

81  

82 global __nvFatbinAddCubin 

83 __nvFatbinAddCubin = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddCubin') 

84 if __nvFatbinAddCubin == NULL: 

85 if handle == NULL: 

86 handle = load_library() 

87 __nvFatbinAddCubin = _cyb_dlsym(handle, 'nvFatbinAddCubin') 

88  

89 global __nvFatbinAddLTOIR 

90 __nvFatbinAddLTOIR = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddLTOIR') 

91 if __nvFatbinAddLTOIR == NULL: 

92 if handle == NULL: 

93 handle = load_library() 

94 __nvFatbinAddLTOIR = _cyb_dlsym(handle, 'nvFatbinAddLTOIR') 1aMNOPQRSTUVWXYZ0123bcdefghiIJjklmnopqrstuvwxyzKDL4

95  

96 global __nvFatbinSize 

97 __nvFatbinSize = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinSize') 

98 if __nvFatbinSize == NULL: 

99 if handle == NULL: 

100 handle = load_library() 

101 __nvFatbinSize = _cyb_dlsym(handle, 'nvFatbinSize') 

102  

103 global __nvFatbinGet 

104 __nvFatbinGet = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinGet') 

105 if __nvFatbinGet == NULL: 

106 if handle == NULL: 

107 handle = load_library() 

108 __nvFatbinGet = _cyb_dlsym(handle, 'nvFatbinGet') 

109  

110 global __nvFatbinVersion 

111 __nvFatbinVersion = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinVersion') 

112 if __nvFatbinVersion == NULL: 

113 if handle == NULL: 

114 handle = load_library() 

115 __nvFatbinVersion = _cyb_dlsym(handle, 'nvFatbinVersion') 

116  

117 global __nvFatbinAddIndex 

118 __nvFatbinAddIndex = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddIndex') 

119 if __nvFatbinAddIndex == NULL: 

120 if handle == NULL: 

121 handle = load_library() 

122 __nvFatbinAddIndex = _cyb_dlsym(handle, 'nvFatbinAddIndex') 

123  

124 global __nvFatbinAddReloc 

125 __nvFatbinAddReloc = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddReloc') 

126 if __nvFatbinAddReloc == NULL: 

127 if handle == NULL: 

128 handle = load_library() 

129 __nvFatbinAddReloc = _cyb_dlsym(handle, 'nvFatbinAddReloc') 

130  

131 global __nvFatbinAddTileIR 

132 __nvFatbinAddTileIR = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddTileIR') 

133 if __nvFatbinAddTileIR == NULL: 

134 if handle == NULL: 

135 handle = load_library() 

136 __nvFatbinAddTileIR = _cyb_dlsym(handle, 'nvFatbinAddTileIR') 

137  

138 _cyb___py_nvfatbin_init = True 

139 return 0 

140  

141cdef inline int _check_or_init_nvfatbin() except -1 nogil: 

142 if _cyb___py_nvfatbin_init: 1aABCMNOPQRSTUVWXYZ0123bcdefghiIJjklmnopqrstuvwxyEFGHzKDL4

143 return 0 1ABCMNOPQRSTUVWXYZ0123bcdefghiIJjklmnopqrstuvwxyEFGHzKDL4

144  

145 return _init_nvfatbin() 

146  

147  

148cpdef dict _inspect_function_pointers(): 

149 global _cyb_func_ptrs 

150 if _cyb_func_ptrs is not None: 

151 return _cyb_func_ptrs 

152  

153 _check_or_init_nvfatbin() 

154 cdef dict data = {} 

155 global __nvFatbinGetErrorString 

156 data["__nvFatbinGetErrorString"] = <_cyb_intptr_t>__nvFatbinGetErrorString 

157  

158 global __nvFatbinCreate 

159 data["__nvFatbinCreate"] = <_cyb_intptr_t>__nvFatbinCreate 

160  

161 global __nvFatbinDestroy 

162 data["__nvFatbinDestroy"] = <_cyb_intptr_t>__nvFatbinDestroy 

163  

164 global __nvFatbinAddPTX 

165 data["__nvFatbinAddPTX"] = <_cyb_intptr_t>__nvFatbinAddPTX 1MNOPQRSTUVWXYZ0123

166  

167 global __nvFatbinAddCubin 

168 data["__nvFatbinAddCubin"] = <_cyb_intptr_t>__nvFatbinAddCubin 

169  

170 global __nvFatbinAddLTOIR 

171 data["__nvFatbinAddLTOIR"] = <_cyb_intptr_t>__nvFatbinAddLTOIR 

172  

173 global __nvFatbinSize 

174 data["__nvFatbinSize"] = <_cyb_intptr_t>__nvFatbinSize 

175  

176 global __nvFatbinGet 

177 data["__nvFatbinGet"] = <_cyb_intptr_t>__nvFatbinGet 

178  

179 global __nvFatbinVersion 

180 data["__nvFatbinVersion"] = <_cyb_intptr_t>__nvFatbinVersion 

181  

182 global __nvFatbinAddIndex 

183 data["__nvFatbinAddIndex"] = <_cyb_intptr_t>__nvFatbinAddIndex 

184  

185 global __nvFatbinAddReloc 

186 data["__nvFatbinAddReloc"] = <_cyb_intptr_t>__nvFatbinAddReloc 1bcdefghiIJjklmnopqrstuvwxyzKD

187  

188 global __nvFatbinAddTileIR 

189 data["__nvFatbinAddTileIR"] = <_cyb_intptr_t>__nvFatbinAddTileIR 1bcdefghiIJjklmnopqrstuvwxyzKD

190 _cyb_func_ptrs = data 

191 return data 

192  

193  

194cpdef _inspect_function_pointer(str name): 

195 global _cyb_func_ptrs 

196 if _cyb_func_ptrs is None: 1jklmnopqrstuvwxy

197 _cyb_func_ptrs = _inspect_function_pointers() 

198 return _cyb_func_ptrs[name] 

199  

200  

201  

202  

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

204 cdef uintptr_t handle = load_nvidia_dynamic_lib("nvfatbin")._handle_uint 

205 return <void*>handle 1afghiIJ

206  

207  

208############################################################################### 

209# Wrapper functions 

210############################################################################### 

211  

212cdef const char* _nvFatbinGetErrorString(nvFatbinResult result) except?NULL nogil: 

213 global __nvFatbinGetErrorString 

214 _check_or_init_nvfatbin() 1MNOPQRSTUVWXYZ0123

215 if __nvFatbinGetErrorString == NULL: 1MNOPQRSTUVWXYZ0123bcde

216 with gil: 1bcde

217 raise FunctionNotFoundError("function nvFatbinGetErrorString is not found") 

218 return (<const char* (*)(nvFatbinResult) noexcept nogil>__nvFatbinGetErrorString)( 1MNOPQRSTUVWXYZ0123

219 result) 

220  

221  

222cdef nvFatbinResult _nvFatbinCreate(nvFatbinHandle* handle_indirect, const char** options, size_t optionsCount) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

223 global __nvFatbinCreate 

224 _check_or_init_nvfatbin() 1ABCbcdefghiIJjklmnopqrstuvwxyEFGHzKD4

225 if __nvFatbinCreate == NULL: 1ABCbcdefghiIJjklmnopqrstuvwxyEFGHzKD4

226 with gil: 1bcdefghijklmnopqrstuvwxyzD

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

228 return (<nvFatbinResult (*)(nvFatbinHandle*, const char**, size_t) noexcept nogil>__nvFatbinCreate)( 1ABCbcdefghiIJjklmnopqrstuvwxyEFGHzKD4

229 handle_indirect, options, optionsCount) 

230  

231  

232cdef nvFatbinResult _nvFatbinDestroy(nvFatbinHandle* handle_indirect) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

233 global __nvFatbinDestroy 

234 _check_or_init_nvfatbin() 1ABCbcdefghiIJjklmnopqrstuvwxyEFGHzKD

235 if __nvFatbinDestroy == NULL: 1ABCbcdefghiIJjklmnopqrstuvwxyEFGHzKD

236 with gil: 1bcdefghijklmnopqrstuvwxyzD

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

238 return (<nvFatbinResult (*)(nvFatbinHandle*) noexcept nogil>__nvFatbinDestroy)( 1ABCbcdefghiIJjklmnopqrstuvwxyEFGHzKD

239 handle_indirect) 

240  

241  

242cdef nvFatbinResult _nvFatbinAddPTX(nvFatbinHandle handle, const char* code, size_t size, const char* arch, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

243 global __nvFatbinAddPTX 

244 _check_or_init_nvfatbin() 1ABCjklmnopqrstuvwxy

245 if __nvFatbinAddPTX == NULL: 1aABCjklmnopqrstuvwxyL

246 with gil: 1aL

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

248 return (<nvFatbinResult (*)(nvFatbinHandle, const char*, size_t, const char*, const char*, const char*) noexcept nogil>__nvFatbinAddPTX)( 1ABCjklmnopqrstuvwxy

249 handle, code, size, arch, identifier, optionsCmdLine) 

250  

251  

252cdef nvFatbinResult _nvFatbinAddCubin(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

253 global __nvFatbinAddCubin 

254 _check_or_init_nvfatbin() 1ABCfghiIJ

255 if __nvFatbinAddCubin == NULL: 1ABCfghiIJ

256 with gil: 

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

258 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*) noexcept nogil>__nvFatbinAddCubin)( 1ABCfghiIJ

259 handle, code, size, arch, identifier) 

260  

261  

262cdef nvFatbinResult _nvFatbinAddLTOIR(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

263 global __nvFatbinAddLTOIR 

264 _check_or_init_nvfatbin() 1bcde

265 if __nvFatbinAddLTOIR == NULL: 1bcde

266 with gil: 

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

268 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*, const char*) noexcept nogil>__nvFatbinAddLTOIR)( 1bcde

269 handle, code, size, arch, identifier, optionsCmdLine) 

270  

271  

272cdef nvFatbinResult _nvFatbinSize(nvFatbinHandle handle, size_t* size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

273 global __nvFatbinSize 

274 _check_or_init_nvfatbin() 1ABCbcdefghijklmnopqrstuvwxyEFGHzD

275 if __nvFatbinSize == NULL: 1ABCbcdefghijklmnopqrstuvwxyEFGHzD

276 with gil: 1z

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

278 return (<nvFatbinResult (*)(nvFatbinHandle, size_t*) noexcept nogil>__nvFatbinSize)( 1ABCbcdefghijklmnopqrstuvwxyEFGHzD

279 handle, size) 

280  

281  

282cdef nvFatbinResult _nvFatbinGet(nvFatbinHandle handle, void* buffer) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

283 global __nvFatbinGet 

284 _check_or_init_nvfatbin() 1ABCbcdefghijklmnopqrstuvwxyEFGHzD

285 if __nvFatbinGet == NULL: 1ABCbcdefghijklmnopqrstuvwxyEFGHzD

286 with gil: 

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

288 return (<nvFatbinResult (*)(nvFatbinHandle, void*) noexcept nogil>__nvFatbinGet)( 1ABCbcdefghijklmnopqrstuvwxyEFGHzD

289 handle, buffer) 

290  

291  

292cdef nvFatbinResult _nvFatbinVersion(unsigned int* major, unsigned int* minor) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

293 global __nvFatbinVersion 

294 _check_or_init_nvfatbin() 1aL

295 if __nvFatbinVersion == NULL: 1aL

296 with gil: 

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

298 return (<nvFatbinResult (*)(unsigned int*, unsigned int*) noexcept nogil>__nvFatbinVersion)( 1aL

299 major, minor) 

300  

301  

302cdef nvFatbinResult _nvFatbinAddIndex(nvFatbinHandle handle, const void* code, size_t size, const char* identifier) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

303 global __nvFatbinAddIndex 

304 _check_or_init_nvfatbin() 

305 if __nvFatbinAddIndex == NULL: 

306 with gil: 

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

308 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*) noexcept nogil>__nvFatbinAddIndex)( 

309 handle, code, size, identifier) 

310  

311  

312cdef nvFatbinResult _nvFatbinAddReloc(nvFatbinHandle handle, const void* code, size_t size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

313 global __nvFatbinAddReloc 

314 _check_or_init_nvfatbin() 1EFGH

315 if __nvFatbinAddReloc == NULL: 1EFGH

316 with gil: 

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

318 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t) noexcept nogil>__nvFatbinAddReloc)( 1EFGH

319 handle, code, size) 

320  

321  

322cdef nvFatbinResult _nvFatbinAddTileIR(nvFatbinHandle handle, const void* code, size_t size, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 

323 global __nvFatbinAddTileIR 

324 _check_or_init_nvfatbin() 1z

325 if __nvFatbinAddTileIR == NULL: 1z

326 with gil: 

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

328 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*) noexcept nogil>__nvFatbinAddTileIR)( 1z

329 handle, code, size, identifier, optionsCmdLine)