MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / rnn_forward

Method rnn_forward

crates/cudnn/src/context.rs:1593–1667  ·  view source on GitHub ↗

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::Trai

(
        &self,
        rnn_desc: &RnnDescriptor<T1, T2>,
        forward_mode: ForwardMode,
        device_seq_lengths: &impl GpuBuffer<i32>,
        x_desc: &RnnDataDescriptor<T1, L>,
        x: &i

Source from the content-addressed store, hash-verified

1591 /// Returns errors is an unsupported arguments combination is detected or if the supplied
1592 /// buffers are too small.
1593 pub fn rnn_forward<T1, T2, L>(
1594 &self,
1595 rnn_desc: &RnnDescriptor<T1, T2>,
1596 forward_mode: ForwardMode,
1597 device_seq_lengths: &impl GpuBuffer<i32>,
1598 x_desc: &RnnDataDescriptor<T1, L>,
1599 x: &impl GpuBuffer<T1>,
1600 y_desc: &RnnDataDescriptor<T1, L>,
1601 y: &impl GpuBuffer<T1>,
1602 h_desc: &TensorDescriptor<T1, NCHW, 3>,
1603 hx: Option<&impl GpuBuffer<T1>>,
1604 hy: Option<&mut impl GpuBuffer<T1>>,
1605 c_desc: Option<&TensorDescriptor<T1, NCHW, 3>>,
1606 cx: Option<&impl GpuBuffer<T1>>,
1607 cy: Option<&mut impl GpuBuffer<T1>>,
1608 weight_space: &mut impl GpuBuffer<u8>,
1609 work_space: &mut impl GpuBuffer<u8>,
1610 reserve_space: Option<&mut impl GpuBuffer<u8>>,
1611 ) -> Result<(), CudnnError>
1612 where
1613 T1: DataType + RnnDataType,
1614 T2: DataType + SupportedPrec<T1>,
1615 L: RnnDataLayout,
1616 NCHW: SupportedType<T1>,
1617 {
1618 let device_sequence_lengths_ptr = device_seq_lengths.as_device_ptr().as_ptr();
1619
1620 let x_ptr = x.as_device_ptr().as_raw();
1621 let y_ptr = y.as_device_ptr().as_ptr();
1622
1623 let hx_ptr = hx.map_or(std::ptr::null(), |buff| buff.as_device_ptr().as_ptr());
1624 let hy_ptr = hy.map_or(std::ptr::null_mut(), |buff| {
1625 buff.as_device_ptr().as_mut_ptr()
1626 });
1627
1628 let c_desc = c_desc.map_or(std::ptr::null_mut(), |desc| desc.raw);
1629
1630 let cx_ptr = cx.map_or(std::ptr::null(), |buff| buff.as_device_ptr().as_ptr());
1631 let cy_ptr = cy.map_or(std::ptr::null_mut(), |buff| {
1632 buff.as_device_ptr().as_mut_ptr()
1633 });
1634
1635 let weight_space_ptr = weight_space.as_device_ptr().as_ptr();
1636 let work_space_ptr = work_space.as_device_ptr().as_ptr();
1637 let (reserve_space_ptr, reserve_space_size) = reserve_space
1638 .map_or((std::ptr::null_mut(), 0), |buff| {
1639 (buff.as_device_ptr().as_mut_ptr(), buff.len())
1640 });
1641
1642 unsafe {
1643 sys::cudnnRNNForward(
1644 self.raw,
1645 rnn_desc.raw,
1646 forward_mode.into(),
1647 device_sequence_lengths_ptr,
1648 x_desc.raw,
1649 x_ptr as *const std::ffi::c_void,
1650 y_desc.raw,

Callers

nothing calls this directly

Calls 6

as_ptrMethod · 0.80
as_device_ptrMethod · 0.45
as_rawMethod · 0.45
as_mut_ptrMethod · 0.45
lenMethod · 0.45
into_resultMethod · 0.45

Tested by

no test coverage detected