Updated tests to align with new sequence memory management workflow

This commit is contained in:
Alejandro Saucedo 2020-11-01 20:25:53 +00:00
parent 473031d1f3
commit e2f6e876bc
4 changed files with 54 additions and 46 deletions

View file

@ -32,14 +32,14 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegression)
kp::Manager mgr;
std::shared_ptr<kp::Sequence> sqTensor =
mgr.createManagedSequence().lock();
mgr.createManagedSequence();
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence();
// Record op algo base
sq->begin();
@ -115,14 +115,14 @@ TEST(TestLogisticRegressionAlgorithm, TestMainLogisticRegressionManualCopy)
kp::Manager mgr;
std::shared_ptr<kp::Sequence> sqTensor =
mgr.createManagedSequence().lock();
mgr.createManagedSequence();
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence();
// Record op algo base
sq->begin();

View file

@ -35,9 +35,10 @@ TEST(TestManager, OpMultSequenceFlow)
kp::Manager mgr;
std::weak_ptr<kp::Sequence> sqWeakPtr =
mgr.getOrCreateManagedSequence("newSequence");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence");
sq->begin();
sq->record<kp::OpTensorCreate>({ tensorLHS });
@ -51,7 +52,6 @@ TEST(TestManager, OpMultSequenceFlow)
sq->end();
sq->eval();
}
sqWeakPtr.reset();
EXPECT_EQ(tensorOutput->data(), std::vector<float>({ 0, 4, 12 }));
}
@ -60,22 +60,22 @@ TEST(TestManager, TestMultipleSequences)
{
kp::Manager mgr;
std::weak_ptr<kp::Sequence> sqWeakPtrOne =
std::shared_ptr<kp::Sequence> sqOne =
mgr.getOrCreateManagedSequence("sqOne");
std::weak_ptr<kp::Sequence> sqWeakPtrTwo =
std::shared_ptr<kp::Sequence> sqTwo =
mgr.getOrCreateManagedSequence("sqTwo");
std::weak_ptr<kp::Sequence> sqWeakPtrOneRef =
std::shared_ptr<kp::Sequence> sqOneRef =
mgr.getOrCreateManagedSequence("sqOne");
std::weak_ptr<kp::Sequence> sqWeakPtrTwoRef =
std::shared_ptr<kp::Sequence> sqTwoRef =
mgr.getOrCreateManagedSequence("sqTwo");
EXPECT_EQ(sqWeakPtrOne.lock(), sqWeakPtrOneRef.lock());
EXPECT_NE(sqWeakPtrTwo.lock(), sqWeakPtrOneRef.lock());
EXPECT_EQ(sqWeakPtrTwo.lock(), sqWeakPtrTwoRef.lock());
EXPECT_NE(sqWeakPtrOneRef.lock(), sqWeakPtrTwoRef.lock());
EXPECT_EQ(sqOne, sqOneRef);
EXPECT_NE(sqTwo, sqOneRef);
EXPECT_EQ(sqTwo, sqTwoRef);
EXPECT_NE(sqOneRef, sqTwoRef);
}
TEST(TestManager, TestMultipleTensorsAtOnce)
@ -89,9 +89,10 @@ TEST(TestManager, TestMultipleTensorsAtOnce)
kp::Manager mgr;
std::weak_ptr<kp::Sequence> sqWeakPtr =
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
{
sq->begin();
sq->record<kp::OpTensorCreate>({ tensorLHS, tensorRHS, tensorOutput });
@ -107,7 +108,6 @@ TEST(TestManager, TestMultipleTensorsAtOnce)
sq->end();
sq->eval();
}
sqWeakPtr.reset();
EXPECT_EQ(tensorOutput->data(), std::vector<float>({ 0, 4, 12 }));
}

View file

@ -19,9 +19,10 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord)
pa[index] = pa[index] + 1;
})");
std::weak_ptr<kp::Sequence> sqWeakPtr =
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
{
sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA });
@ -38,7 +39,6 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord)
sq->end();
sq->eval();
}
sqWeakPtr.reset();
EXPECT_EQ(tensorA->data(), std::vector<float>({ 3, 3, 3 }));
}
@ -58,9 +58,9 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords)
pa[index] = pa[index] + 1;
})");
std::shared_ptr<kp::Sequence> sqTensor = mgr.createManagedSequence().lock();
std::shared_ptr<kp::Sequence> sqTensor = mgr.createManagedSequence();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence();
// First create the tensor in a separate sequence
sqTensor->begin();
@ -111,9 +111,10 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
pa[index] = pa[index] + 1;
})");
std::weak_ptr<kp::Sequence> sqWeakPtr =
mgr.getOrCreateManagedSequence("newSequence");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence");
sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA });
@ -125,9 +126,10 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
sq->eval();
}
std::weak_ptr<kp::Sequence> sqWeakPtr2 =
mgr.getOrCreateManagedSequence("newSequence2");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence2");
sq->begin();
sq->record<kp::OpAlgoBase>(
@ -137,9 +139,10 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
sq->eval();
}
std::weak_ptr<kp::Sequence> sqWeakPtr3 =
mgr.getOrCreateManagedSequence("newSequence3");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr3.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence3");
sq->begin();
sq->record<kp::OpAlgoBase>(
@ -149,9 +152,10 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
sq->eval();
}
std::weak_ptr<kp::Sequence> sqWeakPtr4 =
mgr.getOrCreateManagedSequence("newSequence5");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr4.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence5");
sq->begin();
sq->record<kp::OpTensorSyncLocal>({ tensorA });
@ -179,9 +183,10 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
pa[index] = pa[index] + 1;
})");
std::weak_ptr<kp::Sequence> sqWeakPtr =
mgr.getOrCreateManagedSequence("newSequence");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence");
sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA });
@ -190,9 +195,10 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
sq->eval();
}
std::weak_ptr<kp::Sequence> sqWeakPtr2 =
mgr.getOrCreateManagedSequence("newSequence2");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence2");
sq->begin();
sq->record<kp::OpAlgoBase>(
@ -205,9 +211,11 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
sq->eval();
}
std::weak_ptr<kp::Sequence> sqWeakPtr3 =
mgr.getOrCreateManagedSequence("newSequence3");
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr2.lock()) {
{
std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("newSequence3");
sq->begin();
sq->record<kp::OpTensorSyncLocal>({ tensorA });

View file

@ -24,7 +24,7 @@ TEST(TestTensor, CopyFromHostData)
kp::Manager mgr;
if (std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("new").lock()) {
mgr.getOrCreateManagedSequence("new")) {
sq->begin();
sq->record<kp::OpTensorCreate>({ tensorA, tensorB });