9 #ifndef TALVOS_MEMORY_H
10 #define TALVOS_MEMORY_H
53 uint64_t
allocate(uint64_t NumBytes);
58 T
atomic(uint64_t Address, uint32_t Opcode, uint32_t Scope,
59 uint32_t Semantics, T Value = 0);
64 uint32_t EqualSemantics, uint32_t UnequalSemantics,
65 uint32_t Value, uint32_t Comparator);
71 void dump(uint64_t Address)
const;
77 void load(uint8_t *Result, uint64_t Address, uint64_t NumBytes)
const;
80 uint8_t *
map(uint64_t Base, uint64_t Offset, uint64_t NumBytes);
86 void store(uint64_t Address, uint64_t NumBytes,
const uint8_t *Data);
89 void unmap(uint64_t Base);
93 static void copy(uint64_t DstAddress,
Memory &DstMem, uint64_t SrcAddress,
94 const Memory &SrcMem, uint64_t NumBytes);
135 bool isAccessValid(uint64_t Address, uint64_t NumBytes)
const;
uint8_t * map(uint64_t Base, uint64_t Offset, uint64_t NumBytes)
Map a region of memory and return a pointer to it.
void unmap(uint64_t Base)
Unmap a previously mapped region of memory.
void dump() const
Dump the entire contents of this memory to stdout.
std::mutex AtomicMutexes[NUM_ATOMIC_MUTEXES]
Set of mutexes for synchronizing atomic operations.
static void copy(uint64_t DstAddress, Memory &DstMem, uint64_t SrcAddress, const Memory &SrcMem, uint64_t NumBytes)
Copy data between memory instances.
uint32_t atomicCmpXchg(uint64_t Address, uint32_t Scope, uint32_t EqualSemantics, uint32_t UnequalSemantics, uint32_t Value, uint32_t Comparator)
Perform an atomic compare-exchange operation at Address.
MemoryScope
Describes the scope of a memory instance.
void release(uint64_t Address)
Release the allocation with base address Address.
uint64_t NumBytes
The size of the allocation in bytes.
Memory & operator=(const Memory &)=delete
This class represents a single execution of a SPIR-V entry point.
T atomic(uint64_t Address, uint32_t Opcode, uint32_t Scope, uint32_t Semantics, T Value=0)
Atomically apply operation defined by Opcode to Address.
This class represents an address space in the virtual device.
MemoryScope getScope() const
Get the scope of this memory instance.
std::vector< uint64_t > FreeBuffers
Base addresses available for reuse.
std::mutex Mutex
Mutex for guarding allocate/release operations.
A Device instance encapsulates properties and state for the virtual device.
void load(uint8_t *Result, uint64_t Address, uint64_t NumBytes) const
Load NumBytes of data from Address into Result.
MemoryScope Scope
The scope of this memory instance.
uint64_t allocate(uint64_t NumBytes)
Allocate a new buffer of size NumBytes.
void store(uint64_t Address, uint64_t NumBytes, const uint8_t *Data)
Store NumBytes of data from Data to Address.
An allocation within this memory instance.
static const char * scopeToString(MemoryScope Scope)
Returns the string representation of Scope.
Memory(Device &D, MemoryScope Scope)
Create a new Memory instance.
bool isAccessValid(uint64_t Address, uint64_t NumBytes) const
Check whether an access resides in an allocated region of memory.
static const uint32_t NUM_ATOMIC_MUTEXES
Number of mutexes to use for synchronizing atomic operations.
uint8_t * Data
The raw data backing the allocation.
std::vector< Buffer > Buffers
List of allocations.
Device & Dev
The device this memory instance is part of.