mirror of
https://github.com/nomic-ai/kompute.git
synced 2026-05-11 17:09:59 +00:00
Added function in sequence freeMemoryDestroyGPUResources to de-init
This commit is contained in:
@@ -1100,6 +1100,11 @@ class Sequence
|
||||
*/
|
||||
bool isInit();
|
||||
|
||||
/**
|
||||
* Destroys and frees the GPU resources which include the buffer and memory.
|
||||
*/
|
||||
void freeMemoryDestroyGPUResources();
|
||||
|
||||
/**
|
||||
* Record function for operation to be added to the GPU queue in batch. This
|
||||
* template requires classes to be derived from the OpBase class. This
|
||||
|
||||
@@ -63,7 +63,7 @@ Manager::~Manager()
|
||||
"managed sequences");
|
||||
for (const std::pair<std::string, std::shared_ptr<Sequence>>& sqPair :
|
||||
this->mManagedSequences) {
|
||||
sqPair.second->~Sequence();
|
||||
sqPair.second->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
this->mManagedSequences.clear();
|
||||
}
|
||||
|
||||
@@ -28,46 +28,13 @@ Sequence::~Sequence()
|
||||
SPDLOG_DEBUG("Kompute Sequence Destructor started");
|
||||
|
||||
if (!this->mIsInit) {
|
||||
SPDLOG_WARN("Kompute Sequence destructor called but sequence is not "
|
||||
"initialized.");
|
||||
SPDLOG_INFO("Kompute Sequence destructor called but sequence is not "
|
||||
"initialized so no need to removing GPU resources.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_ERROR(
|
||||
"Kompute Sequence destructor reached with null Device pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
else {
|
||||
this->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
|
||||
if (this->mFreeCommandBuffer) {
|
||||
SPDLOG_INFO("Freeing CommandBuffer");
|
||||
if (!this->mCommandBuffer) {
|
||||
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
|
||||
"CommandPool pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
}
|
||||
this->mDevice->freeCommandBuffers(
|
||||
*this->mCommandPool, 1, this->mCommandBuffer.get());
|
||||
SPDLOG_DEBUG("Kompute Sequence Freed CommandBuffer");
|
||||
}
|
||||
|
||||
if (this->mFreeCommandPool) {
|
||||
SPDLOG_INFO("Destroying CommandPool");
|
||||
if (this->mCommandPool == nullptr) {
|
||||
SPDLOG_ERROR("Kompute Sequence destructor reached with null "
|
||||
"CommandPool pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
*this->mCommandPool,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool");
|
||||
}
|
||||
|
||||
this->mIsInit = false;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -234,6 +201,53 @@ Sequence::isInit()
|
||||
return this->mIsInit;
|
||||
}
|
||||
|
||||
void
|
||||
Sequence::freeMemoryDestroyGPUResources()
|
||||
{
|
||||
if (!this->mIsInit) {
|
||||
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called "
|
||||
"but Sequence is not initialized so there's no relevant GPU resources.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_ERROR(
|
||||
"Kompute Sequence freeMemoryDestroyGPUResources called with null Device pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mFreeCommandBuffer) {
|
||||
SPDLOG_INFO("Freeing CommandBuffer");
|
||||
if (!this->mCommandBuffer) {
|
||||
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called with null "
|
||||
"CommandPool pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
}
|
||||
this->mDevice->freeCommandBuffers(
|
||||
*this->mCommandPool, 1, this->mCommandBuffer.get());
|
||||
SPDLOG_DEBUG("Kompute Sequence Freed CommandBuffer");
|
||||
}
|
||||
|
||||
if (this->mFreeCommandPool) {
|
||||
SPDLOG_INFO("Destroying CommandPool");
|
||||
if (this->mCommandPool == nullptr) {
|
||||
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called with null "
|
||||
"CommandPool pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
*this->mCommandPool,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool");
|
||||
}
|
||||
|
||||
this->mIsInit = false;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Sequence::createCommandPool()
|
||||
{
|
||||
|
||||
@@ -106,6 +106,11 @@ class Sequence
|
||||
*/
|
||||
bool isInit();
|
||||
|
||||
/**
|
||||
* Destroys and frees the GPU resources which include the buffer and memory.
|
||||
*/
|
||||
void freeMemoryDestroyGPUResources();
|
||||
|
||||
/**
|
||||
* Record function for operation to be added to the GPU queue in batch. This
|
||||
* template requires classes to be derived from the OpBase class. This
|
||||
|
||||
Reference in New Issue
Block a user