Base working compilation

This commit is contained in:
Alejandro Saucedo 2020-08-19 18:58:22 +01:00
parent 5596b6f029
commit 7c3af1189f
8 changed files with 40 additions and 37 deletions

View file

@ -12,13 +12,11 @@ SCMP=/c/VulkanSDK/1.2.141.2/Bin32/glslangValidator.exe
####### Main Target Rules ####### ####### Main Target Rules #######
build: build_shaders build: clean build_shaders
$(CC) \ $(CC) \
src/* \ src/* \
-w \ -w \
-std=c++17 \ -std=c++17 \
-g -fexceptions -fPIC \
-static-libgcc -static-libstdc++ \
-DDEBUG=1 \ -DDEBUG=1 \
-I"./external/" \ -I"./external/" \
-I"./src/" \ -I"./src/" \
@ -26,6 +24,12 @@ build: build_shaders
-L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \
-lvulkan-1 \ -lvulkan-1 \
-o ./bin/main.exe -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: build_linux:
g++ \ g++ \
@ -72,7 +76,7 @@ format:
$(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.hpp src/*.h $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.hpp src/*.h
clean: clean:
rm ./bin/main.exe; rm ./bin/main.exe || echo "No main.exe"
run: run:
./bin/main.exe; ./bin/main.exe;

View file

@ -12,43 +12,33 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "Tensor.hpp"
namespace kp { namespace kp {
template<class T> class OpBase
class BaseOp
{ {
private: private:
public: public:
BaseOp() {} OpBase() {}
BaseOp(std::shared_ptr<vk::PhysicalDevice> physicalDevice, OpBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device, std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer) { std::shared_ptr<vk::CommandBuffer> commandBuffer) {
SPDLOG_DEBUG("Compute BaseOp constructor started"); SPDLOG_DEBUG("Compute OpBase constructor started");
this->mPhysicalDevice = physicalDevice; this->mPhysicalDevice = physicalDevice;
this->mDevice = device; this->mDevice = device;
this->mCommandBuffer = commandBuffer; this->mCommandBuffer = commandBuffer;
} }
~BaseOp() ~OpBase()
{ {
SPDLOG_DEBUG("Compute BaseOp destructor started"); SPDLOG_DEBUG("Compute OpBase destructor started");
} }
template<typename... TArgs> virtual void init(std::shared_ptr<Tensor> tensor, ...) = 0;
void init(TArgs&&... args) virtual void record() = 0;
{
SPDLOG_DEBUG("Compute BaseOp init started");
static_cast<T*>(this)->init(std::forward<TArgs>(args)...);
}
template<typename... TArgs>
void record(TArgs&&... args)
{
SPDLOG_DEBUG("Compute BaseOp record started");
static_cast<T*>(this)->record(std::forward<TArgs>(args)...);
}
protected: protected:
std::shared_ptr<vk::PhysicalDevice> mPhysicalDevice; std::shared_ptr<vk::PhysicalDevice> mPhysicalDevice;

View file

@ -13,7 +13,7 @@ OpCreateTensor::OpCreateTensor() {
OpCreateTensor::OpCreateTensor(std::shared_ptr<vk::PhysicalDevice> physicalDevice, OpCreateTensor::OpCreateTensor(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device, std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer) std::shared_ptr<vk::CommandBuffer> commandBuffer)
: BaseOp(physicalDevice, device, commandBuffer) : OpBase(physicalDevice, device, commandBuffer)
{ {
SPDLOG_DEBUG("Kompute OpCreateTensor constructor with params"); SPDLOG_DEBUG("Kompute OpCreateTensor constructor with params");
} }
@ -23,15 +23,17 @@ OpCreateTensor::~OpCreateTensor() {
} }
void void
OpCreateTensor::init(std::shared_ptr<Tensor> tensor, std::vector<uint32_t> data) OpCreateTensor::init(std::shared_ptr<Tensor> tensor, ...)
{ {
SPDLOG_DEBUG("Kompute OpCreateTensor init called"); SPDLOG_DEBUG("Kompute OpCreateTensor init called");
this->mPrimaryTensor = tensor; this->mPrimaryTensor = tensor;
std::vector<uint32_t> data = this->mPrimaryTensor->data();
if (tensor->tensorType() == Tensor::TensorTypes::eDevice) { if (tensor->tensorType() == Tensor::TensorTypes::eDevice) {
tensor->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer); tensor->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer);
this->mStagingTensor = std::make_shared<Tensor>(tensor->shape(), Tensor::TensorTypes::eStaging); this->mStagingTensor = std::make_shared<Tensor>(tensor->data(), Tensor::TensorTypes::eStaging);
this->mStagingTensor->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, data); this->mStagingTensor->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, data);

View file

@ -12,11 +12,11 @@
#include "Tensor.hpp" #include "Tensor.hpp"
#include "BaseOp.hpp" #include "OpBase.hpp"
namespace kp { namespace kp {
class OpCreateTensor : BaseOp<OpCreateTensor> class OpCreateTensor : OpBase
{ {
public: public:
OpCreateTensor(); OpCreateTensor();
@ -27,9 +27,9 @@ class OpCreateTensor : BaseOp<OpCreateTensor>
~OpCreateTensor(); ~OpCreateTensor();
void init(std::shared_ptr<Tensor> tensor, std::vector<uint32_t> data); void init(std::shared_ptr<Tensor> tensor, ...) override;
void record(); void record() override;
private: private:

View file

@ -10,6 +10,8 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "OpBase.hpp"
namespace kp { namespace kp {
class Sequence class Sequence
@ -31,6 +33,8 @@ class Sequence
template<typename T, typename... TArgs> template<typename T, typename... TArgs>
void record(TArgs&&... args) void record(TArgs&&... args)
{ {
static_assert(std::is_base_of<OpBase, T>::value, "Template only valid with OpBase derived classes");
SPDLOG_DEBUG("Kompute Sequence record"); SPDLOG_DEBUG("Kompute Sequence record");
T op(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer); T op(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer);
op.init(std::forward<TArgs>(args)...); op.init(std::forward<TArgs>(args)...);
@ -47,6 +51,9 @@ class Sequence
std::shared_ptr<vk::CommandBuffer> mCommandBuffer = nullptr; std::shared_ptr<vk::CommandBuffer> mCommandBuffer = nullptr;
bool mFreeCommandBuffer = false; bool mFreeCommandBuffer = false;
// Base op objects
std::vector<OpBase> operations;
// Record state // Record state
bool mRecording = false; bool mRecording = false;

View file

@ -8,11 +8,12 @@ Tensor::Tensor() {
this->mTensorType = TensorTypes::eDevice; this->mTensorType = TensorTypes::eDevice;
} }
Tensor::Tensor(std::array<uint32_t, KP_MAX_DIM_SIZE> shape, TensorTypes tensorType) Tensor::Tensor(std::vector<uint32_t> data, TensorTypes tensorType)
{ {
SPDLOG_DEBUG("Kompute Tensor constructor shape and type"); SPDLOG_DEBUG("Kompute Tensor constructor shape and type");
this->mShape = shape; this->mData = data;
this->mShape = {data.size()};
this->mTensorType = tensorType; this->mTensorType = tensorType;
} }

View file

@ -27,7 +27,7 @@ class Tensor
Tensor(); Tensor();
Tensor(std::array<uint32_t, KP_MAX_DIM_SIZE> shape, TensorTypes tensorType = TensorTypes::eDevice); Tensor(std::vector<uint32_t> data, TensorTypes tensorType = TensorTypes::eDevice);
~Tensor(); ~Tensor();

View file

@ -620,10 +620,9 @@ main()
// Run Kompute // Run Kompute
spdlog::info("Creating manager"); spdlog::info("Creating manager");
kp::Manager mgr; kp::Manager mgr;
std::vector<uint32_t> data = {0.0, 1.0, 2.0}; kp::Tensor tensor({0.0, 1.0, 2.0});
kp::Tensor tensor({data.size()});
spdlog::info("Calling manager eval w opcreatetensor"); spdlog::info("Calling manager eval w opcreatetensor");
mgr.evalOp<kp::OpCreateTensor>(std::shared_ptr<kp::Tensor>(&tensor), data); mgr.evalOp<kp::OpCreateTensor>(std::shared_ptr<kp::Tensor>(&tensor));
spdlog::info("Called manager eval success"); spdlog::info("Called manager eval success");
std::vector<uint32_t> outData = tensor.data(); std::vector<uint32_t> outData = tensor.data();
spdlog::info("Output data: {}", outData); spdlog::info("Output data: {}", outData);