Class CUDAFatAgentStateList

Class Documentation

class CUDAFatAgentStateList

Represents state list properties shared between mapped agents

Public Functions

explicit CUDAFatAgentStateList(const AgentData &description)

Constructs a new state list with variables from the provided description Memory for buffers is not allocated until resize() is called

CUDAFatAgentStateList(const CUDAFatAgentStateList &other)

Copy constructor, this clones an existing CUDAFatAgentStateList However buffers must be uninitialised (bufferLen == 0)

~CUDAFatAgentStateList()

Destructor

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

Adds variables from a sub agent to the state list Variables which are not mapped will have a new VariableBuffer created Variables which are mapped will be assigned to the corresponding VariableBuffer

Parameters:
  • description – Agent description of the sub agent

  • master_fat_index – Fat index of the sub agent’s mapped (parent) agent within the CUDAFatAgent

  • sub_fat_index – Fat index of the sub agent within the CUDAFatAgent

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

std::shared_ptr<VariableBuffer> getVariableBuffer(unsigned int fat_index, const std::string &name)

Returns the VariableBuffer for the corresponding agent variable

Parameters:
  • fat_index – Fat index of the corresponding agent

  • name – Name of the variable within the corresponding agent

void resize(unsigned int minSize, bool retainData, cudaStream_t stream)

Resize all variable buffers

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

  • retainData – If true existing buffer data is retained

  • stream – The stream to be used if data requires copying

unsigned int getSize() const

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

unsigned int getSizeWithDisabled() const

Returns the total number of agents in the state list, including disabled agents

unsigned int getAllocatedSize() const

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

void setAgentCount(unsigned int newCount, bool resetDisabled = false)

Updates the number of alive agents within the list

Parameters:
  • newCount – New number of alive (and active agents)

  • resetDisabled – If true, the disableAgents count will be set to 0, else it will be added to newCount for the internal true alive count

unsigned int scatterDeath(detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Scatters all living agents (including disabled, according to the provided stream’s death flag)

Parameters:
  • 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

Returns:

The number of agents that are still alive (this includes temporarily disabled agents due to agent function condition)

unsigned int scatterAgentFunctionConditionFalse(detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Scatters all living agents which failed the agent function condition into the swap buffer (there should be no disabled at this time) This does not swap buffers or update disabledAgent)

See also

scatterAgentFunctionConditionTrue(unsigned int, unsigned int)

Parameters:
  • 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

Returns:

The number of agents that were scattered (the number of agents which failed the condition)

unsigned int scatterAgentFunctionConditionTrue(unsigned int conditionFailCount, detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Scatters all living agents which passed the agent function condition into the swap buffer (there should be no disabled at this time) Also swaps the buffers and sets the number of disabled agents

See also

scatterAgentFunctionConditionFalse(unsigned int)

See also

setConditionState(unsigned int)

Parameters:
  • conditionFailCount – The number of agents which failed the condition (they should already have been scattered to swap)

  • 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

Returns:

The number of agents that were scattered (the number of agents which passed the condition)

void scatterSort_async(detail::CUDAScatter &scatter, unsigned int streamId, 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 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 setDisabledAgents(unsigned int numberOfDisabled)

Set the number of disabled agents within the state list Updates member var disabledAgents and data_condition for every item inside variables_unique

Parameters:

numberOfDisabled – The new number of disabled agents (this can increase of decrease)

void initVariables(std::set<std::shared_ptr<VariableBuffer>> &exclusionSet, const unsigned int initCount, const unsigned initOffset, detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Resets the value of all variables not present in exclusionSet to their defaults

This is useful for when an agent in a submodel is birthed, and it’s parent model requires variables initialising and other similar features

Parameters:
  • exclusionSet – Set of variable buffers not to be initialised

  • initCount – Total number of agents which require variables to be initialised

  • initOffset – Offset into the agent list to initialise variables from

  • 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

std::list<std::shared_ptr<VariableBuffer>> &getUniqueVariables()

Returns the collection of unique variable buffers held by this CUDAFatAgentStateList

void swap(CUDAFatAgentStateList *other)

Swaps the internals of the two buffers This is used when performing a state transition to an empty statelist

std::list<std::shared_ptr<VariableBuffer>> getBuffers(std::set<std::shared_ptr<VariableBuffer>> &exclusionSet)

Returns a list of variable buffers managed by the CUDAFatAgentStateList, which do not occur in exclusionSet

Note

Comparison checks for identical shared_ptr, not equality of VariableBuffer

Note

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

Parameters:

exclusionSet – A set of buffers to compare against