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, unsigned int _fat_index, const AgentData &description, bool _isSubStateList = false)

Construct a CUDAAgentStateList view into the provided fat_list

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

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.

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

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

See also

CUDAFatAgentStateList::resize(unsigned int, bool)

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

  • retainData – If true existing buffer data is retained

  • stream – The stream used to perform memcpys if 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, detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Store agent data from agent state memory into state list

Parameters:
  • data – data Source for agent data

  • scatter – Scatter instance and scan arrays to be used

  • 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 getAgentData(AgentVector &data) const

Retrieve agent data from the agent state list into agent state memory

Parameters:

data – data Destination for agent data

void scatterHostCreation(unsigned int newSize, char *const d_inBuff, const VarOffsetStruct &offsets, detail::CUDAScatter &scatter, unsigned int streamId, 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 – 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 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

unsigned int scatterNew(void *d_newBuff, unsigned int newSize, detail::CUDAScatter &scatter, unsigned int streamId, 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&, unsigned int, 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 – 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 newly birthed agents

bool getIsSubStatelist()

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

void initUnmappedVars(detail::CUDAScatter &scatter, unsigned int streamId, 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 – 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 initExcludedVars(unsigned int count, unsigned int offset, CUDAScatter &scatter, unsigned int streamId, 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 – 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 clear()

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

void setAgentCount(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:

exception::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