Skip to main content

KernelFunction

Struct KernelFunction 

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

A context-specific CUDA kernel function that retains its module and loading context.

Implementations§

Source§

impl KernelFunction

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn module(&self) -> &Module

Returns the module retained by this function.

Source

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.

Source

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.

Source

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.

Source

pub fn set_max_dynamic_shared_memory_bytes(&self, bytes: i32) -> Result<()>

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.

Source

pub fn set_preferred_shared_memory_carveout( &self, carveout: SharedMemoryCarveout, ) -> Result<()>

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.

Source

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.

Source

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:

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.

Source

pub fn occupancy_available_dynamic_shared_memory_per_block( &self, num_blocks: i32, block_size: i32, ) -> Result<usize>

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.

Source

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:

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.

Source

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.

Source

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.

Source

pub const fn as_raw(&self) -> DeviceFunction

Returns the borrowed device function handle without retaining another module owner.

Source§

impl KernelFunction

Source

pub fn set_shared_memory_mode(&self, mode: SharedMemoryMode) -> Result<()>

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.

Source

pub fn shared_memory_mode(&self) -> Result<SharedMemoryMode>

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.

Source

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.

Trait Implementations§

Source§

impl Clone for KernelFunction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for KernelFunction

Source§

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

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

impl Send for KernelFunction

Source§

impl Sync for KernelFunction

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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, 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.