KomputeProject / kompute

General purpose GPU compute framework built on Vulkan to support 1000s of cross vendor graphics cards (AMD, Qualcomm, NVIDIA & friends). Blazing fast, mobile-enabled, asynchronous and optimized for advanced GPU data processing usecases. Backed by the Linux Foundation.
http://kompute.cc/
Apache License 2.0
1.98k stars 153 forks source link

"Kompute Tensor device is null" when rebuilding tensor #300

Open MiroPalmu opened 2 years ago

MiroPalmu commented 2 years ago

When creating a tensor from manager with

inline std::shared_ptr<kp::TensorT<float>> kp::Manager::tensorT<float>(const kp::Constants &data, kp::Tensor::TensorTypes tensorType = kp::Tensor::TensorTypes::eDevice)

and then calling rebuild on created tensor it will throw "Kompute Tensor device is null"

I'm not very familiar with kompute yet but it seems if in rebuild member function following branch gets executed

if (this->mPrimaryBuffer || this->mPrimaryMemory) {
        KP_LOG_DEBUG(
          "Kompute Tensor destroying existing resources before rebuild");
        this->destroy();
    }

then in allocateMemoryCreateGPUResources

if (!this->mDevice) {
        throw std::runtime_error("Kompute Tensor device is null");
    }

gets executed every time because after this->destroy() mDevice is nullptr every time. This can be seen at Tensor.cpp:548

if (this->mDevice) {
    this->mDevice = nullptr;
}