MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / from_file

Method from_file

crates/cust/src/module.rs:163–179  ·  view source on GitHub ↗

Load a module from the given path into the current context. The given path should be either a cubin file, a ptx file, or a fatbin file such as those produced by `nvcc`. # Example ``` # use cust::*; # use std::error::Error; # fn main() -> Result<(), Box > { # let _ctx = quick_init()?; use cust::module::Module; use std::ffi::CString; let module = Module::from_file("./resources/add.ptx"

(path: P)

Source from the content-addressed store, hash-verified

161 /// # }
162 /// ```
163 pub fn from_file<P: AsRef<Path>>(path: P) -> CudaResult<Module> {
164 unsafe {
165 let mut bytes = path_to_bytes(path);
166 if !bytes.contains(&0) {
167 bytes.push(0);
168 }
169 let mut module = Module {
170 inner: ptr::null_mut(),
171 };
172 cuda::cuModuleLoad(
173 &mut module.inner as *mut cuda::CUmodule,
174 bytes.as_ptr() as *const _,
175 )
176 .to_result()?;
177 Ok(module)
178 }
179 }
180
181 /// Creates a new module by loading a fatbin (fat binary) file.
182 ///

Callers

nothing calls this directly

Calls 5

path_to_bytesFunction · 0.85
as_ptrMethod · 0.80
containsMethod · 0.45
pushMethod · 0.45
to_resultMethod · 0.45

Tested by

no test coverage detected