pub struct KernelFunction { /* private fields */ }Expand description
A context-specific CUDA kernel function that retains its module and loading context.
Implementations§
Source§impl KernelFunction
impl KernelFunction
Sourcepub unsafe fn set_typed_graph_node_params<K: KernelSignature>(
&self,
executable: &mut ExecutableGraph,
node: &GraphNode,
geometry: &LaunchGeometry,
arguments: K::Arguments<'_>,
) -> Result<()>
pub unsafe fn set_typed_graph_node_params<K: KernelSignature>( &self, executable: &mut ExecutableGraph, node: &GraphNode, geometry: &LaunchGeometry, arguments: K::Arguments<'_>, ) -> Result<()>
Updates an executable node’s geometry and arguments, retaining this kernel’s code.
Launch attributes remain unchanged.
§Safety
K must describe this function and the executable’s existing attributes must satisfy it.
Arguments must satisfy the kernel’s bounds, initialization and aliasing requirements for every execution.
Keep storage and the executable or another code owner alive until queued executions complete.
§Errors
Returns an error for ABI, view-context or geometry mismatches, or if CUDA rejects the update.
Source§impl KernelFunction
impl KernelFunction
Sourcepub unsafe fn from_raw(handle: DeviceFunction, module: &Module) -> Self
pub unsafe fn from_raw(handle: DeviceFunction, module: &Module) -> Self
Adopts a function handle while retaining its module.
§Safety
handle must identify a live function in module and its actual context.
Sourcepub unsafe fn launch_async<'a, P>(
&self,
config: &LaunchConfig,
params: P,
stream: &Stream,
) -> Result<()>where
P: KernelLaunchArgs<'a>,
pub unsafe fn launch_async<'a, P>(
&self,
config: &LaunchConfig,
params: P,
stream: &Stream,
) -> Result<()>where
P: KernelLaunchArgs<'a>,
Invokes this kernel function on a grid of blocks using the given stream.
Each block contains the threads specified by LaunchConfig::block_dim.
LaunchConfig::shared_memory_bytes sets the amount of dynamic shared memory available to each thread block.
Kernel parameters are passed with KernelParameters or tuples of shared or mutable references.
Launching the kernel invalidates the persistent function state set through the following deprecated APIs: sys::cuFuncSetBlockShape, sys::cuFuncSetSharedSize, sys::cuParamSetSize, sys::cuParamSeti, sys::cuParamSetf, sys::cuParamSetv.
The kernel must either have been compiled with toolchain version 3.2 or later so that it contains kernel parameter information, or have no kernel parameters.
If either of these conditions is not met, the launch returns crate::error::Status::InvalidImage.
§Safety
Arguments must match the kernel ABI and satisfy its access and value requirements. Keep the function and all pointed-to storage alive until execution completes. Order conflicting accesses and preserve exclusive writable access during execution. Successful submission does not establish output initialization or completion.
§Errors
Returns crate::error::Status::InvalidImage if the kernel parameter metadata requirements above are not met.
Also returns an error if stream belongs to a different context, the module context cannot be bound, CUDA rejects the launch, or a previous asynchronous launch reports an error.
Sourcepub unsafe fn add_to_graph<'a, P>(
&self,
graph: &mut Graph,
dependencies: &[GraphNode],
config: &LaunchConfig,
params: P,
) -> Result<GraphNode>where
P: KernelLaunchArgs<'a>,
pub unsafe fn add_to_graph<'a, P>(
&self,
graph: &mut Graph,
dependencies: &[GraphNode],
config: &LaunchConfig,
params: P,
) -> Result<GraphNode>where
P: KernelLaunchArgs<'a>,
Adds this kernel to graph as a kernel node.
§Safety
CUDA copies each kernel argument value during this call. Non-pointer argument values may be borrowed from stack or temporary storage that outlives this call. If an argument value is a pointer, CUDA stores only the pointer address. The caller must ensure every copied pointer value remains valid for every graph instantiation, update, and launch that can execute the created node. Mutable pointer arguments must remain exclusive for the work ordered by those launches. Arguments must match the function ABI and satisfy its value and access requirements. Keep the graph, executable or another code owner alive until queued executions complete.
§Errors
Returns Error::ContextMismatch if the graph is associated with another context.
Also propagates context binding errors, dependency ownership errors, and CUDA failures when creating the kernel node or setting its launch attributes.
Sourcepub unsafe fn set_graph_node_params<'a, P>(
&self,
executable: &mut ExecutableGraph,
node: &GraphNode,
geometry: &LaunchGeometry,
params: P,
) -> Result<()>where
P: KernelLaunchArgs<'a>,
pub unsafe fn set_graph_node_params<'a, P>(
&self,
executable: &mut ExecutableGraph,
node: &GraphNode,
geometry: &LaunchGeometry,
params: P,
) -> Result<()>where
P: KernelLaunchArgs<'a>,
Updates this kernel’s parameters in an executable graph node.
§Safety
CUDA copies each kernel argument value during this call.
Non-pointer argument values may be borrowed from stack or temporary storage that outlives this call.
If an argument value is a pointer, CUDA stores only the pointer address.
The caller must ensure every copied pointer value remains valid for every future launch that can execute node.
Mutable pointer arguments must remain exclusive for the work ordered by those launches.
Arguments must match the function ABI and satisfy its value and access requirements.
Keep the graph, executable or another code owner alive until queued executions complete.
Launch attributes are preserved; they must remain compatible with this kernel and geometry.
§Errors
Returns Error::ContextMismatch if the executable is associated with another context.
Also propagates context binding errors, node ownership errors, and CUDA failures when updating the node.
Sourcepub fn name(&self) -> Result<String>
pub fn name(&self) -> Result<String>
Returns the native function name, replacing invalid UTF-8 sequences.
§Errors
Returns an error if the module context cannot be bound, CUDA cannot query the name, or CUDA returns a null name pointer.
Sourcepub fn attribute(&self, attribute: FunctionAttribute) -> Result<i32>
pub fn attribute(&self, attribute: FunctionAttribute) -> Result<i32>
Returns one function attribute for this module context.
§Errors
Returns an error if the module context cannot be bound or CUDA rejects the requested function attribute.
Sourcepub fn set_attribute(
&self,
attribute: FunctionAttribute,
value: i32,
) -> Result<()>
pub fn set_attribute( &self, attribute: FunctionAttribute, value: i32, ) -> Result<()>
Sets a mutable function attribute.
See FunctionAttribute for the supported attributes and their value constraints.
§Errors
Returns an error if the module context cannot be bound or CUDA rejects the selected attribute or value.
Sets the maximum dynamic shared memory permitted per block, in bytes.
The requested size plus static shared memory must fit the device’s opt-in per-block limit.
This attribute does not enable oversized shared memory; use Self::set_shared_memory_mode for that.
§Errors
Returns an error if the module context cannot be bound or CUDA rejects the selected attribute or value.
Sets the preferred shared-memory carveout for this function.
On devices sharing hardware resources between L1 cache and shared memory, the driver treats this as a hint and may choose another ratio.
§Errors
Returns an error if the module context cannot be bound or CUDA rejects the selected attribute or value.
Sourcepub fn attributes(&self) -> Result<FunctionAttributes>
pub fn attributes(&self) -> Result<FunctionAttributes>
Queries the function’s resource usage, compilation versions, and launch constraints.
Each field is queried separately; the result is not an atomic snapshot of concurrent attribute changes.
§Errors
Returns an error if the module context cannot be bound or any constituent attribute query fails. No partial result is returned.
Sourcepub fn occupancy_max_active_blocks_per_multiprocessor(
&self,
block_size: i32,
dynamic_shared_memory_bytes: usize,
flags: OccupancyFlags,
) -> Result<i32>
pub fn occupancy_max_active_blocks_per_multiprocessor( &self, block_size: i32, dynamic_shared_memory_bytes: usize, flags: OccupancyFlags, ) -> Result<i32>
Returns the maximum number of active blocks per streaming multiprocessor for block_size threads and the specified dynamic shared-memory bytes per block.
flags controls how special cases are handled.
The valid flags are:
-
OccupancyFlags::DEFAULT, which maintains the default behavior assys::cuOccupancyMaxActiveBlocksPerMultiprocessor; -
OccupancyFlags::DISABLE_CACHING_OVERRIDE, which suppresses the default behavior on platforms where global caching affects occupancy. On such platforms, if caching is enabled, but per-block SM resource usage would result in zero occupancy, the occupancy calculator will calculate the occupancy as if caching is disabled. SettingOccupancyFlags::DISABLE_CACHING_OVERRIDEmakes the occupancy calculator return 0 in such cases. More information can be found about this feature in the “Unified L1/Texture Cache” section of the Maxwell tuning guide.
For context-less kernels queried via Library::kernel.
Here, this wrapper uses the current context for calculations.
§Errors
Returns an error if the module context cannot be bound, CUDA rejects the occupancy query, or a previous asynchronous launch reports an error.
Returns dynamic shared memory available per block when launching num_blocks blocks on a streaming multiprocessor.
The returned value is the maximum size of dynamic shared memory that allows num_blocks blocks per streaming multiprocessor.
For context-less kernels queried via Library::kernel.
Here, this wrapper uses the current context for calculations.
§Errors
Returns an error if the module context cannot be bound, CUDA rejects the occupancy query, or a previous asynchronous launch reports an error.
Sourcepub fn occupancy_max_potential_block_size(
&self,
dynamic_shared_memory_bytes: usize,
block_size_limit: i32,
flags: OccupancyFlags,
) -> Result<OccupancyMaxPotentialBlockSize>
pub fn occupancy_max_potential_block_size( &self, dynamic_shared_memory_bytes: usize, block_size_limit: i32, flags: OccupancyFlags, ) -> Result<OccupancyMaxPotentialBlockSize>
Selects a block size with maximum potential occupancy for the supplied dynamic shared-memory bytes per block.
block_size_limit restricts the block size; zero adds no limit.
flags controls how special cases are handled.
The valid flags are:
-
OccupancyFlags::DEFAULT, which maintains the default behavior assys::cuOccupancyMaxPotentialBlockSize; -
OccupancyFlags::DISABLE_CACHING_OVERRIDE, which suppresses the default behavior on platforms where global caching affects occupancy. On such platforms, the launch configurations that produce maximal occupancy might not support global caching. SettingOccupancyFlags::DISABLE_CACHING_OVERRIDEguarantees that the produced launch configuration is global caching compatible at a potential cost of occupancy. More information can be found about this feature in the “Unified L1/Texture Cache” section of the Maxwell tuning guide.
For context-less kernels queried via Library::kernel.
Here, this wrapper uses the current context for calculations.
§Errors
Returns an error if the module context cannot be bound, CUDA rejects the occupancy query, or a previous asynchronous launch reports an error.
Sourcepub fn occupancy_max_potential_cluster_size(
&self,
config: &LaunchConfig,
) -> Result<i32>
pub fn occupancy_max_potential_cluster_size( &self, config: &LaunchConfig, ) -> Result<i32>
Given this kernel and launch configuration, returns the maximum cluster size.
The cluster dimensions in config are ignored.
If the kernel has a required cluster size set, the returned value reflects the required cluster size.
By default this returns a value that is portable on future hardware. A higher value may be returned if the kernel function allows non-portable cluster sizes.
Respects the compile-time launch bounds.
For context-less kernels queried via Library::kernel.
Here, this wrapper uses the current context for calculations.
§Errors
Returns an error if the module context cannot be bound, CUDA rejects the occupancy query, or a previous asynchronous launch reports an error.
Sourcepub fn occupancy_max_active_clusters(
&self,
config: &LaunchConfig,
) -> Result<i32>
pub fn occupancy_max_active_clusters( &self, config: &LaunchConfig, ) -> Result<i32>
Given this kernel and launch configuration, returns the maximum number of clusters that could co-exist on the target device.
If the kernel already has a required cluster size set, the cluster size from config must either be unspecified or match the required size.
Without required sizes, the cluster size must be specified in config; otherwise this method returns an error.
Various kernel function attributes may affect occupancy calculation. Runtime environment may affect how the hardware schedules the clusters, so the calculated occupancy is not guaranteed to be achievable.
For context-less kernels queried via Library::kernel.
Here, this wrapper uses the current context for calculations.
§Errors
Returns an error if the module context cannot be bound, config does not specify a valid cluster size for this kernel, CUDA rejects the occupancy query, or a previous asynchronous launch reports an error.
Sourcepub const fn as_raw(&self) -> DeviceFunction
pub const fn as_raw(&self) -> DeviceFunction
Returns the borrowed device function handle without retaining another module owner.
Source§impl KernelFunction
impl KernelFunction
Specifies whether the function may use oversized shared memory configurations.
§Errors
Returns an error if the module context cannot be bound or CUDA rejects the selected attribute or value.
Returns the shared memory mode configured for this function.
§Errors
Returns an error if the module context cannot be bound or CUDA rejects the requested function attribute.
Returns Error::UnknownEnumValue if CUDA returns an unrecognized shared-memory mode.
Sourcepub unsafe fn launch_green_async<'a, P: KernelLaunchArgs<'a>>(
&self,
config: &LaunchConfig,
params: P,
stream: &GreenStream,
) -> Result<()>
pub unsafe fn launch_green_async<'a, P: KernelLaunchArgs<'a>>( &self, config: &LaunchConfig, params: P, stream: &GreenStream, ) -> Result<()>
Invokes this kernel on a stream provisioned by a green context.
§Safety
Arguments must match the kernel ABI and satisfy its access and value requirements. Keep the function and all pointed-to storage alive until execution completes. Order conflicting accesses and preserve exclusive writable access during execution. Successful submission does not establish output initialization or completion.
§Errors
Returns Error::StreamContextMismatch unless the function was loaded in the primary context of the green context’s device.
Also returns an error if the module context cannot be bound, argument encoding fails, CUDA rejects the launch, or previous asynchronous work reports an error.