Added functional optensorsyncDevice and optensorsynclocal

This commit is contained in:
Alejandro Saucedo 2020-09-06 15:51:31 +01:00
parent e6f4097acb
commit e68d09dbdc
15 changed files with 258 additions and 50 deletions

View file

@ -57,9 +57,15 @@ OpTensorCopy::record()
}
void
OpTensorCopy::postSubmit()
OpTensorCopy::preEval()
{
SPDLOG_DEBUG("Kompute OpTensorCopy postSubmit called");
SPDLOG_DEBUG("Kompute OpTensorCopy preEval called");
}
void
OpTensorCopy::postEval()
{
SPDLOG_DEBUG("Kompute OpTensorCopy postEval called");
// Copy the data from the first tensor into all the tensors
for (size_t i = 1; i < this->mTensors.size(); i++) {

View file

@ -80,12 +80,15 @@ OpTensorCreate::record()
}
void
OpTensorCreate::postSubmit()
OpTensorCreate::preEval()
{
SPDLOG_DEBUG("Kompute OpTensorCreate postSubmit called");
SPDLOG_DEBUG("Kompute OpTensorCreate preEval called");
}
SPDLOG_DEBUG("Kompute OpTensorCreate destroying staging tensors");
this->mStagingTensors.clear();
void
OpTensorCreate::postEval()
{
SPDLOG_DEBUG("Kompute OpTensorCreate postEval called");
}
}

View file

@ -36,8 +36,8 @@ OpTensorSyncDevice::init()
}
for (std::shared_ptr<Tensor> tensor: this->mTensors) {
if (tensor->isInit()) {
throw std::runtime_error("Kompute OpTensorSyncDevice: Tensor has already been initialized");
if (!tensor->isInit()) {
throw std::runtime_error("Kompute OpTensorSyncDevice: Tensor param has not been initialized");
}
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
throw std::runtime_error("Kompute OpTensorSyncLocal tensor parameter is of type TensorTypes::eStorage and hence cannot be used to receive or pass data.");
@ -78,14 +78,25 @@ OpTensorSyncDevice::record()
}
void
OpTensorSyncDevice::postSubmit()
OpTensorSyncDevice::preEval()
{
SPDLOG_DEBUG("Kompute OpTensorSyncDevice postSubmit called");
SPDLOG_DEBUG("Kompute OpTensorSyncDevice preEval called");
// Remove all staging tensors as they are not required after operation
SPDLOG_DEBUG("Kompute OpTensorSyncDevice destroying staging tensors");
// TODO: This would cause issues if there is no CPU barrier
this->mStagingTensors.clear();
// Performing sync of data as eval can be called multiple times with same op
for (size_t i = 0; i < this->mTensors.size(); i++) {
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
this->mStagingTensors[i]->setData(this->mTensors[i]->data());
this->mStagingTensors[i]->mapDataIntoHostMemory();
} else {
this->mTensors[i]->mapDataFromHostMemory();
}
}
}
void
OpTensorSyncDevice::postEval()
{
SPDLOG_DEBUG("Kompute OpTensorSyncDevice postEval called");
}
}

View file

@ -74,10 +74,17 @@ OpTensorSyncLocal::record()
}
void
OpTensorSyncLocal::postSubmit()
OpTensorSyncLocal::preEval()
{
SPDLOG_DEBUG("Kompute OpTensorSyncLocal postSubmit called");
SPDLOG_DEBUG("Kompute OpTensorSyncLocal preEval called");
}
void
OpTensorSyncLocal::postEval()
{
SPDLOG_DEBUG("Kompute OpTensorSyncLocal postEval called");
SPDLOG_DEBUG("Kompute OpTensorSyncLocal mapping data into tensor local");
for (size_t i = 0; i < this->mTensors.size(); i++) {
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
this->mStagingTensors[i]->mapDataFromHostMemory();
@ -86,10 +93,6 @@ OpTensorSyncLocal::postSubmit()
this->mTensors[i]->mapDataFromHostMemory();
}
}
// Remove all staging tensors as they are not required after operation
SPDLOG_DEBUG("Kompute OpTensorSyncLocal destroying staging tensors");
this->mStagingTensors.clear();
}
}

View file

@ -125,6 +125,10 @@ Sequence::eval()
return false;
}
for (size_t i = 0; i < this->mOperations.size(); i++) {
this->mOperations[i]->preEval();
}
const vk::PipelineStageFlags waitStageMask =
vk::PipelineStageFlagBits::eTransfer;
vk::SubmitInfo submitInfo(
@ -140,7 +144,7 @@ Sequence::eval()
this->mDevice->destroy(fence);
for (size_t i = 0; i < this->mOperations.size(); i++) {
this->mOperations[i]->postSubmit();
this->mOperations[i]->postEval();
}
SPDLOG_DEBUG("Kompute sequence EVAL success");

View file

@ -120,12 +120,18 @@ class OpAlgoBase : public OpBase
*/
virtual void record() override;
/**
* Does not perform any preEval commands.
*/
virtual void preEval() override;
/**
* Executes after the recorded commands are submitted, and performs a copy
* of the GPU Device memory into the staging buffer so the output data can
* be retrieved.
*/
virtual void postSubmit() override;
virtual void postEval() override;
protected:
// -------------- NEVER OWNED RESOURCES
@ -316,7 +322,14 @@ OpAlgoBase<tX, tY, tZ>::record()
template<uint32_t tX, uint32_t tY, uint32_t tZ>
void
OpAlgoBase<tX, tY, tZ>::postSubmit()
OpAlgoBase<tX, tY, tZ>::preEval()
{
SPDLOG_DEBUG("Kompute OpAlgoBase preEval called");
}
template<uint32_t tX, uint32_t tY, uint32_t tZ>
void
OpAlgoBase<tX, tY, tZ>::postEval()
{
SPDLOG_DEBUG("Kompute OpAlgoBase postSubmit called");

View file

@ -90,11 +90,24 @@ class OpBase
virtual void record() = 0;
/**
* Post submit is called after the Sequence has submitted the commands to
* the GPU for processing, and can be used to perform any tear-down steps
* required as the computation iteration finishes.
* Pre eval is called before the Sequence has called eval and submitted the commands to
* the GPU for processing, and can be used to perform any per-eval setup steps
* required as the computation iteration begins. It's worth noting that
* there are situations where eval can be called multiple times, so the
* resources that are created should be idempotent in case it's called multiple
* times in a row.
*/
virtual void postSubmit() = 0;
virtual void preEval() = 0;
/**
* Post eval is called after the Sequence has called eval and submitted the commands to
* the GPU for processing, and can be used to perform any tear-down steps
* required as the computation iteration finishes. It's worth noting that
* there are situations where eval can be called multiple times, so the
* resources that are destroyed should not require a re-init unless explicitly
* provided by the user.
*/
virtual void postEval() = 0;
protected:
// -------------- NEVER OWNED RESOURCES

View file

@ -44,10 +44,15 @@ class OpTensorCopy : public OpBase
*/
void record() override;
/**
* Does not perform any preEval commands.
*/
virtual void preEval() override;
/**
* Copies the local vectors for all the tensors to sync the data with the gpu.
*/
void postSubmit() override;
virtual void postEval() override;
private:
};

View file

@ -56,11 +56,17 @@ class OpTensorCreate : public OpBase
*/
void record() override;
/**
* Does not perform any preEval commands.
*/
virtual void preEval() override;
/**
* Performs a copy back into the main tensor to ensure that the data
* contained is the one that is now being stored in the GPU.
*/
void postSubmit() override;
virtual void postEval() override;
private:
// Never owned resources

View file

@ -45,9 +45,14 @@ class OpTensorSyncDevice : public OpBase
void record() override;
/**
* Does not perform any further sync functions. Frees the staging tensors together with their respective memory.
* Does not perform any preEval commands.
*/
void postSubmit() override;
virtual void preEval() override;
/**
* Does not perform any postEval commands.
*/
virtual void postEval() override;
private:
// Never owned resources

View file

@ -45,9 +45,15 @@ class OpTensorSyncLocal : public OpBase
void record() override;
/**
* For host tensors it performs the map command from the host memory into local memory. Frees the staging tensors together with their respective memory.
* Does not perform any preEval commands.
*/
void postSubmit() override;
virtual void preEval() override;
/**
* For host tensors it performs the map command from the host memory into local memory.
*/
virtual void postEval() override;
private:
// Never owned resources