#include "gtest/gtest.h" #include "kompute/Kompute.hpp" TEST(TestManager, EndToEndOpMultFlow) { kp::Manager mgr; std::shared_ptr tensorLHS{ new kp::Tensor({ 0, 1, 2 }) }; mgr.evalOpDefault({ tensorLHS }); std::shared_ptr tensorRHS{ new kp::Tensor({ 2, 4, 6 }) }; mgr.evalOpDefault({ tensorRHS }); std::shared_ptr tensorOutput{ new kp::Tensor({ 0, 0, 0 }) }; mgr.evalOpDefault({ tensorOutput }); mgr.evalOpDefault({ tensorLHS, tensorRHS, tensorOutput }); mgr.evalOpDefault({ tensorOutput }); EXPECT_EQ(tensorOutput->data(), std::vector({ 0, 4, 12 })); } TEST(TestManager, OpMultSequenceFlow) { std::shared_ptr tensorLHS{ new kp::Tensor({ 0, 1, 2 }) }; std::shared_ptr tensorRHS{ new kp::Tensor({ 2, 4, 6 }) }; std::shared_ptr tensorOutput{ new kp::Tensor({ 0, 0, 0 }) }; kp::Manager mgr; { std::shared_ptr sq = mgr.getOrCreateManagedSequence("newSequence"); sq->begin(); sq->record({ tensorLHS }); sq->record({ tensorRHS }); sq->record({ tensorOutput }); sq->record({ tensorLHS, tensorRHS, tensorOutput }); sq->record({ tensorOutput }); sq->end(); sq->eval(); } EXPECT_EQ(tensorOutput->data(), std::vector({ 0, 4, 12 })); } TEST(TestManager, TestMultipleSequences) { kp::Manager mgr; std::shared_ptr sqOne = mgr.getOrCreateManagedSequence("sqOne"); std::shared_ptr sqTwo = mgr.getOrCreateManagedSequence("sqTwo"); std::shared_ptr sqOneRef = mgr.getOrCreateManagedSequence("sqOne"); std::shared_ptr sqTwoRef = mgr.getOrCreateManagedSequence("sqTwo"); EXPECT_EQ(sqOne, sqOneRef); EXPECT_NE(sqTwo, sqOneRef); EXPECT_EQ(sqTwo, sqTwoRef); EXPECT_NE(sqOneRef, sqTwoRef); } TEST(TestManager, TestMultipleTensorsAtOnce) { std::shared_ptr tensorLHS{ new kp::Tensor({ 0, 1, 2 }) }; std::shared_ptr tensorRHS{ new kp::Tensor({ 2, 4, 6 }) }; std::shared_ptr tensorOutput{ new kp::Tensor({ 0, 0, 0 }) }; kp::Manager mgr; std::shared_ptr sq = mgr.getOrCreateManagedSequence("newSequence"); { sq->begin(); sq->record({ tensorLHS, tensorRHS, tensorOutput }); EXPECT_TRUE(tensorLHS->isInit()); EXPECT_TRUE(tensorRHS->isInit()); EXPECT_TRUE(tensorOutput->isInit()); sq->record({ tensorLHS, tensorRHS, tensorOutput }); sq->record({ tensorOutput }); sq->end(); sq->eval(); } EXPECT_EQ(tensorOutput->data(), std::vector({ 0, 4, 12 })); } TEST(TestManager, TestCreateInitTensor) { kp::Manager mgr; std::shared_ptr tensorA = mgr.buildTensor({ 0, 1, 2 }); std::shared_ptr tensorB = mgr.buildTensor({ 0, 0, 0 }); mgr.evalOpDefault({ tensorA, tensorB }); mgr.evalOpDefault({ tensorB }); EXPECT_EQ(tensorB->data(), std::vector({ 0, 1, 2 })); std::shared_ptr tensorC = mgr.buildTensor({ 0, 0, 0 }, kp::Tensor::TensorTypes::eStaging); mgr.evalOpDefault({ tensorA, tensorC }); EXPECT_EQ(tensorC->data(), std::vector({ 0, 1, 2 })); }