pub fn rnn_forward<T1, T2, L>(
        &self,
        rnn_desc: &RnnDescriptor<T1, T2>,
        forward_mode: ForwardMode,
        device_seq_lengths: &impl GpuBuffer<i32>,
        x_desc: &RnnDataDescriptor<T1, L>,
        x: &impl GpuBuffer<T1>,
        y_desc: &RnnDataDescriptor<T1, L>,
        y: &impl GpuBuffer<T1>,
        h_desc: &TensorDescriptor<T1, NCHW, 3>,
        hx: Option<&impl GpuBuffer<T1>>,
        hy: Option<&mut impl GpuBuffer<T1>>,
        c_desc: Option<&TensorDescriptor<T1, NCHW, 3>>,
        cx: Option<&impl GpuBuffer<T1>>,
        cy: Option<&mut impl GpuBuffer<T1>>,
        weight_space: &mut impl GpuBuffer<u8>,
        work_space: &mut impl GpuBuffer<u8>,
        reserve_space: Option<&mut impl GpuBuffer<u8>>,
    ) -> Result<(), CudnnError>
    where
        T1: DataType + RnnDataType,
        T2: DataType + SupportedPrec<T1>,
        L: RnnDataLayout,
        NCHW: SupportedType<T1>,
    {
        let device_sequence_lengths_ptr = device_seq_lengths.as_device_ptr().as_raw();

        let x_ptr = x.as_device_ptr().as_raw();
        let y_ptr = y.as_device_ptr().as_raw_mut();

        let hx_ptr = hx.map_or(std::ptr::null(), |buff| buff.as_device_ptr().as_raw());
        let hy_ptr = hy.map_or(std::ptr::null_mut(), |buff| {
            buff.as_device_ptr().as_raw_mut()
        });

        let c_desc = c_desc.map_or(std::ptr::null_mut(), |desc| desc.raw);

        let cx_ptr = cx.map_or(std::ptr::null(), |buff| buff.as_device_ptr().as_raw());
        let cy_ptr = cy.map_or(std::ptr::null_mut(), |buff| {
            buff.as_device_ptr().as_raw_mut()
        });

        let weight_space_ptr = weight_space.as_device_ptr().as_raw_mut();
        let work_space_ptr = work_space.as_device_ptr().as_raw_mut();
        let (reserve_space_ptr, reserve_space_size) = reserve_space
            .map_or((std::ptr::null_mut(), 0), |buff| {
                (buff.as_device_ptr().as_raw_mut(), buff.len())
            });

        unsafe {
            sys::cudnnRNNForward(
                self.raw,
                rnn_desc.raw,
                forward_mode.into(),
                device_sequence_lengths_ptr,
                x_desc.raw,
                x_ptr as *const std::ffi::c_void,
                y_desc.raw,
                y_ptr as *mut std::ffi::c_void,
                h_desc.raw,
                hx_ptr as *const std::ffi::c_void,
                hy_ptr as *mut std::ffi::c_void,
                c_desc,
                cx_ptr as *const std::ffi::c_void,
                cy_ptr as *mut std::ffi::c_void,
                weight_space.len(),
                weight_space_ptr as *const std::ffi::c_void,
                work_space.len(),
                work_space_ptr as *mut std::ffi::c_void,
                reserve_space_size,
                reserve_space_ptr as *mut std::ffi::c_void,
            )
            .into_result()
        }
    }
/// This routine computes the forward response of the recurrent neural network described by
/// `rnn_desc` with inputs in `x`, `hx`, `cx`, and weights / biases in the `weight_space`
/// buffer. RNN outputs are written to `y`, `hy`, and `cy` buffers.
///
/// Note that internal RNN signals between time-steps and between layers are not exposed to the
/// user.
///
/// When the `forward_mode` parameter is set to `ForwardMode::Training`, this function stores
/// intermediate data required to compute first order derivatives in the reserve space buffer.
/// Work and reserve space buffer sizes should be computed by the `get_rnn_temp_space_sizes`
/// function with the same `forward_mode` setting as used in the `rnn_forward()` call.
///
/// The same layout type must be specified in `x_desc` and `y_desc` descriptors. The same
/// sequence lengths must be configured in `x_desc`, `y_desc` and in the device array
/// `device_seq_lengths`. The `rnn_forward()` function does not verify that sequence lengths
/// stored in `device_seq_lengths` in GPU memory are the same as in `x_desc` and `y_desc`
/// descriptors in CPU memory.
///
/// Sequence length arrays from `x_desc` and `y_desc` descriptors are checked for consistency,
/// however.
///
/// # Arguments
///
/// * `rnn_desc` - a RNN descriptor.
///
/// * `forward_mode` - specifies inference or training mode. In the training mode, additional
/// data is stored in the reserve space buffer. This information is used in the backward pass
/// to compute derivatives.
///
/// * `device_seq_lengths` - a copy of `seq_lengths` from `x_desc` or `y_desc` RNN data
/// descriptors. The `device_seq_lengths`  must be stored in GPU memory as it is accessed
/// asynchronously by GPU kernels, possibly after the `rnn_forward()` function exists.
///
/// * `x_desc` -  a descriptor corresponding to the RNN model primary input.
///
/// * `x` - GPU memory associated with the RNN data descriptor `x_desc`.
///
/// * `y_desc` - a RNN data descriptor. The data type, layout, maximum sequence length, batch
/// size, and sequence lengths array must match that of `x_desc`. The parameter `vector_size` of
/// `y_desc`  depends on whether LSTM projection is enabled (only for LSTM) and whether the
/// network is bidirectional. Specifically: for unidirectional models, the parameter
/// `vector_size` must match the `hidden_size` argument passed to the RNN descriptor
/// constructor. If the LSTM projection is enabled, the `vector_size` must be the same as the
/// `projection_size` argument passed to the RNN descriptor constructor. For bidirectional
/// models, if the RNN `cell_mode` is `RnnMode::Lstm` and the projection feature is enabled,
/// the parameter `vector_size` must be double the `projection_size` argument passed to the
/// RNN descriptor constructor. Otherwise, it should be double the `hidden_size` value.
///
/// * `y` - GPU memory associated with the RNN data descriptor `y_desc`.
///
/// * `h_desc` - tensor descriptor describing the initial or final hidden state of RNN. The
/// first dimension of the tensor depends on the `dir_mode` argument passed to the descriptor
/// constructor function. If `dir_mode` is `RnnDirectionMode::Unidirectional`, then the first
/// dimension should match the `num_layers` argument passed to the RNN descriptor constructor.
/// If `dir_mode` is `RnnDirectionMode::Bidirectional`, then the first dimension should
/// match double the `num_layers` argument passed to the RNN descriptor constructor.
/// The second dimension must match the `bath_size` parameter described in `x_desc`. The third
/// dimension depends on whether RNN mode is `RnnMode::Lstm` and whether the LSTM projection is
/// enabled. Specifically: if RNN mode is `RnnMode::Lstm` and LSTM projection is enabled, the
/// third dimension must match the `projection_size` argument passed to the RNN descriptor
/// constructor. Otherwise, the third dimension must match the `hidden_size` argument passed
/// to the RNN descriptor constructor.
///
/// * `hx` - GPU buffer with the RNN initial hidden state. Data dimensions are described by the
/// `h_desc` tensor descriptor. If `None` is passed, the initial hidden state of the network
/// will be initialized to zero.
///
/// * `hy` - GPU buffer where the final RNN hidden state should be stored. Data dimensions are
/// described by the `h_desc` tensor descriptor. If `None` is passed, the final hidden state of
/// the network will not be saved.
///
/// * `c_desc` - for LSTM networks only. A tensor descriptor describing the initial or final
/// cell state for LSTM networks only. The first dimension of the tensor depends on the
/// `dir_mode` argument passed to the RNN descriptor constructor call.
///
/// * `cx` -  For LSTM networks only. GPU buffer with the initial LSTM state data. Data
/// dimensions are described by the `c_desc` tensor descriptor. If `None` is passed, the
/// initial cell state of the network will be initialized to zero.
///
/// * `cy` - For LSTM networks only. GPU buffer where final LSTM state data should be stored.
/// Data dimensions are described by the `c_desc` tensor descriptor. If `None` is passed, the
/// final LSTM cell state will not be saved.
///
/// * `weight_space` - weight space buffer in GPU memory.
///
/// * `work_space` - buffer in GPU memory to store temporary data.
///
/// * `reserve_space` - reserve-space buffer in GPU memory.
///
/// # Errors
///
/// Returns errors is an unsupported arguments combination is detected or if the supplied
/// buffers are too small.


Note that internal RNN signals between time-steps and between layers are not exposed to the
user.

When the `forward_mode` parameter is set to `ForwardMode::Training`, this function stores
intermediate data required to compute first order derivatives in the reserve space buffer.

The same layout type must be specified in `x_desc` and `y_desc` descriptors.

Sequence length arrays from `x_desc` and `y_desc` descriptors are checked for consistency,
however.
Note that internal RNN signals between time - steps and between layers are not exposed to the user . When the ` forward_mode ` parameter is set to ` ForwardMode :: Training ` this function stores intermediate data required to compute first order derivatives in the reserve space buffer . The same layout type must be specified in ` x_desc ` and ` y_desc ` descriptors . Sequence length arrays from ` x_desc ` and ` y_desc ` descriptors are checked for consistency however .
pub fn rnn_forward<T1, T2, L>(
        &self,
        rnn_desc: &RnnDescriptor<T1, T2>,
        forward_mode: ForwardMode,
        device_seq_lengths: &impl GpuBuffer<i32>,
        x_desc: &RnnDataDescriptor<T1, L>,
        x: &impl GpuBuffer<T1>,
        y_desc: &RnnDataDescriptor<T1, L>,
        y: &impl GpuBuffer<T1>,
        h_desc: &TensorDescriptor<T1, NCHW, 3>,
        hx: Option<&impl GpuBuffer<T1>>,
        hy: Option<&mut impl GpuBuffer<T1>>,
        c_desc: Option<&TensorDescriptor<T1, NCHW, 3>>,
        cx: Option<&impl GpuBuffer<T1>>,
        cy: Option<&mut impl GpuBuffer<T1>>,
        weight_space: &mut impl GpuBuffer<u8>,
        work_space: &mut impl GpuBuffer<u8>,
        reserve_space: Option<&mut impl GpuBuffer<u8>>,
    ) -> Result<(), CudnnError>
    where
        T1: DataType + RnnDataType,
        T2: DataType + SupportedPrec<T1>,
        L: RnnDataLayout,
        NCHW: SupportedType<T1>,
    {
        let device_sequence_lengths_ptr = device_seq_lengths.as_device_ptr().as_raw();
        let x_ptr = x.as_device_ptr().as_raw();
        let y_ptr = y.as_device_ptr().as_raw_mut();
        let hx_ptr = hx.map_or(std::ptr::null(), |buff| buff.as_device_ptr().as_raw());
        let hy_ptr = hy.map_or(std::ptr::null_mut(), |buff| {
            buff.as_device_ptr().as_raw_mut()
        });
        let c_desc = c_desc.map_or(std::ptr::null_mut(), |desc| desc.raw);
        let cx_ptr = cx.map_or(std::ptr::null(), |buff| buff.as_device_ptr().as_raw());
        let cy_ptr = cy.map_or(std::ptr::null_mut(), |buff| {
            buff.as_device_ptr().as_raw_mut()
        });
        let weight_space_ptr = weight_space.as_device_ptr().as_raw_mut();
        let work_space_ptr = work_space.as_device_ptr().as_raw_mut();
        let (reserve_space_ptr, reserve_space_size) = reserve_space
            .map_or((std::ptr::null_mut(), 0), |buff| {
                (buff.as_device_ptr().as_raw_mut(), buff.len())
            });
        unsafe {
            sys::cudnnRNNForward(
                self.raw,
                rnn_desc.raw,
                forward_mode.into(),
                device_sequence_lengths_ptr,
                x_desc.raw,
                x_ptr as *const std::ffi::c_void,
                y_desc.raw,
                y_ptr as *mut std::ffi::c_void,
                h_desc.raw,
                hx_ptr as *const std::ffi::c_void,
                hy_ptr as *mut std::ffi::c_void,
                c_desc,
                cx_ptr as *const std::ffi::c_void,
                cy_ptr as *mut std::ffi::c_void,
                weight_space.len(),
                weight_space_ptr as *const std::ffi::c_void,
                work_space.len(),
                work_space_ptr as *mut std::ffi::c_void,
                reserve_space_size,
                reserve_space_ptr as *mut std::ffi::c_void,
            )
            .into_result()
        }
    }
pub fn rnn_forward < T1 , T2 , L > ( & self , rnn_desc : & RnnDescriptor < T1 , T2 > , forward_mode : ForwardMode , device_seq_lengths : & impl GpuBuffer < i32 > , x_desc : & RnnDataDescriptor < T1 , L > , x : & impl GpuBuffer < T1 > , y_desc : & RnnDataDescriptor < T1 , L > , y : & impl GpuBuffer < T1 > , h_desc : & TensorDescriptor < T1 , NCHW , 3 > , hx : Option < & impl GpuBuffer < T1 > > , hy : Option < & mut impl GpuBuffer < T1 > > , c_desc : Option < & TensorDescriptor < T1 , NCHW , 3 > > , cx : Option < & impl GpuBuffer < T1 > > , cy : Option < & mut impl GpuBuffer < T1 > > , weight_space : & mut impl GpuBuffer < u8 > , work_space : & mut impl GpuBuffer < u8 > , reserve_space : Option < & mut impl GpuBuffer < u8 > > , ) -> Result < ( ) , CudnnError > where T1 : DataType + RnnDataType , T2 : DataType + SupportedPrec < T1 > , L : RnnDataLayout , NCHW : SupportedType < T1 > , { let device_sequence_lengths_ptr = device_seq_lengths . as_device_ptr ( ) . as_raw ( ) ; let x_ptr = x . as_device_ptr ( ) . as_raw ( ) ; let y_ptr = y . as_device_ptr ( ) . as_raw_mut ( ) ; let hx_ptr = hx . map_or ( std :: ptr :: null ( ) , | buff | buff . as_device_ptr ( ) . as_raw ( ) ) ; let hy_ptr = hy . map_or ( std :: ptr :: null_mut ( ) , | buff | { buff . as_device_ptr ( ) . as_raw_mut ( ) } ) ; let c_desc = c_desc . map_or ( std :: ptr :: null_mut ( ) , | desc | desc . raw ) ; let cx_ptr = cx . map_or ( std :: ptr :: null ( ) , | buff | buff . as_device_ptr ( ) . as_raw ( ) ) ; let cy_ptr = cy . map_or ( std :: ptr :: null_mut ( ) , | buff | { buff . as_device_ptr ( ) . as_raw_mut ( ) } ) ; let weight_space_ptr = weight_space . as_device_ptr ( ) . as_raw_mut ( ) ; let work_space_ptr = work_space . as_device_ptr ( ) . as_raw_mut ( ) ; let ( reserve_space_ptr , reserve_space_size ) = reserve_space . map_or ( ( std :: ptr :: null_mut ( ) , 0 ) , | buff | { ( buff . as_device_ptr ( ) . as_raw_mut ( ) , buff . len ( ) ) } ) ; unsafe { sys :: cudnnRNNForward ( self . raw , rnn_desc . raw , forward_mode . into ( ) , device_sequence_lengths_ptr , x_desc . raw , x_ptr as * const std :: ffi :: c_void , y_desc . raw , y_ptr as * mut std :: ffi :: c_void , h_desc . raw , hx_ptr as * const std :: ffi :: c_void , hy_ptr as * mut std :: ffi :: c_void , c_desc , cx_ptr as * const std :: ffi :: c_void , cy_ptr as * mut std :: ffi :: c_void , weight_space . len ( ) , weight_space_ptr as * const std :: ffi :: c_void , work_space . len ( ) , work_space_ptr as * mut std :: ffi :: c_void , reserve_space_size , reserve_space_ptr as * mut std :: ffi :: c_void , ) . into_result ( ) } }
This routine computes the forward response of the recurrent neural network described by
`rnn_desc` with inputs in `x`, `hx`, `cx`, and weights / biases in the `weight_space`
buffer.
This routine computes the forward response of the recurrent neural network described by ` rnn_desc ` with inputs in ` x ` ` hx ` ` cx ` and weights / biases in the ` weight_space ` buffer .
&self
rnn_desc
&RnnDescriptor<T1, T2>
forward_mode
ForwardMode
device_seq_lengths
&impl GpuBuffer<i32>
x_desc
&RnnDataDescriptor<T1, L>
x
&impl GpuBuffer<T1>
y_desc
&RnnDataDescriptor<T1, L>
y
&impl GpuBuffer<T1>
h_desc
&TensorDescriptor<T1, NCHW, 3>
hx
Option<&impl GpuBuffer<T1>>
hy
Option<&mut impl GpuBuffer<T1>>
c_desc
Option<&TensorDescriptor<T1, NCHW, 3>>
cx
Option<&impl GpuBuffer<T1>>
cy
Option<&mut impl GpuBuffer<T1>>
weight_space
&mut impl GpuBuffer<u8>
work_space
&mut impl GpuBuffer<u8>
reserve_space
Option<&mut impl GpuBuffer<u8>>
&self
rnn_desc
&RnnDescriptor<T1, T2>
forward_mode
ForwardMode
device_seq_lengths
&impl GpuBuffer<i32>
x_desc
&RnnDataDescriptor<T1, L>
x
&impl GpuBuffer<T1>
y_desc
&RnnDataDescriptor<T1, L>
y
&impl GpuBuffer<T1>
h_desc
&TensorDescriptor<T1, NCHW, 3>
hx
Option<&impl GpuBuffer<T1>>
hy
Option<&mut impl GpuBuffer<T1>>
c_desc
Option<&TensorDescriptor<T1, NCHW, 3>>
cx
Option<&impl GpuBuffer<T1>>
cy
Option<&mut impl GpuBuffer<T1>>
weight_space
&mut impl GpuBuffer<u8>
work_space
&mut impl GpuBuffer<u8>
reserve_space
Option<&mut impl GpuBuffer<u8>>
errors
Returns errors is an unsupported arguments combination is detected or if the supplied
buffers are too small.
Returns errors is an unsupported arguments combination is detected or if the supplied buffers are too small .