Updated tests to reflect manager tensor memory ownership

This commit is contained in:
Alejandro Saucedo 2021-02-08 19:17:32 +00:00
parent fc3d23d3f9
commit 4dedfadfef
10 changed files with 117 additions and 54 deletions

View file

@ -49,7 +49,7 @@ TEST(TestAsyncOperations, TestManagerParallelExecution)
inputsSyncB.push_back(std::make_shared<kp::Tensor>(kp::Tensor(data))); inputsSyncB.push_back(std::make_shared<kp::Tensor>(kp::Tensor(data)));
} }
mgr.evalOpDefault<kp::OpTensorCreate>(inputsSyncB); mgr.rebuildTensors(inputsSyncB);
auto startSync = std::chrono::high_resolution_clock::now(); auto startSync = std::chrono::high_resolution_clock::now();
@ -77,7 +77,7 @@ TEST(TestAsyncOperations, TestManagerParallelExecution)
inputsAsyncB.push_back(std::make_shared<kp::Tensor>(kp::Tensor(data))); inputsAsyncB.push_back(std::make_shared<kp::Tensor>(kp::Tensor(data)));
} }
mgrAsync.evalOpDefault<kp::OpTensorCreate>(inputsAsyncB); mgrAsync.rebuildTensors(inputsAsyncB);
for (uint32_t i = 0; i < numParallel; i++) { for (uint32_t i = 0; i < numParallel; i++) {
mgrAsync.createManagedSequence("async" + std::to_string(i), i); mgrAsync.createManagedSequence("async" + std::to_string(i), i);
@ -149,7 +149,7 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution)
mgr.createManagedSequence("asyncOne"); mgr.createManagedSequence("asyncOne");
mgr.createManagedSequence("asyncTwo"); mgr.createManagedSequence("asyncTwo");
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpAsync<kp::OpAlgoBase>( mgr.evalOpAsync<kp::OpAlgoBase>(
{ tensorA }, "asyncOne", std::vector<char>(shader.begin(), shader.end())); { tensorA }, "asyncOne", std::vector<char>(shader.begin(), shader.end()));

View file

@ -32,12 +32,8 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression)
{ {
kp::Manager mgr; kp::Manager mgr;
std::shared_ptr<kp::Sequence> sqTensor = mgr.createManagedSequence(); mgr.rebuildTensors(params);
mgr.evalOpDefault<kp::OpTensorSyncDevice>(params);
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence(); std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence();
@ -122,12 +118,8 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy)
{ {
kp::Manager mgr; kp::Manager mgr;
std::shared_ptr<kp::Sequence> sqTensor = mgr.createManagedSequence(); mgr.rebuildTensors(params);
mgr.evalOpDefault<kp::OpTensorSyncDevice>(params);
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence(); std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence();

View file

@ -8,14 +8,16 @@ TEST(TestManager, EndToEndOpMultFlow)
kp::Manager mgr; kp::Manager mgr;
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor({ 0, 1, 2 }) }; std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor({ 0, 1, 2 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorLHS }); mgr.rebuildTensors({ tensorLHS });
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor({ 2, 4, 6 }) }; std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor({ 2, 4, 6 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorRHS }); mgr.rebuildTensors({ tensorRHS });
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0, 0, 0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorOutput }); mgr.rebuildTensors({ tensorOutput });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorLHS, tensorRHS, tensorOutput });
mgr.evalOpDefault<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput }); mgr.evalOpDefault<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput });
@ -36,14 +38,16 @@ TEST(TestManager, OpMultSequenceFlow)
kp::Manager mgr; kp::Manager mgr;
{ {
mgr.rebuildTensors({ tensorLHS, tensorRHS, tensorOutput });
std::shared_ptr<kp::Sequence> sq = std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence"); mgr.getOrCreateManagedSequence("newSequence");
sq->begin(); sq->begin();
sq->record<kp::OpTensorCreate>({ tensorLHS }); sq->record<kp::OpTensorSyncDevice>({ tensorLHS });
sq->record<kp::OpTensorCreate>({ tensorRHS }); sq->record<kp::OpTensorSyncDevice>({ tensorRHS });
sq->record<kp::OpTensorCreate>({ tensorOutput }); sq->record<kp::OpTensorSyncDevice>({ tensorOutput });
sq->record<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput }); sq->record<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput });
@ -93,14 +97,16 @@ TEST(TestManager, TestMultipleTensorsAtOnce)
mgr.getOrCreateManagedSequence("newSequence"); mgr.getOrCreateManagedSequence("newSequence");
{ {
sq->begin(); mgr.rebuildTensors({ tensorLHS, tensorRHS, tensorOutput });
sq->record<kp::OpTensorCreate>({ tensorLHS, tensorRHS, tensorOutput });
EXPECT_TRUE(tensorLHS->isInit()); EXPECT_TRUE(tensorLHS->isInit());
EXPECT_TRUE(tensorRHS->isInit()); EXPECT_TRUE(tensorRHS->isInit());
EXPECT_TRUE(tensorOutput->isInit()); EXPECT_TRUE(tensorOutput->isInit());
sq->begin();
sq->record<kp::OpTensorSyncDevice>({ tensorLHS, tensorRHS, tensorOutput });
sq->record<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput }); sq->record<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput });
sq->record<kp::OpTensorSyncLocal>({ tensorOutput }); sq->record<kp::OpTensorSyncLocal>({ tensorOutput });
@ -119,6 +125,10 @@ TEST(TestManager, TestCreateInitTensor)
std::shared_ptr<kp::Tensor> tensorA = mgr.buildTensor({ 0, 1, 2 }); std::shared_ptr<kp::Tensor> tensorA = mgr.buildTensor({ 0, 1, 2 });
std::shared_ptr<kp::Tensor> tensorB = mgr.buildTensor({ 0, 0, 0 }); std::shared_ptr<kp::Tensor> tensorB = mgr.buildTensor({ 0, 0, 0 });
mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB }); mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB }); mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorB });

View file

@ -19,13 +19,15 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord)
pa[index] = pa[index] + 1; pa[index] = pa[index] + 1;
})"); })");
mgr.rebuildTensors({ tensorA });
std::shared_ptr<kp::Sequence> sq = std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence"); mgr.getOrCreateManagedSequence("newSequence");
{ {
sq->begin(); sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA }); sq->record<kp::OpTensorSyncDevice>({ tensorA });
sq->record<kp::OpAlgoBase>( sq->record<kp::OpAlgoBase>(
{ tensorA }, std::vector<char>(shader.begin(), shader.end())); { tensorA }, std::vector<char>(shader.begin(), shader.end()));
@ -58,13 +60,15 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords)
pa[index] = pa[index] + 1; pa[index] = pa[index] + 1;
})"); })");
mgr.rebuildTensors({ tensorA });
std::shared_ptr<kp::Sequence> sqTensor = mgr.createManagedSequence(); std::shared_ptr<kp::Sequence> sqTensor = mgr.createManagedSequence();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence(); std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence();
// First create the tensor in a separate sequence // First create the tensor in a separate sequence
sqTensor->begin(); sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>({ tensorA }); sqTensor->record<kp::OpTensorSyncDevice>({ tensorA });
sqTensor->end(); sqTensor->end();
sqTensor->eval(); sqTensor->eval();
@ -111,13 +115,15 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
pa[index] = pa[index] + 1; pa[index] = pa[index] + 1;
})"); })");
mgr.rebuildTensors({ tensorA });
{ {
std::shared_ptr<kp::Sequence> sq = std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence"); mgr.getOrCreateManagedSequence("newSequence");
sq->begin(); sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA }); sq->record<kp::OpTensorSyncDevice>({ tensorA });
sq->record<kp::OpAlgoBase>( sq->record<kp::OpAlgoBase>(
{ tensorA }, std::vector<char>(shader.begin(), shader.end())); { tensorA }, std::vector<char>(shader.begin(), shader.end()));
@ -183,13 +189,15 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
pa[index] = pa[index] + 1; pa[index] = pa[index] + 1;
})"); })");
mgr.rebuildTensors({ tensorA });
{ {
std::shared_ptr<kp::Sequence> sq = std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence"); mgr.getOrCreateManagedSequence("newSequence");
sq->begin(); sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA }); sq->record<kp::OpTensorSyncDevice>({ tensorA });
sq->end(); sq->end();
sq->eval(); sq->eval();
@ -238,7 +246,9 @@ TEST(TestMultipleAlgoExecutions, ManagerEvalMultSourceStrOpCreate)
std::shared_ptr<kp::Tensor> tensorInB{ new kp::Tensor({ 0.0, 1.0, 2.0 }) }; std::shared_ptr<kp::Tensor> tensorInB{ new kp::Tensor({ 0.0, 1.0, 2.0 }) };
std::shared_ptr<kp::Tensor> tensorOut{ new kp::Tensor({ 0.0, 0.0, 0.0 }) }; std::shared_ptr<kp::Tensor> tensorOut{ new kp::Tensor({ 0.0, 0.0, 0.0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorInA, tensorInB, tensorOut }); mgr.rebuildTensors({ tensorInA, tensorInB, tensorOut });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorInA, tensorInB, tensorOut });
std::string shader(R"( std::string shader(R"(
// The version to use // The version to use
@ -296,6 +306,8 @@ TEST(TestMultipleAlgoExecutions, ManagerEvalMultSourceStrMgrCreate)
} }
)"); )");
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorInA, tensorInB, tensorOut });
mgr.evalOpDefault<kp::OpAlgoBase>( mgr.evalOpDefault<kp::OpAlgoBase>(
{ tensorInA, tensorInB, tensorOut }, { tensorInA, tensorInB, tensorOut },
std::vector<char>(shader.begin(), shader.end())); std::vector<char>(shader.begin(), shader.end()));

View file

@ -30,13 +30,15 @@ TEST(TestProcessingIterations, IterateThroughMultipleSumAndCopies)
} }
)"); )");
mgr.rebuildTensors({ tensorA, tensorB });
{ {
std::shared_ptr<kp::Sequence> sq = std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("default"); mgr.getOrCreateManagedSequence("default");
sq->begin(); sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA, tensorB }); sq->record<kp::OpTensorSyncDevice>({ tensorA, tensorB });
sq->end(); sq->end();

View file

@ -11,7 +11,7 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
std::string shader(R"( std::string shader(R"(
#version 450 #version 450
@ -28,6 +28,8 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor)
} }
)"); )");
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase>( mgr.evalOpDefault<kp::OpAlgoBase>(
{ tensorA, tensorB }, std::vector<char>(shader.begin(), shader.end())); { tensorA, tensorB }, std::vector<char>(shader.begin(), shader.end()));
@ -43,7 +45,9 @@ TEST(TestOpAlgoBase, ShaderCompiledDataFromConstructor)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase>( mgr.evalOpDefault<kp::OpAlgoBase>(
{ tensorA, tensorB }, { tensorA, tensorB },
@ -65,7 +69,9 @@ TEST(TestOpAlgoBase, ShaderRawDataFromFile)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase>( mgr.evalOpDefault<kp::OpAlgoBase>(
{ tensorA, tensorB }, "test/shaders/glsl/test_op_custom_shader.comp"); { tensorA, tensorB }, "test/shaders/glsl/test_op_custom_shader.comp");
@ -82,7 +88,9 @@ TEST(TestOpAlgoBase, ShaderCompiledDataFromFile)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 }) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase>( mgr.evalOpDefault<kp::OpAlgoBase>(
{ tensorA, tensorB }, "test/shaders/glsl/test_op_custom_shader.comp.spv"); { tensorA, tensorB }, "test/shaders/glsl/test_op_custom_shader.comp.spv");

View file

@ -14,7 +14,9 @@ TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -41,7 +43,9 @@ TEST(TestOpTensorCopy, CopyDeviceToDeviceTensorMulti)
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
std::shared_ptr<kp::Tensor> tensorC{ new kp::Tensor(testVecC) }; std::shared_ptr<kp::Tensor> tensorC{ new kp::Tensor(testVecC) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB, tensorC }); mgr.rebuildTensors({ tensorA, tensorB, tensorC });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -70,7 +74,10 @@ TEST(TestOpTensorCopy, CopyDeviceToHostTensor)
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor( std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(
testVecB, kp::Tensor::TensorTypes::eHost) }; testVecB, kp::Tensor::TensorTypes::eHost) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
// Only calling sync on device type tensor
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -96,7 +103,10 @@ TEST(TestOpTensorCopy, CopyHostToDeviceTensor)
testVecA, kp::Tensor::TensorTypes::eHost) }; testVecA, kp::Tensor::TensorTypes::eHost) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
// Only calling sync on device type tensor
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -123,7 +133,9 @@ TEST(TestOpTensorCopy, CopyHostToHostTensor)
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor( std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(
testVecB, kp::Tensor::TensorTypes::eHost) }; testVecB, kp::Tensor::TensorTypes::eHost) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
// Not calling OpTensorSyncDevice
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -147,7 +159,7 @@ TEST(TestOpTensorCopy, SingleTensorShouldFail)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor( std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(
testVecA, kp::Tensor::TensorTypes::eHost) }; testVecA, kp::Tensor::TensorTypes::eHost) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());

View file

@ -12,7 +12,7 @@ TEST(TestOpTensorCreate, CreateSingleTensorSingleOp)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
@ -33,7 +33,7 @@ TEST(TestOpTensorCreate, CreateMultipleTensorSingleOp)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB }); mgr.rebuildTensors({ tensorA, tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -53,8 +53,8 @@ TEST(TestOpTensorCreate, CreateMultipleTensorMultipleOp)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorB }); mgr.rebuildTensors({ tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -63,7 +63,7 @@ TEST(TestOpTensorCreate, CreateMultipleTensorMultipleOp)
EXPECT_EQ(tensorB->data(), testVecB); EXPECT_EQ(tensorB->data(), testVecB);
} }
TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed) TEST(TestOpTensorCreate, TestTensorMemoryManagedByManagerDestroyed)
{ {
std::vector<float> testVecA{ 9, 8, 7 }; std::vector<float> testVecA{ 9, 8, 7 };
@ -74,8 +74,8 @@ TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed)
{ {
kp::Manager mgr; kp::Manager mgr;
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorB }); mgr.rebuildTensors({ tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -88,6 +88,32 @@ TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed)
EXPECT_FALSE(tensorB->isInit()); EXPECT_FALSE(tensorB->isInit());
} }
TEST(TestOpTensorCreate, TestTensorMemoryManagedByManagerNOTDestroyed)
{
std::vector<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecA) };
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor(testVecB) };
kp::Manager mgr;
{
mgr.rebuildTensors({ tensorA });
mgr.rebuildTensors({ tensorB });
EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit());
EXPECT_EQ(tensorA->data(), testVecA);
EXPECT_EQ(tensorB->data(), testVecB);
}
EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit());
}
TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore) TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore)
{ {
@ -99,8 +125,8 @@ TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore)
kp::Manager mgr; kp::Manager mgr;
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorB }); mgr.rebuildTensors({ tensorB });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());
@ -123,7 +149,7 @@ TEST(TestOpTensorCreate, ExceptionOnZeroSizeTensor)
kp::Manager mgr; kp::Manager mgr;
try { try {
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
} catch (const std::runtime_error& err) { } catch (const std::runtime_error& err) {
// check exception // check exception
ASSERT_TRUE(std::string(err.what()).find("zero-sized") != ASSERT_TRUE(std::string(err.what()).find("zero-sized") !=

View file

@ -13,7 +13,7 @@ TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor)
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecPreA) }; std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecPreA) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA }); mgr.rebuildTensors({ tensorA });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
@ -37,7 +37,7 @@ TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor)
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 }) };
std::shared_ptr<kp::Tensor> tensorC{ new kp::Tensor({ 0, 0, 0 }) }; std::shared_ptr<kp::Tensor> tensorC{ new kp::Tensor({ 0, 0, 0 }) };
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB, tensorC }); mgr.rebuildTensors({ tensorA, tensorB, tensorC });
EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit()); EXPECT_TRUE(tensorB->isInit());

View file

@ -23,12 +23,13 @@ TEST(TestTensor, CopyFromHostData)
kp::Manager mgr; kp::Manager mgr;
mgr.rebuildTensors({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA, tensorB });
if (std::shared_ptr<kp::Sequence> sq = if (std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("new")) { mgr.getOrCreateManagedSequence("new")) {
sq->begin(); sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA, tensorB });
sq->record<kp::OpTensorCopy>({ tensorA, tensorB }); sq->record<kp::OpTensorCopy>({ tensorA, tensorB });
sq->end(); sq->end();