Skip to main content

cubecl_core/frontend/operation/
copy_op.rs

1use crate::prelude::*;
2
3/// Bulk copy `length` elements between two array-likes without intermediates.
4///
5/// # Arguments
6///
7/// `from` - slice to copy from
8/// `to` - slice to copy to
9///
10/// # Example
11///
12/// ```ignore
13/// copy_bulk(input.as_slice(), shared, 16);
14/// ```
15pub fn copy_bulk<C: CubePrimitive>(_from: &[C], _to: &mut [C], _length: usize) {}
16
17pub mod copy_bulk {
18    use cubecl_ir::dialect::memory::CopyOp;
19
20    use crate::ir::Scope;
21
22    use super::*;
23
24    /// The expand function for [`copy_bulk()`]
25    pub fn expand<C: CubePrimitive>(
26        scope: &Scope,
27        from: &SliceExpand<C>,
28        to: &mut SliceExpand<C>,
29        length: usize,
30    ) {
31        let source = unsafe { *from.__expand_as_ptr_method(scope) }.value(scope);
32        let target = unsafe { *to.__expand_as_mut_ptr_method(scope) }.value(scope);
33
34        scope.register(&CopyOp::new(scope.ctx_mut(), source, target, length));
35    }
36}
37
38/// Copy one element between two array-likes without intermediates.
39///
40/// # Arguments
41///
42/// `from` - The reference to copy from
43/// `to` - The reference to copy to
44///
45/// # Example
46///
47/// ```ignore
48/// copy(input[0], shared[0]);
49/// ```
50pub fn copy<C: CubePrimitive>(_from: &C, _to: &mut C) {}
51
52pub mod copy {
53    use cubecl_ir::dialect::memory::CopyOp;
54
55    use crate::ir::Scope;
56
57    use super::*;
58
59    /// The expand function for [`copy_bulk()`]
60    pub fn expand<C: CubePrimitive>(
61        scope: &Scope,
62        from: &NativeExpand<C>,
63        to: &mut NativeExpand<C>,
64    ) {
65        let source = from.value(scope);
66        let target = to.value(scope);
67
68        scope.register(&CopyOp::new(scope.ctx_mut(), source, target, 1));
69    }
70}