Updated destroy and amended tests to ensure they test tensor in scope

This commit is contained in:
Alejandro Saucedo 2021-03-07 08:10:42 +00:00
parent 1cc369cb19
commit bb64b2b37c
3 changed files with 41 additions and 7 deletions

View file

@ -50,7 +50,7 @@ Tensor::rebuild(void* data,
}
this->allocateMemoryCreateGPUResources();
this->rawMapData();
this->mapRawData();
memcpy(this->mRawData, data, this->memorySize());
}
@ -64,7 +64,10 @@ Tensor::tensorType()
bool
Tensor::isInit()
{
return this->mDevice && this->mPrimaryBuffer && this->mPrimaryMemory;
return this->mDevice
&& this->mPrimaryBuffer
&& this->mPrimaryMemory
&& this->mRawData;
}
@ -360,6 +363,7 @@ Tensor::destroy()
{
KP_LOG_DEBUG("Kompute Tensor started destroy()");
// Setting raw data to null regardless whether device is available to invalidate Tensor
this->mRawData = nullptr;
this->mSize = 0;
this->mDataTypeMemorySize = 0;
@ -370,6 +374,9 @@ Tensor::destroy()
return;
}
// Unmap the current memory data
this->unmapRawData();
if (this->mFreePrimaryBuffer) {
if (!this->mPrimaryBuffer) {
KP_LOG_WARN("Kompose Tensor expected to destroy primary buffer "

View file

@ -217,7 +217,7 @@ class Tensor
void* mRawData;
private:
void rawMapData() {
void mapRawData() {
KP_LOG_DEBUG("Kompute Tensor mapping data from host buffer");
@ -234,12 +234,36 @@ class Tensor
}
vk::DeviceSize bufferSize = this->memorySize();
// Given we request coherent host memory we don't need to invalidate / flush
this->mRawData = this->mDevice->mapMemory(
*hostVisibleMemory, 0, bufferSize, vk::MemoryMapFlags());
vk::MappedMemoryRange mappedMemoryRange(*hostVisibleMemory, 0, bufferSize);
}
void unmapRawData() {
KP_LOG_DEBUG("Kompute Tensor mapping data from host buffer");
std::shared_ptr<vk::DeviceMemory> hostVisibleMemory = nullptr;
if (this->mTensorType == TensorTypes::eHost) {
hostVisibleMemory = this->mPrimaryMemory;
} else if (this->mTensorType == TensorTypes::eDevice) {
hostVisibleMemory = this->mStagingMemory;
} else {
KP_LOG_WARN(
"Kompute Tensor mapping data not supported on storage tensor");
return;
}
vk::DeviceSize bufferSize = this->memorySize();
vk::MappedMemoryRange mappedRange(*hostVisibleMemory, 0, bufferSize);
this->mDevice->flushMappedMemoryRanges(1, &mappedRange);
this->mDevice->unmapMemory(*hostVisibleMemory);
}
// -------------- NEVER OWNED RESOURCES
std::shared_ptr<vk::PhysicalDevice> mPhysicalDevice;
std::shared_ptr<vk::Device> mDevice;