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: CubePrimitive>(
33        scope: &mut Scope,
34        from: SliceExpand<C, ReadOnly>,
35        from_index: ExpandElementTyped<u32>,
36        to: SliceExpand<C, ReadWrite>,
37        to_index: ExpandElementTyped<u32>,
38        length: u32,
39    ) {
40        let (input, input_offset) = from.__to_raw_parts();
41        let (to, to_offset) = to.__to_raw_parts();
42
43        scope.register(Instruction::new(
44            Operator::CopyMemoryBulk(CopyMemoryBulkOperator {
45                out_index: to_index.expand.consume(),
46                input,
47                in_index: from_index.expand.consume(),
48                len: length.into(),
49                offset_input: input_offset,
50                offset_out: to_offset,
51            }),
52            to,
53        ));
54    }
55}