Added end to end implementation of OpMult with postSubmit calls on sequence
This commit is contained in:
parent
03688bc5b2
commit
8f6078c422
8 changed files with 62 additions and 8 deletions
1
Makefile
1
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 \
|
||||
|
|
|
|||
25
shaders/glsl/opmult.comp
Normal file
25
shaders/glsl/opmult.comp
Normal file
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
||||
BIN
shaders/glsl/opmult.comp.spv
Executable file
BIN
shaders/glsl/opmult.comp.spv
Executable file
Binary file not shown.
|
|
@ -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<vk::ShaderModule>();
|
||||
this->mDevice->createShaderModule(&shaderModuleInfo, nullptr, this->mShaderModule.get());
|
||||
this->mShaderModule = std::make_shared<vk::ShaderModule>();
|
||||
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
|
||||
|
|
|
|||
|
|
@ -43,17 +43,24 @@ OpMult::init(std::vector<std::shared_ptr<Tensor>> 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<Tensor>(
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class Sequence
|
|||
void end();
|
||||
void eval();
|
||||
|
||||
// TODO: Explore design without template using just top level class
|
||||
template<typename T, typename... TArgs>
|
||||
void record(TArgs&&... args)
|
||||
{
|
||||
|
|
@ -46,7 +47,7 @@ class Sequence
|
|||
baseOpPtr->init(std::forward<TArgs>(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<std::unique_ptr<OpBase>> operations;
|
||||
std::vector<std::unique_ptr<OpBase>> mOperations;
|
||||
|
||||
// Record state
|
||||
bool mRecording = false;
|
||||
|
|
|
|||
|
|
@ -640,14 +640,19 @@ main()
|
|||
{ 0.0, 0.0, 0.0 }) };
|
||||
mgr.evalOp<kp::OpCreateTensor>({ 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<kp::OpMult>({ 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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue