diff --git a/src/Tensor.cpp b/src/Tensor.cpp index f5341830f..7176fe484 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -80,9 +80,7 @@ bool Tensor::isInit() { return this->mDevice && this->mPrimaryBuffer && - this->mPrimaryMemory && - this->mStagingBuffer && - this->mStagingMemory; + this->mPrimaryMemory; } void @@ -443,14 +441,14 @@ Tensor::destroy() KP_LOG_DEBUG("Kompute Tensor started destroy()"); if (!this->mDevice) { - KP_LOG_ERROR( + KP_LOG_WARN( "Kompute Tensor destructor reached with null Device pointer"); return; } if (this->mFreePrimaryBuffer) { if (!this->mPrimaryBuffer) { - KP_LOG_ERROR("Kompose Tensor expected to destroy primary buffer " + KP_LOG_WARN("Kompose Tensor expected to destroy primary buffer " "but got null buffer"); } else { KP_LOG_DEBUG("Kompose Tensor destroying primary buffer"); @@ -464,7 +462,7 @@ Tensor::destroy() if (this->mFreeStagingBuffer) { if (!this->mStagingBuffer) { - KP_LOG_ERROR("Kompose Tensor expected to destroy staging buffer " + KP_LOG_WARN("Kompose Tensor expected to destroy staging buffer " "but got null buffer"); } else { KP_LOG_DEBUG("Kompose Tensor destroying staging buffer"); @@ -478,7 +476,7 @@ Tensor::destroy() if (this->mFreePrimaryMemory) { if (!this->mPrimaryMemory) { - KP_LOG_ERROR("Kompose Tensor expected to free primary memory but " + KP_LOG_WARN("Kompose Tensor expected to free primary memory but " "got null memory"); } else { KP_LOG_DEBUG("Kompose Tensor freeing primary memory"); @@ -492,7 +490,7 @@ Tensor::destroy() if (this->mFreeStagingMemory) { if (!this->mStagingMemory) { - KP_LOG_ERROR("Kompose Tensor expected to free staging memory but " + KP_LOG_WARN("Kompose Tensor expected to free staging memory but " "got null memory"); } else { KP_LOG_DEBUG("Kompose Tensor freeing staging memory"); diff --git a/test/TestOpTensorCopy.cpp b/test/TestOpTensorCopy.cpp index 449e30da1..dc82a2e50 100644 --- a/test/TestOpTensorCopy.cpp +++ b/test/TestOpTensorCopy.cpp @@ -3,163 +3,154 @@ #include "kompute/Kompute.hpp" -//TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecA{ 1, 2, 3 }; -// std::vector testVecB{ 0, 0, 0 }; -// -// std::shared_ptr tensorA{ new kp::Tensor(testVecA) }; -// std::shared_ptr tensorB{ new kp::Tensor(testVecB) }; -// -// mgr.rebuild({ tensorA, tensorB }); -// -// EXPECT_TRUE(tensorA->isInit()); -// EXPECT_TRUE(tensorB->isInit()); -// -// mgr.evalOpDefault({ tensorA, tensorB }); -// -// EXPECT_EQ(tensorA->data(), tensorB->data()); -// -// // Making sure the GPU holds the same data -// mgr.evalOpDefault({ tensorB }); -// EXPECT_EQ(tensorA->data(), tensorB->data()); -//} -// -//TEST(TestOpTensorCopy, CopyDeviceToDeviceTensorMulti) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecA{ 2, 3, 4 }; -// std::vector testVecB{ 0, 0, 0 }; -// std::vector testVecC{ 0, 0, 0 }; -// -// std::shared_ptr tensorA{ new kp::Tensor(testVecA) }; -// std::shared_ptr tensorB{ new kp::Tensor(testVecB) }; -// std::shared_ptr tensorC{ new kp::Tensor(testVecC) }; -// -// mgr.rebuild({ tensorA, tensorB, tensorC }); -// -// EXPECT_TRUE(tensorA->isInit()); -// EXPECT_TRUE(tensorB->isInit()); -// EXPECT_TRUE(tensorC->isInit()); -// -// mgr.evalOpDefault({ tensorA, tensorB, tensorC }); -// -// EXPECT_EQ(tensorA->data(), tensorB->data()); -// EXPECT_EQ(tensorA->data(), tensorC->data()); -// -// // Making sure the GPU holds the same data -// mgr.evalOpDefault({ tensorB, tensorC }); -// EXPECT_EQ(tensorA->data(), tensorB->data()); -// EXPECT_EQ(tensorA->data(), tensorC->data()); -//} -// -//TEST(TestOpTensorCopy, CopyDeviceToHostTensor) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecA{ 3, 4, 5 }; -// std::vector testVecB{ 0, 0, 0 }; -// -// std::shared_ptr tensorA{ new kp::Tensor(testVecA) }; -// std::shared_ptr tensorB{ new kp::Tensor( -// testVecB, kp::Tensor::TensorTypes::eHost) }; -// -// mgr.rebuild({ tensorA, tensorB }, false); -// -// // Only calling sync on device type tensor -// mgr.evalOpDefault({ tensorA }); -// -// EXPECT_TRUE(tensorA->isInit()); -// EXPECT_TRUE(tensorB->isInit()); -// -// mgr.evalOpDefault({ tensorA, tensorB }); -// -// EXPECT_EQ(tensorA->data(), tensorB->data()); -// -// // Making sure the GPU holds the same data -// mgr.evalOpDefault({ tensorB }); -// EXPECT_EQ(tensorA->data(), tensorB->data()); -//} -// -//TEST(TestOpTensorCopy, CopyHostToDeviceTensor) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecA{ 4, 5, 6 }; -// std::vector testVecB{ 0, 0, 0 }; -// -// std::shared_ptr tensorA{ new kp::Tensor( -// testVecA, kp::Tensor::TensorTypes::eHost) }; -// std::shared_ptr tensorB{ new kp::Tensor(testVecB) }; -// -// mgr.rebuild({ tensorA, tensorB }, false); -// -// // Manually copy data into host memory of Tensor -// tensorA->mapDataIntoHostMemory(); -// -// // Only calling sync on device type tensor -// mgr.evalOpDefault({ tensorB }); -// -// EXPECT_TRUE(tensorA->isInit()); -// EXPECT_TRUE(tensorB->isInit()); -// -// mgr.evalOpDefault({ tensorA, tensorB }); -// -// EXPECT_EQ(tensorA->data(), tensorB->data()); -// -// // Making sure the GPU holds the same data -// mgr.evalOpDefault({ tensorB }); -// EXPECT_EQ(tensorA->data(), tensorB->data()); -//} -// -//TEST(TestOpTensorCopy, CopyHostToHostTensor) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecA{ 5, 6, 7 }; -// std::vector testVecB{ 0, 0, 0 }; -// -// std::shared_ptr tensorA{ new kp::Tensor( -// testVecA, kp::Tensor::TensorTypes::eHost) }; -// std::shared_ptr tensorB{ new kp::Tensor( -// testVecB, kp::Tensor::TensorTypes::eHost) }; -// -// mgr.rebuild({ tensorA, tensorB }); -// -// EXPECT_TRUE(tensorA->isInit()); -// EXPECT_TRUE(tensorB->isInit()); -// -// mgr.evalOpDefault({ tensorA, tensorB }); -// -// EXPECT_EQ(tensorA->data(), tensorB->data()); -// -// // Making sure the GPU holds the same data -// mgr.evalOpDefault({ tensorB }); -// EXPECT_EQ(tensorA->data(), tensorB->data()); -//} -// -//TEST(TestOpTensorCopy, SingleTensorShouldFail) -//{ -// -// kp::Manager mgr; -// -// std::vector testVecA{ 6, 7, 8 }; -// -// std::shared_ptr tensorA{ new kp::Tensor( -// testVecA, kp::Tensor::TensorTypes::eHost) }; -// -// mgr.rebuild({ tensorA }, false); -// -// EXPECT_TRUE(tensorA->isInit()); -// -// EXPECT_THROW(mgr.evalOpDefault({ tensorA }), -// std::runtime_error); -//} +TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor) +{ + + kp::Manager mgr; + + std::vector testVecA{ 1, 2, 3 }; + std::vector testVecB{ 0, 0, 0 }; + + std::shared_ptr tensorA = mgr.tensor(testVecA); + std::shared_ptr tensorB = mgr.tensor(testVecB); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + mgr.sequence() + ->eval({ tensorA, tensorB }) + ->eval({ tensorA, tensorB }) + ->eval({ tensorA, tensorB }); + + // Making sure the GPU holds the same data + EXPECT_EQ(tensorA->data(), tensorB->data()); +} + +TEST(TestOpTensorCopy, CopyDeviceToDeviceTensorMulti) +{ + + kp::Manager mgr; + + std::vector testVecA{ 2, 3, 4 }; + std::vector testVecB{ 0, 0, 0 }; + std::vector testVecC{ 0, 0, 0 }; + + std::shared_ptr tensorA = mgr.tensor(testVecA); + std::shared_ptr tensorB = mgr.tensor(testVecB); + std::shared_ptr tensorC = mgr.tensor(testVecC); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + EXPECT_TRUE(tensorC->isInit()); + + mgr.sequence() + ->eval({tensorA, tensorB, tensorC}) + ->eval({tensorA, tensorB, tensorC }); + + EXPECT_EQ(tensorA->data(), tensorB->data()); + EXPECT_EQ(tensorA->data(), tensorC->data()); + + // Making sure the GPU holds the same data + mgr.sequence() + ->eval({ tensorB, tensorC }); + + EXPECT_EQ(tensorA->data(), tensorB->data()); + EXPECT_EQ(tensorA->data(), tensorC->data()); +} + +TEST(TestOpTensorCopy, CopyDeviceToHostTensor) +{ + + kp::Manager mgr; + + std::vector testVecA{ 3, 4, 5 }; + std::vector testVecB{ 0, 0, 0 }; + + std::shared_ptr tensorA = mgr.tensor(testVecA); + std::shared_ptr tensorB = mgr.tensor( + testVecB, kp::Tensor::TensorTypes::eHost); + + // Only calling sync on device type tensor + mgr.sequence()->eval({ tensorA }); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + mgr.sequence()->eval({ tensorA, tensorB }); + + EXPECT_EQ(tensorA->data(), tensorB->data()); + + // Making sure the GPU holds the same data + mgr.sequence()->eval({ tensorB }); + EXPECT_EQ(tensorA->data(), tensorB->data()); +} + +TEST(TestOpTensorCopy, CopyHostToDeviceTensor) +{ + + kp::Manager mgr; + + std::vector testVecA{ 4, 5, 6 }; + std::vector testVecB{ 0, 0, 0 }; + + std::shared_ptr tensorA = mgr.tensor( + testVecA, kp::Tensor::TensorTypes::eHost); + std::shared_ptr tensorB = mgr.tensor(testVecB); + + // Only calling sync on device type tensor + mgr.sequence()->eval({ tensorA, tensorB }); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + mgr.sequence()->eval({ tensorA, tensorB }); + + EXPECT_EQ(tensorA->data(), tensorB->data()); + + // Making sure the GPU holds the same data + mgr.sequence()->eval({ tensorB }); + EXPECT_EQ(tensorA->data(), tensorB->data()); +} + +TEST(TestOpTensorCopy, CopyHostToHostTensor) +{ + + kp::Manager mgr; + + std::vector testVecA{ 5, 6, 7 }; + std::vector testVecB{ 0, 0, 0 }; + + std::shared_ptr tensorA = mgr.tensor( + testVecA, kp::Tensor::TensorTypes::eHost); + std::shared_ptr tensorB = mgr.tensor( + testVecB, kp::Tensor::TensorTypes::eHost); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + mgr.sequence() + ->eval({ tensorA }) + ->eval({ tensorA, tensorB }); + + EXPECT_EQ(tensorA->data(), tensorB->data()); + + // Making sure the GPU holds the same data + mgr.sequence()->eval({ tensorB }); + EXPECT_EQ(tensorA->data(), tensorB->data()); +} + +TEST(TestOpTensorCopy, SingleTensorShouldFail) +{ + + kp::Manager mgr; + + std::vector testVecA{ 6, 7, 8 }; + + std::shared_ptr tensorA = mgr.tensor( + testVecA, kp::Tensor::TensorTypes::eHost); + + EXPECT_TRUE(tensorA->isInit()); + + EXPECT_THROW(mgr.sequence()->eval({ tensorA }), + std::runtime_error); +}