Coverage for cuda / bindings / nvjitlink.pyx: 97.54%
122 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-08 01:07 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-08 01:07 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4#
5# This code was automatically generated across versions from 12.0.1 to 13.1.1, generator version 0.3.1.dev1322+g646ce84ec. Do not modify it directly.
7cimport cython # NOQA
9from ._internal.utils cimport (get_resource_ptr, get_nested_resource_ptr, nested_resource, nullable_unique_ptr,
10 get_buffer_pointer, get_resource_ptrs)
12from cuda.bindings._internal._fast_enum import FastEnum as _FastEnum
13from libcpp.vector cimport vector
16###############################################################################
17# Enum
18###############################################################################
20class Result(_FastEnum):
21 """
22 The enumerated type nvJitLinkResult defines API call result codes.
23 nvJitLink APIs return nvJitLinkResult codes to indicate the result.
25 See `nvJitLinkResult`.
26 """
27 SUCCESS = NVJITLINK_SUCCESS
28 ERROR_UNRECOGNIZED_OPTION = (NVJITLINK_ERROR_UNRECOGNIZED_OPTION, 'Unrecognized Option')
29 ERROR_MISSING_ARCH = (NVJITLINK_ERROR_MISSING_ARCH, 'Option `-arch=sm_NN` not specified')
30 ERROR_INVALID_INPUT = (NVJITLINK_ERROR_INVALID_INPUT, 'Invalid Input')
31 ERROR_PTX_COMPILE = (NVJITLINK_ERROR_PTX_COMPILE, 'Issue during PTX Compilation')
32 ERROR_NVVM_COMPILE = (NVJITLINK_ERROR_NVVM_COMPILE, 'Issue during NVVM Compilation')
33 ERROR_INTERNAL = (NVJITLINK_ERROR_INTERNAL, 'Internal Error')
34 ERROR_THREADPOOL = (NVJITLINK_ERROR_THREADPOOL, 'Issue with Thread Pool')
35 ERROR_UNRECOGNIZED_INPUT = (NVJITLINK_ERROR_UNRECOGNIZED_INPUT, 'Unrecognized Input')
36 ERROR_FINALIZE = (NVJITLINK_ERROR_FINALIZE, 'Finalizer Error')
37 ERROR_NULL_INPUT = (NVJITLINK_ERROR_NULL_INPUT, 'Null Input')
38 ERROR_INCOMPATIBLE_OPTIONS = (NVJITLINK_ERROR_INCOMPATIBLE_OPTIONS, 'Incompatible Options')
39 ERROR_INCORRECT_INPUT_TYPE = (NVJITLINK_ERROR_INCORRECT_INPUT_TYPE, 'Incorrect Input Type')
40 ERROR_ARCH_MISMATCH = (NVJITLINK_ERROR_ARCH_MISMATCH, 'Arch Mismatch')
41 ERROR_OUTDATED_LIBRARY = (NVJITLINK_ERROR_OUTDATED_LIBRARY, 'Outdated Library')
42 ERROR_MISSING_FATBIN = (NVJITLINK_ERROR_MISSING_FATBIN, 'Missing Fatbin')
43 ERROR_UNRECOGNIZED_ARCH = (NVJITLINK_ERROR_UNRECOGNIZED_ARCH, 'Unrecognized -arch value')
44 ERROR_UNSUPPORTED_ARCH = (NVJITLINK_ERROR_UNSUPPORTED_ARCH, 'Unsupported -arch value')
45 ERROR_LTO_NOT_ENABLED = (NVJITLINK_ERROR_LTO_NOT_ENABLED, 'Requires -lto')
47class InputType(_FastEnum):
48 """
49 The enumerated type nvJitLinkInputType defines the kind of inputs that
50 can be passed to nvJitLinkAdd* APIs.
52 See `nvJitLinkInputType`.
53 """
54 NONE = (NVJITLINK_INPUT_NONE, 'Error Type')
55 CUBIN = (NVJITLINK_INPUT_CUBIN, 'For CUDA Binaries')
56 PTX = (NVJITLINK_INPUT_PTX, 'For PTX')
57 LTOIR = (NVJITLINK_INPUT_LTOIR, 'For LTO-IR')
58 FATBIN = (NVJITLINK_INPUT_FATBIN, 'For Fatbin')
59 OBJECT = (NVJITLINK_INPUT_OBJECT, 'For Host Object')
60 LIBRARY = (NVJITLINK_INPUT_LIBRARY, 'For Host Library')
61 INDEX = (NVJITLINK_INPUT_INDEX, 'For Index File')
62 ANY = (NVJITLINK_INPUT_ANY, 'Dynamically chooses from the valid types')
65###############################################################################
66# Error handling
67###############################################################################
69class nvJitLinkError(Exception):
71 def __init__(self, status):
72 self.status = status 1KLDE
73 s = Result(status) 1KLDE
74 cdef str err = f"{s.name} ({s.value})" 1KLDE
75 super(nvJitLinkError, self).__init__(err) 1KLDE
77 def __reduce__(self):
78 return (type(self), (self.status,))
81@cython.profile(False)
82cdef int check_status(int status) except 1 nogil:
83 if status != 0: 1arstuvwxyzABCFGHInopqbcdefghijklmDJE
84 with gil: 1DE
85 raise nvJitLinkError(status) 1DE
86 return status 1arstuvwxyzABCFGHInopqbcdefghijklmJ
89###############################################################################
90# Wrapper functions
91###############################################################################
93cpdef destroy(intptr_t handle):
94 """nvJitLinkDestroy frees the memory associated with the given handle.
96 Args:
97 handle (intptr_t): nvJitLink handle.
99 .. seealso:: `nvJitLinkDestroy`
100 """
101 cdef Handle h = <Handle>handle 1rstuvwxyzABCFGHInopqbcdefghijklm
102 with nogil: 1rstuvwxyzABCFGHInopqbcdefghijklm
103 status = nvJitLinkDestroy(&h) 1rstuvwxyzABCFGHInopqbcdefghijklm
104 check_status(status) 1rstuvwxyzABCFGHInopqbcdefghijklm
107cpdef intptr_t create(uint32_t num_options, options) except -1:
108 """nvJitLinkCreate creates an instance of nvJitLinkHandle with the given input options, and sets the output parameter ``handle``.
110 Args:
111 num_options (uint32_t): Number of options passed.
112 options (object): Array of size ``num_options`` of option strings. It can be:
114 - an :class:`int` as the pointer address to the nested sequence, or
115 - a Python sequence of :class:`int`\s, each of which is a pointer address
116 to a valid sequence of 'char', or
117 - a nested Python sequence of ``str``.
120 Returns:
121 intptr_t: Address of nvJitLink handle.
123 .. seealso:: `nvJitLinkCreate`
124 """
125 cdef nested_resource[ char ] _options_
126 get_nested_resource_ptr[char](_options_, options, <char*>NULL) 1rstuvwxyzABCFGHInopqbcdefghijklmDE
127 cdef Handle handle
128 with nogil: 1rstuvwxyzABCFGHInopqbcdefghijklmDE
129 __status__ = nvJitLinkCreate(&handle, num_options, <const char**>(_options_.ptrs.data())) 1rstuvwxyzABCFGHInopqbcdefghijklmDE
130 check_status(__status__) 1rstuvwxyzABCFGHInopqbcdefghijklmDE
131 return <intptr_t>handle 1rstuvwxyzABCFGHInopqbcdefghijklm
134cpdef add_data(intptr_t handle, int input_type, data, size_t size, name):
135 """nvJitLinkAddData adds data image to the link.
137 Args:
138 handle (intptr_t): nvJitLink handle.
139 input_type (InputType): kind of input.
140 data (bytes): pointer to data image in memory.
141 size (size_t): size of the data.
142 name (str): name of input object.
144 .. seealso:: `nvJitLinkAddData`
145 """
146 cdef void* _data_ = get_buffer_pointer(data, size, readonly=True) 1rstubcdefghijklm
147 if not isinstance(name, str): 1rstubcdefghijklm
148 raise TypeError("name must be a Python str")
149 cdef bytes _temp_name_ = (<str>name).encode() 1rstubcdefghijklm
150 cdef char* _name_ = _temp_name_ 1rstubcdefghijklm
151 with nogil: 1rstubcdefghijklm
152 __status__ = nvJitLinkAddData(<Handle>handle, <_InputType>input_type, <const void*>_data_, size, <const char*>_name_) 1rstubcdefghijklm
153 check_status(__status__) 1rstubcdefghijklm
156cpdef add_file(intptr_t handle, int input_type, file_name):
157 """nvJitLinkAddFile reads data from file and links it in.
159 Args:
160 handle (intptr_t): nvJitLink handle.
161 input_type (InputType): kind of input.
162 file_name (str): name of file.
164 .. seealso:: `nvJitLinkAddFile`
165 """
166 if not isinstance(file_name, str): 1vwxy
167 raise TypeError("file_name must be a Python str")
168 cdef bytes _temp_file_name_ = (<str>file_name).encode() 1vwxy
169 cdef char* _file_name_ = _temp_file_name_ 1vwxy
170 with nogil: 1vwxy
171 __status__ = nvJitLinkAddFile(<Handle>handle, <_InputType>input_type, <const char*>_file_name_) 1vwxy
172 check_status(__status__) 1vwxy
175cpdef complete(intptr_t handle):
176 """nvJitLinkComplete does the actual link.
178 Args:
179 handle (intptr_t): nvJitLink handle.
181 .. seealso:: `nvJitLinkComplete`
182 """
183 with nogil: 1rstuvwxyzABCnopqbcdefghijklm
184 __status__ = nvJitLinkComplete(<Handle>handle) 1rstuvwxyzABCnopqbcdefghijklm
185 check_status(__status__) 1rstuvwxyzABCnopqbcdefghijklm
188cpdef size_t get_linked_cubin_size(intptr_t handle) except? 0:
189 """nvJitLinkGetLinkedCubinSize gets the size of the linked cubin.
191 Args:
192 handle (intptr_t): nvJitLink handle.
194 Returns:
195 size_t: Size of the linked cubin.
197 .. seealso:: `nvJitLinkGetLinkedCubinSize`
198 """
199 cdef size_t size
200 with nogil: 1fghi
201 __status__ = nvJitLinkGetLinkedCubinSize(<Handle>handle, &size) 1fghi
202 check_status(__status__) 1fghi
203 return size 1fghi
206cpdef get_linked_cubin(intptr_t handle, cubin):
207 """nvJitLinkGetLinkedCubin gets the linked cubin.
209 Args:
210 handle (intptr_t): nvJitLink handle.
211 cubin (bytes): The linked cubin.
213 .. seealso:: `nvJitLinkGetLinkedCubin`
214 """
215 cdef void* _cubin_ = get_buffer_pointer(cubin, -1, readonly=False) 1fghi
216 with nogil: 1fghi
217 __status__ = nvJitLinkGetLinkedCubin(<Handle>handle, <void*>_cubin_) 1fghi
218 check_status(__status__) 1fghi
221cpdef size_t get_linked_ptx_size(intptr_t handle) except? 0:
222 """nvJitLinkGetLinkedPtxSize gets the size of the linked ptx.
224 Args:
225 handle (intptr_t): nvJitLink handle.
227 Returns:
228 size_t: Size of the linked PTX.
230 .. seealso:: `nvJitLinkGetLinkedPtxSize`
231 """
232 cdef size_t size
233 with nogil: 1jklm
234 __status__ = nvJitLinkGetLinkedPtxSize(<Handle>handle, &size) 1jklm
235 check_status(__status__) 1jklm
236 return size 1jklm
239cpdef get_linked_ptx(intptr_t handle, ptx):
240 """nvJitLinkGetLinkedPtx gets the linked ptx.
242 Args:
243 handle (intptr_t): nvJitLink handle.
244 ptx (bytes): The linked PTX.
246 .. seealso:: `nvJitLinkGetLinkedPtx`
247 """
248 cdef void* _ptx_ = get_buffer_pointer(ptx, -1, readonly=False) 1jklm
249 with nogil: 1jklm
250 __status__ = nvJitLinkGetLinkedPtx(<Handle>handle, <char*>_ptx_) 1jklm
251 check_status(__status__) 1jklm
254cpdef size_t get_error_log_size(intptr_t handle) except? 0:
255 """nvJitLinkGetErrorLogSize gets the size of the error log.
257 Args:
258 handle (intptr_t): nvJitLink handle.
260 Returns:
261 size_t: Size of the error log.
263 .. seealso:: `nvJitLinkGetErrorLogSize`
264 """
265 cdef size_t size
266 with nogil: 1nopq
267 __status__ = nvJitLinkGetErrorLogSize(<Handle>handle, &size) 1nopq
268 check_status(__status__) 1nopq
269 return size 1nopq
272cpdef get_error_log(intptr_t handle, log):
273 """nvJitLinkGetErrorLog puts any error messages in the log.
275 Args:
276 handle (intptr_t): nvJitLink handle.
277 log (bytes): The error log.
279 .. seealso:: `nvJitLinkGetErrorLog`
280 """
281 cdef void* _log_ = get_buffer_pointer(log, -1, readonly=False) 1nopq
282 with nogil: 1nopq
283 __status__ = nvJitLinkGetErrorLog(<Handle>handle, <char*>_log_) 1nopq
284 check_status(__status__) 1nopq
287cpdef size_t get_info_log_size(intptr_t handle) except? 0:
288 """nvJitLinkGetInfoLogSize gets the size of the info log.
290 Args:
291 handle (intptr_t): nvJitLink handle.
293 Returns:
294 size_t: Size of the info log.
296 .. seealso:: `nvJitLinkGetInfoLogSize`
297 """
298 cdef size_t size
299 with nogil: 1bcde
300 __status__ = nvJitLinkGetInfoLogSize(<Handle>handle, &size) 1bcde
301 check_status(__status__) 1bcde
302 return size 1bcde
305cpdef get_info_log(intptr_t handle, log):
306 """nvJitLinkGetInfoLog puts any info messages in the log.
308 Args:
309 handle (intptr_t): nvJitLink handle.
310 log (bytes): The info log.
312 .. seealso:: `nvJitLinkGetInfoLog`
313 """
314 cdef void* _log_ = get_buffer_pointer(log, -1, readonly=False) 1bcde
315 with nogil: 1bcde
316 __status__ = nvJitLinkGetInfoLog(<Handle>handle, <char*>_log_) 1bcde
317 check_status(__status__) 1bcde
320cpdef tuple version():
321 """nvJitLinkVersion returns the current version of nvJitLink.
323 Returns:
324 A 2-tuple containing:
326 - unsigned int: The major version.
327 - unsigned int: The minor version.
329 .. seealso:: `nvJitLinkVersion`
330 """
331 cdef unsigned int major
332 cdef unsigned int minor
333 with nogil: 1aJ
334 __status__ = nvJitLinkVersion(&major, &minor) 1aJ
335 check_status(__status__) 1aJ
336 return (major, minor) 1aJ