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)
| 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 | /// |