Class CUDAFatAgent

Nested Relationships

Nested Types

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, 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(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(unsigned int agent_fat_id, const std::string &state_name, detail::CUDAScatter &scatter, unsigned int streamId, 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 – The stream index to use for accessing stream specific resources such as scan compaction arrays and buffers

  • stream – CUDA stream to be used for async CUDA operations

void transitionState(unsigned int agent_fat_id, const std::string &_src, const std::string &_dest, detail::CUDAScatter &scatter, unsigned int streamId, 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 – The stream index to use for accessing stream specific resources such as scan compaction arrays and buffers

  • stream – CUDA stream to be used for async CUDA operations

void processFunctionCondition(unsigned int agent_fat_id, const std::string &state_name, detail::CUDAScatter &scatter, unsigned int streamId, 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 – The stream index to use for accessing stream specific resources such as scan compaction arrays and buffers

  • stream – CUDA stream to be used for async CUDA operations

void setConditionState(unsigned int agent_fat_id, const std::string &state_name, 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(size_t total_agent_size, unsigned int new_agents, 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(size_t, unsigned int, size_t)

unsigned int getMappedAgentCount() const

The number of mapped agents currently represented by this CUDAFatAgent

id_t nextID(unsigned int count = 1)

Returns the next free agent id, and increments the ID tracker by the specified count

Parameters:

count – Number that will be added to the return value on next call to this function

Returns:

An ID that can be assigned to an agent that wil be stored within this CUDAFatAgent

id_t *getDeviceNextID()

Returns a device pointer to the value returns by nextID(0) If the device value is changed, then the internal ID counter must be updated via CUDAAgent::scatterNew()

void notifyDeviceBirths(unsigned int newCount)

After device agent births have been processed, this function should be called by CUDAAgent::scatterNew() It updated _nextID and hd_nextID, based on the assumed changes to d_nextID

Parameters:

newCount – The number of agents birthed on device

void assignIDs(HostAPI &hostapi, CUDAScatter &scatter, cudaStream_t stream, unsigned int streamId)

Assigns IDs to any agents who’s ID has the value ID_NOT_SET

Parameters:
  • hostapiHostAPI object, this is used to provide cub temp storage

  • scatter – Scatter instance and cub temp memory to be used (CUDASimulation::singletons->scatter)

  • stream – The CUDAStream to use for CUDA operations

  • streamId – The stream index to use for accessing stream specific resources such as scan compaction arrays and buffers

inline void markIDsUnset()

Resets the flag agent_ids_have_init

void resetIDCounter()

Resets the ID counter (_nextID) to the first valid ID Useful for submodels which will keep resetting an agent population

Note

This will fail silently if it called if any state contains agents