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
impl PtxCache
Sourcepub fn new() -> Result<Self, Error>
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.
Sourcepub fn with_dir(dir: PathBuf) -> Result<Self, Error>
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.
Sourcepub fn get_or_generate<F>(
&self,
key: &PtxCacheKey,
generate: F,
) -> Result<String, PtxGenError>
pub fn get_or_generate<F>( &self, key: &PtxCacheKey, generate: F, ) -> 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
Sourcepub fn get(&self, key: &PtxCacheKey) -> Option<String>
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.
Sourcepub fn put(&self, key: &PtxCacheKey, ptx: &str) -> Result<(), Error>
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.
Sourcepub fn clear(&self) -> Result<(), Error>
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.