cubecl_core/frontend/operation/
copy.rs

1use crate::prelude::*;
2
3/// Bulk copy `length` elements between two array-likes without intermediates.
4///
5/// # Arguments
6///
7/// `from` - The array/tensor/shared memory to copy from
8/// `from_index` - The `from` index to start the copy from
9/// `to` - The array/tensor/shared memory to copy to
10/// `to_index` - The `to` index to copy the elements to
11///
12/// # Example
13///
14/// ```ignore
15/// copy_bulk(input.as_slice(), idx, shared, shared_idx, 16);
16/// ```
17pub fn copy_bulk<C: CubePrimitive>(
18    _from: &Slice<C>,
19    _from_index: u32,
20    _to: &mut SliceMut<C>,
21    _to_index: u32,
22    _length: u32,
23) {
24}
25
26pub mod copy_bulk {
27    use crate::ir::{CopyMemoryBulkOperator, Instruction, Operator, Scope};
28
29    use super::*;
30
31    /// The expand function for [`copy_bulk()`]
32    pub fn expand<C: CubeType>(
33        scope: &mut Scope,
34        from: ExpandElementTyped<Slice<C>>,
35        from_index: ExpandElementTyped<u32>,
36        to: ExpandElementTyped<SliceMut<C>>,
37        to_index: ExpandElementTyped<u32>,
38        length: u32,
39    ) {
40        scope.register(Instruction::new(
41            Operator::CopyMemoryBulk(CopyMemoryBulkOperator {
42                out_index: to_index.expand.consume(),
43                input: from.expand.consume(),
44                in_index: from_index.expand.consume(),
45                len: length.into(),
46            }),
47            *to.expand,
48        ));
49    }
50}