Skip to main content

cubecl_ir/
memory.rs

1use core::fmt::Display;
2
3use crate::{CopyMemoryOperands, IndexOperands, StoreOperands, TypeHash, Value};
4
5use crate::OperationReflect;
6
7/// Bitwise operations
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, TypeHash, PartialEq, Eq, Hash, OperationReflect)]
10#[operation(opcode_name = MemoryOpCode)]
11pub enum Memory {
12    #[operation(pure)]
13    Index(IndexOperands),
14    Load(#[args(allow_ptr, ptr_read)] Value),
15    Store(StoreOperands),
16    CopyMemory(CopyMemoryOperands),
17}
18
19impl Display for Memory {
20    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21        match self {
22            Memory::Index(op) => write!(f, "&{}[{}]", op.list, op.index),
23            Memory::Load(variable) => write!(f, "load({variable})"),
24            Memory::Store(op) => write!(f, "store({}, {})", op.ptr, op.value),
25            Memory::CopyMemory(op) => {
26                write!(f, "memcpy({}, {}, {})", op.source, op.target, op.len)
27            }
28        }
29    }
30}