Coverage for cuda/bindings/nvfatbin.pyx: 86.52%
141 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-19 01:12 +0000
« 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=22dd0937e8e243f48b06a24f0c1819e09360d102541b621dfe1cdeaa55c2154c
9# <<<< PREAMBLE CONTENT >>>>
11from cuda.bindings._internal._fast_enum import FastEnum as _cyb_FastEnum
14# <<<< END OF PREAMBLE CONTENT >>>>
16cimport cython # NOQA
18from ._internal.utils cimport (get_resource_ptr, get_nested_resource_ptr, nested_resource, nullable_unique_ptr,
19 get_buffer_pointer, get_resource_ptrs)
21from libcpp.vector cimport vector
24###############################################################################
25# Enum
26###############################################################################
28class Result(_cyb_FastEnum):
29 """
30 The enumerated type `nvFatbinResult` defines API call result codes.
31 nvFatbin APIs return `nvFatbinResult` codes to indicate the result.
33 See `nvFatbinResult`.
34 """
35 SUCCESS = NVFATBIN_SUCCESS
36 ERROR_INTERNAL = NVFATBIN_ERROR_INTERNAL
37 ERROR_ELF_ARCH_MISMATCH = NVFATBIN_ERROR_ELF_ARCH_MISMATCH
38 ERROR_ELF_SIZE_MISMATCH = NVFATBIN_ERROR_ELF_SIZE_MISMATCH
39 ERROR_MISSING_PTX_VERSION = NVFATBIN_ERROR_MISSING_PTX_VERSION
40 ERROR_NULL_POINTER = NVFATBIN_ERROR_NULL_POINTER
41 ERROR_COMPRESSION_FAILED = NVFATBIN_ERROR_COMPRESSION_FAILED
42 ERROR_COMPRESSED_SIZE_EXCEEDED = NVFATBIN_ERROR_COMPRESSED_SIZE_EXCEEDED
43 ERROR_UNRECOGNIZED_OPTION = NVFATBIN_ERROR_UNRECOGNIZED_OPTION
44 ERROR_INVALID_ARCH = NVFATBIN_ERROR_INVALID_ARCH
45 ERROR_INVALID_NVVM = NVFATBIN_ERROR_INVALID_NVVM
46 ERROR_EMPTY_INPUT = NVFATBIN_ERROR_EMPTY_INPUT
47 ERROR_MISSING_PTX_ARCH = NVFATBIN_ERROR_MISSING_PTX_ARCH
48 ERROR_PTX_ARCH_MISMATCH = NVFATBIN_ERROR_PTX_ARCH_MISMATCH
49 ERROR_MISSING_FATBIN = NVFATBIN_ERROR_MISSING_FATBIN
50 ERROR_INVALID_INDEX = NVFATBIN_ERROR_INVALID_INDEX
51 ERROR_IDENTIFIER_REUSE = NVFATBIN_ERROR_IDENTIFIER_REUSE
52 ERROR_INTERNAL_PTX_OPTION = NVFATBIN_ERROR_INTERNAL_PTX_OPTION
55###############################################################################
56# Error handling
57###############################################################################
59class nvFatbinError(Exception):
61 def __init__(self, status):
62 self.status = status 1DEK
63 s = Result(status) 1DEK
64 cdef str err = f"{s.name} ({s.value})" 1DEK
65 super(nvFatbinError, self).__init__(err) 1DEK
67 def __reduce__(self):
68 return (type(self), (self.status,))
71@cython.profile(False)
72cdef int check_status(int status) except 1 nogil:
73 if status != 0: 1abcdefghyzABDEijklmnopqrstuvwxFGHICLJMK
74 with gil: 1DEK
75 raise nvFatbinError(status) 1DEK
76 return status 1abcdefghyzABDEijklmnopqrstuvwxFGHICLJM
79###############################################################################
80# Wrapper functions
81###############################################################################
83cpdef destroy(intptr_t handle):
84 """nvFatbinDestroy frees the memory associated with the given handle.
86 Args:
87 handle (intptr_t): nvFatbin handle.
89 .. seealso:: `nvFatbinDestroy`
90 """
91 cdef Handle h = <Handle>handle 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJ
92 with nogil: 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJ
93 status = nvFatbinDestroy(&h) 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJ
94 check_status(status) 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJ
97cpdef str get_error_string(int result):
98 """nvFatbinGetErrorString returns an error description string for each error code.
100 Args:
101 result (Result): error code.
103 .. seealso:: `nvFatbinGetErrorString`
104 """
105 cdef const char* _output_
106 cdef bytes _output_bytes_
107 _output_ = nvFatbinGetErrorString(<_Result>result) 1NOPQRSTUVWXYZ01234
109 if _output_ == NULL: 1NOPQRSTUVWXYZ01234
110 return "" 14
112 _output_bytes_ = <bytes>_output_ 1NOPQRSTUVWXYZ0123
113 return _output_bytes_.decode() 1NOPQRSTUVWXYZ0123
116cpdef intptr_t create(options, size_t options_count) except -1:
117 """nvFatbinCreate creates a new handle.
119 Args:
120 options (object): An array of strings, each containing a single option. It can be:
122 - an :class:`int` as the pointer address to the nested sequence, or
123 - a Python sequence of :class:`int`\s, each of which is a pointer address
124 to a valid sequence of 'char', or
125 - a nested Python sequence of ``str``.
127 options_count (size_t): Number of options.
129 Returns:
130 intptr_t: Address of nvFatbin handle.
132 .. seealso:: `nvFatbinCreate`
133 """
134 cdef nested_resource[ char ] _options_
135 get_nested_resource_ptr[char](_options_, options, <char*>NULL) 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJK
136 cdef Handle handle_indirect
137 with nogil: 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJK
138 __status__ = nvFatbinCreate(&handle_indirect, <const char**>(_options_.ptrs.data()), options_count) 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJK
139 check_status(__status__) 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJK
140 return <intptr_t>handle_indirect 1bcdefghyzABDEijklmnopqrstuvwxFGHICLJ
143cpdef add_ptx(intptr_t handle, code, size_t size, arch, identifier, options_cmd_line):
144 """nvFatbinAddPTX adds PTX to the fatbinary.
146 Args:
147 handle (intptr_t): nvFatbin handle.
148 code (bytes): The PTX code.
149 size (size_t): The size of the PTX code.
150 arch (str): The numerical architecture that this PTX is for (the XX of any sm_XX, lto_XX, or compute_XX).
151 identifier (str): Name of the PTX, useful when extracting the fatbin with tools like cuobjdump.
152 options_cmd_line (str): Options used during JIT compilation.
154 .. seealso:: `nvFatbinAddPTX`
155 """
156 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1bcdijklmnopqrstuvwx
157 if not isinstance(arch, str): 1bcdijklmnopqrstuvwx
158 raise TypeError("arch must be a Python str")
159 cdef bytes _temp_arch_ = (<str>arch).encode() 1bcdijklmnopqrstuvwx
160 cdef char* _arch_ = _temp_arch_ 1bcdijklmnopqrstuvwx
161 if not isinstance(identifier, str): 1bcdijklmnopqrstuvwx
162 raise TypeError("identifier must be a Python str")
163 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1bcdijklmnopqrstuvwx
164 cdef char* _identifier_ = _temp_identifier_ 1bcdijklmnopqrstuvwx
165 if not isinstance(options_cmd_line, str): 1bcdijklmnopqrstuvwx
166 raise TypeError("options_cmd_line must be a Python str")
167 cdef bytes _temp_options_cmd_line_ = (<str>options_cmd_line).encode() 1bcdijklmnopqrstuvwx
168 cdef char* _options_cmd_line_ = _temp_options_cmd_line_ 1bcdijklmnopqrstuvwx
169 with nogil: 1bcdijklmnopqrstuvwx
170 __status__ = nvFatbinAddPTX(<Handle>handle, <const char*>_code_, size, <const char*>_arch_, <const char*>_identifier_, <const char*>_options_cmd_line_) 1bcdijklmnopqrstuvwx
171 check_status(__status__) 1bcdijklmnopqrstuvwx
174cpdef add_cubin(intptr_t handle, code, size_t size, arch, identifier):
175 """nvFatbinAddCubin adds a CUDA binary to the fatbinary.
177 Args:
178 handle (intptr_t): nvFatbin handle.
179 code (bytes): The cubin.
180 size (size_t): The size of the cubin.
181 arch (str): The numerical architecture that this cubin is for (the XX of any sm_XX, lto_XX, or compute_XX).
182 identifier (str): Name of the cubin, useful when extracting the fatbin with tools like cuobjdump.
184 .. seealso:: `nvFatbinAddCubin`
185 """
186 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1bcdyzABDE
187 if not isinstance(arch, str): 1bcdyzABDE
188 raise TypeError("arch must be a Python str")
189 cdef bytes _temp_arch_ = (<str>arch).encode() 1bcdyzABDE
190 cdef char* _arch_ = _temp_arch_ 1bcdyzABDE
191 if not isinstance(identifier, str): 1bcdyzABDE
192 raise TypeError("identifier must be a Python str")
193 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1bcdyzABDE
194 cdef char* _identifier_ = _temp_identifier_ 1bcdyzABDE
195 with nogil: 1bcdyzABDE
196 __status__ = nvFatbinAddCubin(<Handle>handle, <const void*>_code_, size, <const char*>_arch_, <const char*>_identifier_) 1bcdyzABDE
197 check_status(__status__) 1bcdyzABDE
200cpdef add_ltoir(intptr_t handle, code, size_t size, arch, identifier, options_cmd_line):
201 """nvFatbinAddLTOIR adds LTOIR to the fatbinary.
203 Args:
204 handle (intptr_t): nvFatbin handle.
205 code (bytes): The LTOIR code.
206 size (size_t): The size of the LTOIR code.
207 arch (str): The numerical architecture that this LTOIR is for (the XX of any sm_XX, lto_XX, or compute_XX).
208 identifier (str): Name of the LTOIR, useful when extracting the fatbin with tools like cuobjdump.
209 options_cmd_line (str): Options used during JIT compilation.
211 .. seealso:: `nvFatbinAddLTOIR`
212 """
213 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1efgh
214 if not isinstance(arch, str): 1efgh
215 raise TypeError("arch must be a Python str")
216 cdef bytes _temp_arch_ = (<str>arch).encode() 1efgh
217 cdef char* _arch_ = _temp_arch_ 1efgh
218 if not isinstance(identifier, str): 1efgh
219 raise TypeError("identifier must be a Python str")
220 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1efgh
221 cdef char* _identifier_ = _temp_identifier_ 1efgh
222 if not isinstance(options_cmd_line, str): 1efgh
223 raise TypeError("options_cmd_line must be a Python str")
224 cdef bytes _temp_options_cmd_line_ = (<str>options_cmd_line).encode() 1efgh
225 cdef char* _options_cmd_line_ = _temp_options_cmd_line_ 1efgh
226 with nogil: 1efgh
227 __status__ = nvFatbinAddLTOIR(<Handle>handle, <const void*>_code_, size, <const char*>_arch_, <const char*>_identifier_, <const char*>_options_cmd_line_) 1efgh
228 check_status(__status__) 1efgh
231cpdef size_t size(intptr_t handle) except? 0:
232 """nvFatbinSize returns the fatbinary's size.
234 Args:
235 handle (intptr_t): nvFatbin handle.
237 Returns:
238 size_t: The fatbinary's size.
240 .. seealso:: `nvFatbinSize`
241 """
242 cdef size_t size
243 with nogil: 1bcdefghyzABijklmnopqrstuvwxFGHICJ
244 __status__ = nvFatbinSize(<Handle>handle, &size) 1bcdefghyzABijklmnopqrstuvwxFGHICJ
245 check_status(__status__) 1bcdefghyzABijklmnopqrstuvwxFGHICJ
246 return size 1bcdefghyzABijklmnopqrstuvwxFGHICJ
249cpdef get(intptr_t handle, buffer):
250 """nvFatbinGet returns the completed fatbinary.
252 Args:
253 handle (intptr_t): nvFatbin handle.
254 buffer (bytes): memory to store fatbinary.
256 .. seealso:: `nvFatbinGet`
257 """
258 cdef void* _buffer_ = get_buffer_pointer(buffer, -1, readonly=False) 1bcdefghyzABijklmnopqrstuvwxFGHICJ
259 with nogil: 1bcdefghyzABijklmnopqrstuvwxFGHICJ
260 __status__ = nvFatbinGet(<Handle>handle, <void*>_buffer_) 1bcdefghyzABijklmnopqrstuvwxFGHICJ
261 check_status(__status__) 1bcdefghyzABijklmnopqrstuvwxFGHICJ
264cpdef tuple version():
265 """nvFatbinVersion returns the current version of nvFatbin.
267 Returns:
268 A 2-tuple containing:
270 - unsigned int: The major version.
271 - unsigned int: The minor version.
273 .. seealso:: `nvFatbinVersion`
274 """
275 cdef unsigned int major
276 cdef unsigned int minor
277 with nogil: 1aM
278 __status__ = nvFatbinVersion(&major, &minor) 1aM
279 check_status(__status__) 1aM
280 return (major, minor) 1aM
283cpdef add_index(intptr_t handle, code, size_t size, identifier):
284 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True)
285 if not isinstance(identifier, str):
286 raise TypeError("identifier must be a Python str")
287 cdef bytes _temp_identifier_ = (<str>identifier).encode()
288 cdef char* _identifier_ = _temp_identifier_
289 with nogil:
290 __status__ = nvFatbinAddIndex(<Handle>handle, <const void*>_code_, size, <const char*>_identifier_)
291 check_status(__status__)
294cpdef add_reloc(intptr_t handle, code, size_t size):
295 """nvFatbinAddReloc adds relocatable PTX entries from a host object to the fatbinary.
297 Args:
298 handle (intptr_t): nvFatbin handle.
299 code (bytes): The host object image.
300 size (size_t): The size of the host object image code.
302 .. seealso:: `nvFatbinAddReloc`
303 """
304 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1FGHI
305 with nogil: 1FGHI
306 __status__ = nvFatbinAddReloc(<Handle>handle, <const void*>_code_, size) 1FGHI
307 check_status(__status__) 1FGHI
310cpdef add_tile_ir(intptr_t handle, code, size_t size, identifier, options_cmd_line):
311 """nvFatbinAddTileIR adds Tile IR to the fatbinary.
313 Args:
314 handle (intptr_t): nvFatbin handle.
315 code (bytes): The Tile IR.
316 size (size_t): The size of the Tile IR.
317 identifier (str): Name of the Tile IR, useful when extracting the fatbin with tools like cuobjdump.
318 options_cmd_line (str): Options used during JIT compilation.
320 .. seealso:: `nvFatbinAddTileIR`
321 """
322 cdef void* _code_ = get_buffer_pointer(code, size, readonly=True) 1C
323 if not isinstance(identifier, str): 1C
324 raise TypeError("identifier must be a Python str")
325 cdef bytes _temp_identifier_ = (<str>identifier).encode() 1C
326 cdef char* _identifier_ = _temp_identifier_ 1C
327 if not isinstance(options_cmd_line, str): 1C
328 raise TypeError("options_cmd_line must be a Python str")
329 cdef bytes _temp_options_cmd_line_ = (<str>options_cmd_line).encode() 1C
330 cdef char* _options_cmd_line_ = _temp_options_cmd_line_ 1C
331 with nogil: 1C
332 __status__ = nvFatbinAddTileIR(<Handle>handle, <const void*>_code_, size, <const char*>_identifier_, <const char*>_options_cmd_line_) 1C
333 check_status(__status__) 1C
334del _cyb_FastEnum