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

Method get_function

crates/cust/src/module.rs:414–428  ·  view source on GitHub ↗

Get a reference to a kernel function which can then be launched. # Examples ``` # use cust::*; # use std::error::Error; # fn main() -> Result<(), Box > { # let _ctx = quick_init()?; use cust::module::Module; use std::ffi::CString; let ptx = CString::new(include_str!("../resources/add.ptx"))?; let module = Module::load_from_string(&ptx)?; let function = module.get_function("sum")?; # O

(&'_ self, name: T)

Source from the content-addressed store, hash-verified

412 /// # }
413 /// ```
414 pub fn get_function<T: AsRef<str>>(&'_ self, name: T) -> CudaResult<Function<'_>> {
415 unsafe {
416 let name = name.as_ref();
417 let cstr = CString::new(name).expect("Argument to get_function had a nul");
418 let mut func: cuda::CUfunction = ptr::null_mut();
419
420 cuda::cuModuleGetFunction(
421 &mut func as *mut cuda::CUfunction,
422 self.inner,
423 cstr.as_ptr(),
424 )
425 .to_result()?;
426 Ok(Function::new(func, self))
427 }
428 }
429
430 /// Destroy a `Module`, returning an error.
431 ///

Callers 1

mainFunction · 0.80

Calls 5

newFunction · 0.85
as_ptrMethod · 0.80
as_refMethod · 0.45
expectMethod · 0.45
to_resultMethod · 0.45

Tested by

no test coverage detected