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
impl Function
Sourcepub fn num_registers(&self) -> CudaResult<i32>
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.
Returns the static shared memory used by this kernel (bytes).
§Errors
Returns CudaError::NotSupported if the driver lacks
cuFuncGetAttribute, or another error on failure.
Sourcepub fn max_threads_per_block_attr(&self) -> CudaResult<i32>
pub fn max_threads_per_block_attr(&self) -> CudaResult<i32>
Sourcepub fn local_memory_bytes(&self) -> CudaResult<i32>
pub fn local_memory_bytes(&self) -> CudaResult<i32>
Sourcepub fn ptx_version(&self) -> CudaResult<i32>
pub fn ptx_version(&self) -> CudaResult<i32>
Sourcepub fn binary_version(&self) -> CudaResult<i32>
pub fn binary_version(&self) -> CudaResult<i32>
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.
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
impl Function
Sourcepub fn raw(&self) -> CUfunction
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
impl Function
Sourcepub fn max_active_blocks_per_sm(
&self,
block_size: i32,
dynamic_smem: usize,
) -> CudaResult<i32>
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 to0if the kernel does not use dynamic shared memory).
§Errors
Returns a CudaError if the function
handle is invalid or the driver call fails.
Sourcepub fn optimal_block_size(&self, dynamic_smem: usize) -> CudaResult<(i32, i32)>
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 to0if the kernel does not use dynamic shared memory).
§Errors
Returns a CudaError if the function
handle is invalid or the driver call fails.