Skip to main content

Program

Struct Program 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn with_headers(self, headers: &[Header<'_>]) -> Self

Copies virtual headers in slice order for native program creation. Add headers before materializing the program.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn as_raw_if_materialized(&self) -> Option<nvrtcProgram>

Returns the raw NVRTC program handle only if it has already been materialized.

Source

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

Source

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.

Trait Implementations§

Source§

impl Debug for Program

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Program

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.