Skip to main content

gwr_models/memory/
traits.rs

1// Copyright (c) 2023 Graphcore Ltd. All rights reserved.
2
3use gwr_engine::traits::{Routable, TotalBytes};
4use gwr_engine::types::SimError;
5
6use crate::memory::CacheHintType;
7use crate::memory::memory_map::DeviceId;
8
9pub trait ReadMemory {
10    fn read(&self) -> Vec<u8>;
11}
12
13/// Trait implemented by all types that memory components support
14pub trait AccessMemory
15where
16    Self: Routable + TotalBytes,
17{
18    /// Return the destination address of this access
19    fn dst_addr(&self) -> u64;
20
21    /// Return the source address of this access
22    fn src_addr(&self) -> u64;
23
24    /// Return the destination device of this access
25    fn dst_device(&self) -> DeviceId;
26
27    /// Return the source device of this access
28    fn src_device(&self) -> DeviceId;
29
30    /// Return the size of the access in bytes
31    fn access_size_bytes(&self) -> usize;
32
33    /// Returns the appropriate response for a request
34    fn to_response(&self, mem: &impl ReadMemory) -> Result<Self, SimError>
35    where
36        Self: Sized;
37
38    /// Returns the requested caching behaviour of a request
39    fn cache_hint(&self) -> CacheHintType;
40}