Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
talvos::Memory Class Reference

This class represents an address space in the virtual device. More...

#include <talvos/Memory.h>

Classes

struct  Buffer
 An allocation within this memory instance. More...
 

Public Member Functions

 Memory (Device &D, MemoryScope Scope)
 Create a new Memory instance. More...
 
 ~Memory ()
 
uint64_t allocate (uint64_t NumBytes)
 Allocate a new buffer of size NumBytes. More...
 
template<typename 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. More...
 
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. More...
 
void dump () const
 Dump the entire contents of this memory to stdout. More...
 
void dump (uint64_t Address) const
 Dump the contents of the buffer with base address Address to stdout. More...
 
MemoryScope getScope () const
 Get the scope of this memory instance. More...
 
void load (uint8_t *Result, uint64_t Address, uint64_t NumBytes) const
 Load NumBytes of data from Address into Result. More...
 
uint8_t * map (uint64_t Base, uint64_t Offset, uint64_t NumBytes)
 Map a region of memory and return a pointer to it. More...
 
void release (uint64_t Address)
 Release the allocation with base address Address. More...
 
void store (uint64_t Address, uint64_t NumBytes, const uint8_t *Data)
 Store NumBytes of data from Data to Address. More...
 
void unmap (uint64_t Base)
 Unmap a previously mapped region of memory. More...
 
 Memory (const Memory &)=delete
 
Memoryoperator= (const Memory &)=delete
 

Static Public Member Functions

static void copy (uint64_t DstAddress, Memory &DstMem, uint64_t SrcAddress, const Memory &SrcMem, uint64_t NumBytes)
 Copy data between memory instances. More...
 
static const char * scopeToString (MemoryScope Scope)
 Returns the string representation of Scope. More...
 

Private Member Functions

bool isAccessValid (uint64_t Address, uint64_t NumBytes) const
 Check whether an access resides in an allocated region of memory. More...
 

Private Attributes

DeviceDev
 The device this memory instance is part of. More...
 
MemoryScope Scope
 The scope of this memory instance. More...
 
std::mutex Mutex
 Mutex for guarding allocate/release operations. More...
 
std::mutex AtomicMutexes [NUM_ATOMIC_MUTEXES]
 Set of mutexes for synchronizing atomic operations. More...
 
std::vector< BufferBuffers
 List of allocations. More...
 
std::vector< uint64_t > FreeBuffers
 Base addresses available for reuse. More...
 

Static Private Attributes

static const uint32_t NUM_ATOMIC_MUTEXES = 100
 Number of mutexes to use for synchronizing atomic operations. More...
 

Detailed Description

This class represents an address space in the virtual device.

This class provides methods to allocate and release buffers and access their data. A virtual addressing scheme is used for memory addresses. Base addresses for buffers are unique within an instance of this class, but not across separate instances. It is therefore the responsibility of the caller to route load/store calls to the correct Memory object.

Definition at line 37 of file Memory.h.

Constructor & Destructor Documentation

talvos::Memory::Memory ( Device D,
MemoryScope  Scope 
)

Create a new Memory instance.

Definition at line 39 of file Memory.cpp.

talvos::Memory::~Memory ( )

Definition at line 45 of file Memory.cpp.

talvos::Memory::Memory ( const Memory )
delete

Member Function Documentation

uint64_t talvos::Memory::allocate ( uint64_t  NumBytes)

Allocate a new buffer of size NumBytes.

Returns
the virtual base address of the allocation.

Definition at line 52 of file Memory.cpp.

template<typename T >
template int32_t talvos::Memory::atomic ( uint64_t  Address,
uint32_t  Opcode,
uint32_t  Scope,
uint32_t  Semantics,
Value = 0 
)

Atomically apply operation defined by Opcode to Address.

Returns
the original value of the memory location.

Definition at line 81 of file Memory.cpp.

uint32_t talvos::Memory::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.

Returns
the original value of the memory location.

Definition at line 156 of file Memory.cpp.

void talvos::Memory::copy ( uint64_t  DstAddress,
Memory DstMem,
uint64_t  SrcAddress,
const Memory SrcMem,
uint64_t  NumBytes 
)
static

Copy data between memory instances.

DstMem and SrcMem can be the same memory instance.

Definition at line 328 of file Memory.cpp.

void talvos::Memory::dump ( ) const

Dump the entire contents of this memory to stdout.

Definition at line 202 of file Memory.cpp.

void talvos::Memory::dump ( uint64_t  Address) const

Dump the contents of the buffer with base address Address to stdout.

Definition at line 211 of file Memory.cpp.

MemoryScope talvos::Memory::getScope ( ) const
inline

Get the scope of this memory instance.

Definition at line 74 of file Memory.h.

bool talvos::Memory::isAccessValid ( uint64_t  Address,
uint64_t  NumBytes 
) const
private

Check whether an access resides in an allocated region of memory.

Definition at line 236 of file Memory.cpp.

void talvos::Memory::load ( uint8_t *  Result,
uint64_t  Address,
uint64_t  NumBytes 
) const

Load NumBytes of data from Address into Result.

Definition at line 249 of file Memory.cpp.

uint8_t * talvos::Memory::map ( uint64_t  Base,
uint64_t  Offset,
uint64_t  NumBytes 
)

Map a region of memory and return a pointer to it.

Definition at line 273 of file Memory.cpp.

Memory& talvos::Memory::operator= ( const Memory )
delete
void talvos::Memory::release ( uint64_t  Address)

Release the allocation with base address Address.

Definition at line 292 of file Memory.cpp.

static const char* talvos::Memory::scopeToString ( MemoryScope  Scope)
inlinestatic

Returns the string representation of Scope.

Definition at line 97 of file Memory.h.

void talvos::Memory::store ( uint64_t  Address,
uint64_t  NumBytes,
const uint8_t *  Data 
)

Store NumBytes of data from Data to Address.

Definition at line 306 of file Memory.cpp.

void talvos::Memory::unmap ( uint64_t  Base)

Unmap a previously mapped region of memory.

Definition at line 326 of file Memory.cpp.

Member Data Documentation

std::mutex talvos::Memory::AtomicMutexes[NUM_ATOMIC_MUTEXES]
private

Set of mutexes for synchronizing atomic operations.

Definition at line 123 of file Memory.h.

std::vector<Buffer> talvos::Memory::Buffers
private

List of allocations.

Definition at line 131 of file Memory.h.

Device& talvos::Memory::Dev
private

The device this memory instance is part of.

Definition at line 113 of file Memory.h.

std::vector<uint64_t> talvos::Memory::FreeBuffers
private

Base addresses available for reuse.

Definition at line 132 of file Memory.h.

std::mutex talvos::Memory::Mutex
private

Mutex for guarding allocate/release operations.

Definition at line 117 of file Memory.h.

const uint32_t talvos::Memory::NUM_ATOMIC_MUTEXES = 100
staticprivate

Number of mutexes to use for synchronizing atomic operations.

Definition at line 120 of file Memory.h.

MemoryScope talvos::Memory::Scope
private

The scope of this memory instance.

Definition at line 115 of file Memory.h.