OpenASIP  2.0
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MemorySystem Class Reference

#include <MemorySystem.hh>

Collaboration diagram for MemorySystem:
Collaboration graph

Public Types

typedef boost::shared_ptr< MemoryMemoryPtr
 

Public Member Functions

 MemorySystem (const TTAMachine::Machine &machine)
 
virtual ~MemorySystem ()
 
void addAddressSpace (const TTAMachine::AddressSpace &as, MemoryPtr mem, bool shared=true)
 
MemoryPtr memory (const TTAMachine::AddressSpace &as)
 
const MemoryPtr memoryConst (const TTAMachine::AddressSpace &as) const
 
MemoryPtr memory (const std::string &addressSpaceName)
 
unsigned int memoryCount () const
 
MemoryPtr memory (unsigned int i)
 
const TTAMachine::AddressSpaceaddressSpace (unsigned int i)
 
const TTAMachine::AddressSpaceaddressSpace (const std::string &name)
 
void shareMemoriesWith (MemorySystem &other)
 
void advanceClockOfLocalMemories ()
 
void advanceClockOfSharedMemories ()
 
void resetAllMemories ()
 
void fillAllMemoriesWithZero ()
 
void deleteSharedMemories ()
 
bool hasMemory (const TCEString &aSpaceName) const
 

Private Types

typedef std::map< const TTAMachine::AddressSpace *, MemoryPtrMemoryMap
 Maps address spaces to memory instances. More...
 
typedef std::vector< MemoryPtrMemoryContainer
 Container for memory instances for faster traversal. More...
 

Private Member Functions

 MemorySystem (const MemorySystem &)
 Copying not allowed. More...
 
MemorySystemoperator= (const MemorySystem &)
 Assignment not allowed. More...
 

Private Attributes

const TTAMachine::Machinemachine_
 Machine in which MemorySystem belongs to. More...
 
MemoryMap memories_
 Contains all memories indexed by AddressSpaces. More...
 
MemoryContainer memoryList_
 List of all the memories for faster traversal. More...
 
MemoryContainer sharedMemories_
 All memories shared between multiple cores. More...
 
MemoryContainer localMemories_
 All private/local memories used by a single core only. More...
 
MemoryContainer replacedSharedMemories_
 Shared memories which have been replaced with a shared memory from another core. Just for garbage removal. More...
 

Detailed Description

The collection of memory simulation models seen by a single core.

Definition at line 55 of file MemorySystem.hh.

Member Typedef Documentation

◆ MemoryContainer

typedef std::vector<MemoryPtr> MemorySystem::MemoryContainer
private

Container for memory instances for faster traversal.

Definition at line 95 of file MemorySystem.hh.

◆ MemoryMap

typedef std::map<const TTAMachine::AddressSpace*, MemoryPtr> MemorySystem::MemoryMap
private

Maps address spaces to memory instances.

Definition at line 92 of file MemorySystem.hh.

◆ MemoryPtr

typedef boost::shared_ptr<Memory> MemorySystem::MemoryPtr

Definition at line 57 of file MemorySystem.hh.

Constructor & Destructor Documentation

◆ MemorySystem() [1/2]

MemorySystem::MemorySystem ( const TTAMachine::Machine machine)
explicit

Constructor.

Parameters
machineMachine in which MemorySystem belongs to.

Definition at line 54 of file MemorySystem.cc.

54  :
55  machine_(&machine) {
56 }

◆ ~MemorySystem()

MemorySystem::~MemorySystem ( )
virtual

Destructor.

Deletes all the Memory instances.

Definition at line 73 of file MemorySystem.cc.

73  {
74  localMemories_.clear();
76 }

References localMemories_, and replacedSharedMemories_.

◆ MemorySystem() [2/2]

MemorySystem::MemorySystem ( const MemorySystem )
private

Copying not allowed.

Member Function Documentation

◆ addAddressSpace()

void MemorySystem::addAddressSpace ( const TTAMachine::AddressSpace as,
MemoryPtr  mem,
bool  shared = true 
)

Adds AddressSpace and corresponding memory to data structure.

Parameters
asAddressSpace to be added.
memMemory to be added. Becomes property of the MemorySystem, that is, MemorySystems is responsible for deallocating it.
sharedIf the given Memory instace is shared by multiple MemorySystems (cores).
Exceptions
IllegalRegistrationIf the AddressSpace does not belong to the target machine.

Definition at line 90 of file MemorySystem.cc.

91  {
93  if (!nav.hasItem(as.name())) {
94  string msg = "Address space doesn't belong to the target machine";
95  throw IllegalRegistration(__FILE__, __LINE__, __func__, msg);
96  }
97 
98  memories_[&as] = mem;
99 
100  if (shared) {
101  sharedMemories_.push_back(mem);
102  } else {
103  localMemories_.push_back(mem);
104  }
105  memoryList_.push_back(mem);
106 }

References __func__, TTAMachine::Machine::addressSpaceNavigator(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), localMemories_, machine_, memories_, memoryList_, TTAMachine::Component::name(), and sharedMemories_.

Referenced by SimulatorFrontend::initializeMemorySystem().

Here is the call graph for this function:

◆ addressSpace() [1/2]

const AddressSpace & MemorySystem::addressSpace ( const std::string &  name)

Returns the address space with the given name.

Parameters
nameThe name of the address space.
Returns
AddressSpace.
Exceptions
InstanceNotFoundif the address space is not found.

Definition at line 286 of file MemorySystem.cc.

286  {
287  MemoryMap::const_iterator iter = memories_.begin();
288  while (iter != memories_.end()) {
289  if ((*iter).first->name() == name)
290  return *((*iter).first);
291  ++iter;
292  }
293 
294  throw InstanceNotFound(
295  __FILE__, __LINE__, __func__,
296  "Address space with the given name not found.");
297 }

References __func__, and memories_.

◆ addressSpace() [2/2]

const AddressSpace & MemorySystem::addressSpace ( unsigned int  i)

Returns the address space of the ith Memory instance in the memory system.

Returns
Address Space of the memory instance.
Exceptions
OutOfRangeif i is out of bounds.

Definition at line 261 of file MemorySystem.cc.

261  {
262  if (i > memories_.size() - 1) {
263  const string msg =
264  "Index out of bounds. Count of memories is " +
266  throw OutOfRange(__FILE__, __LINE__, __func__, msg);
267  }
268 
269  unsigned int foundCount = 0;
270  MemoryMap::const_iterator iter = memories_.begin();
271  while (iter != memories_.end() && foundCount < i) {
272  ++iter;
273  ++foundCount;
274  }
275  return *((*iter).first);
276 }

References __func__, memories_, memoryCount(), and Conversion::toString().

Referenced by MemDumpCommand::execute(), SimulatorFrontend::initializeDataMemories(), ProximMemoryWindow::loadProgramMemory(), ProximMemoryWindow::onASChoice(), and shareMemoriesWith().

Here is the call graph for this function:

◆ advanceClockOfLocalMemories()

void MemorySystem::advanceClockOfLocalMemories ( )

◆ advanceClockOfSharedMemories()

void MemorySystem::advanceClockOfSharedMemories ( )

◆ deleteSharedMemories()

void MemorySystem::deleteSharedMemories ( )

Deletes all shared memory instances.

Must be called only once for all MemorySystems sharing the memories.

Definition at line 64 of file MemorySystem.cc.

64  {
65  sharedMemories_.clear();
66 }

References sharedMemories_.

◆ fillAllMemoriesWithZero()

void MemorySystem::fillAllMemoriesWithZero ( )

◆ hasMemory()

bool MemorySystem::hasMemory ( const TCEString aSpaceName) const

Definition at line 109 of file MemorySystem.cc.

109  {
110  MemoryMap::const_iterator iter = memories_.begin();
111  while (iter != memories_.end()) {
112  const AddressSpace& space = *((*iter).first);
113  if (space.name() == aSpaceName) {
114  return true;
115  }
116  ++iter;
117  }
118  return false;
119 }

References memories_, and TTAMachine::Component::name().

Referenced by shareMemoriesWith().

Here is the call graph for this function:

◆ memory() [1/3]

MemorySystem::MemoryPtr MemorySystem::memory ( const std::string &  addressSpaceName)

Returns Memory instance bound to an address space with the given name.

The returned memory instance is writable.

Parameters
addressSpaceNameThe name of the address space.
Returns
Memory bound to AddressSpace.
Exceptions
InstanceNotFoundIf no memory is found with the name.

Definition at line 184 of file MemorySystem.cc.

184  {
185  MemoryMap::const_iterator iter = memories_.begin();
186  while (iter != memories_.end()) {
187  const AddressSpace& space = *((*iter).first);
188  MemoryPtr mem = ((*iter).second);
189  if (space.name() == addressSpaceName) {
190  return mem;
191  }
192  ++iter;
193  }
194  string msg = "No memory model found for address space " + addressSpaceName;
195  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
196 }

References __func__, memories_, and TTAMachine::Component::name().

Here is the call graph for this function:

◆ memory() [2/3]

MemorySystem::MemoryPtr MemorySystem::memory ( const TTAMachine::AddressSpace as)

Returns Memory instance bound to the given AddressSpace.

The returned memory instance is writable.

Parameters
asAddressSpace in which memory is asked.
Returns
Memory bound to AddressSpace.
Exceptions
InstanceNotFoundIf no memory is bound to the given AddressSpace.

Definition at line 170 of file MemorySystem.cc.

170  {
171  return memory(as.name());
172 }

References TTAMachine::Component::name().

Referenced by MachineStateBuilder::buildMachineState(), CompiledSimulation::FUMemory(), SimulatorFrontend::initializeDataMemories(), SimulatorFrontend::initializeMemorySystem(), ProximMemoryWindow::loadMemory(), ProximMemoryWindow::onSimulationStop(), SimulatorFrontend::setControllerForMemories(), SimControlLanguageCommand::setMemoryPointer(), and shareMemoriesWith().

Here is the call graph for this function:

◆ memory() [3/3]

MemorySystem::MemoryPtr MemorySystem::memory ( unsigned int  i)

Returns the ith Memory instance in the memory system.

Returns
The Memory instance.
Exceptions
OutOfRangeif i is out of bounds.

Definition at line 237 of file MemorySystem.cc.

237  {
238  if (i > memories_.size() - 1) {
239  const string msg =
240  "Index out of bounds. Count of memories is " +
242  throw OutOfRange(__FILE__, __LINE__, __func__, msg);
243  }
244 
245  unsigned int foundCount = 0;
246  MemoryMap::const_iterator iter = memories_.begin();
247  while (iter != memories_.end() && foundCount < i) {
248  ++iter;
249  ++foundCount;
250  }
251  return ((*iter).second);
252 }

References __func__, memories_, memoryCount(), and Conversion::toString().

Here is the call graph for this function:

◆ memoryConst()

const MemorySystem::MemoryPtr MemorySystem::memoryConst ( const TTAMachine::AddressSpace as) const

Returns Memory instance bound to the given AddressSpace.

The returned memory instance is read-only.

Parameters
asAddressSpace in which memory is asked.
Returns
Memory bound to AddressSpace.
Exceptions
InstanceNotFoundIf no memory is bound to the given AddressSpace.
Todo:
These methods need to be changed to compare with the AS attributes not with AS pointer!

Definition at line 211 of file MemorySystem.cc.

211  {
212  MemoryMap::const_iterator iter = memories_.find(&as);
213  if (iter == memories_.end()) {
214  string msg = "No memory found for address space " + as.name();
215  throw InstanceNotFound(__FILE__, __LINE__, __func__, msg);
216  }
217  return ((*iter).second);
218 }

References __func__, memories_, and TTAMachine::Component::name().

Here is the call graph for this function:

◆ memoryCount()

unsigned int MemorySystem::memoryCount ( ) const

Returns the count of Memory instances in this memory system.

Returns
The count of Memory instances.

Definition at line 226 of file MemorySystem.cc.

226  {
227  return memories_.size();
228 }

References memories_.

Referenced by addressSpace(), ProximMemoryWindow::loadProgramMemory(), memory(), SimulatorFrontend::setControllerForMemories(), and shareMemoriesWith().

◆ operator=()

MemorySystem& MemorySystem::operator= ( const MemorySystem )
private

Assignment not allowed.

◆ resetAllMemories()

void MemorySystem::resetAllMemories ( )

◆ shareMemoriesWith()

void MemorySystem::shareMemoriesWith ( MemorySystem other)

In case two TTA simulation models share memories in an heterogeneous multicore simulation, this method should be called after initializing the simulation frontends between all such pairs to fix the memory model references to point to the same memory model.

The matching is done by the address space name. The shared address space must have the 'shared' attribute set.

@fixme An untested method.

remove the replaced memory as it should not be controlled by this MemorySystem anymore

Definition at line 133 of file MemorySystem.cc.

133  {
134  for (std::size_t i = 0; i < other.memoryCount(); ++i) {
135  const AddressSpace& as = other.addressSpace(i);
136  if (!as.isShared() || !hasMemory(as.name())) continue;
137 
139  AddressSpace* thisAS = nav.item(as.name());
140  /// remove the replaced memory as it should not be controlled
141  /// by this MemorySystem anymore
142  memoryList_.erase(
143  std::find(
144  memoryList_.begin(), memoryList_.end(),
145  memories_[thisAS]));
146 
147  sharedMemories_.erase(
148  std::find(
149  sharedMemories_.begin(), sharedMemories_.end(),
150  memories_[thisAS]));
151 
152  replacedSharedMemories_.push_back(memories_[thisAS]);
153 
154  memories_[thisAS] = other.memory(i);
155 
156  }
157 }

References addressSpace(), TTAMachine::Machine::addressSpaceNavigator(), hasMemory(), TTAMachine::AddressSpace::isShared(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine_, memories_, memory(), memoryCount(), memoryList_, TTAMachine::Component::name(), replacedSharedMemories_, and sharedMemories_.

Here is the call graph for this function:

Member Data Documentation

◆ localMemories_

MemoryContainer MemorySystem::localMemories_
private

All private/local memories used by a single core only.

Definition at line 106 of file MemorySystem.hh.

Referenced by addAddressSpace(), and ~MemorySystem().

◆ machine_

const TTAMachine::Machine* MemorySystem::machine_
private

Machine in which MemorySystem belongs to.

Definition at line 98 of file MemorySystem.hh.

Referenced by addAddressSpace(), and shareMemoriesWith().

◆ memories_

MemoryMap MemorySystem::memories_
private

Contains all memories indexed by AddressSpaces.

Definition at line 100 of file MemorySystem.hh.

Referenced by addAddressSpace(), addressSpace(), hasMemory(), memory(), memoryConst(), memoryCount(), and shareMemoriesWith().

◆ memoryList_

MemoryContainer MemorySystem::memoryList_
private

List of all the memories for faster traversal.

Definition at line 102 of file MemorySystem.hh.

Referenced by addAddressSpace(), and shareMemoriesWith().

◆ replacedSharedMemories_

MemoryContainer MemorySystem::replacedSharedMemories_
private

Shared memories which have been replaced with a shared memory from another core. Just for garbage removal.

Definition at line 109 of file MemorySystem.hh.

Referenced by shareMemoriesWith(), and ~MemorySystem().

◆ sharedMemories_

MemoryContainer MemorySystem::sharedMemories_
private

All memories shared between multiple cores.

Definition at line 104 of file MemorySystem.hh.

Referenced by addAddressSpace(), deleteSharedMemories(), and shareMemoriesWith().


The documentation for this class was generated from the following files:
MemorySystem::sharedMemories_
MemoryContainer sharedMemories_
All memories shared between multiple cores.
Definition: MemorySystem.hh:104
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
OutOfRange
Definition: Exception.hh:320
MemorySystem::machine_
const TTAMachine::Machine * machine_
Machine in which MemorySystem belongs to.
Definition: MemorySystem.hh:98
Conversion::toString
static std::string toString(const T &source)
MemorySystem::MemoryPtr
boost::shared_ptr< Memory > MemoryPtr
Definition: MemorySystem.hh:57
TTAMachine::AddressSpace::isShared
virtual bool isShared() const
Definition: AddressSpace.hh:72
MemorySystem::memoryCount
unsigned int memoryCount() const
Definition: MemorySystem.cc:226
MemorySystem::localMemories_
MemoryContainer localMemories_
All private/local memories used by a single core only.
Definition: MemorySystem.hh:106
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::Machine::addressSpaceNavigator
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition: Machine.cc:392
MemorySystem::hasMemory
bool hasMemory(const TCEString &aSpaceName) const
Definition: MemorySystem.cc:109
IllegalRegistration
Definition: Exception.hh:532
MemorySystem::replacedSharedMemories_
MemoryContainer replacedSharedMemories_
Shared memories which have been replaced with a shared memory from another core. Just for garbage rem...
Definition: MemorySystem.hh:109
MemorySystem::memoryList_
MemoryContainer memoryList_
List of all the memories for faster traversal.
Definition: MemorySystem.hh:102
MemorySystem::memory
MemoryPtr memory(const TTAMachine::AddressSpace &as)
Definition: MemorySystem.cc:170
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
MemorySystem::memories_
MemoryMap memories_
Contains all memories indexed by AddressSpaces.
Definition: MemorySystem.hh:100
MemorySystem::addressSpace
const TTAMachine::AddressSpace & addressSpace(unsigned int i)
Definition: MemorySystem.cc:261
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
InstanceNotFound
Definition: Exception.hh:304