Added test optensorsync for device and local
This commit is contained in:
parent
e68d09dbdc
commit
eddba0fcf9
5 changed files with 60 additions and 3 deletions
|
|
@ -235,7 +235,7 @@ class Tensor
|
|||
* @param data Vector of data that will be used by the tensor
|
||||
* @param tensorType Type for the tensor which is of type TensorTypes
|
||||
*/
|
||||
Tensor(std::vector<float> data,
|
||||
Tensor(const std::vector<float>& data,
|
||||
TensorTypes tensorType = TensorTypes::eDevice);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ Tensor::Tensor()
|
|||
this->mTensorType = TensorTypes::eDevice;
|
||||
}
|
||||
|
||||
Tensor::Tensor(std::vector<float> data, TensorTypes tensorType)
|
||||
Tensor::Tensor(const std::vector<float>& data, TensorTypes tensorType)
|
||||
{
|
||||
#if DEBUG
|
||||
SPDLOG_DEBUG(
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Tensor
|
|||
* @param data Vector of data that will be used by the tensor
|
||||
* @param tensorType Type for the tensor which is of type TensorTypes
|
||||
*/
|
||||
Tensor(std::vector<float> data,
|
||||
Tensor(const std::vector<float>& data,
|
||||
TensorTypes tensorType = TensorTypes::eDevice);
|
||||
|
||||
/**
|
||||
|
|
|
|||
57
test/TestOpTensorSync.cpp
Normal file
57
test/TestOpTensorSync.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#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.evalOpDefault<kp::OpTensorCreate>({tensorA});
|
||||
|
||||
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.evalOpDefault<kp::OpTensorCreate>({tensorA, tensorB, tensorC});
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue