Coverage for cuda/bindings/nvvm.pyx: 90.91%
110 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) 2025-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=869e6761e7af952be9590fcd26675047c19ff23ee9c1521f64dd7e8f6842bced
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_buffer_pointer, get_nested_resource_ptr,
19 nested_resource)
22###############################################################################
23# Enum
24###############################################################################
26class Result(_cyb_FastEnum):
27 """
28 NVVM API call result code.
30 See `nvvmResult`.
31 """
32 SUCCESS = NVVM_SUCCESS
33 ERROR_OUT_OF_MEMORY = NVVM_ERROR_OUT_OF_MEMORY
34 ERROR_PROGRAM_CREATION_FAILURE = NVVM_ERROR_PROGRAM_CREATION_FAILURE
35 ERROR_IR_VERSION_MISMATCH = NVVM_ERROR_IR_VERSION_MISMATCH
36 ERROR_INVALID_INPUT = NVVM_ERROR_INVALID_INPUT
37 ERROR_INVALID_PROGRAM = NVVM_ERROR_INVALID_PROGRAM
38 ERROR_INVALID_IR = NVVM_ERROR_INVALID_IR
39 ERROR_INVALID_OPTION = NVVM_ERROR_INVALID_OPTION
40 ERROR_NO_MODULE_IN_PROGRAM = NVVM_ERROR_NO_MODULE_IN_PROGRAM
41 ERROR_COMPILATION = NVVM_ERROR_COMPILATION
42 ERROR_CANCELLED = NVVM_ERROR_CANCELLED
45###############################################################################
46# Error handling
47###############################################################################
49class nvvmError(Exception):
51 def __init__(self, status):
52 self.status = status 1ajklmnoAB(pq
53 s = Result(status) 1ajklmnoAB(pq
54 cdef str err = f"{s.name} ({s.value})" 1ajklmnoAB(pq
55 super(nvvmError, self).__init__(err) 1ajklmnoAB(pq
57 def __reduce__(self):
58 return (type(self), (self.status,))
61@cython.profile(False)
62cdef int check_status(int status) except 1 nogil:
63 if status != 0: 1aEFjQkRlSmTnoABbUcVdWeXfYgZh0i1GCD2P3u4v5w6x7y8z9!#$%'HIJKLMNOprqst
64 with gil: 1ajklmnoABpq
65 raise nvvmError(status) 1ajklmnoABpq
66 return status 1aEFjQkRlSmTnoABbUcVdWeXfYgZh0i1GCD2P3u4v5w6x7y8z9!#$%'HIJKLMNOprqst
69###############################################################################
70# Wrapper functions
71###############################################################################
73cpdef destroy_program(intptr_t prog):
74 """Destroy a program.
76 Args:
77 prog (intptr_t): nvvm prog.
79 .. seealso:: `nvvmDestroyProgram`
80 """
81 cdef Program p = <Program>prog 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
82 with nogil: 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
83 status = nvvmDestroyProgram(&p) 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
84 check_status(status) 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
87cpdef str get_error_string(int result):
88 """Get the message string for the given ``nvvmResult`` code.
90 Args:
91 result (Result): NVVM API result code.
93 .. seealso:: `nvvmGetErrorString`
94 """
95 cdef const char *_output_cstr_
96 cdef bytes _output_
97 with nogil: 1)
98 _output_cstr_ = nvvmGetErrorString(<_Result>result) 1)
99 _output_ = _output_cstr_ 1)
100 return _output_.decode() 1)
103cpdef tuple version():
104 """Get the NVVM version.
106 Returns:
107 A 2-tuple containing:
109 - int: NVVM major version number.
110 - int: NVVM minor version number.
112 .. seealso:: `nvvmVersion`
113 """
114 cdef int major
115 cdef int minor
116 with nogil: 1a3HIJKLMNO
117 __status__ = nvvmVersion(&major, &minor) 1a3HIJKLMNO
118 check_status(__status__) 1a3HIJKLMNO
119 return (major, minor) 1a3HIJKLMNO
122cpdef tuple ir_version():
123 """Get the NVVM IR version.
125 Returns:
126 A 4-tuple containing:
128 - int: NVVM IR major version number.
129 - int: NVVM IR minor version number.
130 - int: NVVM IR debug metadata major version number.
131 - int: NVVM IR debug metadata minor version number.
133 .. seealso:: `nvvmIRVersion`
134 """
135 cdef int major_ir
136 cdef int minor_ir
137 cdef int major_dbg
138 cdef int minor_dbg
139 with nogil: 1aQRSTUVWXYZ012456789!#$%'HIJKLMNOprqst
140 __status__ = nvvmIRVersion(&major_ir, &minor_ir, &major_dbg, &minor_dbg) 1aQRSTUVWXYZ012456789!#$%'HIJKLMNOprqst
141 check_status(__status__) 1aQRSTUVWXYZ012456789!#$%'HIJKLMNOprqst
142 return (major_ir, minor_ir, major_dbg, minor_dbg) 1aQRSTUVWXYZ012456789!#$%'HIJKLMNOprqst
145cpdef intptr_t create_program() except? 0:
146 """Create a program, and set the value of its handle to ``*prog``.
148 Returns:
149 intptr_t: NVVM program.
151 .. seealso:: `nvvmCreateProgram`
152 """
153 cdef Program prog
154 with nogil: 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
155 __status__ = nvvmCreateProgram(&prog) 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
156 check_status(__status__) 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
157 return <intptr_t>prog 1aEFjklmnoABbcdefghiGCDuvwxyzprqst
160cpdef add_module_to_program(intptr_t prog, buffer, size_t size, name):
161 """Add a module level NVVM IR to a program.
163 Args:
164 prog (intptr_t): NVVM program.
165 buffer (bytes): NVVM IR module in the bitcode or text
166 representation.
167 size (size_t): Size of the NVVM IR module.
168 name (str): Name of the NVVM IR module. If NULL, "<unnamed>"
169 is used as the name.
171 .. seealso:: `nvvmAddModuleToProgram`
172 """
173 cdef void* _buffer_ = get_buffer_pointer(buffer, size, readonly=True) 1aEjklmnobcdefghiuvwxyzprqst
174 if not isinstance(name, str): 1ajklmnobcdefghiuvwxyzprqst
175 raise TypeError("name must be a Python str")
176 cdef bytes _temp_name_ = (<str>name).encode() 1ajklmnobcdefghiuvwxyzprqst
177 cdef char* _name_ = _temp_name_ 1ajklmnobcdefghiuvwxyzprqst
178 with nogil: 1ajklmnobcdefghiuvwxyzprqst
179 __status__ = nvvmAddModuleToProgram(<Program>prog, <const char*>_buffer_, size, <const char*>_name_) 1ajklmnobcdefghiuvwxyzprqst
180 check_status(__status__) 1ajklmnobcdefghiuvwxyzprqst
183cpdef lazy_add_module_to_program(intptr_t prog, buffer, size_t size, name):
184 """Add a module level NVVM IR to a program.
186 Args:
187 prog (intptr_t): NVVM program.
188 buffer (bytes): NVVM IR module in the bitcode representation.
189 size (size_t): Size of the NVVM IR module.
190 name (str): Name of the NVVM IR module. If NULL, "<unnamed>"
191 is used as the name.
193 .. seealso:: `nvvmLazyAddModuleToProgram`
194 """
195 cdef void* _buffer_ = get_buffer_pointer(buffer, size, readonly=True) 1F
196 if not isinstance(name, str):
197 raise TypeError("name must be a Python str")
198 cdef bytes _temp_name_ = (<str>name).encode()
199 cdef char* _name_ = _temp_name_
200 with nogil:
201 __status__ = nvvmLazyAddModuleToProgram(<Program>prog, <const char*>_buffer_, size, <const char*>_name_)
202 check_status(__status__)
205cpdef compile_program(intptr_t prog, int num_options, options):
206 """Compile the NVVM program.
208 Args:
209 prog (intptr_t): NVVM program.
210 num_options (int): Number of compiler ``options`` passed.
211 options (object): Compiler options in the form of C string
212 array. It can be:
214 - an :class:`int` as the pointer address to the nested sequence, or
215 - a Python sequence of :class:`int`\s, each of which is a pointer address
216 to a valid sequence of 'char', or
217 - a nested Python sequence of ``str``.
220 .. seealso:: `nvvmCompileProgram`
221 """
222 cdef nested_resource[ char ] _options_
223 get_nested_resource_ptr[char](_options_, options, <char*>NULL) 1ajlnAbcdefghiprqst
224 with nogil: 1ajlnAbcdefghiprqst
225 __status__ = nvvmCompileProgram(<Program>prog, num_options, <const char**>(_options_.ptrs.data())) 1ajlnAbcdefghiprqst
226 check_status(__status__) 1ajlnAbcdefghiprqst
229cpdef verify_program(intptr_t prog, int num_options, options):
230 """Verify the NVVM program.
232 Args:
233 prog (intptr_t): NVVM program.
234 num_options (int): Number of compiler ``options`` passed.
235 options (object): Compiler options in the form of C string
236 array. It can be:
238 - an :class:`int` as the pointer address to the nested sequence, or
239 - a Python sequence of :class:`int`\s, each of which is a pointer address
240 to a valid sequence of 'char', or
241 - a nested Python sequence of ``str``.
244 .. seealso:: `nvvmVerifyProgram`
245 """
246 cdef nested_resource[ char ] _options_
247 get_nested_resource_ptr[char](_options_, options, <char*>NULL) 1kmoBuvwxyz
248 with nogil: 1kmoBuvwxyz
249 __status__ = nvvmVerifyProgram(<Program>prog, num_options, <const char**>(_options_.ptrs.data())) 1kmoBuvwxyz
250 check_status(__status__) 1kmoBuvwxyz
253cpdef size_t get_compiled_result_size(intptr_t prog) except? 0:
254 """Get the size of the compiled result.
256 Args:
257 prog (intptr_t): NVVM program.
259 Returns:
260 size_t: Size of the compiled result (including the trailing
261 NULL).
263 .. seealso:: `nvvmGetCompiledResultSize`
264 """
265 cdef size_t buffer_size_ret
266 with nogil: 1bcdefghiC
267 __status__ = nvvmGetCompiledResultSize(<Program>prog, &buffer_size_ret) 1bcdefghiC
268 check_status(__status__) 1bcdefghiC
269 return buffer_size_ret 1bcdefghiC
272cpdef get_compiled_result(intptr_t prog, buffer):
273 """Get the compiled result.
275 Args:
276 prog (intptr_t): NVVM program.
277 buffer (bytes): Compiled result.
279 .. seealso:: `nvvmGetCompiledResult`
280 """
281 cdef void* _buffer_ = get_buffer_pointer(buffer, -1, readonly=False) 1bcdefghiC
282 with nogil: 1bcdefghiC
283 __status__ = nvvmGetCompiledResult(<Program>prog, <char*>_buffer_) 1bcdefghiC
284 check_status(__status__) 1bcdefghiC
287cpdef size_t get_program_log_size(intptr_t prog) except? 0:
288 """Get the Size of Compiler/Verifier Message.
290 Args:
291 prog (intptr_t): NVVM program.
293 Returns:
294 size_t: Size of the compilation/verification log (including
295 the trailing NULL).
297 .. seealso:: `nvvmGetProgramLogSize`
298 """
299 cdef size_t buffer_size_ret
300 with nogil: 1jklmnobcdefghiD
301 __status__ = nvvmGetProgramLogSize(<Program>prog, &buffer_size_ret) 1jklmnobcdefghiD
302 check_status(__status__) 1jklmnobcdefghiD
303 return buffer_size_ret 1jklmnobcdefghiD
306cpdef get_program_log(intptr_t prog, buffer):
307 """Get the Compiler/Verifier Message.
309 Args:
310 prog (intptr_t): NVVM program.
311 buffer (bytes): Compilation/Verification log.
313 .. seealso:: `nvvmGetProgramLog`
314 """
315 cdef void* _buffer_ = get_buffer_pointer(buffer, -1, readonly=False) 1jklmnobcdefghiD
316 with nogil: 1jklmnobcdefghiD
317 __status__ = nvvmGetProgramLog(<Program>prog, <char*>_buffer_) 1jklmnobcdefghiD
318 check_status(__status__) 1jklmnobcdefghiD
321cpdef int llvm_version(arch) except? 0:
322 """Get the LLVM IR version guaranteed to be supported by NVVM.
324 Args:
325 arch (str): Architecture string.
327 Returns:
328 int: IR version number.
330 .. seealso:: `nvvmLLVMVersion`
331 """
332 if not isinstance(arch, str): 1P
333 raise TypeError("arch must be a Python str")
334 cdef bytes _temp_arch_ = (<str>arch).encode() 1P
335 cdef char* _arch_ = _temp_arch_ 1P
336 cdef int major
337 with nogil: 1P
338 __status__ = nvvmLLVMVersion(<const char*>_arch_, &major) 1P
339 check_status(__status__) 1P
340 return major 1P
341del _cyb_FastEnum