[][src]Struct rustacuda::module::Module

pub struct Module { /* fields omitted */ }

A compiled CUDA module, loaded into a context.

Implementations

impl Module[src]

pub fn load_from_file(filename: &CStr) -> CudaResult<Module>[src]

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")?;
let module = Module::load_from_file(&filename)?;

pub fn load_from_string(image: &CStr) -> CudaResult<Module>[src]

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"))?;
let module = Module::load_from_string(&image)?;

pub fn get_global<'a, T: DeviceCopy>(
    &'a self,
    name: &CStr
) -> CudaResult<Symbol<'a, T>>
[src]

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"))?;
let module = Module::load_from_string(&ptx)?;
let name = CString::new("my_constant")?;
let symbol = module.get_global::<u32>(&name)?;
let mut host_const = 0;
symbol.copy_to(&mut host_const)?;
assert_eq!(314, host_const);

pub fn get_function<'a>(&'a self, name: &CStr) -> CudaResult<Function<'a>>[src]

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"))?;
let module = Module::load_from_string(&ptx)?;
let name = CString::new("sum")?;
let function = module.get_function(&name)?;

pub fn drop(module: Module) -> DropResult<Module>[src]

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"))?;
let module = Module::load_from_string(&ptx)?;
match Module::drop(module) {
    Ok(()) => println!("Successfully destroyed"),
    Err((e, module)) => {
        println!("Failed to destroy module: {:?}", e);
        // Do something with module
    },
}

Trait Implementations

impl Debug for Module[src]

impl Drop for Module[src]

Auto Trait Implementations

impl RefUnwindSafe for Module

impl !Send for Module

impl !Sync for Module

impl Unpin for Module

impl UnwindSafe for Module

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.