pub struct Program { /* private fields */ }Expand description
Owned NVRTC program with copied source and virtual headers. The native program is created lazily on the first operation that needs its handle and destroyed when this wrapper is dropped. Builder changes made after materialization do not recreate the existing native program.
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.
Sourcepub fn with_name(self, name: &str) -> Self
pub fn with_name(self, name: &str) -> Self
Copies the source filename used in diagnostics when the native program is first created. An already materialized program keeps its existing name.
Sourcepub fn with_header(self, header: Header<'_>) -> Self
pub fn with_header(self, header: Header<'_>) -> Self
Copies a virtual header’s source and include name for native program creation. Add headers before materializing the program.
Sourcepub fn with_headers(self, headers: &[Header<'_>]) -> Self
pub fn with_headers(self, headers: &[Header<'_>]) -> Self
Copies virtual headers in slice order for native program creation. Add headers before materializing the program.
Sourcepub unsafe fn from_raw(raw: RawProgram) -> Result<Self>
pub unsafe fn from_raw(raw: RawProgram) -> Result<Self>
Takes ownership of a raw NVRTC program.
§Safety
raw.handle must be a valid NVRTC program that is not owned by any other wrapper.
Any flow callback registered on it must be NVRTC’s default, a callback that reads no payload, or this crate’s cancellation callback with raw.cancel_flag as its payload.
The returned wrapper destroys the handle on drop.
§Errors
Returns an error if raw.handle is null.
Sourcepub fn compile(&self, options: &CompileOptions<'_>) -> Result<()>
pub fn compile(&self, options: &CompileOptions<'_>) -> Result<()>
Renders options and compiles the program synchronously.
Call Self::log to inspect compiler diagnostics after a successful or failed compilation.
With a flag set through CompileOptions::cancel_flag(), another thread can cancel compilation by setting the flag to true.
The wrapper then registers its own native callback and attempts to replace it with a no-op callback after compilation, including failed attempts, and the program keeps a clone of the flag until that replacement succeeds.
§Errors
Returns an error if lazy program creation fails, an option contains an interior NUL, the option count does not fit an i32, or NVRTC rejects an option or fails compilation.
Compilation diagnostics remain available from Self::log.
Errors from registering or clearing the cancellation callback are also returned.
A compilation error takes precedence over a later callback-clear error.
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.
Sourcepub fn ptx(&self) -> Result<Vec<u8>>
pub fn ptx(&self) -> Result<Vec<u8>>
Returns the PTX bytes produced by the last compilation, including the native trailing NUL byte.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, or the native output size cannot be represented as usize.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn ptx_image(&self) -> Result<ModuleImage<'static>>
pub fn ptx_image(&self) -> Result<ModuleImage<'static>>
Copies the last compilation’s PTX bytes into an owned module image.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, the native output size cannot be represented as usize, or the output is empty.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn ptx_string(&self) -> Result<String>
pub fn ptx_string(&self) -> Result<String>
Returns the last compilation’s PTX as a string, removing its trailing NUL and replacing invalid UTF-8 lossily.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, or the native output size cannot be represented as usize.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn cubin(&self) -> Result<Vec<u8>>
pub fn cubin(&self) -> Result<Vec<u8>>
Returns the GPU machine-code binary produced by the last compilation for a real GPU architecture target.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, or the native output size cannot be represented as usize.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn cubin_image(&self) -> Result<ModuleImage<'static>>
pub fn cubin_image(&self) -> Result<ModuleImage<'static>>
Copies the last compilation’s GPU machine-code binary into an owned module image.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, the native output size cannot be represented as usize, or the output is empty.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn tile_ir(&self) -> Result<Vec<u8>>
pub fn tile_ir(&self) -> Result<Vec<u8>>
Returns the cuda_tile IR generated by the previous compilation of this program.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, or the native output size cannot be represented as usize.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn lto_ir(&self) -> Result<Vec<u8>>
pub fn lto_ir(&self) -> Result<Vec<u8>>
Returns the device link-time intermediate representation produced by the last compilation.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, or the native output size cannot be represented as usize.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn optix_ir(&self) -> Result<Vec<u8>>
pub fn optix_ir(&self) -> Result<Vec<u8>>
Returns the OptiX intermediate representation produced by the last compilation.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the requested output, or the native output size cannot be represented as usize.
The requested code format must have been generated by the preceding compilation.
Sourcepub fn log(&self) -> Result<String>
pub fn log(&self) -> Result<String>
Returns the program compilation log, removing its trailing NUL and replacing invalid UTF-8 lossily. The log may contain diagnostics from either a successful or failed compilation.
§Errors
Returns an error if lazy program creation fails, NVRTC cannot query or copy the log, or the native log size cannot be represented as usize.
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 by compiling a new Program.
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<RawProgram>
pub fn into_raw(self) -> Result<RawProgram>
Transfers ownership of the raw NVRTC program to the caller.
If the program has not been materialized yet, this creates the raw handle first. The host copies of the source and headers are dropped, since NVRTC keeps its own. The caller becomes responsible for destroying the returned handle.
§Errors
Returns an error if lazy program creation fails because source, filenames, or headers contain an interior NUL, the header count exceeds the native integer range, or NVRTC cannot create the program.
Source§impl Program
impl Program
Sourcepub fn artifact(&self, kind: OutputKind) -> Result<CompilationArtifact>
pub fn artifact(&self, kind: OutputKind) -> Result<CompilationArtifact>
Returns the requested compilation output as an owned, format-tagged artifact.
§Errors
Returns an error if the selected output cannot be retrieved or is empty.