Merge pull request #75 from EthicalML/74_sequence_clear
74 Fixing manager default sequence creation
This commit is contained in:
commit
0b221c9ebd
7 changed files with 150 additions and 123 deletions
|
|
@ -1310,11 +1310,11 @@ class Manager
|
|||
* Create a new managed Kompute sequence so it's available within the
|
||||
* manager.
|
||||
*
|
||||
* @param sequenceName The name for the named sequence to be created
|
||||
* @param sequenceName The name for the named sequence to be created, if empty then default indexed value is used
|
||||
* @param queueIndex The queue to use from the available queues
|
||||
* @return Weak pointer to the manager owned sequence resource
|
||||
*/
|
||||
std::weak_ptr<Sequence> createManagedSequence(std::string sequenceName,
|
||||
std::weak_ptr<Sequence> createManagedSequence(std::string sequenceName = "",
|
||||
uint32_t queueIndex = 0);
|
||||
|
||||
/**
|
||||
|
|
@ -1351,7 +1351,7 @@ class Manager
|
|||
}
|
||||
|
||||
/**
|
||||
* Function that evaluates operation against default sequence.
|
||||
* Function that evaluates operation against a newly created sequence.
|
||||
*
|
||||
* @param tensors The tensors to be used in the operation recorded
|
||||
* @param TArgs Template parameters that will be used to initialise
|
||||
|
|
@ -1362,8 +1362,9 @@ class Manager
|
|||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOp<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward<TArgs>(params)...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1380,14 +1381,11 @@ class Manager
|
|||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered");
|
||||
|
||||
std::weak_ptr<Sequence> sqWeakPtr =
|
||||
this->getOrCreateManagedSequence(sequenceName);
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
|
||||
found = this->mManagedSequences.find(sequenceName);
|
||||
|
||||
if (found != this->mManagedSequences.end()) {
|
||||
std::shared_ptr<Sequence> sq = found->second;
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
|
||||
sq->begin();
|
||||
|
|
@ -1419,8 +1417,9 @@ class Manager
|
|||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOpAsync<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward<TArgs>(params)...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1460,7 +1459,7 @@ class Manager
|
|||
void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
|
||||
this->evalOpAwait(KP_DEFAULT_SESSION, waitFor);
|
||||
this->evalOpAwait(KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), waitFor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1504,6 +1503,8 @@ class Manager
|
|||
std::vector<uint32_t> mComputeQueueFamilyIndeces;
|
||||
std::vector<std::shared_ptr<vk::Queue>> mComputeQueues;
|
||||
|
||||
uint32_t mCurrentSequenceIndex = -1;
|
||||
|
||||
#if DEBUG
|
||||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS
|
||||
vk::DebugReportCallbackEXT mDebugReportCallback;
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ std::weak_ptr<Sequence>
|
|||
Manager::getOrCreateManagedSequence(std::string sequenceName)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager creating Sequence object");
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator found =
|
||||
this->mManagedSequences.find(sequenceName);
|
||||
|
||||
|
|
@ -120,7 +121,16 @@ Manager::createManagedSequence(std::string sequenceName, uint32_t queueIndex)
|
|||
this->mComputeQueues[queueIndex],
|
||||
this->mComputeQueueFamilyIndeces[queueIndex]);
|
||||
sq->init();
|
||||
this->mManagedSequences.insert({ sequenceName, sq });
|
||||
|
||||
if (sequenceName.empty()) {
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->mManagedSequences.insert({ KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), sq });
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Check if sequence doens't already exist
|
||||
this->mManagedSequences.insert({ sequenceName, sq });
|
||||
}
|
||||
return sq;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,10 +75,20 @@ Sequence::begin()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (this->isRunning()) {
|
||||
SPDLOG_WARN("Kompute Sequence begin called when sequence still running");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->mCommandPool) {
|
||||
throw std::runtime_error("Kompute Sequence command pool is null");
|
||||
}
|
||||
|
||||
if (this->mOperations.size()) {
|
||||
SPDLOG_INFO("Kompute Sequence clearing previous operations");
|
||||
this->mOperations.clear();
|
||||
}
|
||||
|
||||
if (!this->mRecording) {
|
||||
SPDLOG_INFO("Kompute Sequence command recording BEGIN");
|
||||
this->mCommandBuffer->begin(vk::CommandBufferBeginInfo());
|
||||
|
|
@ -177,9 +187,10 @@ Sequence::evalAwait(uint64_t waitFor)
|
|||
this->mDevice->waitForFences(1, &this->mFence, VK_TRUE, waitFor);
|
||||
this->mDevice->destroy(this->mFence);
|
||||
|
||||
this->mIsRunning = false;
|
||||
|
||||
if (result == vk::Result::eTimeout) {
|
||||
SPDLOG_WARN("Kompute Sequence evalAwait timed out");
|
||||
this->mIsRunning = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -187,8 +198,6 @@ Sequence::evalAwait(uint64_t waitFor)
|
|||
this->mOperations[i]->postEval();
|
||||
}
|
||||
|
||||
this->mIsRunning = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@ class Manager
|
|||
* Create a new managed Kompute sequence so it's available within the
|
||||
* manager.
|
||||
*
|
||||
* @param sequenceName The name for the named sequence to be created
|
||||
* @param sequenceName The name for the named sequence to be created, if empty then default indexed value is used
|
||||
* @param queueIndex The queue to use from the available queues
|
||||
* @return Weak pointer to the manager owned sequence resource
|
||||
*/
|
||||
std::weak_ptr<Sequence> createManagedSequence(std::string sequenceName,
|
||||
std::weak_ptr<Sequence> createManagedSequence(std::string sequenceName = "",
|
||||
uint32_t queueIndex = 0);
|
||||
|
||||
/**
|
||||
|
|
@ -113,7 +113,7 @@ class Manager
|
|||
}
|
||||
|
||||
/**
|
||||
* Function that evaluates operation against default sequence.
|
||||
* Function that evaluates operation against a newly created sequence.
|
||||
*
|
||||
* @param tensors The tensors to be used in the operation recorded
|
||||
* @param TArgs Template parameters that will be used to initialise
|
||||
|
|
@ -124,8 +124,9 @@ class Manager
|
|||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOp<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward<TArgs>(params)...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -142,14 +143,11 @@ class Manager
|
|||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered");
|
||||
|
||||
std::weak_ptr<Sequence> sqWeakPtr =
|
||||
this->getOrCreateManagedSequence(sequenceName);
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
|
||||
found = this->mManagedSequences.find(sequenceName);
|
||||
|
||||
if (found != this->mManagedSequences.end()) {
|
||||
std::shared_ptr<Sequence> sq = found->second;
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
|
||||
sq->begin();
|
||||
|
|
@ -181,8 +179,9 @@ class Manager
|
|||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOpAsync<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward<TArgs>(params)...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,7 +221,7 @@ class Manager
|
|||
void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
|
||||
this->evalOpAwait(KP_DEFAULT_SESSION, waitFor);
|
||||
this->evalOpAwait(KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), waitFor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -266,6 +265,8 @@ class Manager
|
|||
std::vector<uint32_t> mComputeQueueFamilyIndeces;
|
||||
std::vector<std::shared_ptr<vk::Queue>> mComputeQueues;
|
||||
|
||||
uint32_t mCurrentSequenceIndex = -1;
|
||||
|
||||
#if DEBUG
|
||||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS
|
||||
vk::DebugReportCallbackEXT mDebugReportCallback;
|
||||
|
|
|
|||
|
|
@ -142,23 +142,32 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution)
|
|||
std::vector<float> data(size, 0.0);
|
||||
std::vector<float> resultAsync(size, 100000000);
|
||||
|
||||
kp::Manager mgrAsync(0);
|
||||
kp::Manager mgr;
|
||||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> inputsAsyncB;
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(data) };
|
||||
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(data) };
|
||||
|
||||
inputsAsyncB.push_back(std::make_shared<kp::Tensor>(kp::Tensor(data)));
|
||||
mgr.createManagedSequence("asyncOne");
|
||||
mgr.createManagedSequence("asyncTwo");
|
||||
|
||||
mgrAsync.evalOpAsyncDefault<kp::OpTensorCreate>(inputsAsyncB);
|
||||
mgrAsync.evalOpAwaitDefault();
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
|
||||
mgrAsync.evalOpAsyncDefault<kp::OpAlgoBase<>>(
|
||||
{ inputsAsyncB[0] },
|
||||
mgr.evalOpAsync<kp::OpAlgoBase<>>(
|
||||
{ tensorA },
|
||||
"asyncOne",
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
mgrAsync.evalOpAwaitDefault();
|
||||
mgr.evalOpAsync<kp::OpAlgoBase<>>(
|
||||
{ tensorB },
|
||||
"asyncTwo",
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
mgrAsync.evalOpAsyncDefault<kp::OpTensorSyncLocal>({ inputsAsyncB });
|
||||
mgrAsync.evalOpAwaitDefault();
|
||||
mgr.evalOpAwait("asyncOne");
|
||||
mgr.evalOpAwait("asyncTwo");
|
||||
|
||||
EXPECT_EQ(inputsAsyncB[0]->data(), resultAsync);
|
||||
mgr.evalOpAsyncDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
mgr.evalOpAwaitDefault();
|
||||
|
||||
EXPECT_EQ(tensorA->data(), resultAsync);
|
||||
EXPECT_EQ(tensorB->data(), resultAsync);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,38 +31,38 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression)
|
|||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("createTensors").lock()) {
|
||||
std::shared_ptr<kp::Sequence> sqTensor =
|
||||
mgr.createManagedSequence().lock();
|
||||
|
||||
sq->begin();
|
||||
sqTensor->begin();
|
||||
sqTensor->record<kp::OpTensorCreate>(params);
|
||||
sqTensor->end();
|
||||
sqTensor->eval();
|
||||
|
||||
sq->record<kp::OpTensorCreate>(params);
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.createManagedSequence().lock();
|
||||
|
||||
// Record op algo base
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncDevice>({ wIn, bIn });
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
params, "test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
|
||||
|
||||
sq->end();
|
||||
|
||||
// Iterate across all expected iterations
|
||||
for (size_t i = 0; i < ITERATIONS; i++) {
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
// Record op algo base
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncDevice>({ wIn, bIn });
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
params, "test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
|
||||
|
||||
sq->end();
|
||||
|
||||
// Iterate across all expected iterations
|
||||
for (size_t i = 0; i < ITERATIONS; i++) {
|
||||
|
||||
sq->eval();
|
||||
|
||||
for (size_t j = 0; j < bOut->size(); j++) {
|
||||
wIn->data()[0] -= learningRate * wOutI->data()[j];
|
||||
wIn->data()[1] -= learningRate * wOutJ->data()[j];
|
||||
bIn->data()[0] -= learningRate * bOut->data()[j];
|
||||
}
|
||||
for (size_t j = 0; j < bOut->size(); j++) {
|
||||
wIn->data()[0] -= learningRate * wOutI->data()[j];
|
||||
wIn->data()[1] -= learningRate * wOutJ->data()[j];
|
||||
bIn->data()[0] -= learningRate * bOut->data()[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -115,39 +115,39 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy)
|
|||
{
|
||||
kp::Manager mgr;
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("createTensors").lock()) {
|
||||
std::shared_ptr<kp::Sequence> sqTensor =
|
||||
mgr.createManagedSequence().lock();
|
||||
|
||||
sq->begin();
|
||||
sqTensor->begin();
|
||||
sqTensor->record<kp::OpTensorCreate>(params);
|
||||
sqTensor->end();
|
||||
sqTensor->eval();
|
||||
|
||||
sq->record<kp::OpTensorCreate>(params);
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.createManagedSequence().lock();
|
||||
|
||||
// Record op algo base
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
params, "test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
|
||||
|
||||
sq->end();
|
||||
|
||||
// Iterate across all expected iterations
|
||||
for (size_t i = 0; i < ITERATIONS; i++) {
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
// Record op algo base
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<>>(
|
||||
params, "test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
|
||||
|
||||
sq->end();
|
||||
|
||||
// Iterate across all expected iterations
|
||||
for (size_t i = 0; i < ITERATIONS; i++) {
|
||||
|
||||
sq->eval();
|
||||
|
||||
for (size_t j = 0; j < bOut->size(); j++) {
|
||||
wIn->data()[0] -= learningRate * wOutI->data()[j];
|
||||
wIn->data()[1] -= learningRate * wOutJ->data()[j];
|
||||
bIn->data()[0] -= learningRate * bOut->data()[j];
|
||||
}
|
||||
wIn->mapDataIntoHostMemory();
|
||||
bIn->mapDataIntoHostMemory();
|
||||
for (size_t j = 0; j < bOut->size(); j++) {
|
||||
wIn->data()[0] -= learningRate * wOutI->data()[j];
|
||||
wIn->data()[1] -= learningRate * wOutJ->data()[j];
|
||||
bIn->data()[0] -= learningRate * bOut->data()[j];
|
||||
}
|
||||
wIn->mapDataIntoHostMemory();
|
||||
bIn->mapDataIntoHostMemory();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord)
|
|||
|
||||
TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords)
|
||||
{
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 0, 0, 0 }) };
|
||||
|
|
@ -59,43 +58,41 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords)
|
|||
pa[index] = pa[index] + 1;
|
||||
})");
|
||||
|
||||
std::weak_ptr<kp::Sequence> sqWeakPtr =
|
||||
mgr.getOrCreateManagedSequence("newSequence");
|
||||
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
|
||||
sq->begin();
|
||||
std::shared_ptr<kp::Sequence> sqTensor =
|
||||
mgr.createManagedSequence().lock();
|
||||
|
||||
sq->record<kp::OpTensorCreate>({ tensorA });
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.createManagedSequence().lock();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
// First create the tensor in a separate sequence
|
||||
sqTensor->begin();
|
||||
sqTensor->record<kp::OpTensorCreate>({ tensorA });
|
||||
sqTensor->end();
|
||||
sqTensor->eval();
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
// Then perform the computations
|
||||
sq->begin();
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
sq->begin();
|
||||
sq->begin();
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
sq->begin();
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpAlgoBase<3, 1, 1>>(
|
||||
{ tensorA }, std::vector<char>(shader.begin(), shader.end()));
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA });
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
}
|
||||
sqWeakPtr.reset();
|
||||
sq->begin();
|
||||
sq->record<kp::OpTensorSyncLocal>({ tensorA });
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
EXPECT_EQ(tensorA->data(), std::vector<float>({ 3, 3, 3 }));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue