Coverage for cuda/bindings/_internal/nvfatbin.pyx: 67.38%
187 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +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=7d6e928f56af8543c123889e5337a34f9270cbd554c699a8e013f720362988c1
9# <<<< PREAMBLE CONTENT >>>>
11cdef extern from * nogil:
12 """
13 #if defined(_MSC_VER) && !defined(__clang__)
14 #include <intrin.h>
15 static __forceinline int atomic_int_load(int *p) {
16 int v = *(int volatile *)p; _ReadBarrier(); return v;
17 }
18 static __forceinline void atomic_int_store(int *p, int v) {
19 _WriteBarrier(); *(int volatile *)p = v;
20 }
21 #elif defined(__cplusplus)
22 /* GCC/Clang __atomic builtins work in any C++ standard without headers */
23 static inline int atomic_int_load(int *p) {
24 return __atomic_load_n(p, __ATOMIC_ACQUIRE);
25 }
26 static inline void atomic_int_store(int *p, int v) {
27 __atomic_store_n(p, v, __ATOMIC_RELEASE);
28 }
29 #else
30 #include <stdatomic.h>
31 static inline int atomic_int_load(int *p) {
32 return (int)atomic_load_explicit((atomic_int *)p, memory_order_acquire);
33 }
34 static inline void atomic_int_store(int *p, int v) {
35 atomic_store_explicit((atomic_int *)p, v, memory_order_release);
36 }
37 #endif
39 """
40 cdef int _cyb_atomic_int_load "atomic_int_load"(int *p) nogil
41 cdef void _cyb_atomic_int_store "atomic_int_store"(int *p, int v) nogil
43cdef extern from "<dlfcn.h>":
44 void* _cyb_dlsym "dlsym"(void*, const char*) nogil
45 const void * _cyb_RTLD_DEFAULT "RTLD_DEFAULT"
47from libc.stdint cimport intptr_t
49import threading as _cyb_threading
51cdef int _cyb___py_nvfatbin_init = 0
52cdef dict _cyb_func_ptrs = None
53cdef object _cyb_symbol_lock = _cyb_threading.Lock()
55# <<<< END OF PREAMBLE CONTENT >>>>
57from libc.stdint cimport uintptr_t
59from .utils import FunctionNotFoundError, NotSupportedError
60from cuda.pathfinder import load_nvidia_dynamic_lib
63###############################################################################
64# Wrapper init
65###############################################################################
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
80cdef int _init_nvfatbin() except -1 nogil:
81 global _cyb___py_nvfatbin_init
82 cdef void* handle = NULL
83 with gil, _cyb_symbol_lock:
84 if _cyb___py_nvfatbin_init: return 0
86 global __nvFatbinGetErrorString
87 __nvFatbinGetErrorString = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinGetErrorString')
88 if __nvFatbinGetErrorString == NULL:
89 if handle == NULL:
90 handle = load_library()
91 __nvFatbinGetErrorString = _cyb_dlsym(handle, 'nvFatbinGetErrorString')
93 global __nvFatbinCreate
94 __nvFatbinCreate = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinCreate')
95 if __nvFatbinCreate == NULL:
96 if handle == NULL:
97 handle = load_library()
98 __nvFatbinCreate = _cyb_dlsym(handle, 'nvFatbinCreate')
100 global __nvFatbinDestroy
101 __nvFatbinDestroy = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinDestroy')
102 if __nvFatbinDestroy == NULL:
103 if handle == NULL:
104 handle = load_library()
105 __nvFatbinDestroy = _cyb_dlsym(handle, 'nvFatbinDestroy')
107 global __nvFatbinAddPTX
108 __nvFatbinAddPTX = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddPTX')
109 if __nvFatbinAddPTX == NULL:
110 if handle == NULL:
111 handle = load_library()
112 __nvFatbinAddPTX = _cyb_dlsym(handle, 'nvFatbinAddPTX')
114 global __nvFatbinAddCubin
115 __nvFatbinAddCubin = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddCubin')
116 if __nvFatbinAddCubin == NULL:
117 if handle == NULL:
118 handle = load_library()
119 __nvFatbinAddCubin = _cyb_dlsym(handle, 'nvFatbinAddCubin')
121 global __nvFatbinAddLTOIR
122 __nvFatbinAddLTOIR = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddLTOIR')
123 if __nvFatbinAddLTOIR == NULL:
124 if handle == NULL:
125 handle = load_library()
126 __nvFatbinAddLTOIR = _cyb_dlsym(handle, 'nvFatbinAddLTOIR')
128 global __nvFatbinSize
129 __nvFatbinSize = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinSize') 2a - . / : ; = ? @ [ ] ^ _ ` { | } ~ abe f g h m n o p $ % q r s t u v w x y z A B C D E F G ) 2 + tbb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbi j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 1 * 3 , ub
130 if __nvFatbinSize == NULL: 2a - . / : ; = ? @ [ ] ^ _ ` { | } ~ abe f g h m n o p $ % q r s t u v w x y z A B C D E F G ) 2 + tbb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbi j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 1 * 3 , ub
131 if handle == NULL:
132 handle = load_library()
133 __nvFatbinSize = _cyb_dlsym(handle, 'nvFatbinSize')
135 global __nvFatbinGet
136 __nvFatbinGet = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinGet')
137 if __nvFatbinGet == NULL:
138 if handle == NULL:
139 handle = load_library()
140 __nvFatbinGet = _cyb_dlsym(handle, 'nvFatbinGet')
142 global __nvFatbinVersion
143 __nvFatbinVersion = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinVersion')
144 if __nvFatbinVersion == NULL:
145 if handle == NULL:
146 handle = load_library()
147 __nvFatbinVersion = _cyb_dlsym(handle, 'nvFatbinVersion')
149 global __nvFatbinAddIndex
150 __nvFatbinAddIndex = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddIndex')
151 if __nvFatbinAddIndex == NULL:
152 if handle == NULL:
153 handle = load_library()
154 __nvFatbinAddIndex = _cyb_dlsym(handle, 'nvFatbinAddIndex')
156 global __nvFatbinAddReloc
157 __nvFatbinAddReloc = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddReloc')
158 if __nvFatbinAddReloc == NULL:
159 if handle == NULL:
160 handle = load_library()
161 __nvFatbinAddReloc = _cyb_dlsym(handle, 'nvFatbinAddReloc')
163 global __nvFatbinAddTileIR
164 __nvFatbinAddTileIR = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinAddTileIR')
165 if __nvFatbinAddTileIR == NULL:
166 if handle == NULL:
167 handle = load_library()
168 __nvFatbinAddTileIR = _cyb_dlsym(handle, 'nvFatbinAddTileIR')
170 _cyb_atomic_int_store(<int *>&_cyb___py_nvfatbin_init, 1)
171 return 0
173cdef inline int _check_or_init_nvfatbin() except -1 nogil:
174 if _cyb_atomic_int_load(<int *>&_cyb___py_nvfatbin_init): 2a - . / : ; = ? @ [ ] ^ _ ` { | } ~ abe f g h m n o p $ % q r s t u v w x y z A B C D E F 4 5 6 7 G ) 2 + tbb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbi j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 8 9 ! # 1 * 3 , ub
175 return 0 2a - . / : ; = ? @ [ ] ^ _ ` { | } ~ abe f g h m n o p $ % q r s t u v w x y z A B C D E F 4 5 6 7 G ) 2 + tbb c d bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbi j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 8 9 ! # 1 * 3 , ub
177 return _init_nvfatbin()
180cpdef dict _inspect_function_pointers():
181 global _cyb_func_ptrs
182 if _cyb_func_ptrs is not None:
183 return _cyb_func_ptrs
185 _check_or_init_nvfatbin()
186 cdef dict data = {}
187 global __nvFatbinGetErrorString
188 data["__nvFatbinGetErrorString"] = <intptr_t>__nvFatbinGetErrorString
190 global __nvFatbinCreate
191 data["__nvFatbinCreate"] = <intptr_t>__nvFatbinCreate
193 global __nvFatbinDestroy
194 data["__nvFatbinDestroy"] = <intptr_t>__nvFatbinDestroy
196 global __nvFatbinAddPTX
197 data["__nvFatbinAddPTX"] = <intptr_t>__nvFatbinAddPTX
199 global __nvFatbinAddCubin
200 data["__nvFatbinAddCubin"] = <intptr_t>__nvFatbinAddCubin 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb
202 global __nvFatbinAddLTOIR
203 data["__nvFatbinAddLTOIR"] = <intptr_t>__nvFatbinAddLTOIR
205 global __nvFatbinSize
206 data["__nvFatbinSize"] = <intptr_t>__nvFatbinSize
208 global __nvFatbinGet
209 data["__nvFatbinGet"] = <intptr_t>__nvFatbinGet
211 global __nvFatbinVersion
212 data["__nvFatbinVersion"] = <intptr_t>__nvFatbinVersion
214 global __nvFatbinAddIndex
215 data["__nvFatbinAddIndex"] = <intptr_t>__nvFatbinAddIndex
217 global __nvFatbinAddReloc
218 data["__nvFatbinAddReloc"] = <intptr_t>__nvFatbinAddReloc
220 global __nvFatbinAddTileIR
221 data["__nvFatbinAddTileIR"] = <intptr_t>__nvFatbinAddTileIR 1efghmnop$%qrstuvwxyzABCDEFG)2bcdijklHIJK'(LMNOPQRSTUVWXYZ01*3
222 _cyb_func_ptrs = data
223 return data
226cpdef _inspect_function_pointer(str name):
227 global _cyb_func_ptrs
228 if _cyb_func_ptrs is None:
229 _cyb_func_ptrs = _inspect_function_pointers()
230 return _cyb_func_ptrs[name] 1qrstuvwxyzABCDEFbcdLMNOPQRSTUVWXYZ0
235cdef void* load_library() except* with gil:
236 cdef uintptr_t handle = load_nvidia_dynamic_lib("nvfatbin")._handle_uint
237 return <void*>handle
240###############################################################################
241# Wrapper functions
242###############################################################################
244cdef const char* _nvFatbinGetErrorString(nvFatbinResult result) except?NULL nogil: 1amnop$%bcdHIJK'(
245 global __nvFatbinGetErrorString
246 _check_or_init_nvfatbin() 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb
247 if __nvFatbinGetErrorString == NULL: 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb
248 with gil:
249 raise FunctionNotFoundError("function nvFatbinGetErrorString is not found")
250 return (<const char* (*)(nvFatbinResult) noexcept nogil>__nvFatbinGetErrorString)( 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abe f g h bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbi j k l
251 result)
254cdef nvFatbinResult _nvFatbinCreate(nvFatbinHandle* handle_indirect, const char** options, size_t optionsCount) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 1aefghijkl
255 global __nvFatbinCreate
256 _check_or_init_nvfatbin() 2e f g h m n o p $ % q r s t u v w x y z A B C D E F 4 5 6 7 G ) 2 tbb c d i j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 8 9 ! # 1 * 3 ub
257 if __nvFatbinCreate == NULL: 2e f g h m n o p $ % q r s t u v w x y z A B C D E F 4 5 6 7 G ) 2 tbb c d i j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 8 9 ! # 1 * 3 ub
258 with gil:
259 raise FunctionNotFoundError("function nvFatbinCreate is not found")
260 return (<nvFatbinResult (*)(nvFatbinHandle*, const char**, size_t) noexcept nogil>__nvFatbinCreate)( 2e f g h m n o p $ % q r s t u v w x y z A B C D E F 4 5 6 7 G ) 2 tbb c d i j k l H I J K ' ( L M N O P Q R S T U V W X Y Z 0 8 9 ! # 1 * 3 ub
261 handle_indirect, options, optionsCount)
264cdef nvFatbinResult _nvFatbinDestroy(nvFatbinHandle* handle_indirect) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 1aefghmnopqrstuvwxyzABCDEFG2bcdijklHIJKLMNOPQRSTUVWXYZ013
265 global __nvFatbinDestroy
266 _check_or_init_nvfatbin() 1efghmnop$%qrstuvwxyzABCDEF4567G)2bcdijklHIJK'(LMNOPQRSTUVWXYZ089!#1*3
267 if __nvFatbinDestroy == NULL: 1efghmnop$%qrstuvwxyzABCDEF4567G)2bcdijklHIJK'(LMNOPQRSTUVWXYZ089!#1*3
268 with gil:
269 raise FunctionNotFoundError("function nvFatbinDestroy is not found")
270 return (<nvFatbinResult (*)(nvFatbinHandle*) noexcept nogil>__nvFatbinDestroy)( 1efghmnop$%qrstuvwxyzABCDEF4567G)2bcdijklHIJK'(LMNOPQRSTUVWXYZ089!#1*3
271 handle_indirect)
274cdef 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: 1aefghmnopqrstuvwxyzABCDEFG2bcdijklHIJKLMNOPQRSTUVWXYZ013
275 global __nvFatbinAddPTX
276 _check_or_init_nvfatbin() 1qrstuvwxyzABCDEFbcdLMNOPQRSTUVWXYZ0
277 if __nvFatbinAddPTX == NULL: 1qrstuvwxyzABCDEFbcdLMNOPQRSTUVWXYZ0
278 with gil:
279 raise FunctionNotFoundError("function nvFatbinAddPTX is not found")
280 return (<nvFatbinResult (*)(nvFatbinHandle, const char*, size_t, const char*, const char*, const char*) noexcept nogil>__nvFatbinAddPTX)( 1aqrstuvwxyzABCDEF+bcdLMNOPQRSTUVWXYZ0,
281 handle, code, size, arch, identifier, optionsCmdLine)
284cdef nvFatbinResult _nvFatbinAddCubin(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 1a+,
285 global __nvFatbinAddCubin
286 _check_or_init_nvfatbin() 1mnop$%bcdHIJK'(
287 if __nvFatbinAddCubin == NULL: 1mnop$%bcdHIJK'(
288 with gil:
289 raise FunctionNotFoundError("function nvFatbinAddCubin is not found")
290 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*) noexcept nogil>__nvFatbinAddCubin)( 1mnop$%bcdHIJK'(
291 handle, code, size, arch, identifier)
294cdef 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:
295 global __nvFatbinAddLTOIR
296 _check_or_init_nvfatbin() 1efghijkl
297 if __nvFatbinAddLTOIR == NULL: 1efghijkl
298 with gil:
299 raise FunctionNotFoundError("function nvFatbinAddLTOIR is not found")
300 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*, const char*) noexcept nogil>__nvFatbinAddLTOIR)( 1efghijkl
301 handle, code, size, arch, identifier, optionsCmdLine)
304cdef nvFatbinResult _nvFatbinSize(nvFatbinHandle handle, size_t* size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
305 global __nvFatbinSize
306 _check_or_init_nvfatbin() 1efghmnopqrstuvwxyzABCDEF4567G2bcdijklHIJKLMNOPQRSTUVWXYZ089!#13
307 if __nvFatbinSize == NULL: 1efghmnopqrstuvwxyzABCDEF4567G2bcdijklHIJKLMNOPQRSTUVWXYZ089!#13
308 with gil:
309 raise FunctionNotFoundError("function nvFatbinSize is not found")
310 return (<nvFatbinResult (*)(nvFatbinHandle, size_t*) noexcept nogil>__nvFatbinSize)( 1efghmnopqrstuvwxyzABCDEF4567G2bcdijklHIJKLMNOPQRSTUVWXYZ089!#13
311 handle, size)
314cdef nvFatbinResult _nvFatbinGet(nvFatbinHandle handle, void* buffer) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: 1aG1
315 global __nvFatbinGet
316 _check_or_init_nvfatbin() 1efghmnopqrstuvwxyzABCDEF4567G2bcdijklHIJKLMNOPQRSTUVWXYZ089!#13
317 if __nvFatbinGet == NULL: 1efghmnopqrstuvwxyzABCDEF4567G2bcdijklHIJKLMNOPQRSTUVWXYZ089!#13
318 with gil:
319 raise FunctionNotFoundError("function nvFatbinGet is not found")
320 return (<nvFatbinResult (*)(nvFatbinHandle, void*) noexcept nogil>__nvFatbinGet)( 1efghmnopqrstuvwxyzABCDEF4567G2bcdijklHIJKLMNOPQRSTUVWXYZ089!#13
321 handle, buffer)
324cdef nvFatbinResult _nvFatbinVersion(unsigned int* major, unsigned int* minor) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
325 global __nvFatbinVersion
326 _check_or_init_nvfatbin() 1a+,
327 if __nvFatbinVersion == NULL: 1a+,
328 with gil:
329 raise FunctionNotFoundError("function nvFatbinVersion is not found")
330 return (<nvFatbinResult (*)(unsigned int*, unsigned int*) noexcept nogil>__nvFatbinVersion)( 1a+,
331 major, minor)
334cdef nvFatbinResult _nvFatbinAddIndex(nvFatbinHandle handle, const void* code, size_t size, const char* identifier) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
335 global __nvFatbinAddIndex
336 _check_or_init_nvfatbin()
337 if __nvFatbinAddIndex == NULL:
338 with gil:
339 raise FunctionNotFoundError("function nvFatbinAddIndex is not found")
340 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*) noexcept nogil>__nvFatbinAddIndex)(
341 handle, code, size, identifier)
344cdef nvFatbinResult _nvFatbinAddReloc(nvFatbinHandle handle, const void* code, size_t size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
345 global __nvFatbinAddReloc
346 _check_or_init_nvfatbin() 1456789!#
347 if __nvFatbinAddReloc == NULL: 1456789!#
348 with gil:
349 raise FunctionNotFoundError("function nvFatbinAddReloc is not found")
350 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t) noexcept nogil>__nvFatbinAddReloc)( 1456789!#
351 handle, code, size)
354cdef nvFatbinResult _nvFatbinAddTileIR(nvFatbinHandle handle, const void* code, size_t size, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
355 global __nvFatbinAddTileIR
356 _check_or_init_nvfatbin() 1G1
357 if __nvFatbinAddTileIR == NULL: 1G1
358 with gil:
359 raise FunctionNotFoundError("function nvFatbinAddTileIR is not found")
360 return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*) noexcept nogil>__nvFatbinAddTileIR)( 1G1
361 handle, code, size, identifier, optionsCmdLine)