diff --git a/Makefile b/Makefile index 14196b13e..6c6968aff 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,11 @@ SCMP=/c/VulkanSDK/1.2.141.2/Bin32/glslangValidator.exe ####### Main Target Rules ####### -build: build_shaders +build: clean build_shaders $(CC) \ src/* \ -w \ -std=c++17 \ - -g -fexceptions -fPIC \ - -static-libgcc -static-libstdc++ \ -DDEBUG=1 \ -I"./external/" \ -I"./src/" \ @@ -26,6 +24,12 @@ build: build_shaders -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ -lvulkan-1 \ -o ./bin/main.exe + #\ + #-L"C:\\Users\\axsau\\Programming\\lib\\vcpkg\\installed\\x64-windows\\lib\\" \ + #-lspdlog \ + #\ + #-g -fexceptions -fPIC \ + #-static-libgcc -static-libstdc++ \ build_linux: g++ \ @@ -72,7 +76,7 @@ format: $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.hpp src/*.h clean: - rm ./bin/main.exe; + rm ./bin/main.exe || echo "No main.exe" run: ./bin/main.exe; diff --git a/src/BaseOp.hpp b/src/OpBase.hpp similarity index 53% rename from src/BaseOp.hpp rename to src/OpBase.hpp index 3c5532e10..a433c214b 100644 --- a/src/BaseOp.hpp +++ b/src/OpBase.hpp @@ -12,43 +12,33 @@ #include +#include "Tensor.hpp" + namespace kp { -template -class BaseOp +class OpBase { private: public: - BaseOp() {} + OpBase() {} - BaseOp(std::shared_ptr physicalDevice, + OpBase(std::shared_ptr physicalDevice, std::shared_ptr device, std::shared_ptr commandBuffer) { - SPDLOG_DEBUG("Compute BaseOp constructor started"); + SPDLOG_DEBUG("Compute OpBase constructor started"); this->mPhysicalDevice = physicalDevice; this->mDevice = device; this->mCommandBuffer = commandBuffer; } - ~BaseOp() + ~OpBase() { - SPDLOG_DEBUG("Compute BaseOp destructor started"); + SPDLOG_DEBUG("Compute OpBase destructor started"); } - template - void init(TArgs&&... args) - { - SPDLOG_DEBUG("Compute BaseOp init started"); - static_cast(this)->init(std::forward(args)...); - } - - template - void record(TArgs&&... args) - { - SPDLOG_DEBUG("Compute BaseOp record started"); - static_cast(this)->record(std::forward(args)...); - } + virtual void init(std::shared_ptr tensor, ...) = 0; + virtual void record() = 0; protected: std::shared_ptr mPhysicalDevice; diff --git a/src/OpCreateTensor.cpp b/src/OpCreateTensor.cpp index 3ec39cf6b..99546f2e5 100644 --- a/src/OpCreateTensor.cpp +++ b/src/OpCreateTensor.cpp @@ -13,7 +13,7 @@ OpCreateTensor::OpCreateTensor() { OpCreateTensor::OpCreateTensor(std::shared_ptr physicalDevice, std::shared_ptr device, std::shared_ptr commandBuffer) - : BaseOp(physicalDevice, device, commandBuffer) + : OpBase(physicalDevice, device, commandBuffer) { SPDLOG_DEBUG("Kompute OpCreateTensor constructor with params"); } @@ -23,15 +23,17 @@ OpCreateTensor::~OpCreateTensor() { } void -OpCreateTensor::init(std::shared_ptr tensor, std::vector data) +OpCreateTensor::init(std::shared_ptr tensor, ...) { SPDLOG_DEBUG("Kompute OpCreateTensor init called"); + this->mPrimaryTensor = tensor; + std::vector data = this->mPrimaryTensor->data(); if (tensor->tensorType() == Tensor::TensorTypes::eDevice) { tensor->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer); - this->mStagingTensor = std::make_shared(tensor->shape(), Tensor::TensorTypes::eStaging); + this->mStagingTensor = std::make_shared(tensor->data(), Tensor::TensorTypes::eStaging); this->mStagingTensor->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, data); diff --git a/src/OpCreateTensor.hpp b/src/OpCreateTensor.hpp index 50e2ecb67..eb7085439 100644 --- a/src/OpCreateTensor.hpp +++ b/src/OpCreateTensor.hpp @@ -12,11 +12,11 @@ #include "Tensor.hpp" -#include "BaseOp.hpp" +#include "OpBase.hpp" namespace kp { -class OpCreateTensor : BaseOp +class OpCreateTensor : OpBase { public: OpCreateTensor(); @@ -27,9 +27,9 @@ class OpCreateTensor : BaseOp ~OpCreateTensor(); - void init(std::shared_ptr tensor, std::vector data); + void init(std::shared_ptr tensor, ...) override; - void record(); + void record() override; private: diff --git a/src/Sequence.hpp b/src/Sequence.hpp index fa4b1a387..442ce1ba8 100644 --- a/src/Sequence.hpp +++ b/src/Sequence.hpp @@ -10,6 +10,8 @@ #include +#include "OpBase.hpp" + namespace kp { class Sequence @@ -31,6 +33,8 @@ class Sequence template void record(TArgs&&... args) { + static_assert(std::is_base_of::value, "Template only valid with OpBase derived classes"); + SPDLOG_DEBUG("Kompute Sequence record"); T op(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer); op.init(std::forward(args)...); @@ -47,6 +51,9 @@ class Sequence std::shared_ptr mCommandBuffer = nullptr; bool mFreeCommandBuffer = false; + // Base op objects + std::vector operations; + // Record state bool mRecording = false; diff --git a/src/Tensor.cpp b/src/Tensor.cpp index a57959239..9d8c80880 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -8,11 +8,12 @@ Tensor::Tensor() { this->mTensorType = TensorTypes::eDevice; } -Tensor::Tensor(std::array shape, TensorTypes tensorType) +Tensor::Tensor(std::vector data, TensorTypes tensorType) { SPDLOG_DEBUG("Kompute Tensor constructor shape and type"); - this->mShape = shape; + this->mData = data; + this->mShape = {data.size()}; this->mTensorType = tensorType; } diff --git a/src/Tensor.hpp b/src/Tensor.hpp index c0423e5ff..df47c0aa4 100644 --- a/src/Tensor.hpp +++ b/src/Tensor.hpp @@ -27,7 +27,7 @@ class Tensor Tensor(); - Tensor(std::array shape, TensorTypes tensorType = TensorTypes::eDevice); + Tensor(std::vector data, TensorTypes tensorType = TensorTypes::eDevice); ~Tensor(); diff --git a/src/main.cpp b/src/main.cpp index 672c50a40..17cc1a533 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -620,10 +620,9 @@ main() // Run Kompute spdlog::info("Creating manager"); kp::Manager mgr; - std::vector data = {0.0, 1.0, 2.0}; - kp::Tensor tensor({data.size()}); + kp::Tensor tensor({0.0, 1.0, 2.0}); spdlog::info("Calling manager eval w opcreatetensor"); - mgr.evalOp(std::shared_ptr(&tensor), data); + mgr.evalOp(std::shared_ptr(&tensor)); spdlog::info("Called manager eval success"); std::vector outData = tensor.data(); spdlog::info("Output data: {}", outData);