Class CurveRTCHost

Nested Relationships

Nested Types

Class Documentation

class CurveRTCHost

The Curve RTC host is a class for dynamically building a header file for use in RTC functions. Rather than providing a hashmap of string variable names it will dynamically create a header with agent variables directly accessible via compile time string comparisons. This must be kept around after the header has been compiled, as it also provides access for updating the data available via Curve

Public Functions

CurveRTCHost()

Default constructor

~CurveRTCHost()

Destructor Frees allocated memory

void registerAgentVariable(const char *variableName, const char *type, size_t type_size, unsigned int elements = 1, bool read = true, bool write = true)

Specify an agent variable to be included in the dynamic header

Parameters:
  • variableName – The variable’s name

  • type – The name of the variable’s type (std::type_index::name())

  • type_size – The type size of the variable’s base type (sizeof()), this is the size of a single element if the variable is an array variable.

  • elements – The number of elements in the variable (1 unless the variable is an array variable)

  • read – True if the variable should be readable

  • write – True if the variable should be writable

Throws:

exception::UnknownInternalError – If an agent variable with the same name is already registered

void registerMessageOutVariable(const char *variableName, const char *type, size_t type_size, unsigned int elements = 1, bool read = true, bool write = true)

Specify an output message variable to be included in the dynamic header

Parameters:
  • variableName – The variable’s name

  • type – The name of the variable’s type (std::type_index::name())

  • type_size – The type size of the variable’s base type (sizeof()), this is the size of a single element if the variable is an array variable.

  • elements – The number of elements in the variable (1 unless the variable is an array variable)

  • read – True if the variable should be readable

  • write – True if the variable should be writable

Throws:

exception::UnknownInternalError – If an output message variable with the same name is already registered

void registerMessageInVariable(const char *variableName, const char *type, size_t type_size, unsigned int elements = 1, bool read = true, bool write = true)

Specify an input message variable to be included in the dynamic header

Parameters:
  • variableName – The variable’s name

  • type – The name of the variable’s type (std::type_index::name())

  • type_size – The type size of the variable’s base type (sizeof()), this is the size of a single element if the variable is an array variable.

  • elements – The number of elements in the variable (1 unless the variable is an array variable)

  • read – True if the variable should be readable

  • write – True if the variable should be writable

Throws:

exception::UnknownInternalError – If an input message variable with the same name is already registered

void registerNewAgentVariable(const char *variableName, const char *type, size_t type_size, unsigned int elements = 1, bool read = true, bool write = true)

Specify an output agent variable (device agent birth) to be included in the dynamic header

Parameters:
  • variableName – The variable’s name

  • type – The name of the variable’s type (std::type_index::name())

  • type_size – The type size of the variable’s base type (sizeof()), this is the size of a single element if the variable is an array variable.

  • elements – The number of elements in the variable (1 unless the variable is an array variable)

  • read – True if the variable should be readable

  • write – True if the variable should be writable

Throws:

exception::UnknownInternalError – If an output agent variable with the same name is already registered

void registerEnvironmentDirectedGraphVertexProperty(const std::string &graphName, const std::string &propertyName, const char *type, size_t type_size, unsigned int elements = 1, bool read = true, bool write = false)

Specify an environment directed graph vertex property to be included in the dynamic header

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

  • type – The name of the property’s type (std::type_index::name())

  • type_size – The type size of the property’s base type (sizeof()), this is the size of a single element if the variable is an array property.

  • elements – The number of elements in the property (1 unless the property is an array property)

  • read – True if the property should be readable

  • write – True if the property should be writable

Throws:

exception::UnknownInternalError – If an environment directed graph vertex property with the same name is already registered

void registerEnvironmentDirectedGraphEdgeProperty(const std::string &graphName, const std::string &propertyName, const char *type, size_t type_size, unsigned int elements = 1, bool read = true, bool write = false)

Specify an environment directed graph edge property to be included in the dynamic header

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

  • type – The name of the property’s type (std::type_index::name())

  • type_size – The type size of the property’s base type (sizeof()), this is the size of a single element if the variable is an array property.

  • elements – The number of elements in the property (1 unless the property is an array property)

  • read – True if the property should be readable

  • write – True if the property should be writable

Throws:

exception::UnknownInternalError – If an environment directed graph edge property with the same name is already registered

void unregisterAgentVariable(const char *variableName)

Unregister an agent variable, so that it is nolonger included in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void unregisterMessageOutVariable(const char *variableName)

Unregister an output message variable, so that it is nolonger included in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void unregisterMessageInVariable(const char *variableName)

Unregister an input message variable, so that it is nolonger included in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void unregisterNewAgentVariable(const char *variableName)

Unregister an output agent variable (device agent birth), so that it is nolonger included in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void unregisterEnvironmentDirectedGraphVertexProperty(const std::string &graphName, const std::string &propertyName)

Unregister an environment directed graph vertex property, so that it is nolonger included in the dynamic header

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void unregisterEnvironmentDirectedGraphEdgeProperty(const std::string &graphName, const std::string &propertyName)

Unregister an environment directed graph edge property, so that it is nolonger included in the dynamic header

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void *getAgentVariableCachePtr(const char *variableName)

Returns a host pointer to the memory which stores the device pointer to be included for the specified variable in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void *getMessageOutVariableCachePtr(const char *variableName)

Returns a host pointer to the memory which stores the device pointer to be included for the specified variable in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void *getMessageInVariableCachePtr(const char *variableName)

Returns a host pointer to the memory which stores the device pointer to be included for the specified variable in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void *getNewAgentVariableCachePtr(const char *variableName)

Returns a host pointer to the memory which stores the device pointer to be included for the specified variable in the dynamic header

Parameters:

variableName – The variable’s name

Throws:

exception::UnknownInternalError – If the specified variable is not registered

void *getEnvironmentDirectedGraphVertexPropertyCachePtr(const std::string &graphName, const std::string &propertyName)

Returns a host pointer to the memory which stores the device pointer to be included for the specified property in the dynamic header

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

Throws:

exception::UnknownInternalError – If the specified property is not registered

void *getEnvironmentDirectedGraphEdgePropertyCachePtr(const std::string &graphName, const std::string &propertyName)

Returns a host pointer to the memory which stores the device pointer to be included for the specified property in the dynamic header

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

Throws:

exception::UnknownInternalError – If the specified property is not registered

void setAgentVariableCount(const std::string &variableName, unsigned int count)
void setMessageOutVariableCount(const std::string &variableName, unsigned int count)
void setMessageInVariableCount(const std::string &variableName, unsigned int count)
void setNewAgentVariableCount(const std::string &variableName, unsigned int count)
void setEnvironmentDirectedGraphVertexPropertyCount(const std::string &graphName, const std::string &propertyName, unsigned int count)

Set the number of vertices in the named buffer

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

  • count – The value to set

Throws:

exception::UnknownInternalError – If the specified property is not registered

void setEnvironmentDirectedGraphEdgePropertyCount(const std::string &graphName, const std::string &propertyName, unsigned int count)

Set the number of edges in the named buffer

Parameters:
  • graphName – The properties’s graph’s name

  • propertyName – The properties’s name

  • count – The value to set

Throws:

exception::UnknownInternalError – If the specified property is not registered

void registerEnvVariable(const char *propertyName, ptrdiff_t offset, const char *type, size_t type_size, unsigned int elements = 1)

Specify an environment property to be included in the dynamic header

Parameters:
  • propertyName – The property’s name

  • offset – The property’s offset within the environment property map (EnvironmentManager)

  • type – The name of the property’s type (std::type_index::name())

  • type_size – The type size of the property’s base type (sizeof()), this is the size of a single element if the property is an array property.

  • elements – The number of elements in the property (1 unless the property is an array property)

Throws:

exception::UnknownInternalError – If an environment property with the same name is already registered

void unregisterEnvVariable(const char *propertyName)

Unregister an environment property, so that it is nolonger included in the dynamic header

Parameters:

propertyName – The property’s name

Throws:

exception::UnknownInternalError – If the specified property is not registered

void registerEnvMacroProperty(const char *propertyName, void *d_ptr, const char *type, size_t type_size, const std::array<unsigned int, 4> &dimensions)

Specify an environment macro property to be included in the dynamic header

Parameters:
  • propertyName – The property’s name

  • d_ptr – Pointer to the buffer in device memory

  • type – The name of the property’s type (std::type_index::name())

  • type_size – The type size of the property’s base type (sizeof()), this is the size of a single element if the property is an array property.

  • dimensions – The number of elements in the property (1 unless the property is an array property)

Throws:

exception::UnknownInternalError – If an environment property with the same name is already registered

void unregisterEnvMacroProperty(const char *propertyName)

Unregister an environment property, so that it is nolonger included in the dynamic header

Parameters:

propertyName – The property’s name

Throws:

exception::UnknownInternalError – If the specified property is not registered

void registerAgent(const std::string &agentName, const std::string &agentState)

Register the name of the agent and it’s state of the agent function

Used by ReadOnlyDeviceAPI::isAgent() and ReadOnlyDeviceAPI::isState()

Parameters:
  • agentName – Name of the agent

  • agentState – Name of the agent’s state

Throws:

exception::UnknownInternalError – If the agent has already been registered

void setFileName(const std::string &filename)

Set the filename tagged in the file (goes into a #line statement)

Note

Do not include quotes

Parameters:

filename – Name to be used for the file in compile errors

std::string getDynamicHeader(size_t env_buffer_len)

Generates and returns the dynamic header based on the currently registered variables and properties

Parameters:

env_buffer_len – Length of the environment managers buffer

Returns:

The dynamic Curve header

void updateEnvCache(const void *d_env_ptr, const size_t bufferLen)

Copies the environment managers cache to the rtc header cache

Parameters:
  • d_env_ptr – Device pointer to the Environment managers cache

  • bufferLen – Length of the buffer

void updateDevice_async(const jitify::experimental::KernelInstantiation &instance, cudaStream_t stream)

Copy h_data_buffer to device

Note

This is async, the stream is non synchronised

Parameters:
  • instance – The compiled RTC agent function instance to copy the environment cache to

  • stream – The CUDA stream used for the cuda memcpy

Public Static Functions

static std::string getVariableSymbolName()
Returns:

The identifier used for the environment property cache within the dynamic header

static std::string demangle(const char *verbose_name)

Demangle a verbose type name (e.g. std::type_index.name().c_str()) into a user readable type This is required as different compilers will perform name mangling in different way (or not at all).

Parameters:

verbose_name – The verbose type name to be demangled

Returns:

The demangled type name

static std::string demangle(const std::type_index &type)

Demangle from a std::type_index into a user readable type This is required as different compilers will perform name mangling in different way (or not at all).

Parameters:

type – The type to return the demangled name for

Returns:

The demangled type name of the provided type

Protected Functions

void setHeaderPlaceholder(std::string placeholder, std::string dst)

Utility method for replacing tokens within the dynamic header with dynamically computed strings

Parameters:
  • placeholder – String to locate within the header

  • dst – Replacement for the string located within the header

Throws:

exception::UnknownInternalError – If placeholder could not be found within the header

struct RTCEnvMacroPropertyProperties

Properties for a registered environment macro property

Public Members

std::string type

Name of the property’s base type (e.g. type of an individual element if array property)

std::array<unsigned int, 4> dimensions

Number of elemements in each dimension

size_t type_size

Size of the property’s base type (e.g. size of an individual element if array property)

void *d_ptr

Copy of the device pointer

Note

This assumes it will never be reallocated/resized after registration

void *h_data_ptr

Pointer to a location in host memory where the device pointer to this variables buffer must be stored

struct RTCEnvVariableProperties

Properties for a registered environment property

Public Members

std::string type

Name of the property’s base type (e.g. type of an individual element if array property)

unsigned int elements

Number of elements, 1 unless an array property

ptrdiff_t offset

Offset to the properties data inside the EnvironmentManager’s RTC cache

size_t type_size

Size of the property’s base type (e.g. size of an individual element if array property)

struct RTCVariableProperties

Properties for a registered agent/message-in/message-out/agent-out variable

Public Members

std::string type

Name of the variable’s base type (e.g. type of an individual element if array variable)

bool read

True if the variable should be readable

bool write

True if the variable should be writable

unsigned int elements

Number of elements, 1 unless an array variable

size_t type_size

Size of the variable’s base type (e.g. size of an individual element if array variable)

void *h_data_ptr

Pointer to a location in host memory where the device pointer to this variables buffer must be stored

unsigned int count_index

Index in the count buffer where the count is stored Count being the number of agents/messages/vertices/edges etc in the buffer