Fixed all OpTensorSync tests

This commit is contained in:
Alejandro Saucedo 2021-02-26 21:36:20 +00:00
parent b3abbf1bb4
commit fd0f0d3eb4
2 changed files with 50 additions and 54 deletions

View file

@ -7,12 +7,12 @@ OpTensorCopy::OpTensorCopy(const std::vector<std::shared_ptr<Tensor>>& 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()

View file

@ -3,55 +3,51 @@
#include "kompute/Kompute.hpp"
//TEST(TestOpTensorSync, SyncToDeviceMemorySingleTensor)
//{
//
// kp::Manager mgr;
//
// std::vector<float> testVecPreA{ 0, 0, 0 };
// std::vector<float> testVecPostA{ 9, 8, 7 };
//
// std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor(testVecPreA) };
//
// mgr.rebuild({ tensorA }, false);
//
// EXPECT_TRUE(tensorA->isInit());
//
// tensorA->setData(testVecPostA);
//
// mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA });
//
// mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA });
//
// EXPECT_EQ(tensorA->data(), testVecPostA);
//}
//
//TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor)
//{
//
// kp::Manager mgr;
//
// std::vector<float> testVec{ 9, 8, 7 };
//
// std::shared_ptr<kp::Tensor> tensorA{ 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 }) };
//
// mgr.rebuild({ tensorA, tensorB, tensorC }, false);
//
// EXPECT_TRUE(tensorA->isInit());
// EXPECT_TRUE(tensorB->isInit());
// EXPECT_TRUE(tensorC->isInit());
//
// tensorA->setData(testVec);
//
// mgr.evalOpDefault<kp::OpTensorSyncDevice>({ tensorA });
//
// mgr.evalOpDefault<kp::OpTensorCopy>({ tensorA, tensorB, tensorC });
//
// mgr.evalOpDefault<kp::OpTensorSyncLocal>({ 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<float> testVecPreA{ 0, 0, 0 };
std::vector<float> testVecPostA{ 9, 8, 7 };
std::shared_ptr<kp::Tensor> tensorA = mgr.tensor(testVecPreA);
EXPECT_TRUE(tensorA->isInit());
tensorA->setData(testVecPostA);
mgr.sequence()->eval<kp::OpTensorSyncDevice>({ tensorA });
mgr.sequence()->eval<kp::OpTensorSyncLocal>({ tensorA });
EXPECT_EQ(tensorA->data(), testVecPostA);
}
TEST(TestOpTensorSync, SyncToDeviceMemoryMultiTensor)
{
kp::Manager mgr;
std::vector<float> testVec{ 9, 8, 7 };
std::shared_ptr<kp::Tensor> tensorA = mgr.tensor({ 0, 0, 0 });
std::shared_ptr<kp::Tensor> tensorB = mgr.tensor({ 0, 0, 0 });
std::shared_ptr<kp::Tensor> tensorC = mgr.tensor({ 0, 0, 0 });
EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit());
EXPECT_TRUE(tensorC->isInit());
tensorA->setData(testVec);
mgr.sequence()->eval<kp::OpTensorSyncDevice>({ tensorA });
mgr.sequence()->eval<kp::OpTensorCopy>({ tensorA, tensorB, tensorC });
mgr.sequence()->eval<kp::OpTensorSyncLocal>({ tensorA, tensorB, tensorC });
EXPECT_EQ(tensorA->data(), testVec);
EXPECT_EQ(tensorB->data(), testVec);
EXPECT_EQ(tensorC->data(), testVec);
}