pub struct Module { /* private fields */ }
Expand description
A compiled CUDA module, loaded into a context.
Implementations§
source§impl Module
impl Module
sourcepub fn load_from_file(filename: &CStr) -> CudaResult<Module>
pub fn load_from_file(filename: &CStr) -> CudaResult<Module>
Load a module from the given file name into the current context.
The given file should be either a cubin file, a ptx file, or a fatbin file such as
those produced by nvcc
.
Example:
use rustacuda::module::Module;
use std::ffi::CString;
let filename = CString::new("./resources/add.ptx").unwrap();
let module = Module::load_from_file(&filename).unwrap();
sourcepub fn load_from_string(image: &CStr) -> CudaResult<Module>
pub fn load_from_string(image: &CStr) -> CudaResult<Module>
Load a module from a CStr.
This is useful in combination with include_str!
, to include the device code into the
compiled executable.
The given CStr must contain the bytes of a cubin file, a ptx file or a fatbin file such as
those produced by nvcc
.
Example:
use rustacuda::module::Module;
use std::ffi::CString;
let image = CString::new(include_str!("../resources/add.ptx")).unwrap();
let module = Module::load_from_string(&image).unwrap();
sourcepub fn get_global<'a, T: DeviceCopy>(
&'a self,
name: &CStr
) -> CudaResult<Symbol<'a, T>>
pub fn get_global<'a, T: DeviceCopy>(
&'a self,
name: &CStr
) -> CudaResult<Symbol<'a, T>>
Get a reference to a global symbol, which can then be copied to/from.
Panics:
This function panics if the size of the symbol is not the same as the mem::sizeof<T>()
.
Examples:
use rustacuda::module::Module;
use std::ffi::CString;
let ptx = CString::new(include_str!("../resources/add.ptx")).unwrap();
let module = Module::load_from_string(&ptx).unwrap();
let name = CString::new("my_constant").unwrap();
let symbol = module.get_global::<u32>(&name).unwrap();
let mut host_const = 0;
symbol.copy_to(&mut host_const).unwrap();
assert_eq!(314, host_const);
sourcepub fn get_function<'a>(&'a self, name: &CStr) -> CudaResult<Function<'a>>
pub fn get_function<'a>(&'a self, name: &CStr) -> CudaResult<Function<'a>>
Get a reference to a kernel function which can then be launched.
Examples:
use rustacuda::module::Module;
use std::ffi::CString;
let ptx = CString::new(include_str!("../resources/add.ptx")).unwrap();
let module = Module::load_from_string(&ptx).unwrap();
let name = CString::new("sum").unwrap();
let function = module.get_function(&name).unwrap();
sourcepub fn drop(module: Module) -> DropResult<Module>
pub fn drop(module: Module) -> DropResult<Module>
Destroy a Module
, returning an error.
Destroying a module can return errors from previous asynchronous work. This function destroys the given module and returns the error and the un-destroyed module on failure.
Example:
use rustacuda::module::Module;
use std::ffi::CString;
let ptx = CString::new(include_str!("../resources/add.ptx")).unwrap();
let module = Module::load_from_string(&ptx).unwrap();
match Module::drop(module) {
Ok(()) => println!("Successfully destroyed"),
Err((e, module)) => {
println!("Failed to destroy module: {:?}", e);
// Do something with module
},
}