Class CUDASimulation
Defined in File CUDASimulation.h
Nested Relationships
Nested Types
Inheritance Relationships
Base Type
public flamegpu::Simulation
(Class Simulation)
Class Documentation
-
class CUDASimulation : public flamegpu::Simulation
CUDA runner for Simulation interface Executes a FLAMEGPU2 model using GPU
Public Types
-
typedef std::vector<NewAgentStorage> AgentDataBuffer
-
typedef std::unordered_map<std::string, AgentDataBuffer> AgentDataBufferStateMap
-
typedef std::unordered_map<std::string, VarOffsetStruct> AgentOffsetMap
-
typedef std::unordered_map<std::string, AgentDataBufferStateMap> AgentDataMap
Public Functions
-
inline explicit CUDASimulation(const ModelDescription &model, int argc = 0, const char **argv = nullptr)
Initialise cuda runner Allocates memory for agents/messages, copies environment properties to device etc If provided, you can pass runtime arguments to this constructor, to automatically call inititialise() This is not required, you can call initialise() manually later, or not at all.
- Parameters:
model – The model description to initialise the runner to execute
argc – Runtime argument count
argv – Runtime argument list ptr
-
virtual ~CUDASimulation()
Inverse operation of contructor
-
virtual void initFunctions() override
Run the initFunctions of Simulation
-
virtual bool step() override
Steps the simulation once
- Returns:
False if an exit condition was triggered
-
virtual void exitFunctions() override
Run the exitFunctions of the Simulation..
-
virtual void simulate() override
Execute the simulation until config.steps have been executed, or an exit condition trips Includes init and exit functions calls.
-
void simulate(const RunPlan &plan)
Execute the simulation using the configuration and environment properties from the provided RunPlan
Note
The config.steps and config.random_seed values will be ignored, in favour of those provided by the RunPlan
- Parameters:
plan – The RunPlan to use to execute the simulation
- Throws:
exception::InvalidArgument – If the provided RunPlan does not match the CUDASimulation’s ModelDescription
-
virtual void setPopulationData(AgentVector &population, const std::string &state_name = ModelData::DEFAULT_STATE) override
Replaces internal population data for the specified agent
- Parameters:
population – The agent type and data to replace agents with
state_name – The agent state to add the agents to
- Throws:
exception::InvalidCudaAgent – If the agent type is not recognised
-
virtual void getPopulationData(AgentVector &population, const std::string &state_name = ModelData::DEFAULT_STATE) override
Returns the internal population data for the specified agent
- Parameters:
population – The agent type and data to fetch
state_name – The agent state to get the agents from
- Throws:
exception::InvalidCudaAgent – If the agent type is not recognised
-
template<typename T>
void setEnvironmentProperty(const std::string &property_name, T value) Update the current value of the named environment property
- Parameters:
property_name – Name of the environment property to be updated
value – New value for the named environment property
- Template Parameters:
T – Type of the environment property
- Throws:
exception::InvalidEnvPropertyType – If the named environment property does not exist with the specified type
exception::ReadOnlyEnvProperty – If the named environment property is marked as read-only
-
template<typename T, flamegpu::size_type N>
void setEnvironmentProperty(const std::string &property_name, const std::array<T, N> &value) Update the current value of the named environment property array
- Parameters:
property_name – Name of the environment property to be updated
value – New value for the named environment property
- Template Parameters:
T – Type of the elements of the environment property array
- Throws:
exception::InvalidEnvPropertyType – If the named environment property does not exist with the specified type
exception::ReadOnlyEnvProperty – If the named environment property is marked as read-only
-
template<typename T, flamegpu::size_type N = 0>
void setEnvironmentProperty(const std::string &property_name, flamegpu::size_type index, T value) Update the value of the specified element of the named environment property array
- Parameters:
property_name – Name of the environment property to be updated
index – Index of the element within the property array to be updated
value – New value for the named environment property
- Template Parameters:
T – Type of the elements of the environment property array
N – (Optional) The length of the array variable, available for parity with other APIs, checked if provided
- Throws:
exception::InvalidEnvPropertyType – If the named environment property does not exist with the specified type
exception::ReadOnlyEnvProperty – If the named environment property is marked as read-only
-
template<typename T>
T getEnvironmentProperty(const std::string &property_name) Return the current value of the named environment property
- Parameters:
property_name – Name of the environment property to be returned
- Template Parameters:
T – Type of the environment property
- Throws:
exception::InvalidEnvPropertyType – If the named environment property does not exist with the specified type
-
template<typename T, flamegpu::size_type N>
std::array<T, N> getEnvironmentProperty(const std::string &property_name) Return the current value of the named environment property array
- Parameters:
property_name – Name of the environment property to be returned
- Template Parameters:
T – Type of the elements of the environment property array
- Throws:
exception::InvalidEnvPropertyType – If the named environment property does not exist with the specified type
-
template<typename T, flamegpu::size_type N = 0>
T getEnvironmentProperty(const std::string &property_name, flamegpu::size_type index) Return the current value of the specified element of the named environment property array
- Parameters:
property_name – Name of the environment property to be returned
index – Index of the element within the property array to be returned
- Template Parameters:
T – Type of the elements of the environment property array
N – (Optional) The length of the array variable, available for parity with other APIs, checked if provided
- Throws:
exception::InvalidEnvPropertyType – If the named environment property does not exist with the specified type
-
Config &CUDAConfig()
See also
Simulation::applyConfig() Should be called afterwards to apply changes
- Returns:
A mutable reference to the cuda model specific configuration struct
-
virtual unsigned int getStepCounter() override
Returns the number of times step() has been called since the simulation was last reset/init
-
virtual void resetStepCounter() override
Manually resets the step counter
-
const Config &getCUDAConfig() const
- Returns:
An immutable reference to the cuda model specific configuration struct
-
void setStepLog(const StepLoggingConfig &stepConfig)
Configure which step data should be logged
Note
This must be for the same model description hierarchy as the CUDASimulation
- Parameters:
stepConfig – The step logging config for the CUDASimulation
-
void setExitLog(const LoggingConfig &exitConfig)
Configure which exit data should be logged
Note
This must be for the same model description hierarchy as the CUDASimulation
- Parameters:
exitConfig – The logging config for the CUDASimulation
-
visualiser::ModelVis getVisualisation()
Creates (on first call) and returns the visualisation configuration options for this model instance
-
double getElapsedTimeRTCInitialisation() const
Get the duration of the last time RTC was iniitliased
- Returns:
elapsed time of last simulation call in seconds.
-
double getElapsedTimeSimulation() const
Get the duration of the last call to simulate() in seconds.
- Returns:
elapsed time of last simulation call in seconds.
-
double getElapsedTimeInitFunctions() const
Get the duration of the last call to initFunctions() in seconds.
- Returns:
elapsed time of last simulation call in seconds.
-
double getElapsedTimeExitFunctions() const
Get the duration of the last call to stepFunctions() in seconds.
- Returns:
elapsed time of last simulation call in seconds.
-
std::vector<double> getElapsedTimeSteps() const
Get the duration of each step() since the last call to
reset
- Returns:
vector of step times
-
double getElapsedTimeStep(unsigned int step) const
Get the duration of an individual step in seconds.
- Parameters:
step – Index of step, must be less than the number of steps executed.
- Returns:
elapsed time of required step in seconds
-
inline unsigned int getInstanceID() const
Returns the unique instance id of this CUDASimulation instance
Note
This value is used internally for environment property storage
Protected Functions
-
virtual void reset(bool submodelReset) override
Returns the model to a clean state This clears all agents and message lists, resets environment properties and reseeds random generation. Also calls resetStepCounter();
Note
If triggered on a submodel, agent states and environment properties mapped to a parent agent, and random generation are not affected.
Note
If random was manually seeded, it will return to it’s original state. If random was seeded from time, it will return to a new random state.
- Parameters:
submodelReset – This should only be set to true when called automatically when a submodel reaches it’s exit condition during execution. This performs a subset of the regular reset procedure.
-
virtual void applyConfig_derived() override
Called by Simulation::applyConfig() to trigger any runner specific configs
See also
-
virtual bool checkArgs_derived(int argc, const char **argv, int &i) override
Called by Simulation::checkArgs() to trigger any runner specific argument checking This only handles arg 0 before returning
See also
Simulation::checkArgs()
- Returns:
True if the argument was handled successfully
-
virtual void printHelp_derived() override
Called by Simulation::printHelp() to print help for runner specific runtime args
See also
Simulation::printHelp()
Protected Attributes
-
const bool isPureRTC
If true, the model is pureRTC, and hence does not use non-RTC curve
-
const bool isSWIG
If true, the model is using SWIG Python interface
Friends
- friend class detail::AbstractSimRunner
- friend class visualiser::ModelVis
- friend struct visualiser::ModelVisData
-
struct Config
CUDA runner specific config
Public Members
-
int device_id = 0
GPU to execute model on Defaults to device 0, this is most performant device as detected by CUDA
-
bool inLayerConcurrency = true
Enable / disable the use of concurrency within a layer. Defaults to enabled.
Friends
- friend class detail::AbstractSimRunner
- friend class CUDASimulation
- friend class HostAPI
-
int device_id = 0
-
typedef std::vector<NewAgentStorage> AgentDataBuffer