diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index f3ebd990d..772397a26 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -1351,23 +1351,12 @@ class Manager * * @param sequenceName The name for the named sequence to be retrieved or * created + * @param queueIndex The queue to use from the available queues * @return Shared pointer to the manager owned sequence resource */ - std::shared_ptr getOrCreateManagedSequence( - std::string sequenceName); - - /** - * Create a new managed Kompute sequence so it's available within the - * manager. - * - * @param sequenceName The name for the named sequence to be created, if - * empty then default indexed value is used - * @param queueIndex The queue to use from the available queues - * @return Weak pointer to the manager owned sequence resource - */ - std::shared_ptr createManagedSequence( - std::string sequenceName = "", - uint32_t queueIndex = 0); + std::shared_ptr sequence( + std::string sequenceName = KP_DEFAULT_SESSION, + uint32_t queueIndex = 0); /** * Function that evaluates operation against named sequence. @@ -1384,7 +1373,7 @@ class Manager { SPDLOG_DEBUG("Kompute Manager evalOp triggered"); std::shared_ptr sq = - this->getOrCreateManagedSequence(sequenceName); + this->sequence(sequenceName); SPDLOG_DEBUG("Kompute Manager evalOp running sequence BEGIN"); sq->begin(); @@ -1434,7 +1423,7 @@ class Manager SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered"); std::shared_ptr sq = - this->getOrCreateManagedSequence(sequenceName); + this->sequence(sequenceName); SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN"); sq->begin(); @@ -1521,12 +1510,12 @@ class Manager * @param syncDataToGPU Whether to sync the data to GPU memory * @returns Initialized Tensor with memory Syncd to GPU device */ - std::shared_ptr buildTensor( + std::shared_ptr tensor( const std::vector& data, Tensor::TensorTypes tensorType = Tensor::TensorTypes::eDevice, bool syncDataToGPU = true) { - SPDLOG_DEBUG("Kompute Manager buildTensor triggered"); + SPDLOG_DEBUG("Kompute Manager tensor triggered"); SPDLOG_DEBUG("Kompute Manager creating new tensor shared ptr"); std::shared_ptr tensor = @@ -1548,28 +1537,18 @@ class Manager * create a new Tensor. The tensor memory will then be managed and owned by * the manager. * - * @param data The data to initialize the tensor with - * @param tensorType The type of tensor to initialize + * @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 rebuildTensors(std::vector> tensors, + void rebuild(std::vector> tensors, bool syncDataToGPU = true) { - SPDLOG_DEBUG("Kompute Manager rebuildTensors triggered"); + SPDLOG_DEBUG("Kompute Manager rebuild triggered"); for (std::shared_ptr tensor : tensors) { - if (tensor->isInit()) { - tensor->freeMemoryDestroyGPUResources(); - } - - tensor->init(this->mPhysicalDevice, this->mDevice); - - std::set>::iterator it = - this->mManagedTensors.find(tensor); - if (it == this->mManagedTensors.end()) { - this->mManagedTensors.insert(tensor); - } + // False syncData to run all tensors at once instead one by one + this->rebuild(tensor, false); } if (syncDataToGPU) { @@ -1577,6 +1556,38 @@ class Manager } } + /** + * Function that simplifies the common workflow of tensor initialisation. It + * will take the constructor parameters for a Tensor and will will us it to + * create a new Tensor. The tensor memory will then be managed and owned by + * the 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 tensor, + bool syncDataToGPU = true) + { + SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered"); + + if (tensor->isInit()) { + tensor->freeMemoryDestroyGPUResources(); + } + + tensor->init(this->mPhysicalDevice, this->mDevice); + + std::set>::iterator it = + this->mManagedTensors.find(tensor); + if (it == this->mManagedTensors.end()) { + this->mManagedTensors.insert(tensor); + } + + if (syncDataToGPU) { + this->evalOpDefault({ tensor }); + } + } + private: // -------------- OPTIONALLY OWNED RESOURCES std::shared_ptr mInstance = nullptr;