Renamed tensorcreate and started adding optensorsyncdevice

This commit is contained in:
Alejandro Saucedo 2020-09-06 11:38:08 +01:00
parent 236c349aa0
commit ec89fc6d56
17 changed files with 318 additions and 71 deletions

View file

@ -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 ######

View file

@ -65,7 +65,7 @@ int main() {
auto tensorOut = std::make_shared<kp::Tensor>(kp::Tensor({ 0., 0., 0. }));
// Create tensors data in GPU
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorLhs, tensorRhs, tensorOut });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorLhs, tensorRhs, tensorOut });
// Run Kompute operation on the parameters provided with dispatch layout
mgr.evalOpDefault<kp::OpMult<3, 1, 1>>(
@ -104,7 +104,7 @@ int main() {
)");
// Create tensor data in GPU
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
// Run Kompute operation on the parameters provided with dispatch layout
mgr.evalOpDefault<kp::OpMult<3, 1, 1>>(
@ -129,7 +129,7 @@ int main() {
auto tensorRhs = std::make_shared<kp::Tensor>(kp::Tensor({ 2, 4, 6 }));
// Create tensor data in GPU
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
// Run Kompute operation on the parameters provided with dispatch layout
mgr.evalOpDefault<kp::OpMult<3, 1, 1>>(
@ -163,9 +163,9 @@ int main() {
sq.begin();
// Record batch commands to send to GPU
sq.record<kp::OpCreateTensor>({ tensorLHS });
sq.record<kp::OpCreateTensor>({ tensorRHS });
sq.record<kp::OpCreateTensor>({ tensorOutput });
sq.record<kp::OpTensorCreate>({ tensorLHS });
sq.record<kp::OpTensorCreate>({ tensorRHS });
sq.record<kp::OpTensorCreate>({ tensorOutput });
sq.record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
// Stop recording

View file

@ -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 <doxygen/annotated.html>`_.
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:

View file

@ -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"

View file

@ -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<vk::PhysicalDevice> physicalDevice,
OpTensorCreate(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer,
std::vector<std::shared_ptr<Tensor>> 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;

View file

@ -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<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer,
std::vector<std::shared_ptr<Tensor>> 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> 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) {

View file

@ -0,0 +1,71 @@
#include "kompute/operations/OpTensorSyncDevice.hpp"
namespace kp {
OpTensorSyncDevice::OpTensorSyncDevice()
{
SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor base");
}
OpTensorSyncDevice::OpTensorSyncDevice(
std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer,
std::vector<std::shared_ptr<Tensor>> 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> 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());
}
}
}

View file

@ -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<std::shared_ptr<Tensor>> 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;

View file

@ -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<vk::PhysicalDevice> physicalDevice,
OpTensorCreate(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer,
std::vector<std::shared_ptr<Tensor>> 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

View file

@ -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<vk::PhysicalDevice> physicalDevice,
std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::CommandBuffer> commandBuffer,
std::vector<std::shared_ptr<Tensor>> 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

View file

@ -35,7 +35,7 @@ TEST(LogisticRegressionAlgorithm, TestMainLogisticRegression) {
sq->begin();
sq->record<kp::OpCreateTensor>(params);
sq->record<kp::OpTensorCreate>(params);
sq->end();
sq->eval();

View file

@ -8,15 +8,15 @@ TEST(TestManager, EndToEndOpMultFlow)
kp::Manager mgr;
std::shared_ptr<kp::Tensor> tensorLHS{ new kp::Tensor({ 0, 1, 2 }) };
mgr.evalOp<kp::OpCreateTensor>({ tensorLHS });
mgr.evalOp<kp::OpTensorCreate>({ tensorLHS });
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor(
{ 2, 4, 6 }) };
mgr.evalOp<kp::OpCreateTensor>({ tensorRHS });
mgr.evalOp<kp::OpTensorCreate>({ tensorRHS });
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor(
{ 0, 0, 0 }) };
mgr.evalOp<kp::OpCreateTensor>({ tensorOutput });
mgr.evalOp<kp::OpTensorCreate>({ tensorOutput });
mgr.evalOp<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
@ -40,9 +40,9 @@ TEST(TestManager, OpMultSequenceFlow) {
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
sq->begin();
sq->record<kp::OpCreateTensor>({ tensorLHS });
sq->record<kp::OpCreateTensor>({ tensorRHS });
sq->record<kp::OpCreateTensor>({ tensorOutput });
sq->record<kp::OpTensorCreate>({ tensorLHS });
sq->record<kp::OpTensorCreate>({ tensorRHS });
sq->record<kp::OpTensorCreate>({ tensorOutput });
sq->record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
@ -92,7 +92,7 @@ TEST(TestManager, TestMultipleTensorsAtOnce) {
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
sq->begin();
sq->record<kp::OpCreateTensor>({ tensorLHS, tensorRHS, tensorOutput });
sq->record<kp::OpTensorCreate>({ tensorLHS, tensorRHS, tensorOutput });
EXPECT_TRUE(tensorLHS->isInit());
EXPECT_TRUE(tensorRHS->isInit());

View file

@ -23,7 +23,7 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord) {
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
sq->begin();
sq->record<kp::OpCreateTensor>({ tensorA });
sq->record<kp::OpTensorCreate>({ tensorA });
sq->record<kp::OpAlgoBase<3, 1, 1>>(
{ tensorA },
@ -66,7 +66,7 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords) {
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
sq->begin();
sq->record<kp::OpCreateTensor>({ tensorA });
sq->record<kp::OpTensorCreate>({ tensorA });
sq->record<kp::OpAlgoBase<3, 1, 1>>(
{ tensorA },
@ -122,7 +122,7 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences) {
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
sq->begin();
sq->record<kp::OpCreateTensor>({ tensorA });
sq->record<kp::OpTensorCreate>({ tensorA });
sq->record<kp::OpAlgoBase<3, 1, 1>>(
{ tensorA },
@ -183,7 +183,7 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval) {
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
sq->begin();
sq->record<kp::OpCreateTensor>({ tensorA });
sq->record<kp::OpTensorCreate>({ tensorA });
sq->end();
sq->eval();

View file

@ -10,7 +10,7 @@ TEST(TestOpAlgoBase, ShaderRawDataFromConstructor) {
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
std::string shader(R"(
#version 450
@ -41,7 +41,7 @@ TEST(TestOpAlgoBase, ShaderCompiledDataFromConstructor) {
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase<>>(
{ tensorA, tensorB },
@ -60,7 +60,7 @@ TEST(TestOpAlgoBase, ShaderRawDataFromFile) {
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase<>>(
{ tensorA, tensorB },
@ -76,7 +76,7 @@ TEST(TestOpAlgoBase, ShaderCompiledDataFromFile) {
std::shared_ptr<kp::Tensor> tensorA{ new kp::Tensor({ 3, 4, 5 })};
std::shared_ptr<kp::Tensor> tensorB{ new kp::Tensor({ 0, 0, 0 })};
mgr.evalOpDefault<kp::OpCreateTensor>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
mgr.evalOpDefault<kp::OpAlgoBase<>>(
{ tensorA, tensorB },

111
test/TestOpTensorCopy.cpp Normal file
View file

@ -0,0 +1,111 @@
#include "gtest/gtest.h"
#include "kompute/Kompute.hpp"
TEST(TestOpTensorCopy, CopyDeviceToDeviceTensor) {
kp::Manager mgr;
std::vector<float> testVecA{ 9, 8, 7 };
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
EXPECT_TRUE(tensorA->isInit());
EXPECT_EQ(tensorA->data(), testVecA);
tensorA->freeMemoryDestroyGPUResources();
EXPECT_FALSE(tensorA->isInit());
}
TEST(TestOpTensorCopy, CreateMultipleTensorSingleOp) {
kp::Manager mgr;
std::vector<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
mgr.evalOpDefault<kp::OpTensorCreate>({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<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({tensorB});
EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit());
EXPECT_EQ(tensorA->data(), testVecA);
EXPECT_EQ(tensorB->data(), testVecB);
}
TEST(TestOpTensorCopy, ManageTensorMemoryWhenOpTensorCreateDestroyed) {
std::vector<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
{
kp::Manager mgr;
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({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<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
std::shared_ptr<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
kp::Manager mgr;
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({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());
}

View file

@ -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<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({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<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA, tensorB});
mgr.evalOpDefault<kp::OpTensorCreate>({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<kp::Tensor> tensorA{new kp::Tensor(testVecA)};
std::shared_ptr<kp::Tensor> tensorB{new kp::Tensor(testVecB)};
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
mgr.evalOpDefault<kp::OpCreateTensor>({tensorB});
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({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<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
@ -70,8 +70,8 @@ TEST(TestOpCreateTensor, ManageTensorMemoryWhenOpCreateTensorDestroyed) {
{
kp::Manager mgr;
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
mgr.evalOpDefault<kp::OpCreateTensor>({tensorB});
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({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<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
@ -94,8 +94,8 @@ TEST(TestOpCreateTensor, NoErrorIfTensorFreedBefore) {
kp::Manager mgr;
mgr.evalOpDefault<kp::OpCreateTensor>({tensorA});
mgr.evalOpDefault<kp::OpCreateTensor>({tensorB});
mgr.evalOpDefault<kp::OpTensorCreate>({tensorA});
mgr.evalOpDefault<kp::OpTensorCreate>({tensorB});
EXPECT_TRUE(tensorA->isInit());
EXPECT_TRUE(tensorB->isInit());

View file

@ -28,7 +28,7 @@ TEST(TestTensor, CopyFromHostData) {
{
sq->begin();
sq->record<kp::OpCreateTensor>({tensorA, tensorB});
sq->record<kp::OpTensorCreate>({tensorA, tensorB});
sq->record<kp::OpTensorCopy>({tensorA, tensorB});