Skip to content

Commit

Permalink
Added functionaliy for eStorage buffers to work correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Saucedo <[email protected]>
  • Loading branch information
axsaucedo committed Dec 3, 2022
1 parent 201e43b commit f7a77ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/OpTensorCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@ OpTensorCopy::postEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpTensorCopy postEval called");

// Do not copy on CPU side if source is storage tensor
if (this->mTensors[0]->tensorType() == kp::Tensor::TensorTypes::eStorage)
{
KP_LOG_DEBUG("Kompute OpTensorCopy not copying tensor source given it's of eStorage type");
return;
}
void* data = this->mTensors[0]->rawData();

// Copy the data from the first tensor into all the tensors
for (size_t i = 1; i < this->mTensors.size(); i++) {
if (this->mTensors[i]->tensorType() == kp::Tensor::TensorTypes::eStorage) {
KP_LOG_DEBUG("Kompute OpTensorCopy not copying to tensor dest given it's of eStorage type");
continue;
}
this->mTensors[i]->setRawData(data);
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ Tensor::rebuild(void* data,
}

this->allocateMemoryCreateGPUResources();
this->mapRawData();

memcpy(this->mRawData, data, this->memorySize());
if (this->tensorType() != Tensor::TensorTypes::eStorage) {
this->mapRawData();
memcpy(this->mRawData, data, this->memorySize());
}
}

Tensor::TensorTypes
Expand Down Expand Up @@ -155,7 +157,7 @@ Tensor::mapRawData()
hostVisibleMemory = this->mStagingMemory;
} else {
KP_LOG_WARN(
"Kompute Tensor mapping data not supported on storage tensor");
"Kompute Tensor mapping data not supported on {} tensor", toString(this->tensorType()));
return;
}

Expand All @@ -182,7 +184,7 @@ Tensor::unmapRawData()
hostVisibleMemory = this->mStagingMemory;
} else {
KP_LOG_WARN(
"Kompute Tensor mapping data not supported on storage tensor");
"Kompute Tensor mapping data not supported on {} tensor", toString(this->tensorType()));
return;
}

Expand Down Expand Up @@ -520,7 +522,9 @@ Tensor::destroy()
}

// Unmap the current memory data
this->unmapRawData();
if (this->tensorType() != Tensor::TensorTypes::eStorage) {
this->unmapRawData();
}

if (this->mFreePrimaryBuffer) {
if (!this->mPrimaryBuffer) {
Expand Down

0 comments on commit f7a77ed

Please sign in to comment.