diff --git a/src/OpTensorCopy.cpp b/src/OpTensorCopy.cpp index 374fe4ea1..87f0a3b20 100644 --- a/src/OpTensorCopy.cpp +++ b/src/OpTensorCopy.cpp @@ -7,12 +7,12 @@ OpTensorCopy::OpTensorCopy(const std::vector>& tensors) { KP_LOG_DEBUG("Kompute OpTensorCopy constructor with params"); + this->mTensors = tensors; + if (this->mTensors.size() < 2) { throw std::runtime_error( "Kompute OpTensorCopy called with less than 2 tensor"); } - - this->mTensors = tensors; } OpTensorCopy::~OpTensorCopy() diff --git a/test/TestOpTensorSync.cpp b/test/TestOpTensorSync.cpp index 8e8c4cda2..55e02ad13 100644 --- a/test/TestOpTensorSync.cpp +++ b/test/TestOpTensorSync.cpp @@ -3,55 +3,51 @@ #include "kompute/Kompute.hpp" -//TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecPreA{ 0, 0, 0 }; -// std::vector testVecPostA{ 9, 8, 7 }; -// -// std::shared_ptr tensorA{ new kp::Tensor(testVecPreA) }; -// -// mgr.rebuild({ tensorA }, false); -// -// EXPECT_TRUE(tensorA->isInit()); -// -// tensorA->setData(testVecPostA); -// -// mgr.evalOpDefault({ tensorA }); -// -// mgr.evalOpDefault({ tensorA }); -// -// EXPECT_EQ(tensorA->data(), testVecPostA); -//} -// -//TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor) -//{ -// -// kp::Manager mgr; -// -// std::vector testVec{ 9, 8, 7 }; -// -// std::shared_ptr tensorA{ new kp::Tensor({ 0, 0, 0 }) }; -// std::shared_ptr tensorB{ new kp::Tensor({ 0, 0, 0 }) }; -// std::shared_ptr tensorC{ new kp::Tensor({ 0, 0, 0 }) }; -// -// mgr.rebuild({ tensorA, tensorB, tensorC }, false); -// -// EXPECT_TRUE(tensorA->isInit()); -// EXPECT_TRUE(tensorB->isInit()); -// EXPECT_TRUE(tensorC->isInit()); -// -// tensorA->setData(testVec); -// -// mgr.evalOpDefault({ tensorA }); -// -// mgr.evalOpDefault({ tensorA, tensorB, tensorC }); -// -// mgr.evalOpDefault({ tensorA, tensorB, tensorC }); -// -// EXPECT_EQ(tensorA->data(), testVec); -// EXPECT_EQ(tensorB->data(), testVec); -// EXPECT_EQ(tensorC->data(), testVec); -//} +TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor) +{ + + kp::Manager mgr; + + std::vector testVecPreA{ 0, 0, 0 }; + std::vector testVecPostA{ 9, 8, 7 }; + + std::shared_ptr tensorA = mgr.tensor(testVecPreA); + + EXPECT_TRUE(tensorA->isInit()); + + tensorA->setData(testVecPostA); + + mgr.sequence()->eval({ tensorA }); + + mgr.sequence()->eval({ tensorA }); + + EXPECT_EQ(tensorA->data(), testVecPostA); +} + +TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor) +{ + + kp::Manager mgr; + + std::vector testVec{ 9, 8, 7 }; + + std::shared_ptr tensorA = mgr.tensor({ 0, 0, 0 }); + std::shared_ptr tensorB = mgr.tensor({ 0, 0, 0 }); + std::shared_ptr tensorC = mgr.tensor({ 0, 0, 0 }); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + EXPECT_TRUE(tensorC->isInit()); + + tensorA->setData(testVec); + + mgr.sequence()->eval({ tensorA }); + + mgr.sequence()->eval({ tensorA, tensorB, tensorC }); + + mgr.sequence()->eval({ tensorA, tensorB, tensorC }); + + EXPECT_EQ(tensorA->data(), testVec); + EXPECT_EQ(tensorB->data(), testVec); + EXPECT_EQ(tensorC->data(), testVec); +}