Class ReadOnlyDeviceAPI

Class Documentation

class ReadOnlyDeviceAPI

FLAMEGPU_API is a singleton class for the device runtime.

Public Functions

__device__ inline ReadOnlyDeviceAPI(detail::curandState *&d_rng)
Parameters:

d_rng – Pointer to the device random state buffer to be used

template<typename T, unsigned int N>
__device__ T getVariable(const char (&variable_name)[N]) const

Returns the specified variable from the currently executing agent

Parameters:

variable_name – name used for accessing the variable, this value should be a string literal e.g. “foobar”

Template Parameters:
  • T – Type of the agent variable being accessed

  • N – Length of variable name, this should always be implicit if passing a string literal

Throws:
  • exception::DeviceError – If name is not a valid variable within the agent (flamegpu must be built with FLAMEGPU_SEATBELTS enabled for device error checking)

  • exception::DeviceError – If T is not the type of variable ‘name’ within the agent (flamegpu must be built with FLAMEGPU_SEATBELTS enabled for device error checking)

template<typename T, unsigned int N, unsigned int M>
__device__ T getVariable(const char (&variable_name)[M], unsigned int index) const

Returns the specified variable array element from the currently executing agent

Parameters:
  • variable_name – name used for accessing the variable, this value should be a string literal e.g. “foobar”

  • index – Index of the element within the variable array to return

Template Parameters:
  • T – Type of the agent variable being accessed

  • N – The length of the array variable, as set within the model description hierarchy

  • M – Length of variable_name, this should always be implicit if passing a string literal

Throws:
  • exception::DeviceError – If name is not a valid variable within the agent (flamegpu must be built with FLAMEGPU_SEATBELTS enabled for device error checking)

  • exception::DeviceError – If T is not the type of variable ‘name’ within the agent (flamegpu must be built with FLAMEGPU_SEATBELTS enabled for device error checking)

  • exception::DeviceError – If index is out of bounds for the variable array specified by name (flamegpu must be built with FLAMEGPU_SEATBELTS enabled for device error checking)

__device__ inline id_t getID()

Returns the agent’s unique identifier

__forceinline__ __device__ inline unsigned int getStepCounter() const

Access the current stepCount

Returns:

the current step count, 0 indexed unsigned.

__forceinline__ __device__ inline bool isAgent(const char *agent_name)

When passed an agent name, returns a boolean to confirm whether it matches the name of the current agent

This function may be useful if an agent function is shared between multiple agents

Note

The performance of this function is unlikely to be cheap unless used as part of an RTC agent function.

__forceinline__ __device__ inline bool isState(const char *agent_state)

When passed an agent state, returns a boolean to confirm whether it matches the name of the agent input state of the current agent function

This function may be useful if an agent function is shared between multiple agent states

Note

The performance of this function is unlikely to be cheap unless used as part of an RTC agent function (whereby it can be processed at compile time).

Public Members

const AgentRandom random

Provides access to random functionality inside agent functions

Note

random state isn’t stored within the object, so it can be const

const ReadOnlyDeviceEnvironment environment

Provides access to environment variables inside agent functions

Public Static Functions

__forceinline__ __device__ static inline unsigned int getIndex()

Returns the current index of the agent within the state list population. As agents are mapped linearly to a unique thread this is in effect the thread index within the execution grid block. The index may change between agent functions as a result of state list transitions or other internal algorithms which effect order. Thread indices begin at 0 and continue to 1 below the number of agents executing