Renamed tensorcreate and started adding optensorsyncdevice
This commit is contained in:
parent
236c349aa0
commit
ec89fc6d56
17 changed files with 318 additions and 71 deletions
|
|
@ -1,30 +1,30 @@
|
|||
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
#include "kompute/operations/OpCreateTensor.hpp"
|
||||
#include "kompute/operations/OpTensorCreate.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
OpCreateTensor::OpCreateTensor()
|
||||
OpTensorCreate::OpTensorCreate()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor constructor base");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate constructor base");
|
||||
}
|
||||
|
||||
OpCreateTensor::OpCreateTensor(
|
||||
OpTensorCreate::OpTensorCreate(
|
||||
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, true)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor constructor with params");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate constructor with params");
|
||||
}
|
||||
|
||||
OpCreateTensor::~OpCreateTensor()
|
||||
OpTensorCreate::~OpTensorCreate()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor destructor started");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate destructor started");
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor destroying staging tensors");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate destroying staging tensors");
|
||||
for (size_t i = 0; i < this->mStagingTensors.size(); i++) {
|
||||
if (this->mStagingTensors[i]) {
|
||||
this->mStagingTensors[i]->freeMemoryDestroyGPUResources();
|
||||
|
|
@ -33,18 +33,18 @@ OpCreateTensor::~OpCreateTensor()
|
|||
}
|
||||
|
||||
void
|
||||
OpCreateTensor::init()
|
||||
OpTensorCreate::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor init called");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate init called");
|
||||
|
||||
if (this->mTensors.size() < 1) {
|
||||
throw std::runtime_error(
|
||||
"Kompute OpCreateTensor called with less than 1 tensor");
|
||||
"Kompute OpTensorCreate called with less than 1 tensor");
|
||||
}
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
|
||||
if (tensor->isInit()) {
|
||||
throw std::runtime_error("Kompute OpCreateTensor: Tensor has already been initialized");
|
||||
throw std::runtime_error("Kompute OpTensorCreate: Tensor has already been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
tensor->init(
|
||||
|
|
@ -73,9 +73,9 @@ OpCreateTensor::init()
|
|||
}
|
||||
|
||||
void
|
||||
OpCreateTensor::record()
|
||||
OpTensorCreate::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor record called");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate record called");
|
||||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
|
|
@ -87,9 +87,9 @@ OpCreateTensor::record()
|
|||
}
|
||||
|
||||
void
|
||||
OpCreateTensor::postSubmit()
|
||||
OpTensorCreate::postSubmit()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpCreateTensor postSubmit called");
|
||||
SPDLOG_DEBUG("Kompute OpTensorCreate postSubmit called");
|
||||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
71
src/OpTensorSyncDevice.cpp
Normal file
71
src/OpTensorSyncDevice.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
#include "kompute/operations/OpTensorSyncDevice.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
OpTensorSyncDevice::OpTensorSyncDevice()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor base");
|
||||
}
|
||||
|
||||
OpTensorSyncDevice::OpTensorSyncDevice(
|
||||
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 OpTensorSyncDevice constructor with params");
|
||||
}
|
||||
|
||||
OpTensorSyncDevice::~OpTensorSyncDevice()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice destructor started");
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice destroying staging tensors");
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorSyncDevice::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice init called");
|
||||
|
||||
if (this->mTensors.size() < 2) {
|
||||
throw std::runtime_error(
|
||||
"Kompute OpTensorSyncDevice called with less than 2 tensor");
|
||||
}
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
|
||||
if (!tensor->isInit()) {
|
||||
throw std::runtime_error("Kompute OpTensorSyncDevice tensor parameter has not been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
|
||||
throw std::runtime_error("Kompute OpTensorSyncDevice tensor parameter is of type storage and hence cannot be used to receive or pass data.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorSyncDevice::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice 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
|
||||
OpTensorSyncDevice::postSubmit()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
namespace kp {
|
||||
|
||||
/**
|
||||
Operation that copies the data from the first tensor to the rest of the tensors provided, using a record command for all the vectors. This operation does not own/manage the memory of the tensors passed to it.
|
||||
Operation that copies the data from the first tensor to the rest of the tensors provided, using a record command for all the vectors. This operation does not own/manage the memory of the tensors passed to it. The operation must only receive tensors of type
|
||||
*/
|
||||
class OpTensorCopy : public OpBase
|
||||
{
|
||||
|
|
@ -30,13 +30,12 @@ class OpTensorCopy : public OpBase
|
|||
std::vector<std::shared_ptr<Tensor>> tensors);
|
||||
|
||||
/**
|
||||
* Default destructor which in this case expects the parent class to free
|
||||
* the tensors
|
||||
* Default destructor. This class does not manage memory so it won't be expecting the parent to perform a release.
|
||||
*/
|
||||
~OpTensorCopy() override;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Performs basic checks such as ensuring there are at least two tensors provided, that they are initialised and that they are not of type TensorTypes::eStorage.
|
||||
*/
|
||||
void init() override;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ namespace kp {
|
|||
Operation that creates tensor and manages the memory of the components
|
||||
created
|
||||
*/
|
||||
class OpCreateTensor : public OpBase
|
||||
class OpTensorCreate : public OpBase
|
||||
{
|
||||
public:
|
||||
OpCreateTensor();
|
||||
OpTensorCreate();
|
||||
|
||||
/**
|
||||
* Default constructor with parameters that provides the bare minimum
|
||||
|
|
@ -28,7 +28,7 @@ class OpCreateTensor : public OpBase
|
|||
* @param tensors Tensors that will be used to create in operation.
|
||||
* @param freeTensors Whether operation manages the memory of the Tensors
|
||||
*/
|
||||
OpCreateTensor(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
OpTensorCreate(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);
|
||||
|
|
@ -37,7 +37,7 @@ class OpCreateTensor : public OpBase
|
|||
* Default destructor which in this case expects the parent class to free
|
||||
* the tensors
|
||||
*/
|
||||
~OpCreateTensor() override;
|
||||
~OpTensorCreate() override;
|
||||
|
||||
/**
|
||||
* In charge of initialising the primary Tensor as well as the staging
|
||||
57
src/include/kompute/operations/OpTensorSyncDevice.hpp
Normal file
57
src/include/kompute/operations/OpTensorSyncDevice.hpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#pragma once
|
||||
|
||||
#include "kompute/Core.hpp"
|
||||
|
||||
#include "kompute/Tensor.hpp"
|
||||
|
||||
#include "kompute/operations/OpBase.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
/**
|
||||
Operation that syncs tensor's device by mapping local data into the device memory. For TensorTypes::eDevice it will use a staging tensor to perform the copy. For TensorTypes::eStaging it will only copy the data and perform a map, which will be executed during the record (as opposed to during the sequence eval/submit). This function cannot be carried out for TensorTypes::eStaging.
|
||||
*/
|
||||
class OpTensorSyncDevice : public OpBase
|
||||
{
|
||||
public:
|
||||
OpTensorSyncDevice();
|
||||
|
||||
/**
|
||||
* Default constructor with parameters that provides the core vulkan resources and the tensors that will be used in the operation. The tensos provided cannot be of type TensorTypes::eStorage.
|
||||
*
|
||||
* @param physicalDevice Vulkan physical device used to find device queues
|
||||
* @param device Vulkan logical device for passing to Algorithm
|
||||
* @param commandBuffer Vulkan Command Buffer to record commands into
|
||||
* @param tensors Tensors that will be used to create in operation.
|
||||
*/
|
||||
OpTensorSyncDevice(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);
|
||||
|
||||
/**
|
||||
* Default destructor. This class does not manage memory so it won't be expecting the parent to perform a release.
|
||||
*/
|
||||
~OpTensorSyncDevice() override;
|
||||
|
||||
/**
|
||||
* Performs basic checks such as ensuring that there is at least one tensor provided, that they are initialized and that they are not of type TensorTpes::eStaging.
|
||||
*/
|
||||
void init() override;
|
||||
|
||||
/**
|
||||
* Records the copy commands from teh first tensor into all the other tensors provided. Also optionally records a barrier.
|
||||
*/
|
||||
void record() override;
|
||||
|
||||
/**
|
||||
* Copies the local vectors for all the tensors to sync the data with the gpu.
|
||||
*/
|
||||
void postSubmit() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // End namespace kp
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue