Skip to main content

PtxCache

Struct PtxCache 

Source
pub struct PtxCache { /* private fields */ }
Expand description

Disk-based PTX kernel cache.

Caches generated PTX text files on disk to avoid redundant code generation. Files are stored as {kernel_name}_{sm}_{hash:016x}.ptx in the cache directory.

Implementations§

Source§

impl PtxCache

Source

pub fn new() -> Result<Self, Error>

Creates a new PTX cache, initializing the cache directory.

The cache directory is ~/.cache/oxicuda/ptx/. If the home directory cannot be determined, falls back to {temp_dir}/oxicuda_ptx_cache/.

§Errors

Returns std::io::Error if the cache directory cannot be created.

Source

pub fn with_dir(dir: PathBuf) -> Result<Self, Error>

Creates a new PTX cache at a specific directory.

Useful for testing or when a custom cache location is desired.

§Errors

Returns std::io::Error if the directory cannot be created.

Source

pub const fn cache_dir(&self) -> &PathBuf

Returns the cache directory path.

Source

pub fn get_or_generate<F>( &self, key: &PtxCacheKey, generate: F, ) -> Result<String, PtxGenError>
where F: FnOnce() -> Result<String, PtxGenError>,

Looks up a cached PTX string, or generates and caches it if not found.

If the cache contains a file matching the key, its contents are returned directly. Otherwise, the generate closure is called to produce the PTX text, which is then written to the cache before being returned.

§Errors

Returns PtxGenError if:

  • The generate closure fails
  • Disk I/O fails during read or write
Source

pub fn get(&self, key: &PtxCacheKey) -> Option<String>

Retrieves cached PTX for the given key, if it exists.

Returns None if no cached entry is found or the file is empty.

Source

pub fn put(&self, key: &PtxCacheKey, ptx: &str) -> Result<(), Error>

Stores PTX text in the cache under the given key.

§Errors

Returns std::io::Error if the write fails.

Source

pub fn clear(&self) -> Result<(), Error>

Removes all cached PTX files from the cache directory.

Only removes .ptx files; other files and subdirectories are left intact.

§Errors

Returns std::io::Error if directory listing or file removal fails.

Source

pub fn len(&self) -> Result<usize, Error>

Returns the number of cached PTX files.

§Errors

Returns std::io::Error if the directory cannot be read.

Source

pub fn is_empty(&self) -> Result<bool, Error>

Returns true if the cache contains no PTX files.

§Errors

Returns std::io::Error if the directory cannot be read.

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.