From 956883e0cdee22541b284892ff3f53efcf562cbf Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 6 Mar 2021 17:44:17 +0000 Subject: [PATCH] Working iteration of kompute tensor with multiplee types --- examples/array_multiplication/src/Main.cpp | 8 +++++++- single_include/kompute/Kompute.hpp | 15 +++++++++++---- src/Tensor.cpp | 1 + src/include/kompute/Tensor.hpp | 14 +++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/examples/array_multiplication/src/Main.cpp b/examples/array_multiplication/src/Main.cpp index dacc67f89..812a5039f 100755 --- a/examples/array_multiplication/src/Main.cpp +++ b/examples/array_multiplication/src/Main.cpp @@ -7,6 +7,11 @@ int main() { +#if KOMPUTE_ENABLE_SPDLOG + spdlog::set_level( + static_cast(SPDLOG_ACTIVE_LEVEL)); +#endif + kp::Manager mgr; auto tensorInA = mgr.tensor({ 2.0, 4.0, 6.0 }); @@ -39,7 +44,8 @@ int main() mgr.sequence() ->record(params) ->record(algo) - ->record(params); + ->record(params) + ->eval(); // prints "Output { 0 4 12 }" std::cout<< "Output: { "; diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index 41e9434f8..989f58c20 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -1108,16 +1108,17 @@ class TensorView: public Tensor const TensorTypes& tensorType = TensorTypes::eDevice) : Tensor(physicalDevice, device, (void*)data.data(), data.size(), sizeof(T), this->dataType()) { - + KP_LOG_DEBUG("Kompute TensorView constructor with data size {}", data.size()); + this->mData = data; } ~TensorView() { - + KP_LOG_DEBUG("Kompute TensorView destructor"); } void rebuild(const std::vector& data, TensorTypes tensorType = TensorTypes::eDevice) { - + KP_LOG_DEBUG("Kompute TensorView creating with data size {}", data.size()); this->mData = data; Tensor::rebuild(data.data(), data.size(), sizeof(T)); } @@ -1131,6 +1132,7 @@ class TensorView: public Tensor } void setData(const std::vector& data) { + KP_LOG_DEBUG("Kompute TensorView setting data with data size {}", data.size()); if (data.size() != this->mData.size()) { throw std::runtime_error( @@ -1144,6 +1146,8 @@ class TensorView: public Tensor void setRawData(void* data, uint32_t elementTotalCount, uint32_t elementMemorySize) override { + KP_LOG_DEBUG("Kompute TensorView setRawData with data size {}", elementTotalCount); + assert(elementMemorySize == sizeof(T)); this->mData = { (T*)data, ((T*)data) + elementTotalCount }; @@ -1153,10 +1157,14 @@ class TensorView: public Tensor TensorDataTypes dataType() override; uint32_t size() override { + KP_LOG_DEBUG("Kompute TensorView retrieving size: {}", this->mData.size()); + return this->mData.size(); } uint32_t memorySize() override { + KP_LOG_DEBUG("Kompute TensorView retrieving memory size: {}", this->mData.size() * sizeof(T)); + return this->mData.size() * sizeof(T); } @@ -1185,7 +1193,6 @@ class TensorView: public Tensor }; - } // End namespace kp namespace kp { diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 4f188d5af..d3225987e 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -170,6 +170,7 @@ Tensor::recordBufferMemoryBarrier(const vk::CommandBuffer& commandBuffer, vk::DescriptorBufferInfo Tensor::constructDescriptorBufferInfo() { + KP_LOG_WARN("Kompute Tensor construct descriptor buffer info size {}", this->memorySize()); vk::DeviceSize bufferSize = this->memorySize(); return vk::DescriptorBufferInfo(*this->mPrimaryBuffer, 0, // offset diff --git a/src/include/kompute/Tensor.hpp b/src/include/kompute/Tensor.hpp index 03e52d43d..6af4682d6 100644 --- a/src/include/kompute/Tensor.hpp +++ b/src/include/kompute/Tensor.hpp @@ -318,16 +318,17 @@ class TensorView: public Tensor const TensorTypes& tensorType = TensorTypes::eDevice) : Tensor(physicalDevice, device, (void*)data.data(), data.size(), sizeof(T), this->dataType()) { - + KP_LOG_DEBUG("Kompute TensorView constructor with data size {}", data.size()); + this->mData = data; } ~TensorView() { - + KP_LOG_DEBUG("Kompute TensorView destructor"); } void rebuild(const std::vector& data, TensorTypes tensorType = TensorTypes::eDevice) { - + KP_LOG_DEBUG("Kompute TensorView creating with data size {}", data.size()); this->mData = data; Tensor::rebuild(data.data(), data.size(), sizeof(T)); } @@ -341,6 +342,7 @@ class TensorView: public Tensor } void setData(const std::vector& data) { + KP_LOG_DEBUG("Kompute TensorView setting data with data size {}", data.size()); if (data.size() != this->mData.size()) { throw std::runtime_error( @@ -354,6 +356,8 @@ class TensorView: public Tensor void setRawData(void* data, uint32_t elementTotalCount, uint32_t elementMemorySize) override { + KP_LOG_DEBUG("Kompute TensorView setRawData with data size {}", elementTotalCount); + assert(elementMemorySize == sizeof(T)); this->mData = { (T*)data, ((T*)data) + elementTotalCount }; @@ -363,10 +367,14 @@ class TensorView: public Tensor TensorDataTypes dataType() override; uint32_t size() override { + KP_LOG_DEBUG("Kompute TensorView retrieving size: {}", this->mData.size()); + return this->mData.size(); } uint32_t memorySize() override { + KP_LOG_DEBUG("Kompute TensorView retrieving memory size: {}", this->mData.size() * sizeof(T)); + return this->mData.size() * sizeof(T); }