Working initial base
This commit is contained in:
parent
f35a62ee9d
commit
3f1288271d
7 changed files with 65 additions and 31 deletions
2
Makefile
2
Makefile
|
|
@ -57,7 +57,6 @@ MK_KOMPUTE_EXTRA_CXX_FLAGS ?= ""
|
|||
mk_cmake:
|
||||
cmake \
|
||||
-Bbuild \
|
||||
$(MK_CMAKE_EXTRA_FLAGS) \
|
||||
-DKOMPUTE_EXTRA_CXX_FLAGS=$(MK_KOMPUTE_EXTRA_CXX_FLAGS) \
|
||||
-DCMAKE_BUILD_TYPE=$(MK_BUILD_TYPE) \
|
||||
-DCMAKE_INSTALL_PREFIX=$(MK_INSTALL_PATH) \
|
||||
|
|
@ -69,6 +68,7 @@ mk_cmake:
|
|||
-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1 \
|
||||
-DKOMPUTE_OPT_ENABLE_SPDLOG=1 \
|
||||
-DKOMPUTE_OPT_CODE_COVERAGE=1 \
|
||||
$(MK_CMAKE_EXTRA_FLAGS) \
|
||||
-G "Unix Makefiles"
|
||||
|
||||
mk_build_all:
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ Algorithm::Algorithm(
|
|||
KP_LOG_DEBUG("Kompute Algorithm Constructor with device");
|
||||
|
||||
this->mDevice = device;
|
||||
this->setWorkgroup(workgroup);
|
||||
this->mPushConstants = pushConstants;
|
||||
this->rebuild(tensors, spirv, workgroup, specializationConstants, pushConstants);
|
||||
}
|
||||
|
||||
|
|
@ -37,8 +35,8 @@ Algorithm::rebuild(
|
|||
{
|
||||
KP_LOG_DEBUG("Kompute Algorithm rebuild started");
|
||||
|
||||
this->setWorkgroup(workgroup);
|
||||
this->mSpirv = spirv;
|
||||
this->mWorkgroup = workgroup;
|
||||
this->mSpecializationConstants = specializationConstants;
|
||||
this->mPushConstants = pushConstants;
|
||||
|
||||
|
|
@ -300,14 +298,20 @@ Algorithm::createPipeline()
|
|||
throw std::runtime_error("Failed to create pipeline result: " +
|
||||
vk::to_string(pipelineResult.result));
|
||||
}
|
||||
#else
|
||||
vk::Pipeline pipelineResult =
|
||||
this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo);
|
||||
|
||||
vk::Pipeline& pipeline = pipelineResult.value;
|
||||
this->mPipeline = std::make_shared<vk::Pipeline>(pipeline);
|
||||
this->mFreePipeline = true;
|
||||
#else
|
||||
vk::Pipeline pipeline =
|
||||
this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo);
|
||||
this->mPipeline = std::make_shared<vk::Pipeline>(pipeline);
|
||||
#endif
|
||||
|
||||
this->mFreePipeline = true;
|
||||
this->mPipeline = std::make_shared<vk::Pipeline>(pipelineResult);
|
||||
// TODO: Update to consistent
|
||||
// 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");
|
||||
}
|
||||
|
|
@ -317,6 +321,20 @@ Algorithm::recordDispatch(std::shared_ptr<vk::CommandBuffer> commandBuffer)
|
|||
{
|
||||
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,
|
||||
*this->mPipeline);
|
||||
|
||||
|
|
@ -338,6 +356,12 @@ Algorithm::recordDispatch(std::shared_ptr<vk::CommandBuffer> commandBuffer)
|
|||
|
||||
void
|
||||
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
|
||||
// parameters or by default it would take the shape and size of the tensors
|
||||
if (workgroup[0] > 0) {
|
||||
|
|
@ -351,10 +375,6 @@ Algorithm::setWorkgroup(const Workgroup& workgroup, uint32_t minSize) {
|
|||
} else {
|
||||
this->mWorkgroup = { minSize, 1, 1 };
|
||||
}
|
||||
KP_LOG_INFO("Kompute OpAlgoCreate dispatch size X: {}, Y: {}, Z: {}",
|
||||
this->mWorkgroup[0],
|
||||
this->mWorkgroup[1],
|
||||
this->mWorkgroup[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "kompute/Manager.hpp"
|
||||
|
||||
#include "kompute/operations/OpAlgoDispatch.hpp"
|
||||
|
||||
namespace kp {
|
||||
|
||||
#if DEBUG
|
||||
|
|
@ -76,7 +78,7 @@ Manager::~Manager()
|
|||
algorithm->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
}
|
||||
this->mManagedTensors.clear();
|
||||
this->mManagedAlgorithms.clear();
|
||||
}
|
||||
|
||||
if (this->mManagedTensors.size()) {
|
||||
|
|
@ -324,7 +326,6 @@ Manager::tensor(
|
|||
return tensor;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<Algorithm>
|
||||
Manager::algorithm(
|
||||
const std::vector<std::shared_ptr<Tensor>>& tensors,
|
||||
|
|
@ -352,8 +353,7 @@ Manager::algorithm(
|
|||
std::shared_ptr<Sequence>
|
||||
Manager::sequence(uint32_t queueIndex)
|
||||
{
|
||||
KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} "
|
||||
"and queueIndex: {}",
|
||||
KP_LOG_DEBUG("Kompute Manager sequence() with queueIndex: {}",
|
||||
queueIndex);
|
||||
|
||||
std::shared_ptr<Sequence> sq{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ OpAlgoDispatch::OpAlgoDispatch(const std::vector<std::shared_ptr<Tensor>>& tenso
|
|||
{
|
||||
KP_LOG_DEBUG("Kompute OpAlgoDispatch constructor");
|
||||
|
||||
this->mTensors = tensors;
|
||||
this->mAlgorithm = algorithm;
|
||||
}
|
||||
|
||||
OpAlgoDispatch::~OpAlgoDispatch()
|
||||
|
|
|
|||
|
|
@ -40,11 +40,9 @@ Sequence::begin()
|
|||
throw std::runtime_error("Kompute Sequence begin called when sequence still running");
|
||||
}
|
||||
|
||||
if (!this->mRecording) {
|
||||
KP_LOG_INFO("Kompute Sequence command recording BEGIN");
|
||||
this->mCommandBuffer->begin(vk::CommandBufferBeginInfo());
|
||||
this->mRecording = true;
|
||||
}
|
||||
KP_LOG_INFO("Kompute Sequence command now started recording");
|
||||
this->mCommandBuffer->begin(vk::CommandBufferBeginInfo());
|
||||
this->mRecording = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -161,6 +159,10 @@ Sequence::freeMemoryDestroyGPUResources()
|
|||
}
|
||||
this->mDevice->freeCommandBuffers(
|
||||
*this->mCommandPool, 1, this->mCommandBuffer.get());
|
||||
|
||||
this->mCommandBuffer = nullptr;
|
||||
this->mFreeCommandBuffer = false;
|
||||
|
||||
KP_LOG_DEBUG("Kompute Sequence Freed CommandBuffer");
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +177,10 @@ Sequence::freeMemoryDestroyGPUResources()
|
|||
this->mDevice->destroy(
|
||||
*this->mCommandPool,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
|
||||
this->mCommandPool = nullptr;
|
||||
this->mFreeCommandPool = false;
|
||||
|
||||
KP_LOG_DEBUG("Kompute Sequence Destroyed CommandPool");
|
||||
}
|
||||
|
||||
|
|
@ -194,6 +200,7 @@ Sequence::record(std::shared_ptr<OpBase> op)
|
|||
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Sequence running record on OpBase derived class instance");
|
||||
|
||||
op->record(this->mCommandBuffer);
|
||||
|
||||
this->mOperations.push_back(op);
|
||||
|
|
|
|||
|
|
@ -449,6 +449,7 @@ Tensor::freeMemoryDestroyGPUResources()
|
|||
*this->mPrimaryBuffer,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
this->mPrimaryBuffer = nullptr;
|
||||
this->mFreePrimaryBuffer = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -462,6 +463,7 @@ Tensor::freeMemoryDestroyGPUResources()
|
|||
*this->mStagingBuffer,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
this->mStagingBuffer = nullptr;
|
||||
this->mFreeStagingBuffer = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -475,6 +477,7 @@ Tensor::freeMemoryDestroyGPUResources()
|
|||
*this->mPrimaryMemory,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
this->mPrimaryMemory = nullptr;
|
||||
this->mFreePrimaryMemory = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -488,6 +491,7 @@ Tensor::freeMemoryDestroyGPUResources()
|
|||
*this->mStagingMemory,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
this->mStagingMemory = nullptr;
|
||||
this->mFreeStagingMemory = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,16 @@
|
|||
|
||||
TEST(TestWorkgroup, TestSimpleWorkgroup)
|
||||
{
|
||||
std::shared_ptr<kp::Tensor> tensorA = nullptr;
|
||||
std::shared_ptr<kp::Tensor> tensorB = nullptr;
|
||||
{
|
||||
std::shared_ptr<kp::Sequence> sq = nullptr;
|
||||
|
||||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA = mgr.tensor(std::vector<float>(16 * 8));
|
||||
std::shared_ptr<kp::Tensor> tensorB = mgr.tensor(std::vector<float>(16 * 8));
|
||||
tensorA = 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};
|
||||
|
||||
|
|
@ -33,15 +35,14 @@ TEST(TestWorkgroup, TestSimpleWorkgroup)
|
|||
sq->record(std::make_shared<kp::OpAlgoDispatch>(params, algorithm));
|
||||
sq->record(std::make_shared<kp::OpTensorSyncLocal>(params));
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue