From ec89fc6d568bb4581c59d003d13885f8e8e1c633 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 6 Sep 2020 11:38:08 +0100 Subject: [PATCH] Renamed tensorcreate and started adding optensorsyncdevice --- Makefile | 2 +- README.md | 12 +- docs/overview/reference.rst | 13 +- single_include/AggregateHeaders.cpp | 2 +- single_include/kompute/Kompute.hpp | 14 ++- ...{OpCreateTensor.cpp => OpTensorCreate.cpp} | 32 ++--- src/OpTensorSyncDevice.cpp | 71 +++++++++++ .../kompute/operations/OpTensorCopy.hpp | 7 +- ...{OpCreateTensor.hpp => OpTensorCreate.hpp} | 8 +- .../kompute/operations/OpTensorSyncDevice.hpp | 57 +++++++++ test/TestLogisticRegression.cpp | 2 +- test/TestManager.cpp | 14 +-- test/TestMultipleAlgoExecutions.cpp | 8 +- test/TestOpShadersFromStringAndFile.cpp | 8 +- test/TestOpTensorCopy.cpp | 111 ++++++++++++++++++ ...reateTensor.cpp => TestOpTensorCreate.cpp} | 26 ++-- test/TestTensor.cpp | 2 +- 17 files changed, 318 insertions(+), 71 deletions(-) rename src/{OpCreateTensor.cpp => OpTensorCreate.cpp} (74%) create mode 100644 src/OpTensorSyncDevice.cpp rename src/include/kompute/operations/{OpCreateTensor.hpp => OpTensorCreate.hpp} (92%) create mode 100644 src/include/kompute/operations/OpTensorSyncDevice.hpp create mode 100644 test/TestOpTensorCopy.cpp rename test/{TestOpCreateTensor.cpp => TestOpTensorCreate.cpp} (75%) diff --git a/Makefile b/Makefile index 63f76c5db..38f10f1d6 100755 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ vs_run_docs: vs_build_docs (cd build/docs/sphinx && python2.7 -m SimpleHTTPServer) vs_run_tests: vs_build_tests - ./build/test/$(VS_BUILD_TYPE)/test_kompute.exe $(FILTER_TESTS) + ./build/test/$(VS_BUILD_TYPE)/test_kompute.exe --gtest_filter=$(FILTER_TESTS) ####### Create release ###### diff --git a/README.md b/README.md index 85963bef9..a55bd2ae7 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ int main() { auto tensorOut = std::make_shared(kp::Tensor({ 0., 0., 0. })); // Create tensors data in GPU - mgr.evalOpDefault({ tensorLhs, tensorRhs, tensorOut }); + mgr.evalOpDefault({ tensorLhs, tensorRhs, tensorOut }); // Run Kompute operation on the parameters provided with dispatch layout mgr.evalOpDefault>( @@ -104,7 +104,7 @@ int main() { )"); // Create tensor data in GPU - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.evalOpDefault({ tensorA, tensorB }); // Run Kompute operation on the parameters provided with dispatch layout mgr.evalOpDefault>( @@ -129,7 +129,7 @@ int main() { auto tensorRhs = std::make_shared(kp::Tensor({ 2, 4, 6 })); // Create tensor data in GPU - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.evalOpDefault({ tensorA, tensorB }); // Run Kompute operation on the parameters provided with dispatch layout mgr.evalOpDefault>( @@ -163,9 +163,9 @@ int main() { sq.begin(); // Record batch commands to send to GPU - sq.record({ tensorLHS }); - sq.record({ tensorRHS }); - sq.record({ tensorOutput }); + sq.record({ tensorLHS }); + sq.record({ tensorRHS }); + sq.record({ tensorOutput }); sq.record>({ tensorLHS, tensorRHS, tensorOutput }); // Stop recording diff --git a/docs/overview/reference.rst b/docs/overview/reference.rst index 6711f680d..8e7366fcb 100644 --- a/docs/overview/reference.rst +++ b/docs/overview/reference.rst @@ -2,7 +2,7 @@ Reference ======== -This section provides a breakdown of the cpp classes and what each of their functions provide. It is partially generated and augomented from the Doxygen autodoc content. You can also go directly to the `raw doxygen docs `_. +This section provides a breakdown of the cpp classes and what each of their functions provide. It is partially generated and augomented from the Doxygen autodoc content. You can also go directly to the `raw doxygen docs <../doxygen/annotated.html>`_. Below is a diagram that provides insights on the relationship between Vulkan Kompute objects and Vulkan resources, which primarily encompass ownership of either CPU and/or GPU memory. @@ -72,12 +72,19 @@ OpMult .. image:: ../images/kompute-vulkan-architecture-opmult.jpg :width: 100% -OpCreateTensor +OpTensorCreate ------- -.. doxygenclass:: kp::OpCreateTensor +.. doxygenclass:: kp::OpTensorCreate :members: .. image:: ../images/kompute-vulkan-architecture-opcreatetensor.jpg :width: 100% +OpTensorCreate +------- + +.. doxygenclass:: kp::OpTensorCopy + :members: + + diff --git a/single_include/AggregateHeaders.cpp b/single_include/AggregateHeaders.cpp index 2f3607e2d..57cd16e5e 100644 --- a/single_include/AggregateHeaders.cpp +++ b/single_include/AggregateHeaders.cpp @@ -6,7 +6,7 @@ #include "kompute/operations/OpAlgoBase.hpp" #include "kompute/operations/OpAlgoLhsRhsOut.hpp" #include "kompute/operations/OpMult.hpp" -#include "kompute/operations/OpCreateTensor.hpp" +#include "kompute/operations/OpTensorCreate.hpp" #include "kompute/operations/OpTensorCopy.hpp" #include "kompute/Algorithm.hpp" #include "kompute/Tensor.hpp" diff --git a/single_include/kompute/Kompute.hpp b/single_include/kompute/Kompute.hpp index fcaed2666..2d718b9e6 100755 --- a/single_include/kompute/Kompute.hpp +++ b/single_include/kompute/Kompute.hpp @@ -1509,10 +1509,10 @@ namespace kp { Operation that creates tensor and manages the memory of the components created */ -class OpCreateTensor : public OpBase +class OpTensorCreate : public OpBase { public: - OpCreateTensor(); + OpTensorCreate(); /** * Default constructor with parameters that provides the bare minimum @@ -1525,7 +1525,7 @@ class OpCreateTensor : public OpBase * @param tensors Tensors that will be used to create in operation. * @param freeTensors Whether operation manages the memory of the Tensors */ - OpCreateTensor(std::shared_ptr physicalDevice, + OpTensorCreate(std::shared_ptr physicalDevice, std::shared_ptr device, std::shared_ptr commandBuffer, std::vector> tensors); @@ -1534,7 +1534,7 @@ class OpCreateTensor : public OpBase * Default destructor which in this case expects the parent class to free * the tensors */ - ~OpCreateTensor() override; + ~OpTensorCreate() override; /** * In charge of initialising the primary Tensor as well as the staging @@ -1544,8 +1544,10 @@ class OpCreateTensor : public OpBase void init() override; /** - * Records the copy command into the GPU memory from the staging or host - * memory depending on the type of tensor. + * Record runs the core actions to create the tensors. For device tensors + * it records a copyCommand to move the data from the staging tensor to the + * device tensor. For staging tensors it performs a mapDataIntoHostMemory + * which would perform immediately as opposed to on sequence eval/submission. */ void record() override; diff --git a/src/OpCreateTensor.cpp b/src/OpTensorCreate.cpp similarity index 74% rename from src/OpCreateTensor.cpp rename to src/OpTensorCreate.cpp index ae551e259..32688da1f 100644 --- a/src/OpCreateTensor.cpp +++ b/src/OpTensorCreate.cpp @@ -1,30 +1,30 @@ #include "kompute/Tensor.hpp" -#include "kompute/operations/OpCreateTensor.hpp" +#include "kompute/operations/OpTensorCreate.hpp" namespace kp { -OpCreateTensor::OpCreateTensor() +OpTensorCreate::OpTensorCreate() { - SPDLOG_DEBUG("Kompute OpCreateTensor constructor base"); + SPDLOG_DEBUG("Kompute OpTensorCreate constructor base"); } -OpCreateTensor::OpCreateTensor( +OpTensorCreate::OpTensorCreate( std::shared_ptr physicalDevice, std::shared_ptr device, std::shared_ptr commandBuffer, std::vector> tensors) : OpBase(physicalDevice, device, commandBuffer, tensors, true) { - SPDLOG_DEBUG("Kompute OpCreateTensor constructor with params"); + SPDLOG_DEBUG("Kompute OpTensorCreate constructor with params"); } -OpCreateTensor::~OpCreateTensor() +OpTensorCreate::~OpTensorCreate() { - SPDLOG_DEBUG("Kompute OpCreateTensor destructor started"); + SPDLOG_DEBUG("Kompute OpTensorCreate destructor started"); - SPDLOG_DEBUG("Kompute OpCreateTensor destroying staging tensors"); + SPDLOG_DEBUG("Kompute OpTensorCreate destroying staging tensors"); for (size_t i = 0; i < this->mStagingTensors.size(); i++) { if (this->mStagingTensors[i]) { this->mStagingTensors[i]->freeMemoryDestroyGPUResources(); @@ -33,18 +33,18 @@ OpCreateTensor::~OpCreateTensor() } void -OpCreateTensor::init() +OpTensorCreate::init() { - SPDLOG_DEBUG("Kompute OpCreateTensor init called"); + SPDLOG_DEBUG("Kompute OpTensorCreate init called"); if (this->mTensors.size() < 1) { throw std::runtime_error( - "Kompute OpCreateTensor called with less than 1 tensor"); + "Kompute OpTensorCreate called with less than 1 tensor"); } for (std::shared_ptr tensor: this->mTensors) { if (tensor->isInit()) { - throw std::runtime_error("Kompute OpCreateTensor: Tensor has already been initialized"); + throw std::runtime_error("Kompute OpTensorCreate: Tensor has already been initialized"); } if (tensor->tensorType() == Tensor::TensorTypes::eDevice) { tensor->init( @@ -73,9 +73,9 @@ OpCreateTensor::init() } void -OpCreateTensor::record() +OpTensorCreate::record() { - SPDLOG_DEBUG("Kompute OpCreateTensor record called"); + SPDLOG_DEBUG("Kompute OpTensorCreate record called"); for (size_t i = 0; i < this->mTensors.size(); i++) { if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) { @@ -87,9 +87,9 @@ OpCreateTensor::record() } void -OpCreateTensor::postSubmit() +OpTensorCreate::postSubmit() { - SPDLOG_DEBUG("Kompute OpCreateTensor postSubmit called"); + SPDLOG_DEBUG("Kompute OpTensorCreate postSubmit called"); for (size_t i = 0; i < this->mTensors.size(); i++) { if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) { diff --git a/src/OpTensorSyncDevice.cpp b/src/OpTensorSyncDevice.cpp new file mode 100644 index 000000000..1652b88ba --- /dev/null +++ b/src/OpTensorSyncDevice.cpp @@ -0,0 +1,71 @@ + +#include "kompute/operations/OpTensorSyncDevice.hpp" + +namespace kp { + +OpTensorSyncDevice::OpTensorSyncDevice() +{ + SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor base"); +} + +OpTensorSyncDevice::OpTensorSyncDevice( + std::shared_ptr physicalDevice, + std::shared_ptr device, + std::shared_ptr commandBuffer, + std::vector> tensors) + : OpBase(physicalDevice, device, commandBuffer, tensors, false) +{ + SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor with params"); +} + +OpTensorSyncDevice::~OpTensorSyncDevice() +{ + SPDLOG_DEBUG("Kompute OpTensorSyncDevice destructor started"); + + SPDLOG_DEBUG("Kompute OpTensorSyncDevice destroying staging tensors"); +} + +void +OpTensorSyncDevice::init() +{ + SPDLOG_DEBUG("Kompute OpTensorSyncDevice init called"); + + if (this->mTensors.size() < 2) { + throw std::runtime_error( + "Kompute OpTensorSyncDevice called with less than 2 tensor"); + } + + for (std::shared_ptr tensor: this->mTensors) { + if (!tensor->isInit()) { + throw std::runtime_error("Kompute OpTensorSyncDevice tensor parameter has not been initialized"); + } + if (tensor->tensorType() == Tensor::TensorTypes::eStorage) { + throw std::runtime_error("Kompute OpTensorSyncDevice tensor parameter is of type storage and hence cannot be used to receive or pass data."); + } + } +} + +void +OpTensorSyncDevice::record() +{ + SPDLOG_DEBUG("Kompute OpTensorSyncDevice record called"); + + // We iterate from the second tensor onwards and record a copy to all + for (size_t i = 1; i < this->mTensors.size(); i++) { + this->mTensors[i]->recordCopyFrom(this->mCommandBuffer, this->mTensors[0], false); + } +} + +void +OpTensorSyncDevice::postSubmit() +{ + SPDLOG_DEBUG("Kompute OpTensorSyncDevice postSubmit called"); + + // Copy the data from the first tensor into all the tensors + for (size_t i = 1; i < this->mTensors.size(); i++) { + this->mTensors[i]->setData(this->mTensors[0]->data()); + } +} + +} + diff --git a/src/include/kompute/operations/OpTensorCopy.hpp b/src/include/kompute/operations/OpTensorCopy.hpp index 646d1b158..244e22894 100644 --- a/src/include/kompute/operations/OpTensorCopy.hpp +++ b/src/include/kompute/operations/OpTensorCopy.hpp @@ -9,7 +9,7 @@ namespace kp { /** - Operation that copies the data from the first tensor to the rest of the tensors provided, using a record command for all the vectors. This operation does not own/manage the memory of the tensors passed to it. + Operation that copies the data from the first tensor to the rest of the tensors provided, using a record command for all the vectors. This operation does not own/manage the memory of the tensors passed to it. The operation must only receive tensors of type */ class OpTensorCopy : public OpBase { @@ -30,13 +30,12 @@ class OpTensorCopy : public OpBase std::vector> tensors); /** - * Default destructor which in this case expects the parent class to free - * the tensors + * Default destructor. This class does not manage memory so it won't be expecting the parent to perform a release. */ ~OpTensorCopy() override; /** - * TODO + * Performs basic checks such as ensuring there are at least two tensors provided, that they are initialised and that they are not of type TensorTypes::eStorage. */ void init() override; diff --git a/src/include/kompute/operations/OpCreateTensor.hpp b/src/include/kompute/operations/OpTensorCreate.hpp similarity index 92% rename from src/include/kompute/operations/OpCreateTensor.hpp rename to src/include/kompute/operations/OpTensorCreate.hpp index e04e65062..7360e5bdc 100644 --- a/src/include/kompute/operations/OpCreateTensor.hpp +++ b/src/include/kompute/operations/OpTensorCreate.hpp @@ -12,10 +12,10 @@ namespace kp { Operation that creates tensor and manages the memory of the components created */ -class OpCreateTensor : public OpBase +class OpTensorCreate : public OpBase { public: - OpCreateTensor(); + OpTensorCreate(); /** * Default constructor with parameters that provides the bare minimum @@ -28,7 +28,7 @@ class OpCreateTensor : public OpBase * @param tensors Tensors that will be used to create in operation. * @param freeTensors Whether operation manages the memory of the Tensors */ - OpCreateTensor(std::shared_ptr physicalDevice, + OpTensorCreate(std::shared_ptr physicalDevice, std::shared_ptr device, std::shared_ptr commandBuffer, std::vector> tensors); @@ -37,7 +37,7 @@ class OpCreateTensor : public OpBase * Default destructor which in this case expects the parent class to free * the tensors */ - ~OpCreateTensor() override; + ~OpTensorCreate() override; /** * In charge of initialising the primary Tensor as well as the staging diff --git a/src/include/kompute/operations/OpTensorSyncDevice.hpp b/src/include/kompute/operations/OpTensorSyncDevice.hpp new file mode 100644 index 000000000..14f95a7be --- /dev/null +++ b/src/include/kompute/operations/OpTensorSyncDevice.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "kompute/Core.hpp" + +#include "kompute/Tensor.hpp" + +#include "kompute/operations/OpBase.hpp" + +namespace kp { + +/** + Operation that syncs tensor's device by mapping local data into the device memory. For TensorTypes::eDevice it will use a staging tensor to perform the copy. For TensorTypes::eStaging it will only copy the data and perform a map, which will be executed during the record (as opposed to during the sequence eval/submit). This function cannot be carried out for TensorTypes::eStaging. +*/ +class OpTensorSyncDevice : public OpBase +{ + public: + OpTensorSyncDevice(); + + /** + * Default constructor with parameters that provides the core vulkan resources and the tensors that will be used in the operation. The tensos provided cannot be of type TensorTypes::eStorage. + * + * @param physicalDevice Vulkan physical device used to find device queues + * @param device Vulkan logical device for passing to Algorithm + * @param commandBuffer Vulkan Command Buffer to record commands into + * @param tensors Tensors that will be used to create in operation. + */ + OpTensorSyncDevice(std::shared_ptr physicalDevice, + std::shared_ptr device, + std::shared_ptr commandBuffer, + std::vector> tensors); + + /** + * Default destructor. This class does not manage memory so it won't be expecting the parent to perform a release. + */ + ~OpTensorSyncDevice() override; + + /** + * Performs basic checks such as ensuring that there is at least one tensor provided, that they are initialized and that they are not of type TensorTpes::eStaging. + */ + void init() override; + + /** + * Records the copy commands from teh first tensor into all the other tensors provided. Also optionally records a barrier. + */ + void record() override; + + /** + * Copies the local vectors for all the tensors to sync the data with the gpu. + */ + void postSubmit() override; + + private: +}; + +} // End namespace kp + + diff --git a/test/TestLogisticRegression.cpp b/test/TestLogisticRegression.cpp index 8404ced19..68805e86d 100644 --- a/test/TestLogisticRegression.cpp +++ b/test/TestLogisticRegression.cpp @@ -35,7 +35,7 @@ TEST(LogisticRegressionAlgorithm, TestMainLogisticRegression) { sq->begin(); - sq->record(params); + sq->record(params); sq->end(); sq->eval(); diff --git a/test/TestManager.cpp b/test/TestManager.cpp index 8c7fcde49..086b55f2e 100755 --- a/test/TestManager.cpp +++ b/test/TestManager.cpp @@ -8,15 +8,15 @@ TEST(TestManager, EndToEndOpMultFlow) kp::Manager mgr; std::shared_ptr tensorLHS{ new kp::Tensor({ 0, 1, 2 }) }; - mgr.evalOp({ tensorLHS }); + mgr.evalOp({ tensorLHS }); std::shared_ptr tensorRHS{ new kp::Tensor( { 2, 4, 6 }) }; - mgr.evalOp({ tensorRHS }); + mgr.evalOp({ tensorRHS }); std::shared_ptr tensorOutput{ new kp::Tensor( { 0, 0, 0 }) }; - mgr.evalOp({ tensorOutput }); + mgr.evalOp({ tensorOutput }); mgr.evalOp>({ tensorLHS, tensorRHS, tensorOutput }); @@ -40,9 +40,9 @@ TEST(TestManager, OpMultSequenceFlow) { if (std::shared_ptr sq = sqWeakPtr.lock()) { sq->begin(); - sq->record({ tensorLHS }); - sq->record({ tensorRHS }); - sq->record({ tensorOutput }); + sq->record({ tensorLHS }); + sq->record({ tensorRHS }); + sq->record({ tensorOutput }); sq->record>({ tensorLHS, tensorRHS, tensorOutput }); @@ -92,7 +92,7 @@ TEST(TestManager, TestMultipleTensorsAtOnce) { if (std::shared_ptr sq = sqWeakPtr.lock()) { sq->begin(); - sq->record({ tensorLHS, tensorRHS, tensorOutput }); + sq->record({ tensorLHS, tensorRHS, tensorOutput }); EXPECT_TRUE(tensorLHS->isInit()); EXPECT_TRUE(tensorRHS->isInit()); diff --git a/test/TestMultipleAlgoExecutions.cpp b/test/TestMultipleAlgoExecutions.cpp index 6bfdbeffb..df381b97a 100644 --- a/test/TestMultipleAlgoExecutions.cpp +++ b/test/TestMultipleAlgoExecutions.cpp @@ -23,7 +23,7 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) { if (std::shared_ptr sq = sqWeakPtr.lock()) { sq->begin(); - sq->record({ tensorA }); + sq->record({ tensorA }); sq->record>( { tensorA }, @@ -66,7 +66,7 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) { if (std::shared_ptr sq = sqWeakPtr.lock()) { sq->begin(); - sq->record({ tensorA }); + sq->record({ tensorA }); sq->record>( { tensorA }, @@ -122,7 +122,7 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences) { if (std::shared_ptr sq = sqWeakPtr.lock()) { sq->begin(); - sq->record({ tensorA }); + sq->record({ tensorA }); sq->record>( { tensorA }, @@ -183,7 +183,7 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) { if (std::shared_ptr sq = sqWeakPtr.lock()) { sq->begin(); - sq->record({ tensorA }); + sq->record({ tensorA }); sq->end(); sq->eval(); diff --git a/test/TestOpShadersFromStringAndFile.cpp b/test/TestOpShadersFromStringAndFile.cpp index 246644c26..92d2c50e0 100644 --- a/test/TestOpShadersFromStringAndFile.cpp +++ b/test/TestOpShadersFromStringAndFile.cpp @@ -10,7 +10,7 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) { std::shared_ptr tensorA{ new kp::Tensor({ 3, 4, 5 })}; std::shared_ptr tensorB{ new kp::Tensor({ 0, 0, 0 })}; - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.evalOpDefault({ tensorA, tensorB }); std::string shader(R"( #version 450 @@ -41,7 +41,7 @@ TEST(TestOpAlgoBase, ShaderCompiledDataFromConstructor) { std::shared_ptr tensorA{ new kp::Tensor({ 3, 4, 5 })}; std::shared_ptr tensorB{ new kp::Tensor({ 0, 0, 0 })}; - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.evalOpDefault({ tensorA, tensorB }); mgr.evalOpDefault>( { tensorA, tensorB }, @@ -60,7 +60,7 @@ TEST(TestOpAlgoBase, ShaderRawDataFromFile) { std::shared_ptr tensorA{ new kp::Tensor({ 3, 4, 5 })}; std::shared_ptr tensorB{ new kp::Tensor({ 0, 0, 0 })}; - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.evalOpDefault({ tensorA, tensorB }); mgr.evalOpDefault>( { tensorA, tensorB }, @@ -76,7 +76,7 @@ TEST(TestOpAlgoBase, ShaderCompiledDataFromFile) { std::shared_ptr tensorA{ new kp::Tensor({ 3, 4, 5 })}; std::shared_ptr tensorB{ new kp::Tensor({ 0, 0, 0 })}; - mgr.evalOpDefault({ tensorA, tensorB }); + mgr.evalOpDefault({ tensorA, tensorB }); mgr.evalOpDefault>( { tensorA, tensorB }, diff --git a/test/TestOpTensorCopy.cpp b/test/TestOpTensorCopy.cpp new file mode 100644 index 000000000..6b36e078a --- /dev/null +++ b/test/TestOpTensorCopy.cpp @@ -0,0 +1,111 @@ + +#include "gtest/gtest.h" + +#include "kompute/Kompute.hpp" + +TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor) { + + kp::Manager mgr; + + std::vector testVecA{ 9, 8, 7 }; + + std::shared_ptr tensorA{new kp::Tensor(testVecA)}; + + mgr.evalOpDefault({tensorA}); + + EXPECT_TRUE(tensorA->isInit()); + + EXPECT_EQ(tensorA->data(), testVecA); + + tensorA->freeMemoryDestroyGPUResources(); + EXPECT_FALSE(tensorA->isInit()); +} + +TEST(TestOpTensorCopy, CreateMultipleTensorSingleOp) { + + kp::Manager mgr; + + std::vector testVecA{ 9, 8, 7 }; + std::vector testVecB{ 6, 5, 4 }; + + std::shared_ptr tensorA{new kp::Tensor(testVecA)}; + std::shared_ptr tensorB{new kp::Tensor(testVecB)}; + + mgr.evalOpDefault({tensorA, tensorB}); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + EXPECT_EQ(tensorA->data(), testVecA); + EXPECT_EQ(tensorB->data(), testVecB); +} + +TEST(TestOpTensorCopy, CreateMultipleTensorMultipleOp) { + + kp::Manager mgr; + + std::vector testVecA{ 9, 8, 7 }; + std::vector testVecB{ 6, 5, 4 }; + + std::shared_ptr tensorA{new kp::Tensor(testVecA)}; + std::shared_ptr tensorB{new kp::Tensor(testVecB)}; + + mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorB}); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + EXPECT_EQ(tensorA->data(), testVecA); + EXPECT_EQ(tensorB->data(), testVecB); +} + +TEST(TestOpTensorCopy, ManageTensorMemoryWhenOpTensorCreateDestroyed) { + + std::vector testVecA{ 9, 8, 7 }; + std::vector testVecB{ 6, 5, 4 }; + + std::shared_ptr tensorA{new kp::Tensor(testVecA)}; + std::shared_ptr tensorB{new kp::Tensor(testVecB)}; + + { + kp::Manager mgr; + mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorB}); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + EXPECT_EQ(tensorA->data(), testVecA); + EXPECT_EQ(tensorB->data(), testVecB); + } + + EXPECT_FALSE(tensorA->isInit()); + EXPECT_FALSE(tensorB->isInit()); +} + +TEST(TestOpTensorCopy, NoErrorIfTensorFreedBefore) { + + std::vector testVecA{ 9, 8, 7 }; + std::vector testVecB{ 6, 5, 4 }; + + std::shared_ptr tensorA{new kp::Tensor(testVecA)}; + std::shared_ptr tensorB{new kp::Tensor(testVecB)}; + + kp::Manager mgr; + + mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorB}); + + EXPECT_TRUE(tensorA->isInit()); + EXPECT_TRUE(tensorB->isInit()); + + EXPECT_EQ(tensorA->data(), testVecA); + EXPECT_EQ(tensorB->data(), testVecB); + + tensorA->freeMemoryDestroyGPUResources(); + tensorB->freeMemoryDestroyGPUResources(); + EXPECT_FALSE(tensorA->isInit()); + EXPECT_FALSE(tensorB->isInit()); +} + diff --git a/test/TestOpCreateTensor.cpp b/test/TestOpTensorCreate.cpp similarity index 75% rename from test/TestOpCreateTensor.cpp rename to test/TestOpTensorCreate.cpp index bcbed84a5..a3296ce2e 100644 --- a/test/TestOpCreateTensor.cpp +++ b/test/TestOpTensorCreate.cpp @@ -3,7 +3,7 @@ #include "kompute/Kompute.hpp" -TEST(TestOpCreateTensor, CreateSingleTensorSingleOp) { +TEST(TestOpTensorCreate, CreateSingleTensorSingleOp) { kp::Manager mgr; @@ -11,7 +11,7 @@ TEST(TestOpCreateTensor, CreateSingleTensorSingleOp) { std::shared_ptr tensorA{new kp::Tensor(testVecA)}; - mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorA}); EXPECT_TRUE(tensorA->isInit()); @@ -21,7 +21,7 @@ TEST(TestOpCreateTensor, CreateSingleTensorSingleOp) { EXPECT_FALSE(tensorA->isInit()); } -TEST(TestOpCreateTensor, CreateMultipleTensorSingleOp) { +TEST(TestOpTensorCreate, CreateMultipleTensorSingleOp) { kp::Manager mgr; @@ -31,7 +31,7 @@ TEST(TestOpCreateTensor, CreateMultipleTensorSingleOp) { std::shared_ptr tensorA{new kp::Tensor(testVecA)}; std::shared_ptr tensorB{new kp::Tensor(testVecB)}; - mgr.evalOpDefault({tensorA, tensorB}); + mgr.evalOpDefault({tensorA, tensorB}); EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); @@ -40,7 +40,7 @@ TEST(TestOpCreateTensor, CreateMultipleTensorSingleOp) { EXPECT_EQ(tensorB->data(), testVecB); } -TEST(TestOpCreateTensor, CreateMultipleTensorMultipleOp) { +TEST(TestOpTensorCreate, CreateMultipleTensorMultipleOp) { kp::Manager mgr; @@ -50,8 +50,8 @@ TEST(TestOpCreateTensor, CreateMultipleTensorMultipleOp) { std::shared_ptr tensorA{new kp::Tensor(testVecA)}; std::shared_ptr tensorB{new kp::Tensor(testVecB)}; - mgr.evalOpDefault({tensorA}); - mgr.evalOpDefault({tensorB}); + mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorB}); EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); @@ -60,7 +60,7 @@ TEST(TestOpCreateTensor, CreateMultipleTensorMultipleOp) { EXPECT_EQ(tensorB->data(), testVecB); } -TEST(TestOpCreateTensor, ManageTensorMemoryWhenOpCreateTensorDestroyed) { +TEST(TestOpTensorCreate, ManageTensorMemoryWhenOpTensorCreateDestroyed) { std::vector testVecA{ 9, 8, 7 }; std::vector testVecB{ 6, 5, 4 }; @@ -70,8 +70,8 @@ TEST(TestOpCreateTensor, ManageTensorMemoryWhenOpCreateTensorDestroyed) { { kp::Manager mgr; - mgr.evalOpDefault({tensorA}); - mgr.evalOpDefault({tensorB}); + mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorB}); EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); @@ -84,7 +84,7 @@ TEST(TestOpCreateTensor, ManageTensorMemoryWhenOpCreateTensorDestroyed) { EXPECT_FALSE(tensorB->isInit()); } -TEST(TestOpCreateTensor, NoErrorIfTensorFreedBefore) { +TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore) { std::vector testVecA{ 9, 8, 7 }; std::vector testVecB{ 6, 5, 4 }; @@ -94,8 +94,8 @@ TEST(TestOpCreateTensor, NoErrorIfTensorFreedBefore) { kp::Manager mgr; - mgr.evalOpDefault({tensorA}); - mgr.evalOpDefault({tensorB}); + mgr.evalOpDefault({tensorA}); + mgr.evalOpDefault({tensorB}); EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); diff --git a/test/TestTensor.cpp b/test/TestTensor.cpp index 94f8aa92d..5f90dc7bf 100644 --- a/test/TestTensor.cpp +++ b/test/TestTensor.cpp @@ -28,7 +28,7 @@ TEST(TestTensor, CopyFromHostData) { { sq->begin(); - sq->record({tensorA, tensorB}); + sq->record({tensorA, tensorB}); sq->record({tensorA, tensorB});