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)
| 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 | /// |
nothing calls this directly
no test coverage detected