From 8f6078c422db0b9f74b4b72da794c6ea8d844447 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 22 Aug 2020 12:08:18 +0100 Subject: [PATCH] Added end to end implementation of OpMult with postSubmit calls on sequence --- Makefile | 1 + shaders/glsl/opmult.comp | 25 +++++++++++++++++++++++++ shaders/glsl/opmult.comp.spv | Bin 0 -> 1308 bytes src/Algorithm.cpp | 16 +++++++++++++--- src/OpMult.cpp | 9 ++++++++- src/Sequence.cpp | 5 +++++ src/Sequence.hpp | 5 +++-- src/main.cpp | 9 +++++++-- 8 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 shaders/glsl/opmult.comp create mode 100755 shaders/glsl/opmult.comp.spv diff --git a/Makefile b/Makefile index 6c6968aff..72ee3e40d 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ build_linux: build_shaders: $(SCMP) -V shaders/glsl/computeheadless.comp -o shaders/glsl/computeheadless.comp.spv + $(SCMP) -V shaders/glsl/opmult.comp -o shaders/glsl/opmult.comp.spv docker_seldon_run: docker run \ diff --git a/shaders/glsl/opmult.comp b/shaders/glsl/opmult.comp new file mode 100644 index 000000000..69f3840b1 --- /dev/null +++ b/shaders/glsl/opmult.comp @@ -0,0 +1,25 @@ +#version 450 + +layout(binding = 0) buffer tensorLhs { + uint valuesLhs[ ]; +}; + +layout(binding = 1) buffer tensorRhs { + uint valuesRhs[ ]; +}; + +layout(binding = 2) buffer tensorOutput { + uint valuesOutput[ ]; +}; + +// TODO: Explore how to make layout inside shader dynamic +layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +void main() +{ + uint index = gl_GlobalInvocationID.x; + + valuesOutput[index] = valuesLhs[index] * valuesRhs[index]; +} + + diff --git a/shaders/glsl/opmult.comp.spv b/shaders/glsl/opmult.comp.spv new file mode 100755 index 0000000000000000000000000000000000000000..9f528214a96b12c44b65c96f978f6ce6846311f7 GIT binary patch literal 1308 zcmYk5?P?Q26o#jXn^vp+u-5w3x@qdS6o04)qEHZGAt2}lNVGu%=|;?^cmZCSSLGkU z=b6dq&T=^Cea|`X%$(hAw|dJVEQJ-Ghas)a(1HnJHFToy4?YYIXZ6Y9(`QetSPSh~ zXw5n`1^yg%IviIfRTLRXSdXXG@tc_MME!bH&8FYq&FgRT8k(J#BX4{*oXkhF|G9$ww@k1Ko@@BjKlnN$ z?(oRDQg7nzyOHSFR}!bb_y79jT&XYd_U$J+^tqq+(QaYl4SWZ44sTI*Uanqp)U+e# z#I5)2O+9fJbEf8Z@J+pZm!_Uv*7HtHJ+XQ&^={*vdZh_gQ?CSPJ++#8#_I99quv9& z_rH#9aq1SnOSk>T+wAFnCFUx@e4x?fcfjZI#`c)MfLCAs0 zb#`l*^L3`LsPUZZnEY!LtQY6pRbsh}Z!Yi=o!)g9^Zw4xT&~+AHkWaaSe@K=KmFreeShaderModule = true; - this->mShaderModule = std::shared_ptr(); - this->mDevice->createShaderModule(&shaderModuleInfo, nullptr, this->mShaderModule.get()); + this->mShaderModule = std::make_shared(); + this->mDevice->createShaderModule( + &shaderModuleInfo, + nullptr, + this->mShaderModule.get()); + + SPDLOG_DEBUG("Kompute Algorithm create shader module success"); } void Algorithm::createPipeline() { SPDLOG_DEBUG("Kompute Algorithm calling create Pipeline"); + // TODO: Explore design for supporting multiple sets vk::PipelineLayoutCreateInfo pipelineLayoutInfo( vk::PipelineLayoutCreateFlags(), 1, // Set layout count diff --git a/src/OpMult.cpp b/src/OpMult.cpp index 19414d1bd..addc7b25a 100644 --- a/src/OpMult.cpp +++ b/src/OpMult.cpp @@ -43,17 +43,24 @@ OpMult::init(std::vector> tensors) this->mTensorRHS = tensors[1]; this->mTensorOutput = tensors[2]; + // TODO: Explore adding a validate function if (!(this->mTensorLHS->isInit() && this->mTensorRHS->isInit() && this->mTensorOutput->isInit())) { throw std::runtime_error("Kompute OpMult all tensor parameters must be initialised. LHS: " + std::to_string(this->mTensorLHS->isInit()) + " RHS: " + std::to_string(this->mTensorRHS->isInit()) + " Output: " + std::to_string(this->mTensorOutput->isInit())); } + // TODO: Explore use-cases where tensors shouldn't be the same size, and how to deal with those situations + if (!(this->mTensorLHS->size() == this->mTensorRHS->size() && this->mTensorRHS->size() == this->mTensorOutput->size())) { + throw std::runtime_error("Kompute OpMult all tensor parameters must be the same size LHS: " + std::to_string(this->mTensorLHS->size()) + " RHS: " + std::to_string(this->mTensorRHS->size()) + " Output: " + std::to_string(this->mTensorOutput->size())); + } + this->mTensorOutputStaging = std::make_shared( this->mTensorOutput->data(), Tensor::TensorTypes::eStaging); this->mTensorOutputStaging->init(this->mPhysicalDevice, this->mDevice, this->mCommandBuffer, this->mTensorOutput->data()); + // TODO: Make this path configurable this->mAlgorithm->init( - "shaders/glsl/computeheadless.comp.spv", tensors); + "shaders/glsl/opmult.comp.spv", tensors); } void diff --git a/src/Sequence.cpp b/src/Sequence.cpp index eb9e833d7..769348278 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -120,6 +120,11 @@ Sequence::eval() this->end(); } + // TODO: Explore whether moving postSubmit calls to a separate sequence function that is explicitly called by the manager + for (size_t i = 0; i < this->mOperations.size(); i++) { + this->mOperations[i]->postSubmit(); + } + SPDLOG_DEBUG("Kompute sequence EVAL success"); } diff --git a/src/Sequence.hpp b/src/Sequence.hpp index 96a7c4cab..8eeec6aff 100644 --- a/src/Sequence.hpp +++ b/src/Sequence.hpp @@ -29,6 +29,7 @@ class Sequence void end(); void eval(); + // TODO: Explore design without template using just top level class template void record(TArgs&&... args) { @@ -46,7 +47,7 @@ class Sequence baseOpPtr->init(std::forward(args)...); baseOpPtr->record(); - operations.push_back(std::move(baseOpPtr)); + mOperations.push_back(std::move(baseOpPtr)); } private: @@ -60,7 +61,7 @@ class Sequence bool mFreeCommandBuffer = false; // Base op objects - std::vector> operations; + std::vector> mOperations; // Record state bool mRecording = false; diff --git a/src/main.cpp b/src/main.cpp index 810917314..08bf9a698 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -640,14 +640,19 @@ main() { 0.0, 0.0, 0.0 }) }; mgr.evalOp({ tensorOutput }); - spdlog::info("Called manager eval success"); + spdlog::info("OpCreateTensor success for tensors"); spdlog::info("Tensor one: {}", tensorLHS->data()); spdlog::info("Tensor two: {}", tensorRHS->data()); - spdlog::info("Tensor two: {}", tensorOutput->data()); + spdlog::info("Tensor output: {}", tensorOutput->data()); spdlog::info("Calling op mult"); mgr.evalOp({ tensorLHS, tensorRHS, tensorOutput }); + spdlog::info("OpMult call success"); + spdlog::info("Tensor output: {}", tensorOutput->data()); + + spdlog::info("Called manager eval success END PROGRAM"); + return 0; } catch (const std::exception& exc) { spdlog::error("Exception caught: {}", exc.what());