Kompute
Public Member Functions | List of all members
kp::Sequence Class Reference

#include <Sequence.hpp>

Inheritance diagram for kp::Sequence:
Inheritance graph
[legend]
Collaboration diagram for kp::Sequence:
Collaboration graph
[legend]

Public Member Functions

 Sequence (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, std::shared_ptr< vk::Queue > computeQueue, uint32_t queueIndex, uint32_t totalTimestamps=0)
 
 ~Sequence ()
 
std::shared_ptr< Sequencerecord (std::shared_ptr< OpBase > op)
 
template<typename T , typename... TArgs>
std::shared_ptr< Sequencerecord (std::vector< std::shared_ptr< Tensor >> tensors, TArgs &&... params)
 
template<typename T , typename... TArgs>
std::shared_ptr< Sequencerecord (std::shared_ptr< Algorithm > algorithm, TArgs &&... params)
 
std::shared_ptr< Sequenceeval ()
 
std::shared_ptr< Sequenceeval (std::shared_ptr< OpBase > op)
 
template<typename T , typename... TArgs>
std::shared_ptr< Sequenceeval (std::vector< std::shared_ptr< Tensor >> tensors, TArgs &&... params)
 
template<typename T , typename... TArgs>
std::shared_ptr< Sequenceeval (std::shared_ptr< Algorithm > algorithm, TArgs &&... params)
 
std::shared_ptr< SequenceevalAsync ()
 
std::shared_ptr< SequenceevalAsync (std::shared_ptr< OpBase > op)
 
template<typename T , typename... TArgs>
std::shared_ptr< SequenceevalAsync (std::vector< std::shared_ptr< Tensor >> tensors, TArgs &&... params)
 
template<typename T , typename... TArgs>
std::shared_ptr< SequenceevalAsync (std::shared_ptr< Algorithm > algorithm, TArgs &&... params)
 
std::shared_ptr< SequenceevalAwait (uint64_t waitFor=UINT64_MAX)
 
void clear ()
 
std::vector< std::uint64_t > getTimestamps ()
 
void begin ()
 
void end ()
 
bool isRecording () const
 
bool isInit () const
 
void rerecord ()
 
bool isRunning () const
 
void destroy ()
 

Detailed Description

Container of operations that can be sent to GPU as batch

Constructor & Destructor Documentation

◆ Sequence()

kp::Sequence::Sequence ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
std::shared_ptr< vk::Queue >  computeQueue,
uint32_t  queueIndex,
uint32_t  totalTimestamps = 0 
)

Main constructor for sequence which requires core vulkan components to generate all dependent resources.

Parameters
physicalDeviceVulkan physical device
deviceVulkan logical device
computeQueueVulkan compute queue
queueIndexVulkan compute queue index in device
totalTimestampsMaximum number of timestamps to allocate

◆ ~Sequence()

kp::Sequence::~Sequence ( )

Destructor for sequence which is responsible for cleaning all subsequent owned operations.

Member Function Documentation

◆ begin()

void kp::Sequence::begin ( )

Begins recording commands for commands to be submitted into the command buffer.

◆ clear()

void kp::Sequence::clear ( )

Clear function clears all operations currently recorded and starts recording again.

◆ destroy()

void kp::Sequence::destroy ( )

Destroys and frees the GPU resources which include the buffer and memory and sets the sequence as init=False.

◆ end()

void kp::Sequence::end ( )

Ends the recording and stops recording commands when the record command is sent.

◆ eval() [1/4]

std::shared_ptr<Sequence> kp::Sequence::eval ( )

Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job synchronously (with a barrier).

Returns
shared_ptr<Sequence> of the Sequence class itself

◆ eval() [2/4]

template<typename T , typename... TArgs>
std::shared_ptr<Sequence> kp::Sequence::eval ( std::shared_ptr< Algorithm algorithm,
TArgs &&...  params 
)
inline

Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier.

Parameters
algorithmAlgorithm to use for the record often used for OpAlgo operations
TArgsTemplate parameters that are used to initialise operation which allows for extensible configurations on initialisation.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ eval() [3/4]

std::shared_ptr<Sequence> kp::Sequence::eval ( std::shared_ptr< OpBase op)

Resets all the recorded and stored operations, records the operation provided and submits into the gpu as a submit job synchronously (with a barrier).

Returns
shared_ptr<Sequence> of the Sequence class itself

◆ eval() [4/4]

template<typename T , typename... TArgs>
std::shared_ptr<Sequence> kp::Sequence::eval ( std::vector< std::shared_ptr< Tensor >>  tensors,
TArgs &&...  params 
)
inline

Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier.

Parameters
tensorsVector of tensors to use for the operation
TArgsTemplate parameters that are used to initialise operation which allows for extensible configurations on initialisation.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ evalAsync() [1/4]

std::shared_ptr<Sequence> kp::Sequence::evalAsync ( )

Eval Async sends all the recorded and stored operations in the vector of operations into the gpu as a submit job without a barrier. EvalAwait() must ALWAYS be called after to ensure the sequence is terminated correctly.

Returns
Boolean stating whether execution was successful.

◆ evalAsync() [2/4]

template<typename T , typename... TArgs>
std::shared_ptr<Sequence> kp::Sequence::evalAsync ( std::shared_ptr< Algorithm algorithm,
TArgs &&...  params 
)
inline

Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier.

Parameters
algorithmAlgorithm to use for the record often used for OpAlgo operations
TArgsTemplate parameters that are used to initialise operation which allows for extensible configurations on initialisation.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ evalAsync() [3/4]

std::shared_ptr<Sequence> kp::Sequence::evalAsync ( std::shared_ptr< OpBase op)

Clears currnet operations to record provided one in the vector of operations into the gpu as a submit job without a barrier. EvalAwait() must ALWAYS be called after to ensure the sequence is terminated correctly.

Returns
Boolean stating whether execution was successful.

◆ evalAsync() [4/4]

template<typename T , typename... TArgs>
std::shared_ptr<Sequence> kp::Sequence::evalAsync ( std::vector< std::shared_ptr< Tensor >>  tensors,
TArgs &&...  params 
)
inline

Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier.

Parameters
tensorsVector of tensors to use for the operation
TArgsTemplate parameters that are used to initialise operation which allows for extensible configurations on initialisation.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ evalAwait()

std::shared_ptr<Sequence> kp::Sequence::evalAwait ( uint64_t  waitFor = UINT64_MAX)

Eval Await waits for the fence to finish processing and then once it finishes, it runs the postEval of all operations.

Parameters
waitForNumber of milliseconds to wait before timing out.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ getTimestamps()

std::vector<std::uint64_t> kp::Sequence::getTimestamps ( )

Return the timestamps that were latched at the beginning and after each operation during the last eval() call.

◆ isInit()

bool kp::Sequence::isInit ( ) const

Returns true if the sequence has been initialised, and it's based on the GPU resources being referenced.

Returns
Boolean stating if is initialized

◆ isRecording()

bool kp::Sequence::isRecording ( ) const

Returns true if the sequence is currently in recording activated.

Returns
Boolean stating if recording ongoing.

◆ isRunning()

bool kp::Sequence::isRunning ( ) const

Returns true if the sequence is currently running - mostly used for async workloads.

Returns
Boolean stating if currently running.

◆ record() [1/3]

template<typename T , typename... TArgs>
std::shared_ptr<Sequence> kp::Sequence::record ( std::shared_ptr< Algorithm algorithm,
TArgs &&...  params 
)
inline

Record function for operation to be added to the GPU queue in batch. This template requires classes to be derived from the OpBase class. This function also requires the Sequence to be recording, otherwise it will not be able to add the operation.

Parameters
algorithmAlgorithm to use for the record often used for OpAlgo operations
TArgsTemplate parameters that are used to initialise operation which allows for extensible configurations on initialisation.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ record() [2/3]

std::shared_ptr<Sequence> kp::Sequence::record ( std::shared_ptr< OpBase op)

Record function for operation to be added to the GPU queue in batch. This template requires classes to be derived from the OpBase class. This function also requires the Sequence to be recording, otherwise it will not be able to add the operation.

Parameters
opObject derived from kp::BaseOp that will be recoreded by the sequence which will be used when the operation is evaluated.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ record() [3/3]

template<typename T , typename... TArgs>
std::shared_ptr<Sequence> kp::Sequence::record ( std::vector< std::shared_ptr< Tensor >>  tensors,
TArgs &&...  params 
)
inline

Record function for operation to be added to the GPU queue in batch. This template requires classes to be derived from the OpBase class. This function also requires the Sequence to be recording, otherwise it will not be able to add the operation.

Parameters
tensorsVector of tensors to use for the operation
TArgsTemplate parameters that are used to initialise operation which allows for extensible configurations on initialisation.
Returns
shared_ptr<Sequence> of the Sequence class itself

◆ rerecord()

void kp::Sequence::rerecord ( )

Clears command buffer and triggers re-record of all the current operations saved, which is useful if the underlying kp::Tensors or kp::Algorithms are modified and need to be re-recorded.


The documentation for this class was generated from the following file: