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 000000000..9f528214a Binary files /dev/null and b/shaders/glsl/opmult.comp.spv differ diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 75faab7e0..a002e0d67 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -129,16 +129,26 @@ void Algorithm::createShaderModule(std::string shaderFilePath) { fileStream.read(shaderFileData, shaderFileSize); fileStream.close(); - vk::ShaderModuleCreateInfo shaderModuleInfo(vk::ShaderModuleCreateFlags(), shaderFileSize, (uint32_t*)shaderFileData); + vk::ShaderModuleCreateInfo shaderModuleInfo( + vk::ShaderModuleCreateFlags(), + shaderFileSize, + (uint32_t*)shaderFileData); + SPDLOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}", shaderFileSize); this->mFreeShaderModule = 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());