Added initial destroy and updated rebuild functions
This commit is contained in:
parent
d5df5c1f41
commit
d9789b63d2
2 changed files with 141 additions and 19 deletions
|
|
@ -328,4 +328,27 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices)
|
|||
SPDLOG_DEBUG("Kompute Manager compute queue obtained");
|
||||
}
|
||||
|
||||
std::shared_ptr<Tensor>
|
||||
Manager::tensor(
|
||||
const std::vector<float>& data,
|
||||
Tensor::TensorTypes tensorType,
|
||||
bool syncDataToGPU)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager tensor triggered");
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager creating new tensor shared ptr");
|
||||
std::shared_ptr<Tensor> tensor =
|
||||
std::make_shared<Tensor>(kp::Tensor(data, tensorType));
|
||||
|
||||
tensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
if (syncDataToGPU) {
|
||||
this->evalOpDefault<OpTensorSyncDevice>({ tensor });
|
||||
}
|
||||
this->mManagedTensors.insert(tensor);
|
||||
|
||||
return tensor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,23 +226,7 @@ class Manager
|
|||
std::shared_ptr<Tensor> tensor(
|
||||
const std::vector<float>& data,
|
||||
Tensor::TensorTypes tensorType = Tensor::TensorTypes::eDevice,
|
||||
bool syncDataToGPU = true)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager tensor triggered");
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager creating new tensor shared ptr");
|
||||
std::shared_ptr<Tensor> tensor =
|
||||
std::make_shared<Tensor>(kp::Tensor(data, tensorType));
|
||||
|
||||
tensor->init(this->mPhysicalDevice, this->mDevice);
|
||||
|
||||
if (syncDataToGPU) {
|
||||
this->evalOpDefault<OpTensorSyncDevice>({ tensor });
|
||||
}
|
||||
this->mManagedTensors.insert(tensor);
|
||||
|
||||
return tensor;
|
||||
}
|
||||
bool syncDataToGPU = true);
|
||||
|
||||
/**
|
||||
* Function that simplifies the common workflow of tensor initialisation. It
|
||||
|
|
@ -252,7 +236,6 @@ class Manager
|
|||
*
|
||||
* @param tensors Array of tensors to rebuild
|
||||
* @param syncDataToGPU Whether to sync the data to GPU memory
|
||||
* @returns Initialized Tensor with memory Syncd to GPU device
|
||||
*/
|
||||
void rebuild(std::vector<std::shared_ptr<kp::Tensor>> tensors,
|
||||
bool syncDataToGPU = true)
|
||||
|
|
@ -277,7 +260,6 @@ class Manager
|
|||
*
|
||||
* @param tensors Single tensor to rebuild
|
||||
* @param syncDataToGPU Whether to sync the data to GPU memory
|
||||
* @returns Initialized Tensor with memory Syncd to GPU device
|
||||
*/
|
||||
void rebuild(std::shared_ptr<kp::Tensor> tensor,
|
||||
bool syncDataToGPU = true)
|
||||
|
|
@ -301,6 +283,123 @@ class Manager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy owned Vulkan GPU resources and free GPU memory for
|
||||
* single tensor.
|
||||
*
|
||||
* @param tensors Single tensor to rebuild
|
||||
*/
|
||||
void destroy(std::shared_ptr<kp::Tensor> tensor)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
|
||||
if (tensor->isInit()) {
|
||||
tensor->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
|
||||
// TODO: Confirm not limiting destroying tensors owned by this manager allowed
|
||||
std::set<std::shared_ptr<Tensor>>::iterator it =
|
||||
this->mManagedTensors.find(tensor);
|
||||
|
||||
if (it != this->mManagedTensors.end()) {
|
||||
this->mManagedTensors.erase(tensor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy owned Vulkan GPU resources and free GPU memory for
|
||||
* vector of tensors.
|
||||
*
|
||||
* @param tensors Single tensor to rebuild
|
||||
*/
|
||||
void destroy(std::vector<std::shared_ptr<kp::Tensor>> tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor : tensors) {
|
||||
this->destroy(tensor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy owned Vulkan GPU resources and free GPU memory for
|
||||
* vector of sequences. Destroying by sequence name is more efficent
|
||||
* and hence recommended instead of by object.
|
||||
*
|
||||
* @param sequences Vector for shared ptrs with sequences to destroy
|
||||
*/
|
||||
void destroy(std::vector<std::shared_ptr<kp::Sequence>> sequences)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
for (std::shared_ptr<kp::Sequence> sequence : sequences) {
|
||||
this->destroy(sequence);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy owned Vulkan GPU resources and free GPU memory for
|
||||
* single sequence. Destroying by sequence name is more efficent
|
||||
* and hence recommended instead of by object.
|
||||
*
|
||||
* @param sequences Single sequence to rebuild
|
||||
*/
|
||||
void destroy(std::shared_ptr<kp::Sequence> sequence)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
// Inefficient but required to delete by value
|
||||
// Depending on the amount of named sequences created may be worth creating
|
||||
// a set to ensure efficient delete.
|
||||
for (std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator it = this->mManagedSequences.begin(); it != this->mManagedSequences.end(); it++) {
|
||||
if (it->second == sequence) {
|
||||
this->mManagedSequences.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sequence->isInit()) {
|
||||
sequence->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy owned Vulkan GPU resources and free GPU memory for
|
||||
* sequence by name.
|
||||
*
|
||||
* @param sequenceName Single name of named sequence to destroy
|
||||
*/
|
||||
void destroy(const std::string& sequenceName)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
|
||||
found = this->mManagedSequences.find(sequenceName);
|
||||
|
||||
if (found != this->mManagedSequences.end()) {
|
||||
// We don't call destroy(sequence) as erasing sequence by name more efficient
|
||||
if (found->second->isInit()) {
|
||||
found->second->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
this->mManagedSequences.erase(sequenceName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy owned Vulkan GPU resources and free GPU memory for
|
||||
* sequences using vector of named sequence names.
|
||||
*
|
||||
* @param sequenceName Vector of sequence names to destroy
|
||||
*/
|
||||
void destroy(const std::vector<std::string>& sequenceNames)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
for (const std::string& sequenceName : sequenceNames) {
|
||||
this->destroy(sequenceName);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// -------------- OPTIONALLY OWNED RESOURCES
|
||||
std::shared_ptr<vk::Instance> mInstance = nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue