pub struct Program { /* private fields */ }Implementations§
Source§impl Program
impl Program
Sourcepub fn from_source(source: &str) -> Self
pub fn from_source(source: &str) -> Self
Creates a lazy NVRTC program from CUDA source text.
The raw NVRTC handle is created when the program is compiled or otherwise materialized.
pub fn with_name(self, name: &str) -> Self
pub fn with_header(self, header: Header<'_>) -> Self
pub fn with_headers(self, headers: &[Header<'_>]) -> Self
Sourcepub unsafe fn from_raw(handle: nvrtcProgram) -> Result<Self>
pub unsafe fn from_raw(handle: nvrtcProgram) -> Result<Self>
Takes ownership of a raw NVRTC program handle.
§Safety
handle must be a valid nvrtcProgram that is not owned by any other
wrapper. The returned wrapper destroys it with nvrtcDestroyProgram.
pub fn compile(&self, options: &[&str]) -> Result<()>
pub fn compile_with_options(&self, options: &CompileOptions<'_>) -> Result<()>
Sourcepub fn compile_with_options_and_cancel_flag(
&self,
options: &CompileOptions<'_>,
cancel: &AtomicBool,
) -> Result<()>
pub fn compile_with_options_and_cancel_flag( &self, options: &CompileOptions<'_>, cancel: &AtomicBool, ) -> Result<()>
Registers a flow callback that can cancel compilation.
The callback function must satisfy the following constraints:
(1) It must return 1 to cancel compilation or 0 to continue. Other return values are reserved for future use.
(2) It must return consistent values. Once it returns 1 at one point, it must return 1 in all following invocations during the current nvrtcCompileProgram call in progress.
(3) It must be thread-safe.
(4) It must not invoke any NVRTC, libNVVM, or PTX APIs.
Sourcepub fn add_name_expression(&self, name_expression: &str) -> Result<()>
pub fn add_name_expression(&self, name_expression: &str) -> Result<()>
Registers a name expression for a __global__, __device__, or __constant__ symbol.
The identical name expression string must be provided to Program::lowered_name after compilation.
§Errors
Returns an error if name_expression contains an interior NUL byte, if
the program handle is invalid, or if NVRTC rejects the expression.
Sourcepub fn lowered_name(&self, name_expression: &str) -> Result<String>
pub fn lowered_name(&self, name_expression: &str) -> Result<String>
Returns the lowered (mangled) name for a registered name expression.
The identical name expression must have been previously provided to Program::add_name_expression.
§Errors
Returns an error if name_expression contains an interior NUL byte, if
the program handle is invalid, or if NVRTC cannot return the lowered name.
pub fn ptx(&self) -> Result<Vec<u8>>
pub fn ptx_image(&self) -> Result<ModuleImage<'static>>
pub fn ptx_string(&self) -> Result<String>
pub fn cubin(&self) -> Result<Vec<u8>>
pub fn cubin_image(&self) -> Result<ModuleImage<'static>>
pub fn lto_ir(&self) -> Result<Vec<u8>>
pub fn lto_ir_image(&self) -> Result<ModuleImage<'static>>
pub fn optix_ir(&self) -> Result<Vec<u8>>
pub fn optix_ir_image(&self) -> Result<ModuleImage<'static>>
pub fn log(&self) -> Result<String>
Sourcepub fn pch_create_status(&self) -> Result<Status>
pub fn pch_create_status(&self) -> Result<Status>
Returns the PCH creation status.
Status::Success indicates that the PCH was successfully created.
Status::NoPchCreateAttempted indicates that no PCH creation was attempted, either because PCH was not requested during the preceding compile call, or automatic PCH processing was requested, and the compiler chose not to create a PCH file.
Status::PchCreateHeapExhausted indicates that a PCH file could potentially have been created, but the compiler ran out space in the PCH heap.
In this scenario, use Program::pch_heap_size_required to query the required heap size, reallocate the heap with set_pch_heap_size, and retry PCH creation with sys::nvrtcCompileProgram on a new NVRTC program instance.
Status::PchCreate indicates that an error condition prevented the PCH file from being created.
§Errors
Returns an error if the program handle is invalid.
Sourcepub fn pch_heap_size_required(&self) -> Result<usize>
pub fn pch_heap_size_required(&self) -> Result<usize>
Returns the PCH heap size required to compile the given program.
§Errors
Returns an error if the program handle is invalid or if the returned size
is not valid because Program::pch_create_status did not return
Status::Success or Status::PchCreateHeapExhausted.
Sourcepub fn materialize_raw(&self) -> Result<nvrtcProgram>
pub fn materialize_raw(&self) -> Result<nvrtcProgram>
Returns the raw NVRTC program handle, creating it first if needed.
If the program has not been materialized yet, this creates the raw handle first.
§Errors
Returns an error if NVRTC cannot create the program handle.
Sourcepub const fn as_raw_if_materialized(&self) -> Option<nvrtcProgram>
pub const fn as_raw_if_materialized(&self) -> Option<nvrtcProgram>
Returns the raw NVRTC program handle only if it has already been materialized.
Sourcepub fn into_raw(self) -> Result<nvrtcProgram>
pub fn into_raw(self) -> Result<nvrtcProgram>
Transfers ownership of the raw NVRTC program handle to the caller.
If the program has not been materialized yet, this creates the raw
handle first. The caller becomes responsible for destroying the returned
handle with nvrtcDestroyProgram.