Class CUDAAgentStateList

Class Documentation

class CUDAAgentStateList

Manages data for an agent state Forwards alot of operations to parent statelist if they need to affected mapped vars too

Public Functions

CUDAAgentStateList(const std::shared_ptr<CUDAFatAgentStateList> &fat_list, CUDAAgent &cuda_agent, const unsigned int &_fat_index, const AgentData &description, bool _isSubStateList = false)

Construct a CUDAAgentStateList view into the provided fat_list

Parameters
  • fat_list – The parent CUDAFatAgentStateList

  • cuda_agent – The owning CUDAAgent

  • _fat_index – The owning CUDAAgent’s fat index within the CUDAFatAgent

  • description – The owning CUDAAgent’s description, used to identify variables

  • _isSubStateList – If true, the statelist is mapped to a master agent (and will be reset after CUDASimulation::simulate())

  • mapping – Mapping definition for how the variables are to their master state.

CUDAAgentStateList(const std::shared_ptr<CUDAFatAgentStateList> &fat_list, CUDAAgent &cuda_agent, const unsigned int &_fat_index, const AgentData &description, bool _isSubStateList, const SubAgentData::Mapping &mapping)
void resize(const unsigned int &minimumSize, const bool &retainData)

Resize all variable buffers within the parent CUDAFatAgentStateList Only initialises unmapped agent data

See

CUDAFatAgentStateList::resize(const unsigned int &, const bool &)

Parameters
  • minimumSize – The minimum number of agents that must be representable

  • retainData – If true existing buffer data is retained

unsigned int getSize() const

Returns the number of alive and active agents in the state list

unsigned int getAllocatedSize() const

Returns the maximum number of agents that can be stored based on the current buffer allocations

void *getVariablePointer(const std::string &variable_name)

Returns the device pointer for the named variable

void setAgentData(const AgentVector &data, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Store agent data from agent state memory into state list @data data Source for agent data

Parameters
  • scatter – Scatter instance and scan arrays to be used

  • streamId – This is required for scan compaction arrays and async

void getAgentData(AgentVector &data) const

Retrieve agent data from the agent state list into agent state memory @data data Destination for agent data

void scatterHostCreation(const unsigned int &newSize, char *const d_inBuff, const VarOffsetStruct &offsets, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Initialises the specified number of new agents based on agent data from a device buffer Variables in mapped agents are also initialised to their default values Also updates the count of alive agents to accommodate the new agents

Parameters
  • newSize – The number of new agents to initialise

  • d_inBuff – device pointer to buffer of agent init data

  • offsets – Offset data explaining the layout of d_inBuff

  • scatter – Scatter instance and scan arrays to be used

  • streamId – This is required for scan compaction arrays and async

void scatterSort(CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Sorts all agent variables according to the positions stored inside Message Output scan buffer

Parameters
  • scatter – Scatter instance and scan arrays to be used (CUDASimulation::singletons->scatter)

  • streamId – The stream in which the corresponding agent function has executed

void scatterNew(void *d_newBuff, const unsigned int &newSize, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Scatters agents from the currently assigned device agent birth buffer (see member variable newBuffs) The device buffer must be packed in the same format as CUDAAgent::mapNewRuntimeVariables(const AgentFunctionData&, const unsigned int &, const unsigned int &)

Parameters
  • d_newBuff – The buffer holding the new agent data

  • newSize – The maximum number of new agents (this will be the size of the agent state executing func)

  • scatter – Scatter instance and scan arrays to be used

  • streamId – This is required for scan compaction arrays and async

bool getIsSubStatelist()

Returns true if the state list is not the primary statelist (and is mapped to a master agent state)

void initUnmappedVars(CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Returns any unmapped variables (for alive agents) to their default value

Parameters
  • scatter – Scatter instance and scan arrays to be used

  • streamId – This is required for scan compaction arrays and async

void initExcludedVars(const unsigned int &count, const unsigned int &offset, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Initialises any agent variables within the CUDAFatAgentStateList which are not present in this CUDAAgentStateList

Parameters
  • count – Number of variables to init

  • offset – Offset into the buffer of agents to init

  • scatter – Scatter instance and scan arrays to be used

  • streamId – This is required for scan compaction arrays and async

void clear()

Returns the statelist to an empty state This resets the size to 0.

void setAgentCount(const unsigned int &newSize)

Updates the number of alive agents, does not affect disabled agents or change agent data

Parameters

newSize – Number of active agents

Throws

InvalidMemoryCapacity – If the new number of disabled + active agents would exceed currently allocated buffer capacity

std::list<std::shared_ptr<VariableBuffer>> getUnboundVariableBuffers()

Returns a list of variable buffers attached to bound agents, not available in this agent

Note

This access is only intended for DeviceAgentVector’s correctly handling of subagents