Files
rustytorch/cudarc/cudnn.md
T
2026-03-04 00:08:42 +00:00

1757 lines
40 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Safe wrappers around cuDNN.
Convolutions
Allocate tensor descriptors with Cudnn::create_4d_tensor()
Allocate filter descriptors with Cudnn::create_4d_filter()
Allocate conv descriptors with Cudnn::create_conv2d()
Instantiate one of the following algorithms with the descriptors: a. Conv2dForward b. Conv2dBackwardData for computing gradient of image c. Conv2dBackwardFilter for computing gradient of filters
Call the pick_algorithm method of the struct. Specify the number of options to compare with a const generic.
Call the get_workspace_size method of the struct.
Re-allocate the workspace to the appropriate size.
Call the launch method of the struct.
Reductions
Re-exports
pub use super::result::CudnnError;
Structs
ActivationDescriptor
A descriptor of the activation operation. Create with Cudnn::create_activation()
ActivationForward
The activation forward operation. Pass in references to descriptors directly, and then call [ConvForward::launch()] .
ConvBackwardData
The convolution backward operation for the input tensor. Pass in references to descriptors directly, and then call:
ConvBackwardFilter
The convolution 2d backward operation for the filters. Pass in references to descriptors directly, and then call:
ConvBiasActivationForward
The bias + convolution + activation forward operation. The full computation follows the equation y = act (alpha1 * conv(x) + alpha2 * z + bias). Pass in references to descriptors directly, and then call:
ConvDescriptor
A descriptor for a conv operation holding stride, padding, and dilation.
ConvForward
The convolution 2d forward operation. Pass in references to descriptors directly, and then call:
Cudnn
A handle to cuDNN.
FilterDescriptor
A descriptor of the filters for conv operation. Create with Cudnn::create_4d_filter()
FlatIndices
A marker type used with ReductionDescriptor to indicate the reduction operation should return flattened indices. Corresponds to sys::cudnnReduceTensorIndices_t::CUDNN_REDUCE_TENSOR_FLATTENED_INDICES.
NoIndices
A marker type used with ReductionDescriptor to indicate the reduction operation should NOT return indices. Corresponds to sys::cudnnReduceTensorIndices_t::CUDNN_REDUCE_TENSOR_NO_INDICES.
PoolingDescriptor
A descriptor of the window for pooling operation. Create with Cudnn::create_poolingnd()
PoolingForward
The pooling forward operation. Pass in references to descriptors directly, and then call PoolingForward::launch().
ReduceTensor
A reduction operation. Pass in fields directly, and then call launch.
ReductionDescriptor
A reduction descriptor. Create with [Cudnn::create_reduction_with_indices()] if you want the indices returned, or [Cudnn::create_reduction_without_indices()] if not.
Softmax
A handle for the Softmax operation. Create with Cudnn::create_softmax()
SoftmaxForward
The Softmax forward operation. Pass in references to descriptors directly, and then call SoftmaxForward::launch() .
TensorDescriptor
A descriptor of a tensor. Create with:
Traits
CudnnDataType
Maps a rust type to a sys::cudnnDataType_t
Type Aliases
Conv2dBackwardDataDeprecated
Conv2dBackwardFilterDeprecated
Conv2dDescriptorDeprecated
Conv2dForwardDeprecated
Struct Cudnn Copy item path
Source
Search
Settings
Help
Summary
pub struct Cudnn { /* private fields */ }
A handle to cuDNN.
This type is not send/sync because of https://docs.nvidia.com/deeplearning/cudnn/developer-guide/index.html#thread-safety
Implementations
Source
impl Cudnn
Source
pub fn create_activation<T: CudnnDataType>(
self: &Arc<Cudnn>,
mode: cudnnActivationMode_t,
nan_propagation: cudnnNanPropagation_t,
coef: f64,
) -> Result<ActivationDescriptor<T>, CudnnError>
Source
impl Cudnn
Source
pub fn create_4d_filter<T: CudnnDataType>(
self: &Arc<Cudnn>,
format: cudnnTensorFormat_t,
dims: [c_int; 4],
) -> Result<FilterDescriptor<T>, CudnnError>
Create a filter 4d descriptor.
Source
pub fn create_nd_filter<T: CudnnDataType>(
self: &Arc<Cudnn>,
format: cudnnTensorFormat_t,
dims: &[c_int],
) -> Result<FilterDescriptor<T>, CudnnError>
Create a filter Nd descriptor.
Source
pub fn create_3d_filter<T: CudnnDataType>(
self: &Arc<Cudnn>,
format: cudnnTensorFormat_t,
dims: [c_int; 3],
) -> Result<FilterDescriptor<T>, CudnnError>
Create a filter 3d descriptor.
Source
pub fn create_5d_filter<T: CudnnDataType>(
self: &Arc<Cudnn>,
format: cudnnTensorFormat_t,
dims: [c_int; 5],
) -> Result<FilterDescriptor<T>, CudnnError>
Create a filter 5d descriptor.
Source
impl Cudnn
Source
pub fn create_conv2d<T: CudnnDataType>(
self: &Arc<Cudnn>,
pad: [c_int; 2],
stride: [c_int; 2],
dilation: [c_int; 2],
mode: cudnnConvolutionMode_t,
) -> Result<ConvDescriptor<T>, CudnnError>
Creates a conv2d descriptor.
pad is the padding to apply to height and width of tensor
stride is the kernel strides
dilation is the kernel dilation
mode - CROSS_CORRELATION is standard convolution
Source
pub fn create_convnd<T: CudnnDataType>(
self: &Arc<Cudnn>,
pads: &[c_int],
strides: &[c_int],
dilations: &[c_int],
mode: cudnnConvolutionMode_t,
) -> Result<ConvDescriptor<T>, CudnnError>
Creates a ConvDescription for Nd convolution operations.
pads is an array the zero-padding size for each dimension
strides is an array for the kernel strides for each dimension
dilations is an array for the kernel dilation for each dimension
mode - CROSS_CORRELATION is standard convolution
Source
impl Cudnn
Source
pub fn new(stream: Arc<CudaStream>) -> Result<Arc<Self>, CudnnError>
Creates a new cudnn handle and sets the stream to the devices stream.
Source
pub unsafe fn set_stream(
&mut self,
stream: Arc<CudaStream>,
) -> Result<(), CudnnError>
Sets the handles current to either the stream specified, or the devices default work stream.
Safety
This is unsafe because you can end up scheduling multiple concurrent kernels that all write to the same memory address.
Source
impl Cudnn
Source
pub fn create_4d_tensor<T: CudnnDataType>(
self: &Arc<Cudnn>,
format: cudnnTensorFormat_t,
dims: [c_int; 4],
) -> Result<TensorDescriptor<T>, CudnnError>
Creates a 4d tensor descriptor.
Source
pub fn create_4d_tensor_ex<T: CudnnDataType>(
self: &Arc<Cudnn>,
dims: [c_int; 4],
strides: [c_int; 4],
) -> Result<TensorDescriptor<T>, CudnnError>
Creates a 4d tensor descriptor.
Source
pub fn create_nd_tensor<T: CudnnDataType>(
self: &Arc<Cudnn>,
dims: &[c_int],
strides: &[c_int],
) -> Result<TensorDescriptor<T>, CudnnError>
Creates an nd (at LEAST 4d) tensor descriptor.
Source
impl Cudnn
Source
pub fn create_poolingnd<T: CudnnDataType>(
self: &Arc<Cudnn>,
window: &[c_int],
pads: &[c_int],
strides: &[c_int],
mode: cudnnPoolingMode_t,
nan_propagation: cudnnNanPropagation_t,
) -> Result<PoolingDescriptor<T>, CudnnError>
Create a window nd descriptor.
Source
impl Cudnn
Source
pub fn create_reduction_flat_indices<T: CudnnDataType>(
self: &Arc<Cudnn>,
op: cudnnReduceTensorOp_t,
nan_opt: cudnnNanPropagation_t,
) -> Result<ReductionDescriptor<T, FlatIndices>, CudnnError>
Create a reduction descriptor that computes indices.
Source
pub fn create_reduction_no_indices<T: CudnnDataType>(
self: &Arc<Cudnn>,
op: cudnnReduceTensorOp_t,
nan_opt: cudnnNanPropagation_t,
) -> Result<ReductionDescriptor<T, NoIndices>, CudnnError>
Create a reduction descriptor that does NOT compute indices.
Source
impl Cudnn
Source
pub fn create_softmax<T: CudnnDataType>(
self: &Arc<Cudnn>,
mode: cudnnSoftmaxMode_t,
) -> Result<Softmax<T>, CudnnError>
Trait Implementations
Source
impl Debug for Cudnn
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl Drop for Cudnn
Source
fn drop(&mut self)
Executes the destructor for this type. Read more
Auto Trait Implementations
impl Freeze for Cudnn
impl RefUnwindSafe for Cudnn
impl !Send for Cudnn
impl !Sync for Cudnn
impl Unpin for Cudnn
impl UnwindSafe for Cudnn
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
---------------------------------
Struct ActivationDescriptor Copy item path
Source
Search
Settings
Help
Summary
pub struct ActivationDescriptor<T> { /* private fields */ }
A descriptor of the activation operation. Create with Cudnn::create_activation()
Trait Implementations
Source
impl<T: Debug> Debug for ActivationDescriptor<T>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Auto Trait Implementations
impl<T> Freeze for ActivationDescriptor<T>
impl<T> RefUnwindSafe for ActivationDescriptor<T>
where
T: RefUnwindSafe,
impl<T> !Send for ActivationDescriptor<T>
impl<T> !Sync for ActivationDescriptor<T>
impl<T> Unpin for ActivationDescriptor<T>
where
T: Unpin,
impl<T> UnwindSafe for ActivationDescriptor<T>
where
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
---------------------------
Struct ActivationForward Copy item path
Source
Search
Settings
Help
Summary
pub struct ActivationForward<'a, A: CudnnDataType, X: CudnnDataType, Y: CudnnDataType> {
pub act: &'a ActivationDescriptor<A>,
pub x: &'a TensorDescriptor<X>,
pub y: &'a TensorDescriptor<Y>,
}
The activation forward operation. Pass in references to descriptors directly, and then call [ConvForward::launch()] .
Fields
act: &'a ActivationDescriptor<A>
Activation function.
x: &'a TensorDescriptor<X>
y: &'a TensorDescriptor<Y>
Implementations
Source
impl<A, X, Y> ActivationForward<'_, A, X, Y>
where
A: CudnnDataType,
X: CudnnDataType,
Y: CudnnDataType,
Source
pub unsafe fn launch<Src, Dst>(
&self,
(alpha, beta): (Y, Y),
x: &Src,
y: &mut Dst,
) -> Result<(), CudnnError>
where
Src: DevicePtr<A>,
Dst: DevicePtrMut<A>,
Launches the operation.
src is the input tensor
y is the output
Safety
The arguments must match the data type/layout specified in the descriptors in `self.
Auto Trait Implementations
impl<'a, A, X, Y> Freeze for ActivationForward<'a, A, X, Y>
impl<'a, A, X, Y> RefUnwindSafe for ActivationForward<'a, A, X, Y>
where
A: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<'a, A, X, Y> !Send for ActivationForward<'a, A, X, Y>
impl<'a, A, X, Y> !Sync for ActivationForward<'a, A, X, Y>
impl<'a, A, X, Y> Unpin for ActivationForward<'a, A, X, Y>
impl<'a, A, X, Y> UnwindSafe for ActivationForward<'a, A, X, Y>
where
A: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
-----------------------------------
Struct ConvBackwardData Copy item path
Source
Search
Settings
Help
Summary
pub struct ConvBackwardData<'a, X: CudnnDataType, C: CudnnDataType, Y: CudnnDataType> {
pub conv: &'a ConvDescriptor<C>,
pub dx: &'a TensorDescriptor<X>,
pub w: &'a FilterDescriptor<X>,
pub dy: &'a TensorDescriptor<Y>,
}
The convolution backward operation for the input tensor. Pass in references to descriptors directly, and then call:
ConvBackwardData::pick_algorithm() to use cudnn heuristics to select the algorithm
ConvBackwardData::get_workspace_size() to get required workspace size.
ConvBackwardData::launch() to execute it
Fields
conv: &'a ConvDescriptor<C>
Conv descriptor
dx: &'a TensorDescriptor<X>
Input tensor descriptor
w: &'a FilterDescriptor<X>
Filter descriptor
dy: &'a TensorDescriptor<Y>
Output tensor descriptor
Implementations
Source
impl<X: CudnnDataType, C: CudnnDataType, Y: CudnnDataType> ConvBackwardData<'_, X, C, Y>
Source
pub fn pick_algorithm(
&self,
) -> Result<cudnnConvolutionBwdDataAlgo_t, CudnnError>
Picks the fastest algorithm from all available cuDNN algorithms based on cudnn heuristics.
Source
pub fn get_workspace_size(
&self,
algo: cudnnConvolutionBwdDataAlgo_t,
) -> Result<usize, CudnnError>
Returns size in bytes to execute the selected algorithm.
Source
pub unsafe fn launch<Workspace, Src, Filter, Dst>(
&self,
algo: cudnnConvolutionBwdDataAlgo_t,
workspace: Option<&mut Workspace>,
(alpha, beta): (Y, Y),
dx: &mut Src,
filter: &Filter,
dy: &Dst,
) -> Result<(), CudnnError>
where
Workspace: DevicePtrMut<u8>,
Src: DevicePtrMut<X>,
Filter: DevicePtr<X>,
Dst: DevicePtr<Y>,
Launches the operation.
dx is the gradient of the input tensor to populate
filter is the convolution kernels
dy is the gradient of the output tensor
Safety
The arguments must match the data type/layout specified in the descriptors in `self.
Trait Implementations
Source
impl<'a, X: Debug + CudnnDataType, C: Debug + CudnnDataType, Y: Debug + CudnnDataType> Debug for ConvBackwardData<'a, X, C, Y>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Auto Trait Implementations
impl<'a, X, C, Y> Freeze for ConvBackwardData<'a, X, C, Y>
impl<'a, X, C, Y> RefUnwindSafe for ConvBackwardData<'a, X, C, Y>
where
C: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<'a, X, C, Y> !Send for ConvBackwardData<'a, X, C, Y>
impl<'a, X, C, Y> !Sync for ConvBackwardData<'a, X, C, Y>
impl<'a, X, C, Y> Unpin for ConvBackwardData<'a, X, C, Y>
impl<'a, X, C, Y> UnwindSafe for ConvBackwardData<'a, X, C, Y>
where
C: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
---------------------------
Struct ConvBiasActivationForward Copy item path
Source
Search
Settings
Help
Summary
pub struct ConvBiasActivationForward<'a, X: CudnnDataType, C: CudnnDataType, A: CudnnDataType, Y: CudnnDataType> {
pub conv: &'a ConvDescriptor<C>,
pub act: &'a ActivationDescriptor<A>,
pub x: &'a TensorDescriptor<X>,
pub w: &'a FilterDescriptor<X>,
pub z: &'a TensorDescriptor<X>,
pub bias: &'a TensorDescriptor<X>,
pub y: &'a TensorDescriptor<Y>,
}
The bias + convolution + activation forward operation. The full computation follows the equation y = act (alpha1 * conv(x) + alpha2 * z + bias). Pass in references to descriptors directly, and then call:
ConvForward::pick_algorithm() to use cudnn heuristics to select the algorithm
ConvForward::get_workspace_size() to get required workspace size.
ConvForward::launch() to execute it
Fields
conv: &'a ConvDescriptor<C>
Conv parameters.
act: &'a ActivationDescriptor<A>
Activation function.
x: &'a TensorDescriptor<X>
Input tensor descriptor
w: &'a FilterDescriptor<X>
Filter descriptor
z: &'a TensorDescriptor<X>
Z descriptor
bias: &'a TensorDescriptor<X>
Bias descriptor
y: &'a TensorDescriptor<Y>
Output tensor descriptor
Implementations
Source
impl<X, C, A, Y> ConvBiasActivationForward<'_, X, C, A, Y>
where
X: CudnnDataType,
C: CudnnDataType,
A: CudnnDataType,
Y: CudnnDataType,
Source
pub fn pick_algorithm(&self) -> Result<cudnnConvolutionFwdAlgo_t, CudnnError>
Picks the fastest algorithm from all available cuDNN algorithms based on cudnn heuristics.
Source
pub fn get_workspace_size(
&self,
algo: cudnnConvolutionFwdAlgo_t,
) -> Result<usize, CudnnError>
Returns size in bytes to execute the selected algorithm.
Source
pub unsafe fn launch<Workspace, Src, Filter, Dst>(
&self,
algo: cudnnConvolutionFwdAlgo_t,
workspace: Option<&mut Workspace>,
(alpha1, alpha2): (Y, Y),
src: &Src,
filter: &Filter,
z: &Src,
bias: &Src,
y: &mut Dst,
) -> Result<(), CudnnError>
where
Workspace: DevicePtrMut<u8>,
Src: DevicePtr<X>,
Filter: DevicePtr<X>,
Dst: DevicePtrMut<Y>,
Launches the operation.
src is the input tensor
filter is the convolution kernels
y is the output
Safety
The src/filter/y arguments must match the data type/layout specified in the descriptors in `self.
Trait Implementations
Source
impl<'a, X: Debug + CudnnDataType, C: Debug + CudnnDataType, A: Debug + CudnnDataType, Y: Debug + CudnnDataType> Debug for ConvBiasActivationForward<'a, X, C, A, Y>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Auto Trait Implementations
impl<'a, X, C, A, Y> Freeze for ConvBiasActivationForward<'a, X, C, A, Y>
impl<'a, X, C, A, Y> RefUnwindSafe for ConvBiasActivationForward<'a, X, C, A, Y>
where
C: RefUnwindSafe,
A: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<'a, X, C, A, Y> !Send for ConvBiasActivationForward<'a, X, C, A, Y>
impl<'a, X, C, A, Y> !Sync for ConvBiasActivationForward<'a, X, C, A, Y>
impl<'a, X, C, A, Y> Unpin for ConvBiasActivationForward<'a, X, C, A, Y>
impl<'a, X, C, A, Y> UnwindSafe for ConvBiasActivationForward<'a, X, C, A, Y>
where
C: RefUnwindSafe,
A: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
------------------------------
Struct ConvDescriptor Copy item path
Source
Search
Settings
Help
Summary
pub struct ConvDescriptor<T> { /* private fields */ }
A descriptor for a conv operation holding stride, padding, and dilation.
Implementations
Source
impl<T> ConvDescriptor<T>
Source
pub fn set_math_type(
&mut self,
math_type: cudnnMathType_t,
) -> Result<(), CudnnError>
Sets the math type for this convolution. Refer to nvidia docs for more information.
Source
pub fn set_group_count(&mut self, group_count: i32) -> Result<(), CudnnError>
Sets the group count for this convolution. Refer to nvidia docs for more information.
Trait Implementations
Source
impl<T: Debug> Debug for ConvDescriptor<T>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl<T> Drop for ConvDescriptor<T>
Source
fn drop(&mut self)
Executes the destructor for this type. Read more
Auto Trait Implementations
impl<T> Freeze for ConvDescriptor<T>
impl<T> RefUnwindSafe for ConvDescriptor<T>
where
T: RefUnwindSafe,
impl<T> !Send for ConvDescriptor<T>
impl<T> !Sync for ConvDescriptor<T>
impl<T> Unpin for ConvDescriptor<T>
where
T: Unpin,
impl<T> UnwindSafe for ConvDescriptor<T>
where
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
-----------------------------
Struct ConvForward Copy item path
Source
Search
Settings
Help
Summary
pub struct ConvForward<'a, X: CudnnDataType, C: CudnnDataType, Y: CudnnDataType> {
pub conv: &'a ConvDescriptor<C>,
pub x: &'a TensorDescriptor<X>,
pub w: &'a FilterDescriptor<X>,
pub y: &'a TensorDescriptor<Y>,
}
The convolution 2d forward operation. Pass in references to descriptors directly, and then call:
ConvForward::pick_algorithm() to use cudnn heuristics to select the algorithm
ConvForward::get_workspace_size() to get required workspace size.
ConvForward::launch() to execute it
Fields
conv: &'a ConvDescriptor<C>
Conv parameters
x: &'a TensorDescriptor<X>
Input tensor descriptor
w: &'a FilterDescriptor<X>
Filter descriptor
y: &'a TensorDescriptor<Y>
Output tensor descriptor
Implementations
Source
impl<X: CudnnDataType, C: CudnnDataType, Y: CudnnDataType> ConvForward<'_, X, C, Y>
Source
pub fn pick_algorithm(&self) -> Result<cudnnConvolutionFwdAlgo_t, CudnnError>
Picks the fastest algorithm from all available cuDNN algorithms based on cudnn heuristics.
Source
pub fn get_workspace_size(
&self,
algo: cudnnConvolutionFwdAlgo_t,
) -> Result<usize, CudnnError>
Returns size in bytes to execute the selected algorithm.
Source
pub unsafe fn launch<Workspace, Src, Filter, Dst>(
&self,
algo: cudnnConvolutionFwdAlgo_t,
workspace: Option<&mut Workspace>,
(alpha, beta): (Y, Y),
src: &Src,
filter: &Filter,
y: &mut Dst,
) -> Result<(), CudnnError>
where
Workspace: DevicePtrMut<u8>,
Src: DevicePtr<X>,
Filter: DevicePtr<X>,
Dst: DevicePtrMut<Y>,
Launches the operation.
src is the input tensor
filter is the convolution kernels
y is the output
Safety
The src/filter/y arguments must match the data type/layout specified in the descriptors in `self.
Trait Implementations
Source
impl<'a, X: Debug + CudnnDataType, C: Debug + CudnnDataType, Y: Debug + CudnnDataType> Debug for ConvForward<'a, X, C, Y>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Auto Trait Implementations
impl<'a, X, C, Y> Freeze for ConvForward<'a, X, C, Y>
impl<'a, X, C, Y> RefUnwindSafe for ConvForward<'a, X, C, Y>
where
C: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<'a, X, C, Y> !Send for ConvForward<'a, X, C, Y>
impl<'a, X, C, Y> !Sync for ConvForward<'a, X, C, Y>
impl<'a, X, C, Y> Unpin for ConvForward<'a, X, C, Y>
impl<'a, X, C, Y> UnwindSafe for ConvForward<'a, X, C, Y>
where
C: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
-----------------------------
Struct FilterDescriptor Copy item path
Source
Search
Settings
Help
Summary
pub struct FilterDescriptor<T> { /* private fields */ }
A descriptor of the filters for conv operation. Create with Cudnn::create_4d_filter()
Trait Implementations
Source
impl<T: Debug> Debug for FilterDescriptor<T>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl<T> Drop for FilterDescriptor<T>
Source
fn drop(&mut self)
Executes the destructor for this type. Read more
Auto Trait Implementations
impl<T> Freeze for FilterDescriptor<T>
impl<T> RefUnwindSafe for FilterDescriptor<T>
where
T: RefUnwindSafe,
impl<T> !Send for FilterDescriptor<T>
impl<T> !Sync for FilterDescriptor<T>
impl<T> Unpin for FilterDescriptor<T>
where
T: Unpin,
impl<T> UnwindSafe for FilterDescriptor<T>
where
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
---------------------------
Struct FlatIndices Copy item path
Source
Search
Settings
Help
Summary
pub struct FlatIndices;
A marker type used with ReductionDescriptor to indicate the reduction operation should return flattened indices. Corresponds to sys::cudnnReduceTensorIndices_t::CUDNN_REDUCE_TENSOR_FLATTENED_INDICES.
Trait Implementations
Source
impl Clone for FlatIndices
Source
fn clone(&self) -> FlatIndices
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 FlatIndices
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl Default for FlatIndices
Source
fn default() -> FlatIndices
Returns the “default value” for a type. Read more
Source
impl Copy for FlatIndices
Auto Trait Implementations
impl Freeze for FlatIndices
impl RefUnwindSafe for FlatIndices
impl Send for FlatIndices
impl Sync for FlatIndices
impl Unpin for FlatIndices
impl UnwindSafe for FlatIndices
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> CloneToUninit for T
where
T: Clone,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T> ToOwned for T
where
T: Clone,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
--------------------------------
Struct NoIndices Copy item path
Source
Search
Settings
Help
Summary
pub struct NoIndices;
A marker type used with ReductionDescriptor to indicate the reduction operation should NOT return indices. Corresponds to sys::cudnnReduceTensorIndices_t::CUDNN_REDUCE_TENSOR_NO_INDICES.
Trait Implementations
Source
impl Clone for NoIndices
Source
fn clone(&self) -> NoIndices
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 NoIndices
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl Default for NoIndices
Source
fn default() -> NoIndices
Returns the “default value” for a type. Read more
Source
impl Copy for NoIndices
Auto Trait Implementations
impl Freeze for NoIndices
impl RefUnwindSafe for NoIndices
impl Send for NoIndices
impl Sync for NoIndices
impl Unpin for NoIndices
impl UnwindSafe for NoIndices
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> CloneToUninit for T
where
T: Clone,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T> ToOwned for T
where
T: Clone,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
----------------------------
Struct PoolingDescriptor Copy item path
Source
Search
Settings
Help
Summary
pub struct PoolingDescriptor<T> { /* private fields */ }
A descriptor of the window for pooling operation. Create with Cudnn::create_poolingnd()
Auto Trait Implementations
impl<T> Freeze for PoolingDescriptor<T>
impl<T> RefUnwindSafe for PoolingDescriptor<T>
where
T: RefUnwindSafe,
impl<T> !Send for PoolingDescriptor<T>
impl<T> !Sync for PoolingDescriptor<T>
impl<T> Unpin for PoolingDescriptor<T>
where
T: Unpin,
impl<T> UnwindSafe for PoolingDescriptor<T>
where
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
--------------------------------
Struct PoolingForward Copy item path
Source
Search
Settings
Help
Summary
pub struct PoolingForward<'a, P, X, Y> {
pub pooling: &'a PoolingDescriptor<P>,
pub x: &'a TensorDescriptor<X>,
pub y: &'a TensorDescriptor<Y>,
}
The pooling forward operation. Pass in references to descriptors directly, and then call PoolingForward::launch().
Fields
pooling: &'a PoolingDescriptor<P>
x: &'a TensorDescriptor<X>
y: &'a TensorDescriptor<Y>
Implementations
Source
impl<P, X, Y> PoolingForward<'_, P, X, Y>
where
P: CudnnDataType,
X: CudnnDataType,
Y: CudnnDataType,
Source
pub unsafe fn launch<Src, Dst>(
&self,
(alpha, beta): (Y, Y),
src: &Src,
y: &mut Dst,
) -> Result<(), CudnnError>
where
Src: DevicePtr<X>,
Dst: DevicePtrMut<Y>,
Launches the operation.
src is the input tensor
y is the output
Safety
The arguments must match the data type/layout specified in the descriptors in `self.
Auto Trait Implementations
impl<'a, P, X, Y> Freeze for PoolingForward<'a, P, X, Y>
impl<'a, P, X, Y> RefUnwindSafe for PoolingForward<'a, P, X, Y>
where
P: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<'a, P, X, Y> !Send for PoolingForward<'a, P, X, Y>
impl<'a, P, X, Y> !Sync for PoolingForward<'a, P, X, Y>
impl<'a, P, X, Y> Unpin for PoolingForward<'a, P, X, Y>
impl<'a, P, X, Y> UnwindSafe for PoolingForward<'a, P, X, Y>
where
P: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
---------------------------------
Struct ReduceTensor Copy item path
Source
Search
Settings
Help
Summary
pub struct ReduceTensor<'a, T: CudnnDataType, Idx> {
pub reduce: &'a ReductionDescriptor<T, Idx>,
pub a: &'a TensorDescriptor<T>,
pub c: &'a TensorDescriptor<T>,
}
A reduction operation. Pass in fields directly, and then call launch.
Fields
reduce: &'a ReductionDescriptor<T, Idx>
The reduction descriptor.
a: &'a TensorDescriptor<T>
The input tensor
c: &'a TensorDescriptor<T>
The output tensor
Implementations
Source
impl<T: CudnnDataType> ReduceTensor<'_, T, FlatIndices>
Source
pub fn get_indices_size(&self) -> Result<usize, CudnnError>
Gets the size of the indices tensor required for this operation.
See nvidia docs.
Source
impl<T: CudnnDataType, Idx> ReduceTensor<'_, T, Idx>
Source
pub fn get_workspace_size(&self) -> Result<usize, CudnnError>
Gets the size of the workspace for this operation.
See nvidia docs
Source
impl<T: CudnnDataType> ReduceTensor<'_, T, FlatIndices>
Source
pub unsafe fn launch<Indices, Workspace, A, C>(
&self,
indices: &mut Indices,
workspace: &mut Workspace,
(alpha, beta): (T, T),
a: &A,
c: &mut C,
) -> Result<(), CudnnError>
where
Indices: DevicePtrMut<u32>,
Workspace: DevicePtrMut<u8>,
A: DevicePtr<T>,
C: DevicePtrMut<T>,
Launches the operation with indices.
Safety
The arguments must match the data type/layout specified in the descriptors in self.
Source
impl<T: CudnnDataType> ReduceTensor<'_, T, NoIndices>
Source
pub unsafe fn launch<Workspace, A, C>(
&self,
workspace: &mut Workspace,
(alpha, beta): (T, T),
a: &A,
c: &mut C,
) -> Result<(), CudnnError>
where
Workspace: DevicePtrMut<u8>,
A: DevicePtr<T>,
C: DevicePtrMut<T>,
Launches the operation with no indices.
Safety
The arguments must match the data type/layout specified in the descriptors in self.
Auto Trait Implementations
impl<'a, T, Idx> Freeze for ReduceTensor<'a, T, Idx>
impl<'a, T, Idx> RefUnwindSafe for ReduceTensor<'a, T, Idx>
where
Idx: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, Idx> !Send for ReduceTensor<'a, T, Idx>
impl<'a, T, Idx> !Sync for ReduceTensor<'a, T, Idx>
impl<'a, T, Idx> Unpin for ReduceTensor<'a, T, Idx>
impl<'a, T, Idx> UnwindSafe for ReduceTensor<'a, T, Idx>
where
Idx: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
--------------------------------
Struct ReductionDescriptor Copy item path
Source
Search
Settings
Help
Summary
pub struct ReductionDescriptor<T, Idx> { /* private fields */ }
A reduction descriptor. Create with [Cudnn::create_reduction_with_indices()] if you want the indices returned, or [Cudnn::create_reduction_without_indices()] if not.
Trait Implementations
Source
impl<T: Debug, Idx: Debug> Debug for ReductionDescriptor<T, Idx>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl<T, Idx> Drop for ReductionDescriptor<T, Idx>
Source
fn drop(&mut self)
Executes the destructor for this type. Read more
Auto Trait Implementations
impl<T, Idx> Freeze for ReductionDescriptor<T, Idx>
where
Idx: Freeze,
impl<T, Idx> RefUnwindSafe for ReductionDescriptor<T, Idx>
where
Idx: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, Idx> !Send for ReductionDescriptor<T, Idx>
impl<T, Idx> !Sync for ReductionDescriptor<T, Idx>
impl<T, Idx> Unpin for ReductionDescriptor<T, Idx>
where
Idx: Unpin,
T: Unpin,
impl<T, Idx> UnwindSafe for ReductionDescriptor<T, Idx>
where
Idx: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
----------------------------------
Struct Softmax Copy item path
Source
Search
Settings
Help
Summary
pub struct Softmax<T> { /* private fields */ }
A handle for the Softmax operation. Create with Cudnn::create_softmax()
Trait Implementations
Source
impl<T: Debug> Debug for Softmax<T>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Auto Trait Implementations
impl<T> Freeze for Softmax<T>
impl<T> RefUnwindSafe for Softmax<T>
where
T: RefUnwindSafe,
impl<T> !Send for Softmax<T>
impl<T> !Sync for Softmax<T>
impl<T> Unpin for Softmax<T>
where
T: Unpin,
impl<T> UnwindSafe for Softmax<T>
where
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
----------------------------------
Struct SoftmaxForward Copy item path
Source
Search
Settings
Help
Summary
pub struct SoftmaxForward<'a, A: CudnnDataType, X: CudnnDataType, Y: CudnnDataType> {
pub softmax: &'a Softmax<A>,
pub x: &'a TensorDescriptor<X>,
pub y: &'a TensorDescriptor<Y>,
}
The Softmax forward operation. Pass in references to descriptors directly, and then call SoftmaxForward::launch() .
Fields
softmax: &'a Softmax<A>
x: &'a TensorDescriptor<X>
y: &'a TensorDescriptor<Y>
Implementations
Source
impl<A, X, Y> SoftmaxForward<'_, A, X, Y>
where
A: CudnnDataType,
X: CudnnDataType,
Y: CudnnDataType,
Source
pub unsafe fn launch<Src, Dst>(
&self,
(alpha, beta): (Y, Y),
algo: cudnnSoftmaxAlgorithm_t,
x: &Src,
y: &mut Dst,
) -> Result<(), CudnnError>
where
Src: DevicePtr<A>,
Dst: DevicePtrMut<A>,
Launches the operation.
x is the input tensor
y is the output
Safety
The arguments must match the data type/layout specified in the descriptors in `self.
Auto Trait Implementations
impl<'a, A, X, Y> Freeze for SoftmaxForward<'a, A, X, Y>
impl<'a, A, X, Y> RefUnwindSafe for SoftmaxForward<'a, A, X, Y>
where
A: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<'a, A, X, Y> !Send for SoftmaxForward<'a, A, X, Y>
impl<'a, A, X, Y> !Sync for SoftmaxForward<'a, A, X, Y>
impl<'a, A, X, Y> Unpin for SoftmaxForward<'a, A, X, Y>
impl<'a, A, X, Y> UnwindSafe for SoftmaxForward<'a, A, X, Y>
where
A: RefUnwindSafe,
X: RefUnwindSafe,
Y: RefUnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
---------------------------------
Struct TensorDescriptor Copy item path
Source
Search
Settings
Help
Summary
pub struct TensorDescriptor<T> { /* private fields */ }
A descriptor of a tensor. Create with:
Cudnn::create_4d_tensor()
Cudnn::create_4d_tensor_ex()
Cudnn::create_nd_tensor()
Trait Implementations
Source
impl<T: Debug> Debug for TensorDescriptor<T>
Source
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
Source
impl<T> Drop for TensorDescriptor<T>
Source
fn drop(&mut self)
Executes the destructor for this type. Read more
Auto Trait Implementations
impl<T> Freeze for TensorDescriptor<T>
impl<T> RefUnwindSafe for TensorDescriptor<T>
where
T: RefUnwindSafe,
impl<T> !Send for TensorDescriptor<T>
impl<T> !Sync for TensorDescriptor<T>
impl<T> Unpin for TensorDescriptor<T>
where
T: Unpin,
impl<T> UnwindSafe for TensorDescriptor<T>
where
T: UnwindSafe,
Blanket Implementations
Source
impl<T> Any for T
where
T: 'static + ?Sized,
Source
impl<T> Borrow<T> for T
where
T: ?Sized,
Source
impl<T> BorrowMut<T> for T
where
T: ?Sized,
Source
impl<T> From<T> for T
Source
impl<T, U> Into<U> for T
where
U: From<T>,
Source
impl<T, U> TryFrom<U> for T
where
U: Into<T>,
Source
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
Source§
impl<V, T> VZip<V> for T
where
V: MultiLane<T>,
----------------------------------
Trait CudnnDataType Copy item path
Source
Search
Settings
Help
Summary
pub trait CudnnDataType {
type Scalar;
const DATA_TYPE: cudnnDataType_t;
// Required method
fn into_scaling_parameter(self) -> Self::Scalar;
}
Maps a rust type to a sys::cudnnDataType_t
Required Associated Constants
Source
const DATA_TYPE: cudnnDataType_t
Required Associated Types
Source
type Scalar
Certain CUDNN data types have a scaling parameter (usually called alpha/beta) that is a different type. See nvidia docs for more info, but basically f16 has a scalar of f32.
Required Methods
Source
fn into_scaling_parameter(self) -> Self::Scalar
Converts the type into the scaling parameter type. See Self::Scalar.
Dyn Compatibility
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types
Source
impl CudnnDataType for bool
Source
impl CudnnDataType for f32
Source
impl CudnnDataType for f64
Source
impl CudnnDataType for i8
Source
impl CudnnDataType for i32
Source
impl CudnnDataType for i64
Source
impl CudnnDataType for u8
Source
impl CudnnDataType for bf16
Source§
impl CudnnDataType for f16