Coverage for cuda/bindings/_internal/nvfatbin.pyx: 66.31%
187 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-29 01:38 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-29 01:38 +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=f86a7f7527aad594d7b2e67742165454729ecca3810c00e6786f772099b17850
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 as _cyb_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') 2a - . / : ; = ? @ [ ] ^ _ ` { | } ~ abb c d e j k l m $ % n o p q r s t u v w x y z A B C D ) 2 + tbbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbf g h i E F G H ' ( I J K L M N O P Q R S T U V W X Y * 3 , ub
128 global __nvFatbinSize
129 __nvFatbinSize = _cyb_dlsym(_cyb_RTLD_DEFAULT, 'nvFatbinSize')
130 if __nvFatbinSize == NULL:
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 - . / : ; = ? @ [ ] ^ _ ` { | } ~ abb c d e j k l m $ % n o p q r s t u v w x y z A B C 4 5 6 7 D ) 2 + tbZ 0 1 bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbf g h i E F G H ' ( I J K L M N O P Q R S T U V W X 8 9 ! # Y * 3 , ub
175 return 0 2a - . / : ; = ? @ [ ] ^ _ ` { | } ~ abb c d e j k l m $ % n o p q r s t u v w x y z A B C 4 5 6 7 D ) 2 + tbZ 0 1 bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbf g h i E F G H ' ( I J K L M N O P Q R S T U V W X 8 9 ! # Y * 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"] = <_cyb_intptr_t>__nvFatbinGetErrorString
190 global __nvFatbinCreate
191 data["__nvFatbinCreate"] = <_cyb_intptr_t>__nvFatbinCreate
193 global __nvFatbinDestroy
194 data["__nvFatbinDestroy"] = <_cyb_intptr_t>__nvFatbinDestroy
196 global __nvFatbinAddPTX
197 data["__nvFatbinAddPTX"] = <_cyb_intptr_t>__nvFatbinAddPTX 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb
199 global __nvFatbinAddCubin
200 data["__nvFatbinAddCubin"] = <_cyb_intptr_t>__nvFatbinAddCubin
202 global __nvFatbinAddLTOIR
203 data["__nvFatbinAddLTOIR"] = <_cyb_intptr_t>__nvFatbinAddLTOIR
205 global __nvFatbinSize
206 data["__nvFatbinSize"] = <_cyb_intptr_t>__nvFatbinSize
208 global __nvFatbinGet
209 data["__nvFatbinGet"] = <_cyb_intptr_t>__nvFatbinGet
211 global __nvFatbinVersion
212 data["__nvFatbinVersion"] = <_cyb_intptr_t>__nvFatbinVersion
214 global __nvFatbinAddIndex
215 data["__nvFatbinAddIndex"] = <_cyb_intptr_t>__nvFatbinAddIndex
217 global __nvFatbinAddReloc
218 data["__nvFatbinAddReloc"] = <_cyb_intptr_t>__nvFatbinAddReloc 1bcdejklm$%nopqrstuvwxyzABCD)2fghiEFGH'(IJKLMNOPQRSTUVWXY*3
220 global __nvFatbinAddTileIR
221 data["__nvFatbinAddTileIR"] = <_cyb_intptr_t>__nvFatbinAddTileIR 1bcdejklm$%nopqrstuvwxyzABCD)2fghiEFGH'(IJKLMNOPQRSTUVWXY*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: 1nopqrstuvwxyzABCIJKLMNOPQRSTUVWX
229 _cyb_func_ptrs = _inspect_function_pointers()
230 return _cyb_func_ptrs[name]
235cdef void* load_library() except* with gil:
236 cdef uintptr_t handle = load_nvidia_dynamic_lib("nvfatbin")._handle_uint
237 return <void*>handle 1ajklm$%EFGH'(
240###############################################################################
241# Wrapper functions
242###############################################################################
244cdef const char* _nvFatbinGetErrorString(nvFatbinResult result) except?NULL nogil:
245 global __nvFatbinGetErrorString
246 _check_or_init_nvfatbin() 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb
247 if __nvFatbinGetErrorString == NULL: 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abb c d e bbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbf g h i
248 with gil: 1bcdefghi
249 raise FunctionNotFoundError("function nvFatbinGetErrorString is not found")
250 return (<const char* (*)(nvFatbinResult) noexcept nogil>__nvFatbinGetErrorString)( 2- . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsb
251 result)
254cdef nvFatbinResult _nvFatbinCreate(nvFatbinHandle* handle_indirect, const char** options, size_t optionsCount) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
255 global __nvFatbinCreate
256 _check_or_init_nvfatbin() 2b c d e j k l m $ % n o p q r s t u v w x y z A B C 4 5 6 7 D ) 2 tbZ 0 1 f g h i E F G H ' ( I J K L M N O P Q R S T U V W X 8 9 ! # Y * 3 ub
257 if __nvFatbinCreate == NULL: 2b c d e j k l m $ % n o p q r s t u v w x y z A B C 4 5 6 7 D ) 2 tbZ 0 1 f g h i E F G H ' ( I J K L M N O P Q R S T U V W X 8 9 ! # Y * 3 ub
258 with gil: 1bcdejklmnopqrstuvwxyzABCD2fghiEFGHIJKLMNOPQRSTUVWXY3
259 raise FunctionNotFoundError("function nvFatbinCreate is not found")
260 return (<nvFatbinResult (*)(nvFatbinHandle*, const char**, size_t) noexcept nogil>__nvFatbinCreate)( 2b c d e j k l m $ % n o p q r s t u v w x y z A B C 4 5 6 7 D ) 2 tbZ 0 1 f g h i E F G H ' ( I J K L M N O P Q R S T U V W X 8 9 ! # Y * 3 ub
261 handle_indirect, options, optionsCount)
264cdef nvFatbinResult _nvFatbinDestroy(nvFatbinHandle* handle_indirect) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
265 global __nvFatbinDestroy
266 _check_or_init_nvfatbin() 1bcdejklm$%nopqrstuvwxyzABC4567D)2Z01fghiEFGH'(IJKLMNOPQRSTUVWX89!#Y*3
267 if __nvFatbinDestroy == NULL: 1bcdejklm$%nopqrstuvwxyzABC4567D)2Z01fghiEFGH'(IJKLMNOPQRSTUVWX89!#Y*3
268 with gil: 1bcdejklmnopqrstuvwxyzABCD2fghiEFGHIJKLMNOPQRSTUVWXY3
269 raise FunctionNotFoundError("function nvFatbinDestroy is not found")
270 return (<nvFatbinResult (*)(nvFatbinHandle*) noexcept nogil>__nvFatbinDestroy)( 1bcdejklm$%nopqrstuvwxyzABC4567D)2Z01fghiEFGH'(IJKLMNOPQRSTUVWX89!#Y*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:
275 global __nvFatbinAddPTX
276 _check_or_init_nvfatbin() 1nopqrstuvwxyzABCZ01IJKLMNOPQRSTUVWX
277 if __nvFatbinAddPTX == NULL: 1anopqrstuvwxyzABC+Z01IJKLMNOPQRSTUVWX,
278 with gil: 1a+,
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)( 1nopqrstuvwxyzABCZ01IJKLMNOPQRSTUVWX
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:
285 global __nvFatbinAddCubin
286 _check_or_init_nvfatbin() 1jklm$%Z01EFGH'(
287 if __nvFatbinAddCubin == NULL: 1jklm$%Z01EFGH'(
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)( 1jklm$%Z01EFGH'(
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() 1bcdefghi
297 if __nvFatbinAddLTOIR == NULL: 1bcdefghi
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)( 1bcdefghi
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() 1bcdejklmnopqrstuvwxyzABC4567D2Z01fghiEFGHIJKLMNOPQRSTUVWX89!#Y3
307 if __nvFatbinSize == NULL: 1bcdejklmnopqrstuvwxyzABC4567D2Z01fghiEFGHIJKLMNOPQRSTUVWX89!#Y3
308 with gil: 1DY
309 raise FunctionNotFoundError("function nvFatbinSize is not found")
310 return (<nvFatbinResult (*)(nvFatbinHandle, size_t*) noexcept nogil>__nvFatbinSize)( 1bcdejklmnopqrstuvwxyzABC4567D2Z01fghiEFGHIJKLMNOPQRSTUVWX89!#Y3
311 handle, size)
314cdef nvFatbinResult _nvFatbinGet(nvFatbinHandle handle, void* buffer) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil:
315 global __nvFatbinGet
316 _check_or_init_nvfatbin() 1bcdejklmnopqrstuvwxyzABC4567D2Z01fghiEFGHIJKLMNOPQRSTUVWX89!#Y3
317 if __nvFatbinGet == NULL: 1bcdejklmnopqrstuvwxyzABC4567D2Z01fghiEFGHIJKLMNOPQRSTUVWX89!#Y3
318 with gil:
319 raise FunctionNotFoundError("function nvFatbinGet is not found")
320 return (<nvFatbinResult (*)(nvFatbinHandle, void*) noexcept nogil>__nvFatbinGet)( 1bcdejklmnopqrstuvwxyzABC4567D2Z01fghiEFGHIJKLMNOPQRSTUVWX89!#Y3
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() 1DY
357 if __nvFatbinAddTileIR == NULL: 1DY
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)( 1DY
361 handle, code, size, identifier, optionsCmdLine)