Class CUDASimulation

Inheritance Relationships

Base Type

Class Documentation

class CUDASimulation : public Simulation

CUDA runner for Simulation interface Executes a FGPU2 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

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 inititialise() 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..

Returns

False if an exit condition was triggered

virtual void simulate() override

Execute the simulation until config.steps have been executed, or an exit condition trips Includes init and exit functions calls.

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

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

InvalidCudaAgent – If the agent type is not recognised

CUDAAgent &getCUDAAgent(const std::string &agent_name) const

Returns the manager for the specified agent

Todo:

remove? this is mostly internal methods that modeller doesn’t need access to

virtual AgentInterface &getAgent(const std::string &name) override
CUDAMessage &getCUDAMessage(const std::string &message_name) const

Returns the manager for the specified agent

Todo:

remove? this is mostly internal methods that modeller doesn’t need access to

Config &CUDAConfig()

See

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

virtual const RunLog &getRunLog() const

Returns a reference to the current exit log

void RTCSafeCudaMemcpyToSymbol(const void *symbol, const char *rtc_symbol_name, const void *src, size_t count, size_t offset = 0) const

Performs a cudaMemCopyToSymbol in the runtime library and also updates the symbols of any RTC functions (which exist separately within their own cuda module) Will thrown an error if any of the calls fail.

Parameters
  • symbol – A device symbol

  • rtc_symbol_name – The name of the symbol

  • src – Source memory address

  • count – Size in bytes to copy

  • offset – Offset from start of symbol in bytes

void RTCSafeCudaMemcpyToSymbolAddress(void *ptr, const char *rtc_symbol_name, const void *src, size_t count, size_t offset = 0) const

Performs a cudaMemCopy to a pointer in the runtime library and also updates the symbols of any RTC functions (which exist separately within their own cuda module) Will thrown an error if any of the calls fail.

Parameters
  • ptr – a pointer to a symbol in device memory

  • rtc_symbol_name – The name of the symbol

  • src – Source memory address

  • count – Size in bytes to copy

  • offset – Offset from start of symbol in bytes

float getElapsedTimeRTCInitialisation() const

Get the duration of the last time RTC was iniitliased With a resolution of around 0.5 microseconds (cudaEventElapsedtime)

Returns

elapsed time of last simulation call in milliseconds.

float getElapsedTimeSimulation() const

Get the duration of the last call to simulate() in milliseconds. With a resolution of around 0.5 microseconds (cudaEventElapsedtime)

Returns

elapsed time of last simulation call in milliseconds.

float getElapsedTimeInitFunctions() const

Get the duration of the last call to initFunctions() in milliseconds. With a resolution of around 0.5 microseconds (cudaEventElapsedtime)

Returns

elapsed time of last simulation call in milliseconds.

float getElapsedTimeExitFunctions() const

Get the duration of the last call to stepFunctions() in milliseconds. With a resolution of around 0.5 microseconds (cudaEventElapsedtime)

Returns

elapsed time of last simulation call in milliseconds.

std::vector<float> getElapsedTimeSteps() const

Get the duration of each step() since the last call to reset Timing resolution of around 0.5 microseconds (CudaEventElapsedTime)

Returns

vector of step times

float getElapsedTimeStep(unsigned int step) const

Get the duration of an individual step in milliseconds. Timing resolution of around 0.5 microseconds.

Parameters

step – Index of step, must be less than the number of steps executed.

Returns

elapsed time of required step in milliseconds

inline unsigned int getInstanceID() const

Returns the unique instance id of this CUDASimulation instance

Note

This value is used internally for environment property storage

Public Static Attributes

static bool AUTO_CUDA_DEVICE_RESET = true

If changed to false, will not auto cudaDeviceReset when final CUDASimulation instance is destructed

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

CUDASimulation::CUDAConfig()

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

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

Simulation::printHelp()

virtual void resetDerivedConfig() override

Called at the start of Simulation::initialise(int, const char**) to reset runner specific config struct

See

Simulation::initialise(int, const char**)

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.