Working initial base

This commit is contained in:
Alejandro Saucedo 2021-02-25 08:15:44 +00:00
parent f35a62ee9d
commit 3f1288271d
7 changed files with 65 additions and 31 deletions

View file

@ -57,7 +57,6 @@ MK_KOMPUTE_EXTRA_CXX_FLAGS ?= ""
mk_cmake: mk_cmake:
cmake \ cmake \
-Bbuild \ -Bbuild \
$(MK_CMAKE_EXTRA_FLAGS) \
-DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \ -DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \
-DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \ -DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \ -DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \
@ -69,6 +68,7 @@ mk_cmake:
-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \ -DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \
-DKOMPUTE_OPT_ENABLE_SPDLOG=1 \ -DKOMPUTE_OPT_ENABLE_SPDLOG=1 \
-DKOMPUTE_OPT_CODE_COVERAGE=1 \ -DKOMPUTE_OPT_CODE_COVERAGE=1 \
$(MK_CMAKE_EXTRA_FLAGS) \
-G "Unix Makefiles" -G "Unix Makefiles"
mk_build_all: mk_build_all:

View file

@ -15,8 +15,6 @@ Algorithm::Algorithm(
KP_LOG_DEBUG("Kompute Algorithm Constructor with device"); KP_LOG_DEBUG("Kompute Algorithm Constructor with device");
this->mDevice = device; this->mDevice = device;
this->setWorkgroup(workgroup);
this->mPushConstants = pushConstants;
this->rebuild(tensors, spirv, workgroup, specializationConstants, pushConstants); this->rebuild(tensors, spirv, workgroup, specializationConstants, pushConstants);
} }
@ -37,8 +35,8 @@ Algorithm::rebuild(
{ {
KP_LOG_DEBUG("Kompute Algorithm rebuild started"); KP_LOG_DEBUG("Kompute Algorithm rebuild started");
this->setWorkgroup(workgroup);
this->mSpirv = spirv; this->mSpirv = spirv;
this->mWorkgroup = workgroup;
this->mSpecializationConstants = specializationConstants; this->mSpecializationConstants = specializationConstants;
this->mPushConstants = pushConstants; this->mPushConstants = pushConstants;
@ -300,14 +298,20 @@ Algorithm::createPipeline()
throw std::runtime_error("Failed to create pipeline result: " + throw std::runtime_error("Failed to create pipeline result: " +
vk::to_string(pipelineResult.result)); vk::to_string(pipelineResult.result));
} }
#else
vk::Pipeline pipelineResult = vk::Pipeline& pipeline = pipelineResult.value;
this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo); this->mPipeline = std::make_shared<vk::Pipeline>(pipeline);
this->mFreePipeline = true; this->mFreePipeline = true;
#else
vk::Pipeline pipeline =
this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo);
this->mPipeline = std::make_shared<vk::Pipeline>(pipeline);
#endif #endif
this->mFreePipeline = true; // TODO: Update to consistent
this->mPipeline = std::make_shared<vk::Pipeline>(pipelineResult); // this->mPipeline = std::make_shared<vk::Pipeline>();
// this->mDevice->createComputePipelines(
// *this->mPipelineCache, 1, &pipelineInfo, nullptr, this->mPipeline.get());
KP_LOG_DEBUG("Kompute Algorithm Create Pipeline Success"); KP_LOG_DEBUG("Kompute Algorithm Create Pipeline Success");
} }
@ -317,6 +321,20 @@ Algorithm::recordDispatch(std::shared_ptr<vk::CommandBuffer> commandBuffer)
{ {
KP_LOG_DEBUG("Kompute Algorithm calling record dispatch"); KP_LOG_DEBUG("Kompute Algorithm calling record dispatch");
if(this->mPipelineCache) {
KP_LOG_WARN("Value valid");
}
else {
KP_LOG_WARN("NOT Value valid");
}
if(this->mPipeline) {
KP_LOG_WARN("Value valid");
}
else {
KP_LOG_WARN("NOT Value valid");
}
commandBuffer->bindPipeline(vk::PipelineBindPoint::eCompute, commandBuffer->bindPipeline(vk::PipelineBindPoint::eCompute,
*this->mPipeline); *this->mPipeline);
@ -338,6 +356,12 @@ Algorithm::recordDispatch(std::shared_ptr<vk::CommandBuffer> commandBuffer)
void void
Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize) { Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize) {
KP_LOG_INFO("Kompute OpAlgoCreate setting dispatch size X: {}, Y: {}, Z: {}",
this->mWorkgroup[0],
this->mWorkgroup[1],
this->mWorkgroup[2]);
// The dispatch size is set up based on either explicitly provided template // The dispatch size is set up based on either explicitly provided template
// parameters or by default it would take the shape and size of the tensors // parameters or by default it would take the shape and size of the tensors
if (workgroup[0] > 0) { if (workgroup[0] > 0) {
@ -351,10 +375,6 @@ Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize) {
} else { } else {
this->mWorkgroup = { minSize, 1, 1 }; this->mWorkgroup = { minSize, 1, 1 };
} }
KP_LOG_INFO("Kompute OpAlgoCreate dispatch size X: {}, Y: {}, Z: {}",
this->mWorkgroup[0],
this->mWorkgroup[1],
this->mWorkgroup[2]);
} }
} }

View file

@ -4,6 +4,8 @@
#include "kompute/Manager.hpp" #include "kompute/Manager.hpp"
#include "kompute/operations/OpAlgoDispatch.hpp"
namespace kp { namespace kp {
#if DEBUG #if DEBUG
@ -76,7 +78,7 @@ Manager::~Manager()
algorithm->freeMemoryDestroyGPUResources(); algorithm->freeMemoryDestroyGPUResources();
} }
} }
this->mManagedTensors.clear(); this->mManagedAlgorithms.clear();
} }
if (this->mManagedTensors.size()) { if (this->mManagedTensors.size()) {
@ -324,7 +326,6 @@ Manager::tensor(
return tensor; return tensor;
} }
std::shared_ptr<Algorithm> std::shared_ptr<Algorithm>
Manager::algorithm( Manager::algorithm(
const std::vector<std::shared_ptr<Tensor>>& tensors, const std::vector<std::shared_ptr<Tensor>>& tensors,
@ -352,8 +353,7 @@ Manager::algorithm(
std::shared_ptr<Sequence> std::shared_ptr<Sequence>
Manager::sequence(uint32_t queueIndex) Manager::sequence(uint32_t queueIndex)
{ {
KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} " KP_LOG_DEBUG("Kompute Manager sequence() with queueIndex: {}",
"and queueIndex: {}",
queueIndex); queueIndex);
std::shared_ptr<Sequence> sq{ std::shared_ptr<Sequence> sq{

View file

@ -9,6 +9,8 @@ OpAlgoDispatch::OpAlgoDispatch(const std::vector<std::shared_ptr<Tensor>>& tenso
{ {
KP_LOG_DEBUG("Kompute OpAlgoDispatch constructor"); KP_LOG_DEBUG("Kompute OpAlgoDispatch constructor");
this->mTensors = tensors;
this->mAlgorithm = algorithm;
} }
OpAlgoDispatch::~OpAlgoDispatch() OpAlgoDispatch::~OpAlgoDispatch()

View file

@ -40,11 +40,9 @@ Sequence::begin()
throw std::runtime_error("Kompute Sequence begin called when sequence still running"); throw std::runtime_error("Kompute Sequence begin called when sequence still running");
} }
if (!this->mRecording) { KP_LOG_INFO("Kompute Sequence command now started recording");
KP_LOG_INFO("Kompute Sequence command recording BEGIN"); this->mCommandBuffer->begin(vk::CommandBufferBeginInfo());
this->mCommandBuffer->begin(vk::CommandBufferBeginInfo()); this->mRecording = true;
this->mRecording = true;
}
} }
void void
@ -161,6 +159,10 @@ Sequence::freeMemoryDestroyGPUResources()
} }
this->mDevice->freeCommandBuffers( this->mDevice->freeCommandBuffers(
*this->mCommandPool, 1, this->mCommandBuffer.get()); *this->mCommandPool, 1, this->mCommandBuffer.get());
this->mCommandBuffer = nullptr;
this->mFreeCommandBuffer = false;
KP_LOG_DEBUG("Kompute Sequence Freed CommandBuffer"); KP_LOG_DEBUG("Kompute Sequence Freed CommandBuffer");
} }
@ -175,6 +177,10 @@ Sequence::freeMemoryDestroyGPUResources()
this->mDevice->destroy( this->mDevice->destroy(
*this->mCommandPool, *this->mCommandPool,
(vk::Optional<const vk::AllocationCallbacks>)nullptr); (vk::Optional<const vk::AllocationCallbacks>)nullptr);
this->mCommandPool = nullptr;
this->mFreeCommandPool = false;
KP_LOG_DEBUG("Kompute Sequence Destroyed CommandPool"); KP_LOG_DEBUG("Kompute Sequence Destroyed CommandPool");
} }
@ -194,6 +200,7 @@ Sequence::record(std::shared_ptr<OpBase> op)
KP_LOG_DEBUG( KP_LOG_DEBUG(
"Kompute Sequence running record on OpBase derived class instance"); "Kompute Sequence running record on OpBase derived class instance");
op->record(this->mCommandBuffer); op->record(this->mCommandBuffer);
this->mOperations.push_back(op); this->mOperations.push_back(op);

View file

@ -449,6 +449,7 @@ Tensor::freeMemoryDestroyGPUResources()
*this->mPrimaryBuffer, *this->mPrimaryBuffer,
(vk::Optional<const vk::AllocationCallbacks>)nullptr); (vk::Optional<const vk::AllocationCallbacks>)nullptr);
this->mPrimaryBuffer = nullptr; this->mPrimaryBuffer = nullptr;
this->mFreePrimaryBuffer = false;
} }
} }
@ -462,6 +463,7 @@ Tensor::freeMemoryDestroyGPUResources()
*this->mStagingBuffer, *this->mStagingBuffer,
(vk::Optional<const vk::AllocationCallbacks>)nullptr); (vk::Optional<const vk::AllocationCallbacks>)nullptr);
this->mStagingBuffer = nullptr; this->mStagingBuffer = nullptr;
this->mFreeStagingBuffer = false;
} }
} }
@ -475,6 +477,7 @@ Tensor::freeMemoryDestroyGPUResources()
*this->mPrimaryMemory, *this->mPrimaryMemory,
(vk::Optional<const vk::AllocationCallbacks>)nullptr); (vk::Optional<const vk::AllocationCallbacks>)nullptr);
this->mPrimaryMemory = nullptr; this->mPrimaryMemory = nullptr;
this->mFreePrimaryMemory = false;
} }
} }
@ -488,6 +491,7 @@ Tensor::freeMemoryDestroyGPUResources()
*this->mStagingMemory, *this->mStagingMemory,
(vk::Optional<const vk::AllocationCallbacks>)nullptr); (vk::Optional<const vk::AllocationCallbacks>)nullptr);
this->mStagingMemory = nullptr; this->mStagingMemory = nullptr;
this->mFreeStagingMemory = false;
} }
} }

View file

@ -8,14 +8,16 @@
TEST(TestWorkgroup, TestSimpleWorkgroup) TEST(TestWorkgroup, TestSimpleWorkgroup)
{ {
std::shared_ptr<kp::Tensor> tensorA = nullptr;
std::shared_ptr<kp::Tensor> tensorB = nullptr;
{ {
std::shared_ptr<kp::Sequence> sq = nullptr; std::shared_ptr<kp::Sequence> sq = nullptr;
{ {
kp::Manager mgr; kp::Manager mgr;
std::shared_ptr<kp::Tensor> tensorA = mgr.tensor(std::vector<float>(16 * 8)); tensorA = mgr.tensor(std::vector<float>(16 * 8));
std::shared_ptr<kp::Tensor> tensorB = mgr.tensor(std::vector<float>(16 * 8)); tensorB = mgr.tensor(std::vector<float>(16 * 8));
std::vector<std::shared_ptr<kp::Tensor>> params = {tensorA, tensorB}; std::vector<std::shared_ptr<kp::Tensor>> params = {tensorA, tensorB};
@ -33,15 +35,14 @@ TEST(TestWorkgroup, TestSimpleWorkgroup)
sq->record(std::make_shared<kp::OpAlgoDispatch>(params, algorithm)); sq->record(std::make_shared<kp::OpAlgoDispatch>(params, algorithm));
sq->record(std::make_shared<kp::OpTensorSyncLocal>(params)); sq->record(std::make_shared<kp::OpTensorSyncLocal>(params));
sq->eval(); sq->eval();
std::vector<float> expectedA = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15};
std::vector<float> expectedB = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 };
EXPECT_EQ(tensorA->data(), expectedA);
EXPECT_EQ(tensorB->data(), expectedB);
} }
} }
std::vector<float> expectedA = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15};
std::vector<float> expectedB = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 };
EXPECT_EQ(tensorA->data(), expectedA);
EXPECT_EQ(tensorB->data(), expectedB);
} }