Class CUDAFatAgent

Class Documentation

class CUDAFatAgent

This is a shared CUDAFatAgent It manages the buffers for the variables of all agent-state combinations for a group of mapped agents This enables operations applied to mapped agents to impact all affected variables even if not present in the current CUDAAgent

Public Functions

explicit CUDAFatAgent(const AgentData &description)

Constructs a new CUDAFatAgent, by creating a statelist for each of the provided agent’s states The specified agent becomes fat_index 0

Parameters

description – The initial agent to be represented by the CUDAFatAgent

~CUDAFatAgent()

Destructor Frees any buffers allocated for new agents

void addSubAgent(const AgentData &description, const unsigned int &master_fat_index, const std::shared_ptr<SubAgentData> &mapping)

Adds a second agent to the CUDAFatAgent, this agent should be mapped to an agent already part of the CUDAFatAgent

Note

It is expected that the new fat_index will be retrieved prior with getMappedAgentCount(), so this value is not returned

Parameters
  • description – The agent to be added

  • master_fat_index – fat index of the (parent) agent which this is agent is mapped to

  • mapping – Mapping definition for how this agent is connected with its master agent.

std::unordered_map<std::string, std::shared_ptr<CUDAFatAgentStateList>> getStateMap(const unsigned int &fat_index)

This function builds and returns the state_map required by the named CUDAAgent

Parameters

fat_index – The index of the CUDAAgent within this CUDAFatAgent

Returns

a statemap suitable for the named agent

void processDeath(const unsigned int &agent_fat_id, const std::string &state_name, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Scatters all active agents within the named state to remove agents with death flag set This updates the alive agent count

Parameters
  • agent_fat_id – The index of the CUDAAgent within this CUDAFatAgent

  • state_name – The name of the state attached to the named fat agent index

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

  • streamId – Index of the stream used for scan compaction flags (and async cuda ops)

void transitionState(const unsigned int &agent_fat_id, const std::string &_src, const std::string &_dest, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Transitions all active agents from the source state to the destination state

Parameters
  • agent_fat_id – The index of the CUDAAgent within this CUDAFatAgent

  • _src – The name of the source state attached to the named fat agent index

  • _dest – The name of the destination state attached to the named fat agent index

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

  • streamId – Index of the stream used for scan compaction flags (and async cuda ops)

void processFunctionCondition(const unsigned int &agent_fat_id, const std::string &state_name, CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream)

Reads the flags set by an agent function condition in order to sort agents according to whether they passed or failed Failed agents are sorted to the front and marked as disabled, passing agents are then sorted to the back

Parameters
  • agent_fat_id – The index of the CUDAAgent within this CUDAFatAgent

  • state_name – The name of the state attached to the named fat agent index

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

  • streamId – Index of the stream used for scan compaction flags (and async cuda ops)

void setConditionState(const unsigned int &agent_fat_id, const std::string &state_name, const unsigned int numberOfDisabled)

Marks the specified number of agents within the specified statelist as disabled

Parameters
  • agent_fat_id – The index of the CUDAAgent within this CUDAFatAgent

  • state_name – The name of the state attached to the named fat agent index

  • numberOfDisabled – The number of agents to be marked as disabled

void *allocNewBuffer(const size_t &total_agent_size, const unsigned int &new_agents, const size_t &varCount)

Returns a device pointer of atleast type_size x new_agents bytes available

Note

It is assumed that when splitting the buffer into variables, each variable’s sub-buffer will be 64 bit aligned

Note

New buffers are shared between all states and mapped/unmapped agents

Parameters
  • total_agent_size – Total number of bytes required to fit all variables in the agent

  • new_agents – The maximum number of agents that need to be stored in the buffer

  • varCount – The total number of different variables the agent has *

void freeNewBuffer(void *buff)

Marks the named buffer as free

Parameters

buff – The buffer to free, this must be a pointer returned by allocNewBuffer(const size_t &, const unsigned int &, const size_t &)

unsigned int getMappedAgentCount() const

The number of mapped agents currently represented by this CUDAFatAgent