Added updated docstrings

This commit is contained in:
Alejandro Saucedo 2020-08-28 18:39:58 +01:00
parent 85f43c5c8e
commit 6fb99c089b
10 changed files with 334 additions and 72 deletions

View file

@ -7,41 +7,85 @@
namespace kp {
/**
Container of operations that can be sent to GPU as batch
*/
* Container of operations that can be sent to GPU as batch
*/
class Sequence
{
public:
/**
Constructor
* Base constructor for Sequence. Should not be used unless explicit intended.
*/
Sequence();
/**
* Main constructor for sequence which requires core vulkan components to generate all dependent resources.
*
* @param physicalDevice Vulkan physical device
* @param device Vulkan logical device
* @param computeQueue Vulkan compute queue
* @param queueIndex Vulkan compute queue index in device
*/
Sequence(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::Queue> computeQueue,
uint32_t queueIndex);
/**
* Destructor for sequence which is responsible for cleaning all subsequent owned operations.
*/
~Sequence();
// Initialiser
/**
* Initialises sequence including the creation of the command pool and the command buffer.
*/
void init();
// Record command functions
void begin();
void end();
void eval();
/**
* Begins recording commands for commands to be submitted into the command buffer.
*/
bool begin();
/**
* Ends the recording and stops recording commands when the record command is sent.
*/
bool end();
/**
* Eval sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier.
*/
bool eval();
// TODO: Explore design without template using just top level class
/**
* Returns true if the sequence is currently in recording activated.
*
* @return Boolean stating if recording ongoing.
*/
bool isRecording();
/**
* Returns true if the sequence has been successfully initialised.
*
* @return Boolean stating if sequence has been initialised.
*/
bool isInit();
/**
* 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.
*
* @param tensors Vector of tensors to use for the operation
*/
template<typename T, typename... TArgs>
void record(std::vector<std::shared_ptr<Tensor>> tensors)
bool record(std::vector<std::shared_ptr<Tensor>> tensors)
{
static_assert(std::is_base_of<OpBase, T>::value,
"Template only valid with OpBase derived classes");
"Kompute Sequence record(...) template only valid with OpBase derived classes");
SPDLOG_DEBUG("Kompute Sequence record function started");
if (!this->isRecording()) {
spdlog::error("Kompute sequence record attempted when not record BEGIN");
return false;
}
SPDLOG_DEBUG("Kompute Sequence creating OpBase derived class instance");
T* op = new T(
this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, tensors);
T* op =
new T(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, tensors);
OpBase* baseOp = dynamic_cast<OpBase*>(op);
std::unique_ptr<OpBase> baseOpPtr{ baseOp };
@ -55,6 +99,8 @@ class Sequence
baseOpPtr->record();
mOperations.push_back(std::move(baseOpPtr));
return true;
}
private:
@ -70,7 +116,8 @@ class Sequence
// Base op objects
std::vector<std::unique_ptr<OpBase>> mOperations;
// Record state
// State
bool mIsInit = false;
bool mRecording = false;
// Create functions