Skip to main content

Function

Struct Function 

Source
pub struct Function { /* private fields */ }
Expand description

A kernel function handle within a loaded module.

Functions are lightweight handles (a single pointer) — the lifetime is tied to the parent Module. The caller is responsible for ensuring the Module outlives any Function handles obtained from it.

Occupancy query methods are provided in the crate::occupancy module via an impl Function block.

Implementations§

Source§

impl Function

Source

pub fn num_registers(&self) -> CudaResult<i32>

Returns the number of registers used by each thread of this kernel.

§Errors

Returns CudaError::NotSupported if the driver lacks cuFuncGetAttribute, or another error on failure.

Source

pub fn shared_memory_bytes(&self) -> CudaResult<i32>

Returns the static shared memory used by this kernel (bytes).

§Errors

Returns CudaError::NotSupported if the driver lacks cuFuncGetAttribute, or another error on failure.

Source

pub fn max_threads_per_block_attr(&self) -> CudaResult<i32>

Returns the maximum number of threads per block for this kernel.

§Errors

Returns a CudaError on failure.

Source

pub fn local_memory_bytes(&self) -> CudaResult<i32>

Returns the local memory used by each thread of this kernel (bytes).

§Errors

Returns a CudaError on failure.

Source

pub fn ptx_version(&self) -> CudaResult<i32>

Returns the PTX virtual architecture version for this kernel.

§Errors

Returns a CudaError on failure.

Source

pub fn binary_version(&self) -> CudaResult<i32>

Returns the binary (SASS) architecture version for this kernel.

§Errors

Returns a CudaError on failure.

Source

pub fn max_dynamic_shared_memory(&self) -> CudaResult<i32>

Returns the maximum dynamic shared memory size (bytes) for this kernel.

§Errors

Returns a CudaError on failure.

Source

pub fn set_max_dynamic_shared_memory(&self, bytes: i32) -> CudaResult<()>

Sets the maximum dynamic shared memory size (bytes) for this kernel.

This must be called before launching the kernel if you need more dynamic shared memory than the default limit.

§Errors

Returns CudaError::NotSupported if the driver lacks cuFuncSetAttribute, or another error on failure.

Source

pub fn set_preferred_shared_memory_carveout( &self, percent: i32, ) -> CudaResult<()>

Sets the preferred shared memory carve-out (percentage 0-100).

A value of 0 means use the device default. Values between 1 and 100 indicate the desired percentage of L1 cache to use as shared memory.

§Errors

Returns CudaError::NotSupported if the driver lacks cuFuncSetAttribute, or another error on failure.

Source§

impl Function

Source

pub fn raw(&self) -> CUfunction

Returns the raw CUfunction handle.

This is needed for kernel launches and occupancy queries at the FFI level.

Source§

impl Function

Source

pub fn max_active_blocks_per_sm( &self, block_size: i32, dynamic_smem: usize, ) -> CudaResult<i32>

Returns the maximum number of active blocks per streaming multiprocessor for a given block size and dynamic shared memory.

This is useful for evaluating different block sizes to find the configuration that achieves the highest occupancy.

§Parameters
  • block_size — number of threads per block.
  • dynamic_smem — dynamic shared memory per block in bytes (set to 0 if the kernel does not use dynamic shared memory).
§Errors

Returns a CudaError if the function handle is invalid or the driver call fails.

Source

pub fn optimal_block_size(&self, dynamic_smem: usize) -> CudaResult<(i32, i32)>

Suggests an optimal launch configuration that maximises multiprocessor occupancy.

Returns (min_grid_size, optimal_block_size) where:

  • min_grid_size — the minimum number of blocks needed to achieve maximum occupancy across all SMs.
  • optimal_block_size — the block size (number of threads) that achieves maximum occupancy.
§Parameters
  • dynamic_smem — dynamic shared memory per block in bytes (set to 0 if the kernel does not use dynamic shared memory).
§Errors

Returns a CudaError if the function handle is invalid or the driver call fails.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Function

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more