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

#include <Algorithm.hpp>

Public Member Functions

template<typename S = float, typename P = float>
 Algorithm (std::shared_ptr< vk::Device > device, const std::vector< std::shared_ptr< Tensor >> &tensors={}, const std::vector< uint32_t > &spirv={}, const Workgroup &workgroup={}, const std::vector< S > &specializationConstants={}, const std::vector< P > &pushConstants={})
 
template<typename S = float, typename P = float>
void rebuild (const std::vector< std::shared_ptr< Tensor >> &tensors, const std::vector< uint32_t > &spirv, const Workgroup &workgroup={}, const std::vector< S > &specializationConstants={}, const std::vector< P > &pushConstants={})
 
 ~Algorithm ()
 
void recordDispatch (const vk::CommandBuffer &commandBuffer)
 
void recordBindCore (const vk::CommandBuffer &commandBuffer)
 
void recordBindPush (const vk::CommandBuffer &commandBuffer)
 
bool isInit ()
 
void setWorkgroup (const Workgroup &workgroup, uint32_t minSize=1)
 
template<typename T >
void setPushConstants (const std::vector< T > &pushConstants)
 
void setPushConstants (void *data, uint32_t size, uint32_t memorySize)
 
const Workgroup & getWorkgroup ()
 
template<typename T >
const std::vector< T > getSpecializationConstants ()
 
template<typename T >
const std::vector< T > getPushConstants ()
 
const std::vector< std::shared_ptr< Tensor > > & getTensors ()
 
void destroy ()
 

Detailed Description

Abstraction for compute shaders that are run on top of tensors grouped via ParameterGroups (which group descriptorsets)

Constructor & Destructor Documentation

◆ Algorithm()

template<typename S = float, typename P = float>
kp::Algorithm::Algorithm ( std::shared_ptr< vk::Device >  device,
const std::vector< std::shared_ptr< Tensor >> &  tensors = {},
const std::vector< uint32_t > &  spirv = {},
const Workgroup &  workgroup = {},
const std::vector< S > &  specializationConstants = {},
const std::vector< P > &  pushConstants = {} 
)
inline

Main constructor for algorithm with configuration parameters to create the underlying resources.

Parameters
deviceThe Vulkan device to use for creating resources
tensors(optional) The tensors to use to create the descriptor resources
spirv(optional) The spirv code to use to create the algorithm
workgroup(optional) The kp::Workgroup to use for the dispatch which defaults to kp::Workgroup(tensor[0].size(), 1, 1) if not set.
specializationConstants(optional) The templatable param is to be used to initialize the specialization constants which cannot be changed once set.
pushConstants(optional) This templatable param is to be used when initializing the pipeline, which set the size of the push constants
  • these can be modified but all new values must have the same data type and length as otherwise it will result in errors.

◆ ~Algorithm()

kp::Algorithm::~Algorithm ( )

Destructor for Algorithm which is responsible for freeing and desroying respective pipelines and owned parameter groups.

Member Function Documentation

◆ getPushConstants()

template<typename T >
const std::vector<T> kp::Algorithm::getPushConstants ( )
inline

Gets the specialization constants of the current algorithm.

Returns
The std::vector<float> currently set for push constants

◆ getSpecializationConstants()

template<typename T >
const std::vector<T> kp::Algorithm::getSpecializationConstants ( )
inline

Gets the specialization constants of the current algorithm.

Returns
The std::vector<float> currently set for specialization constants

◆ getTensors()

const std::vector<std::shared_ptr<Tensor> >& kp::Algorithm::getTensors ( )

Gets the current tensors that are used in the algorithm.

Returns
The list of tensors used in the algorithm.

◆ getWorkgroup()

const Workgroup& kp::Algorithm::getWorkgroup ( )

Gets the current workgroup from the algorithm.

Parameters
Thekp::Constant to use to set the push constants to use in the next bindPush(...) calls. The constants provided must be of the same size as the ones created during initialization.

◆ isInit()

bool kp::Algorithm::isInit ( )

function that checks all the gpu resource components to verify if these have been created and returns true if all are valid.

Returns
returns true if the algorithm is currently initialized.

◆ rebuild()

template<typename S = float, typename P = float>
void kp::Algorithm::rebuild ( const std::vector< std::shared_ptr< Tensor >> &  tensors,
const std::vector< uint32_t > &  spirv,
const Workgroup &  workgroup = {},
const std::vector< S > &  specializationConstants = {},
const std::vector< P > &  pushConstants = {} 
)
inline

Rebuild function to reconstruct algorithm with configuration parameters to create the underlying resources.

Parameters
tensorsThe tensors to use to create the descriptor resources
spirvThe spirv code to use to create the algorithm
workgroup(optional) The kp::Workgroup to use for the dispatch which defaults to kp::Workgroup(tensor[0].size(), 1, 1) if not set.
specializationConstants(optional) The std::vector<float> to use to initialize the specialization constants which cannot be changed once set.
pushConstants(optional) The std::vector<float> to use when initializing the pipeline, which set the size of the push constants - these can be modified but all new values must have the same vector size as this initial value.

◆ recordBindCore()

void kp::Algorithm::recordBindCore ( const vk::CommandBuffer &  commandBuffer)

Records command that binds the "core" algorithm components which consist of binding the pipeline and binding the descriptorsets.

Parameters
commandBufferCommand buffer to record the algorithm resources to

◆ recordBindPush()

void kp::Algorithm::recordBindPush ( const vk::CommandBuffer &  commandBuffer)

Records command that binds the push constants to the command buffer provided

  • it is required that the pushConstants provided are of the same size as the ones provided during initialization.
Parameters
commandBufferCommand buffer to record the algorithm resources to

◆ recordDispatch()

void kp::Algorithm::recordDispatch ( const vk::CommandBuffer &  commandBuffer)

Records the dispatch function with the provided template parameters or alternatively using the size of the tensor by default.

Parameters
commandBufferCommand buffer to record the algorithm resources to

◆ setPushConstants() [1/2]

template<typename T >
void kp::Algorithm::setPushConstants ( const std::vector< T > &  pushConstants)
inline

Sets the push constants to the new value provided to use in the next bindPush()

Parameters
pushConstantsThe templatable vector is to be used to set the push constants to use in the next bindPush(...) calls. The constants provided must be of the same size as the ones created during initialization.

◆ setPushConstants() [2/2]

void kp::Algorithm::setPushConstants ( void *  data,
uint32_t  size,
uint32_t  memorySize 
)
inline

Sets the push constants to the new value provided to use in the next bindPush() with the raw memory block location and memory size to be used.

Parameters
dataThe raw data point to copy the data from, without modifying the pointer.
sizeThe number of data elements provided in the data
memorySizeThe memory size of each of the data elements in bytes.

◆ setWorkgroup()

void kp::Algorithm::setWorkgroup ( const Workgroup &  workgroup,
uint32_t  minSize = 1 
)

Sets the work group to use in the recordDispatch

Parameters
workgroupThe kp::Workgroup value to use to update the algorithm. It must have a value greater than 1 on the x value (index 1) otherwise it will be initialized on the size of the first tensor (ie. this->mTensor[0]->size())

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