Coverage for cuda/bindings/nvjitlink.pyx: 97.74%
133 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) 2024-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.0.1 to 13.3.0. Do not modify it directly.
6# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=73b6eb59cbe4fda520d37939d18d4625eb3818e37689796be45025a8aa877473
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 `nvJitLinkResult` defines API call result codes.
31 nvJitLink APIs return `nvJitLinkResult` codes to indicate the result.
33 See `nvJitLinkResult`.
34 """
35 SUCCESS = NVJITLINK_SUCCESS
36 ERROR_UNRECOGNIZED_OPTION = (NVJITLINK_ERROR_UNRECOGNIZED_OPTION, 'Unrecognized Option')
37 ERROR_MISSING_ARCH = (NVJITLINK_ERROR_MISSING_ARCH, 'Option `-arch=sm_NN` not specified')
38 ERROR_INVALID_INPUT = (NVJITLINK_ERROR_INVALID_INPUT, 'Invalid Input')
39 ERROR_PTX_COMPILE = (NVJITLINK_ERROR_PTX_COMPILE, 'Issue during PTX Compilation')
40 ERROR_NVVM_COMPILE = (NVJITLINK_ERROR_NVVM_COMPILE, 'Issue during NVVM Compilation')
41 ERROR_INTERNAL = (NVJITLINK_ERROR_INTERNAL, 'Internal Error')
42 ERROR_THREADPOOL = (NVJITLINK_ERROR_THREADPOOL, 'Issue with Thread Pool')
43 ERROR_UNRECOGNIZED_INPUT = (NVJITLINK_ERROR_UNRECOGNIZED_INPUT, 'Unrecognized Input')
44 ERROR_FINALIZE = (NVJITLINK_ERROR_FINALIZE, 'Finalizer Error')
45 ERROR_NULL_INPUT = (NVJITLINK_ERROR_NULL_INPUT, 'Null Input')
46 ERROR_INCOMPATIBLE_OPTIONS = (NVJITLINK_ERROR_INCOMPATIBLE_OPTIONS, 'Incompatible Options')
47 ERROR_INCORRECT_INPUT_TYPE = (NVJITLINK_ERROR_INCORRECT_INPUT_TYPE, 'Incorrect Input Type')
48 ERROR_ARCH_MISMATCH = (NVJITLINK_ERROR_ARCH_MISMATCH, 'Arch Mismatch')
49 ERROR_OUTDATED_LIBRARY = (NVJITLINK_ERROR_OUTDATED_LIBRARY, 'Outdated Library')
50 ERROR_MISSING_FATBIN = (NVJITLINK_ERROR_MISSING_FATBIN, 'Missing Fatbin')
51 ERROR_UNRECOGNIZED_ARCH = (NVJITLINK_ERROR_UNRECOGNIZED_ARCH, 'Unrecognized -arch value')
52 ERROR_UNSUPPORTED_ARCH = (NVJITLINK_ERROR_UNSUPPORTED_ARCH, 'Unsupported -arch value')
53 ERROR_LTO_NOT_ENABLED = (NVJITLINK_ERROR_LTO_NOT_ENABLED, 'Requires -lto')
55class InputType(_cyb_FastEnum):
56 """
57 The enumerated type `nvJitLinkInputType` defines the kind of inputs
58 that can be passed to nvJitLinkAdd* APIs.
60 See `nvJitLinkInputType`.
61 """
62 NONE = (NVJITLINK_INPUT_NONE, 'Error Type')
63 CUBIN = (NVJITLINK_INPUT_CUBIN, 'For CUDA Binaries')
64 PTX = (NVJITLINK_INPUT_PTX, 'For PTX')
65 LTOIR = (NVJITLINK_INPUT_LTOIR, 'For LTO-IR')
66 FATBIN = (NVJITLINK_INPUT_FATBIN, 'For Fatbin')
67 OBJECT = (NVJITLINK_INPUT_OBJECT, 'For Host Object')
68 LIBRARY = (NVJITLINK_INPUT_LIBRARY, 'For Host Library')
69 INDEX = (NVJITLINK_INPUT_INDEX, 'For Index File')
70 ANY = (NVJITLINK_INPUT_ANY, 'Dynamically chooses from the valid types')
73###############################################################################
74# Error handling
75###############################################################################
77class nvJitLinkError(Exception):
79 def __init__(self, status):
80 self.status = status 2% ' qbrb( )
81 s = Result(status) 2% ' qbrb( )
82 cdef str err = f"{s.name} ({s.value})" 2% ' qbrb( )
83 super(nvJitLinkError, self).__init__(err) 2% ' qbrb( )
85 def __reduce__(self):
86 return (type(self), (self.status,))
89@cython.profile(False)
90cdef int check_status(int status) except 1 nogil:
91 if status != 0: 2a P Q R S X Y Z 0 5 6 7 8 * + , - . H I J K b c d e f g h i j k l m n o p q % @ ' T U V W 1 2 3 4 9 ! # $ / : ; = ? L M N O r s t u v w x y z A B C D E F G ( [ ) ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpb
92 with gil: 1%'()
93 raise nvJitLinkError(status) 1%'()
94 return status 2a P Q R S X Y Z 0 5 6 7 8 * + , - . H I J K b c d e f g h i j k l m n o p q @ T U V W 1 2 3 4 9 ! # $ / : ; = ? L M N O r s t u v w x y z A B C D E F G [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpb
97###############################################################################
98# Wrapper functions
99###############################################################################
101cpdef destroy(intptr_t handle):
102 """nvJitLinkDestroy frees the memory associated with the given handle.
104 Args:
105 handle (intptr_t): nvJitLink handle.
107 .. seealso:: `nvJitLinkDestroy`
108 """
109 cdef Handle h = <Handle>handle 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopqTUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG
110 with nogil: 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopqTUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG
111 status = nvJitLinkDestroy(&h) 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopqTUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG
112 check_status(status) 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopqTUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG
115cpdef intptr_t create(uint32_t num_options, options) except -1:
116 """nvJitLinkCreate creates an instance of ``nvJitLinkHandle`` with the given input options, and sets the output parameter ``handle``.
118 Args:
119 num_options (uint32_t): Number of options passed.
120 options (object): Array of size ``num_options`` of option
121 strings. It can be:
123 - an :class:`int` as the pointer address to the nested sequence, or
124 - a Python sequence of :class:`int`\s, each of which is a pointer address
125 to a valid sequence of 'char', or
126 - a nested Python sequence of ``str``.
129 Returns:
130 intptr_t: Address of nvJitLink handle.
132 .. seealso:: `nvJitLinkCreate`
133 """
134 cdef nested_resource[ char ] _options_
135 get_nested_resource_ptr[char](_options_, options, <char*>NULL) 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopq%'TUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG()
136 cdef Handle handle
137 with nogil: 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopq%'TUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG()
138 __status__ = nvJitLinkCreate(&handle, num_options, <const char**>(_options_.ptrs.data())) 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopq%'TUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG()
139 check_status(__status__) 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopq%'TUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG()
140 return <intptr_t>handle 1PQRSXYZ05678*+,-.HIJKbcdefghijklmnopqTUVW12349!#$/:;=?LMNOrstuvwxyzABCDEFG
143cpdef add_data(intptr_t handle, int input_type, data, size_t size, name):
144 """nvJitLinkAddData adds data image to the link.
146 Args:
147 handle (intptr_t): nvJitLink handle.
148 input_type (InputType): kind of input.
149 data (bytes): pointer to data image in memory.
150 size (size_t): size of the data.
151 name (str): name of input object.
153 .. seealso:: `nvJitLinkAddData`
154 """
155 cdef void* _data_ = get_buffer_pointer(data, size, readonly=True) 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
156 if not isinstance(name, str): 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
157 raise TypeError("name must be a Python str")
158 cdef bytes _temp_name_ = (<str>name).encode() 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
159 cdef char* _name_ = _temp_name_ 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
160 with nogil: 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
161 __status__ = nvJitLinkAddData(<Handle>handle, <_InputType>input_type, <const void*>_data_, size, <const char*>_name_) 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
162 check_status(__status__) 1PQRSbcdefghijklmnopqTUVWrstuvwxyzABCDEFG
165cpdef add_file(intptr_t handle, int input_type, file_name):
166 """nvJitLinkAddFile reads data from file and links it in.
168 Args:
169 handle (intptr_t): nvJitLink handle.
170 input_type (InputType): kind of input.
171 file_name (str): name of file.
173 .. seealso:: `nvJitLinkAddFile`
174 """
175 if not isinstance(file_name, str): 1XYZ01234
176 raise TypeError("file_name must be a Python str")
177 cdef bytes _temp_file_name_ = (<str>file_name).encode() 1XYZ01234
178 cdef char* _file_name_ = _temp_file_name_ 1XYZ01234
179 with nogil: 1XYZ01234
180 __status__ = nvJitLinkAddFile(<Handle>handle, <_InputType>input_type, <const char*>_file_name_) 1XYZ01234
181 check_status(__status__) 1XYZ01234
184cpdef complete(intptr_t handle):
185 """nvJitLinkComplete does the actual link.
187 Args:
188 handle (intptr_t): nvJitLink handle.
190 .. seealso:: `nvJitLinkComplete`
191 """
192 with nogil: 1PQRSXYZ05678HIJKbcdefghijklmnopqTUVW12349!#$LMNOrstuvwxyzABCDEFG
193 __status__ = nvJitLinkComplete(<Handle>handle) 1PQRSXYZ05678HIJKbcdefghijklmnopqTUVW12349!#$LMNOrstuvwxyzABCDEFG
194 check_status(__status__) 1PQRSXYZ05678HIJKbcdefghijklmnopqTUVW12349!#$LMNOrstuvwxyzABCDEFG
197cpdef size_t get_linked_cubin_size(intptr_t handle) except? 0:
198 """nvJitLinkGetLinkedCubinSize gets the size of the linked cubin.
200 Args:
201 handle (intptr_t): nvJitLink handle.
203 Returns:
204 size_t: Size of the linked cubin.
206 .. seealso:: `nvJitLinkGetLinkedCubinSize`
207 """
208 cdef size_t size
209 with nogil: 1fghivwxy
210 __status__ = nvJitLinkGetLinkedCubinSize(<Handle>handle, &size) 1fghivwxy
211 check_status(__status__) 1fghivwxy
212 return size 1fghivwxy
215cpdef get_linked_cubin(intptr_t handle, cubin):
216 """nvJitLinkGetLinkedCubin gets the linked cubin.
218 Args:
219 handle (intptr_t): nvJitLink handle.
220 cubin (bytes): The linked cubin.
222 .. seealso:: `nvJitLinkGetLinkedCubin`
223 """
224 cdef void* _cubin_ = get_buffer_pointer(cubin, -1, readonly=False) 1fghivwxy
225 with nogil: 1fghivwxy
226 __status__ = nvJitLinkGetLinkedCubin(<Handle>handle, <void*>_cubin_) 1fghivwxy
227 check_status(__status__) 1fghivwxy
230cpdef size_t get_linked_ptx_size(intptr_t handle) except? 0:
231 """nvJitLinkGetLinkedPtxSize gets the size of the linked ptx.
233 Args:
234 handle (intptr_t): nvJitLink handle.
236 Returns:
237 size_t: Size of the linked PTX.
239 .. seealso:: `nvJitLinkGetLinkedPtxSize`
240 """
241 cdef size_t size
242 with nogil: 1nopqDEFG
243 __status__ = nvJitLinkGetLinkedPtxSize(<Handle>handle, &size) 1nopqDEFG
244 check_status(__status__) 1nopqDEFG
245 return size 1nopqDEFG
248cpdef get_linked_ptx(intptr_t handle, ptx):
249 """nvJitLinkGetLinkedPtx gets the linked ptx.
251 Args:
252 handle (intptr_t): nvJitLink handle.
253 ptx (bytes): The linked PTX.
255 .. seealso:: `nvJitLinkGetLinkedPtx`
256 """
257 cdef void* _ptx_ = get_buffer_pointer(ptx, -1, readonly=False) 1nopqDEFG
258 with nogil: 1nopqDEFG
259 __status__ = nvJitLinkGetLinkedPtx(<Handle>handle, <char*>_ptx_) 1nopqDEFG
260 check_status(__status__) 1nopqDEFG
263cpdef size_t get_error_log_size(intptr_t handle) except? 0:
264 """nvJitLinkGetErrorLogSize gets the size of the error log.
266 Args:
267 handle (intptr_t): nvJitLink handle.
269 Returns:
270 size_t: Size of the error log.
272 .. seealso:: `nvJitLinkGetErrorLogSize`
273 """
274 cdef size_t size
275 with nogil: 1HIJKLMNO
276 __status__ = nvJitLinkGetErrorLogSize(<Handle>handle, &size) 1HIJKLMNO
277 check_status(__status__) 1HIJKLMNO
278 return size 1HIJKLMNO
281cpdef get_error_log(intptr_t handle, log):
282 """nvJitLinkGetErrorLog puts any error messages in the log.
284 Args:
285 handle (intptr_t): nvJitLink handle.
286 log (bytes): The error log.
288 .. seealso:: `nvJitLinkGetErrorLog`
289 """
290 cdef void* _log_ = get_buffer_pointer(log, -1, readonly=False) 1HIJKLMNO
291 with nogil: 1HIJKLMNO
292 __status__ = nvJitLinkGetErrorLog(<Handle>handle, <char*>_log_) 1HIJKLMNO
293 check_status(__status__) 1HIJKLMNO
296cpdef size_t get_info_log_size(intptr_t handle) except? 0:
297 """nvJitLinkGetInfoLogSize gets the size of the info log.
299 Args:
300 handle (intptr_t): nvJitLink handle.
302 Returns:
303 size_t: Size of the info log.
305 .. seealso:: `nvJitLinkGetInfoLogSize`
306 """
307 cdef size_t size
308 with nogil: 1bcderstu
309 __status__ = nvJitLinkGetInfoLogSize(<Handle>handle, &size) 1bcderstu
310 check_status(__status__) 1bcderstu
311 return size 1bcderstu
314cpdef get_info_log(intptr_t handle, log):
315 """nvJitLinkGetInfoLog puts any info messages in the log.
317 Args:
318 handle (intptr_t): nvJitLink handle.
319 log (bytes): The info log.
321 .. seealso:: `nvJitLinkGetInfoLog`
322 """
323 cdef void* _log_ = get_buffer_pointer(log, -1, readonly=False) 1bcderstu
324 with nogil: 1bcderstu
325 __status__ = nvJitLinkGetInfoLog(<Handle>handle, <char*>_log_) 1bcderstu
326 check_status(__status__) 1bcderstu
329cpdef tuple version():
330 """nvJitLinkVersion returns the current version of nvJitLink.
332 Returns:
333 A 2-tuple containing:
335 - unsigned int: The major version.
336 - unsigned int: The minor version.
338 .. seealso:: `nvJitLinkVersion`
339 """
340 cdef unsigned int major
341 cdef unsigned int minor
342 with nogil: 2a @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpb
343 __status__ = nvJitLinkVersion(&major, &minor) 2a @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpb
344 check_status(__status__) 2a @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpb
345 return (major, minor) 2a @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpb
348cpdef size_t get_linked_ltoir_size(intptr_t handle) except? 0:
349 """nvJitLinkGetLinkedLTOIRSize gets the size of the linked LTOIR.
351 Args:
352 handle (intptr_t): nvJitLink handle.
354 Returns:
355 size_t: Size of the linked LTOIR.
357 .. seealso:: `nvJitLinkGetLinkedLTOIRSize`
358 """
359 cdef size_t size
360 with nogil: 1jklmzABC
361 __status__ = nvJitLinkGetLinkedLTOIRSize(<Handle>handle, &size) 1jklmzABC
362 check_status(__status__) 1jklmzABC
363 return size 1jklmzABC
366cpdef get_linked_ltoir(intptr_t handle, ltoir):
367 """nvJitLinkGetLinkedLTOIR gets the linked LTOIR.
369 Args:
370 handle (intptr_t): nvJitLink handle.
371 ltoir (bytes): The linked LTOIR in Container format.
373 .. seealso:: `nvJitLinkGetLinkedLTOIR`
374 """
375 cdef void* _ltoir_ = get_buffer_pointer(ltoir, -1, readonly=False) 1jklmzABC
376 with nogil: 1jklmzABC
377 __status__ = nvJitLinkGetLinkedLTOIR(<Handle>handle, <void*>_ltoir_) 1jklmzABC
378 check_status(__status__) 1jklmzABC
379del _cyb_FastEnum