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

135 statements  

« prev     ^ index     » next       coverage.py v7.18.0, created at 2026-12-03 01:06 +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.5.0. Do not modify it directly. 

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

7  

8  

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

10  

11from libc.stdint cimport intptr_t 

12  

13cdef extern from * nogil: 

14 """ 

15 #if defined(_MSC_VER) && !defined(__clang__) 

16 #include <intrin.h> 

17 static __forceinline int atomic_int_load(int *p) { 

18 int v = *(int volatile *)p; _ReadBarrier(); return v; 

19 } 

20 static __forceinline void atomic_int_store(int *p, int v) { 

21 _WriteBarrier(); *(int volatile *)p = v; 

22 } 

23 #elif defined(__cplusplus) 

24 /* GCC/Clang __atomic builtins work in any C++ standard without headers */ 

25 static inline int atomic_int_load(int *p) { 

26 return __atomic_load_n(p, __ATOMIC_ACQUIRE); 

27 } 

28 static inline void atomic_int_store(int *p, int v) { 

29 __atomic_store_n(p, v, __ATOMIC_RELEASE); 

30 } 

31 #else 

32 #include <stdatomic.h> 

33 static inline int atomic_int_load(int *p) { 

34 return (int)atomic_load_explicit((atomic_int *)p, memory_order_acquire); 

35 } 

36 static inline void atomic_int_store(int *p, int v) { 

37 atomic_store_explicit((atomic_int *)p, v, memory_order_release); 

38 } 

39 #endif 

40  

41 """ 

42 cdef int _cyb_atomic_int_load "atomic_int_load"(int *p) nogil 

43 cdef void _cyb_atomic_int_store "atomic_int_store"(int *p, int v) nogil 

44  

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

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

47 const void * _cyb_RTLD_DEFAULT "RTLD_DEFAULT" 

48  

49import threading as _cyb_threading 

50  

51cdef int _cyb___py_nvfatbin_init = 0 

52cdef dict _cyb_func_ptrs = None 

53cdef object _cyb_symbol_lock = _cyb_threading.Lock() 

54  

55# <<<< END OF PREAMBLE CONTENT >>>> 

56  

57from libc.stdint cimport uintptr_t 

58  

59from .utils import FunctionNotFoundError, NotSupportedError 

60from cuda.pathfinder import load_nvidia_dynamic_lib 

61  

62  

63############################################################################### 

64# Wrapper init 

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

66  

67cdef void* __nvFatbinGetErrorString = NULL 

68cdef void* __nvFatbinCreate = NULL 

69cdef void* __nvFatbinDestroy = NULL 

70cdef void* __nvFatbinAddPTX = NULL 

71cdef void* __nvFatbinAddCubin = NULL 

72cdef void* __nvFatbinAddLTOIR = NULL 

73cdef void* __nvFatbinSize = NULL 

74cdef void* __nvFatbinGet = NULL 

75cdef void* __nvFatbinVersion = NULL 

76cdef void* __nvFatbinAddIndex = NULL 

77cdef void* __nvFatbinAddReloc = NULL 

78cdef void* __nvFatbinAddTileIR = NULL 

79  

80cdef enum: _cyb_nvfatbin_n_functions = 12 

81cdef void** _cyb_nvfatbin_slots[_cyb_nvfatbin_n_functions] 

82cdef const char* _cyb_nvfatbin_names[_cyb_nvfatbin_n_functions] 

83_cyb_nvfatbin_slots[0] = &__nvFatbinGetErrorString; _cyb_nvfatbin_names[0] = b'nvFatbinGetErrorString' 

84_cyb_nvfatbin_slots[1] = &__nvFatbinCreate; _cyb_nvfatbin_names[1] = b'nvFatbinCreate' 

85_cyb_nvfatbin_slots[2] = &__nvFatbinDestroy; _cyb_nvfatbin_names[2] = b'nvFatbinDestroy' 

86_cyb_nvfatbin_slots[3] = &__nvFatbinAddPTX; _cyb_nvfatbin_names[3] = b'nvFatbinAddPTX' 

87_cyb_nvfatbin_slots[4] = &__nvFatbinAddCubin; _cyb_nvfatbin_names[4] = b'nvFatbinAddCubin' 

88_cyb_nvfatbin_slots[5] = &__nvFatbinAddLTOIR; _cyb_nvfatbin_names[5] = b'nvFatbinAddLTOIR' 

89_cyb_nvfatbin_slots[6] = &__nvFatbinSize; _cyb_nvfatbin_names[6] = b'nvFatbinSize' 

90_cyb_nvfatbin_slots[7] = &__nvFatbinGet; _cyb_nvfatbin_names[7] = b'nvFatbinGet' 

91_cyb_nvfatbin_slots[8] = &__nvFatbinVersion; _cyb_nvfatbin_names[8] = b'nvFatbinVersion' 

92_cyb_nvfatbin_slots[9] = &__nvFatbinAddIndex; _cyb_nvfatbin_names[9] = b'nvFatbinAddIndex' 

93_cyb_nvfatbin_slots[10] = &__nvFatbinAddReloc; _cyb_nvfatbin_names[10] = b'nvFatbinAddReloc' 

94_cyb_nvfatbin_slots[11] = &__nvFatbinAddTileIR; _cyb_nvfatbin_names[11] = b'nvFatbinAddTileIR' 

95  

96cdef int _init_nvfatbin() except -1 nogil: 

97 global _cyb___py_nvfatbin_init 

98 cdef void* handle = NULL 

99 cdef Py_ssize_t i 

100 with gil, _cyb_symbol_lock: 

101 if _cyb___py_nvfatbin_init: return 0 

102  

103 for i in range(_cyb_nvfatbin_n_functions): 

104 _cyb_nvfatbin_slots[i][0] = _cyb_dlsym(_cyb_RTLD_DEFAULT, _cyb_nvfatbin_names[i]) 

105 if _cyb_nvfatbin_slots[i][0] == NULL: 

106 if handle == NULL: 

107 handle = load_library() 

108 _cyb_nvfatbin_slots[i][0] = _cyb_dlsym(handle, _cyb_nvfatbin_names[i]) 

109  

110 _cyb_atomic_int_store(<int *>&_cyb___py_nvfatbin_init, 1) 

111 return 0 

112  

113cdef inline int _check_or_init_nvfatbin() except -1 nogil: 2a + , - . / : ; = ? @ [ ] ^ _ ` { | } e f g h i j k l 4 5 m n o p q r s t u v w x y z A B C ) 2 ~ abb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbD E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 1 * 3 tbub

114 if _cyb_atomic_int_load(<int *>&_cyb___py_nvfatbin_init): 2a + , - . / : ; = ? @ [ ] ^ _ ` { | } e f g h i j k l 4 5 m n o p q r s t u v w x y z A B 8 9 ! # C ) 2 ~ abb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbD E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 $ % ' ( 1 * 3 tbub

115 return 0 2a + , - . / : ; = ? @ [ ] ^ _ ` { | } e f g h i j k l 4 5 m n o p q r s t u v w x y z A B 8 9 ! # C ) 2 ~ abb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbD E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 $ % ' ( 1 * 3 tbub

116  

117 return _init_nvfatbin() 

118  

119  

120cpdef dict _inspect_function_pointers(): 

121 global _cyb_func_ptrs 

122 if _cyb_func_ptrs is not None: 

123 return _cyb_func_ptrs 

124  

125 _check_or_init_nvfatbin() 

126 cdef dict data = {} 

127 cdef Py_ssize_t i 

128 for i in range(_cyb_nvfatbin_n_functions): 

129 data['__' + _cyb_nvfatbin_names[i].decode()] = <intptr_t>_cyb_nvfatbin_slots[i][0] 

130 _cyb_func_ptrs = data 

131 return data 

132  

133  

134cpdef _inspect_function_pointer(str name): 

135 global _cyb_func_ptrs 

136 if _cyb_func_ptrs is None: 

137 _cyb_func_ptrs = _inspect_function_pointers() 

138 return _cyb_func_ptrs[name] 

139  

140  

141  

142  

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

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

145 return <void*>handle 

146  

147  

148############################################################################### 

149# Wrapper functions 

150############################################################################### 

151  

152cdef const char* _nvFatbinGetErrorString(nvFatbinResult result) except?NULL nogil: 2a + , - . / : ; = ? @ [ ] ^ _ ` { | } bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

153 global __nvFatbinGetErrorString 

154 _check_or_init_nvfatbin() 2+ , - . / : ; = ? @ [ ] ^ _ ` { | } bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

155 if __nvFatbinGetErrorString == NULL: 2+ , - . / : ; = ? @ [ ] ^ _ ` { | } bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

156 with gil: 2+ , - . / : ; = ? @ [ ] ^ _ ` { | } bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

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

158 return (<const char* (*)(nvFatbinResult) noexcept nogil>__nvFatbinGetErrorString)( 2+ , - . / : ; = ? @ [ ] ^ _ ` { | } bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb

159 result) 

160  

161  

162cdef nvFatbinResult _nvFatbinCreate(nvFatbinHandle* handle_indirect, const char** options, size_t optionsCount) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 2a e f g h i j k l 4 5 m n o p q r s t u v w x y z A B C ) 2 abb c d D E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 1 * 3 ub

163 global __nvFatbinCreate 

164 _check_or_init_nvfatbin() 2e f g h i j k l 4 5 m n o p q r s t u v w x y z A B 8 9 ! # C ) 2 abb c d D E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 $ % ' ( 1 * 3 ub

165 if __nvFatbinCreate == NULL: 2e f g h i j k l 4 5 m n o p q r s t u v w x y z A B 8 9 ! # C ) 2 abb c d D E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 $ % ' ( 1 * 3 ub

166 with gil: 2e f g h i j k l 4 5 m n o p q r s t u v w x y z A B C ) 2 abb c d D E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 1 * 3 ub

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

168 return (<nvFatbinResult (*)(nvFatbinHandle*, const char**, size_t) noexcept nogil>__nvFatbinCreate)( 2e f g h i j k l 4 5 m n o p q r s t u v w x y z A B 8 9 ! # C ) 2 abb c d D E F G H I J K 6 7 L M N O P Q R S T U V W X Y Z 0 $ % ' ( 1 * 3 ub

169 handle_indirect, options, optionsCount) 

170  

171  

172cdef nvFatbinResult _nvFatbinDestroy(nvFatbinHandle* handle_indirect) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 1aefghijkl45mnopqrstuvwxyzABC)2bcdDEFGHIJK67LMNOPQRSTUVWXYZ01*3

173 global __nvFatbinDestroy 

174 _check_or_init_nvfatbin() 1efghijkl45mnopqrstuvwxyzAB89!#C)2bcdDEFGHIJK67LMNOPQRSTUVWXYZ0$%'(1*3

175 if __nvFatbinDestroy == NULL: 1efghijkl45mnopqrstuvwxyzAB89!#C)2bcdDEFGHIJK67LMNOPQRSTUVWXYZ0$%'(1*3

176 with gil: 1efghijkl45mnopqrstuvwxyzABC)2bcdDEFGHIJK67LMNOPQRSTUVWXYZ01*3

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

178 return (<nvFatbinResult (*)(nvFatbinHandle*) noexcept nogil>__nvFatbinDestroy)( 1efghijkl45mnopqrstuvwxyzAB89!#C)2bcdDEFGHIJK67LMNOPQRSTUVWXYZ0$%'(1*3

179 handle_indirect) 

180  

181  

182cdef 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: 1amnopqrstuvwxyzABbcdLMNOPQRSTUVWXYZ0

183 global __nvFatbinAddPTX 

184 _check_or_init_nvfatbin() 1mnopqrstuvwxyzABbcdLMNOPQRSTUVWXYZ0

185 if __nvFatbinAddPTX == NULL: 1mnopqrstuvwxyzABbcdLMNOPQRSTUVWXYZ0

186 with gil: 1mnopqrstuvwxyzABbcdLMNOPQRSTUVWXYZ0

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

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

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

190  

191  

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

193 global __nvFatbinAddCubin 

194 _check_or_init_nvfatbin() 1ijkl45bcdHIJK67

195 if __nvFatbinAddCubin == NULL: 1ijkl45bcdHIJK67

196 with gil: 1ijkl45bcdHIJK67

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

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

199 handle, code, size, arch, identifier) 

200  

201  

202cdef 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: 1aefghDEFG

203 global __nvFatbinAddLTOIR 

204 _check_or_init_nvfatbin() 1efghDEFG

205 if __nvFatbinAddLTOIR == NULL: 1efghDEFG

206 with gil: 1efghDEFG

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

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

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

210  

211  

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

213 global __nvFatbinSize 

214 _check_or_init_nvfatbin() 1efghijklmnopqrstuvwxyzAB89!#C2bcdDEFGHIJKLMNOPQRSTUVWXYZ0$%'(13

215 if __nvFatbinSize == NULL: 1efghijklmnopqrstuvwxyzAB89!#C2bcdDEFGHIJKLMNOPQRSTUVWXYZ0$%'(13

216 with gil: 1efghijklmnopqrstuvwxyzABC2bcdDEFGHIJKLMNOPQRSTUVWXYZ013

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

218 return (<nvFatbinResult (*)(nvFatbinHandle, size_t*) noexcept nogil>__nvFatbinSize)( 1efghijklmnopqrstuvwxyzAB89!#C2bcdDEFGHIJKLMNOPQRSTUVWXYZ0$%'(13

219 handle, size) 

220  

221  

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

223 global __nvFatbinGet 

224 _check_or_init_nvfatbin() 1efghijklmnopqrstuvwxyzAB89!#C2bcdDEFGHIJKLMNOPQRSTUVWXYZ0$%'(13

225 if __nvFatbinGet == NULL: 1efghijklmnopqrstuvwxyzAB89!#C2bcdDEFGHIJKLMNOPQRSTUVWXYZ0$%'(13

226 with gil: 1efghijklmnopqrstuvwxyzABC2bcdDEFGHIJKLMNOPQRSTUVWXYZ013

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

228 return (<nvFatbinResult (*)(nvFatbinHandle, void*) noexcept nogil>__nvFatbinGet)( 1efghijklmnopqrstuvwxyzAB89!#C2bcdDEFGHIJKLMNOPQRSTUVWXYZ0$%'(13

229 handle, buffer) 

230  

231  

232cdef nvFatbinResult _nvFatbinVersion(unsigned int* major, unsigned int* minor) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 2a ~ tb

233 global __nvFatbinVersion 

234 _check_or_init_nvfatbin() 2a ~ tb

235 if __nvFatbinVersion == NULL: 2a ~ tb

236 with gil: 2a ~ tb

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

238 return (<nvFatbinResult (*)(unsigned int*, unsigned int*) noexcept nogil>__nvFatbinVersion)( 2a ~ tb

239 major, minor) 

240  

241  

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

243 global __nvFatbinAddIndex 

244 _check_or_init_nvfatbin() 

245 if __nvFatbinAddIndex == NULL: 

246 with gil: 

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

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

249 handle, code, size, identifier) 

250  

251  

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

253 global __nvFatbinAddReloc 

254 _check_or_init_nvfatbin() 189!#$%'(

255 if __nvFatbinAddReloc == NULL: 189!#$%'(

256 with gil: 

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

258 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t) noexcept nogil>__nvFatbinAddReloc)( 189!#$%'(

259 handle, code, size) 

260  

261  

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

263 global __nvFatbinAddTileIR 

264 _check_or_init_nvfatbin() 1C1

265 if __nvFatbinAddTileIR == NULL: 1C1

266 with gil: 1C1

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

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

269 handle, code, size, identifier, optionsCmdLine)