cuda.core.Program#
- class cuda.core.Program(
- code: str | bytes | bytearray,
- str code_type: str,
- options: ProgramOptions | None = None,
Represent a compilation machinery to process programs into
ObjectCode.This object provides a unified interface to multiple underlying compiler libraries. Compilation support is enabled for a wide range of code types and compilation types.
- Parameters:
code (str | bytes | bytearray) – The source code to compile. For C++ and PTX, must be a string. For NVVM IR, can be str, bytes, or bytearray.
code_type (str) – The type of source code. Must be one of
"c++","ptx", or"nvvm".options (
ProgramOptions, optional) – Options to customize the compilation process.
Methods
- __init__(*args, **kwargs)#
- close(self)#
Destroy this program.
- compile(
- self,
- str target_type: str,
- name_expressions: tuple | list = (),
- logs=None,
Compile the program to the specified target type.
- Parameters:
target_type (str) – The compilation target. Must be one of
"ptx","cubin", or"ltoir".name_expressions (tuple | list, optional) – Sequence of name expressions to make accessible in the compiled code. Used for template instantiation and similar cases.
logs (object, optional) – Object with a
writemethod to receive compilation logs.
- Returns:
The compiled object code.
- Return type:
- static driver_can_load_nvrtc_ptx_output() bool#
Check if the CUDA driver can load PTX generated by NVRTC.
NVRTC generates PTX targeting a specific CUDA version. If the installed driver is older than the NVRTC version, it may not be able to load the generated PTX.
- Returns:
True if the driver version is new enough to load PTX generated by the current NVRTC version, False otherwise.
- Return type:
Examples
>>> if Program.driver_can_load_nvrtc_ptx_output(): ... obj = program.compile("ptx") ... kernel = obj.get_kernel("my_kernel")
Attributes