Added initial implementation for algorithm and opMult

This commit is contained in:
Alejandro Saucedo 2020-08-21 19:15:07 +01:00
parent 0d18dc50e6
commit d59dc41ffc
11 changed files with 385 additions and 28 deletions

View file

@ -11,12 +11,15 @@ OpMult::OpMult()
SPDLOG_DEBUG("Kompute OpMult constructor base");
}
// TODO: Remove physicalDevice from main initialiser
OpMult::OpMult(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer)
: OpBase(physicalDevice, device, commandBuffer)
{
SPDLOG_DEBUG("Kompute OpMult constructor with params");
this->mAlgorithm = Algorithm(device, commandBuffer);
}
OpMult::~OpMult()
@ -29,18 +32,40 @@ OpMult::init(std::vector<std::shared_ptr<Tensor>> tensors)
{
SPDLOG_DEBUG("Kompute OpMult init called");
if (tensors.size() < 2) {
if (tensors.size() < 3) {
throw std::runtime_error(
"Kompute OpMult called with less than 1 tensor");
} else if (tensors.size() > 2) {
} else if (tensors.size() > 3) {
spdlog::warn("Kompute OpMult called with more than 2 tensor");
}
this->mTensorLHS = tensors[0];
this->mTensorRHS = tensors[1];
this->mTensorOutput = tensors[2];
this->mTensorOutputStaging= std::make_shared<Tensor>(
this->mTensorOutput->data(), Tensor::TensorTypes::eStaging);
this->mAlgorithm.init(
"shaders/glsl/computeheadless.comp.spv", tensors);
}
void
OpMult::record()
{
SPDLOG_DEBUG("Kompute OpMult record called");
this->mAlgorithm.recordDispatch(1, 1, 1);
this->mTensorOutputStaging->recordCopyFrom(this->mTensorOutput);
}
void OpMult::postSubmit()
{
SPDLOG_DEBUG("Kompute OpCreateTensor postSubmit called");
this->mTensorOutputStaging->copyDataFromHostBuffer();
this->mTensorOutput->setData(this->mTensorOutputStaging->data());
}
}