Added optensorcopy operation

This commit is contained in:
Alejandro Saucedo 2020-09-06 11:07:32 +01:00
parent 93c1ba126e
commit 236c349aa0
13 changed files with 238 additions and 45 deletions

71
src/OpTensorCopy.cpp Normal file
View file

@ -0,0 +1,71 @@
#include "kompute/operations/OpTensorCopy.hpp"
namespace kp {
OpTensorCopy::OpTensorCopy()
{
SPDLOG_DEBUG("Kompute OpTensorCopy constructor base");
}
OpTensorCopy::OpTensorCopy(
std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer,
std::vector<std::shared_ptr<Tensor>> tensors)
: OpBase(physicalDevice, device, commandBuffer, tensors, false)
{
SPDLOG_DEBUG("Kompute OpTensorCopy constructor with params");
}
OpTensorCopy::~OpTensorCopy()
{
SPDLOG_DEBUG("Kompute OpTensorCopy destructor started");
SPDLOG_DEBUG("Kompute OpTensorCopy destroying staging tensors");
}
void
OpTensorCopy::init()
{
SPDLOG_DEBUG("Kompute OpTensorCopy init called");
if (this->mTensors.size() < 2) {
throw std::runtime_error(
"Kompute OpTensorCopy called with less than 2 tensor");
}
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
if (!tensor->isInit()) {
throw std::runtime_error("Kompute OpTensorCopy tensor parameter has not been initialized");
}
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
throw std::runtime_error("Kompute OpTensorCopy tensor parameter is of type storage and hence cannot be used to receive or pass data.");
}
}
}
void
OpTensorCopy::record()
{
SPDLOG_DEBUG("Kompute OpTensorCopy record called");
// We iterate from the second tensor onwards and record a copy to all
for (size_t i = 1; i < this->mTensors.size(); i++) {
this->mTensors[i]->recordCopyFrom(this->mCommandBuffer, this->mTensors[0], false);
}
}
void
OpTensorCopy::postSubmit()
{
SPDLOG_DEBUG("Kompute OpTensorCopy postSubmit called");
// Copy the data from the first tensor into all the tensors
for (size_t i = 1; i < this->mTensors.size(); i++) {
this->mTensors[i]->setData(this->mTensors[0]->data());
}
}
}