Class CUDAMessage

Class Documentation

class CUDAMessage

This class is CUDASimulation’s internal handler for message functionality

Public Functions

explicit CUDAMessage(const MessageBruteForce::Data &description, const CUDASimulation &cudaSimulation)

Constructs a CUDAMessage object Allocates enough memory for each variable within the provided MessageData

Parameters:
  • description – The message to represent

  • cudaSimulation – The simulation which owns the CUDAMessage

virtual ~CUDAMessage(void)

Destructor, releases CUDA memory

const MessageBruteForce::Data &getMessageData() const

Return an immutable reference to the message description represented by the CUDAMessage instance

unsigned int getMaximumListSize() const
Returns:

The currently allocated length of the message array (in the number of messages)

unsigned int getMessageCount() const
Returns:

The current number of messages

void setMessageCount(unsigned int _message_count)

Manually update the message count

Note

This should be used cautiously

Note

Required by array message types

void init(detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Initialise the CUDAMessagelist This allocates and initialises any CUDA data structures for reading the messagelist, and sets them asthough the messagelist were empty.

Parameters:
  • scatter – Scatter instance and scan arrays to be used (CUDASimulation::singletons->scatter)

  • streamId – Index of stream specific structures used

  • stream – The CUDAStream to use for CUDA operations

void resize(unsigned int newSize, detail::CUDAScatter &scatter, cudaStream_t stream, unsigned int streamId, unsigned int keepLen = 0)

Updates message_count to equal newSize, internally reallocates buffer space if more space is required

Parameters:
  • newSize – The number of messages that the buffer should be capable of storing

  • scatter – Scatter instance and scan arrays to be used (CUDASimulation::singletons->scatter)

  • stream – The CUDAStream to use for CUDA operations

  • streamId – Index of stream specific structures used

  • keepLen – Number of existing messages worth of data to retain through the resize

void mapReadRuntimeVariables(const AgentFunctionData &func, const CUDAAgent &cuda_agent) const

Uses the cuRVE runtime to map the variables used by the agent function to the cuRVE library so that can be accessed by name within a n agent function The read runtime variables are to be used when reading messages

Parameters:
  • func – The agent function, this is used for the cuRVE hash mapping

  • cuda_agent – Agent which owns the agent function (condition) being mapped, if RTC function this holds the RTC header

void mapWriteRuntimeVariables(const AgentFunctionData &func, const CUDAAgent &cuda_agent, unsigned int writeLen, cudaStream_t stream) const

Uses the cuRVE runtime to map the variables used by the agent function to the cuRVE library so that can be accessed by name within a n agent function The write runtime variables are to be used when creating messages, as they are output to swap space

Note

swap() or scatter() should be called after the agent function has written messages

Parameters:
  • func – The agent function, this is used for the cuRVE hash mapping

  • cuda_agent – Agent which owns the agent function (condition) being mapped, if RTC function this holds the RTC header

  • writeLen – The number of messages to be output, as the length isn’t updated till after output

  • stream – The CUDAStream to use for CUDA operations

void *getReadPtr(const std::string &var_name)
inline const CUDAMessageMap &getReadList()
inline const CUDAMessageMap &getWriteList()
void swap(bool isOptional, unsigned int newMessageCount, detail::CUDAScatter &scatter, cudaStream_t stream, unsigned int streamId)

Swaps the two internal maps within message_list

Parameters:
  • isOptional – If optional newMessageCount will be reduced based on scan_flag[streamId]

  • newMessageCount – The number of output messages (including optional messages which were not output)

  • scatter – Scatter instance and scan arrays to be used (CUDASimulation::singletons->scatter)

  • stream – The CUDAStream to use for CUDA operations

  • streamId – Index of stream specific structures used

Throws:

exception::InvalidCudaMessage – If this is called before the internal buffers have been allocated

void swap()

Basic list swap with no additional actions

inline bool getTruncateMessageListFlag() const
inline void setTruncateMessageListFlag()
inline void clearTruncateMessageListFlag()
inline bool getPBMConstructionRequiredFlag() const
inline void setPBMConstructionRequiredFlag()
inline void clearPBMConstructionRequiredFlag()
void buildIndex(detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream)

Builds index, required to read messages (some messaging types won’t require an implementation)

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

const void *getMetaDataDevicePtr() const

Protected Functions

void zeroAllMessageData(cudaStream_t stream)

Zero all message variable data.