Added tensor tests to validate tensor copies
This commit is contained in:
parent
8adb7ab49d
commit
00c66f347b
1 changed files with 36 additions and 2 deletions
|
|
@ -1,12 +1,46 @@
|
|||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include "kompute/Tensor.hpp"
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
TEST_CASE("Tensor should have same vector as initialised") {
|
||||
TEST_CASE("test_tensor_constructor_data") {
|
||||
std::vector<uint32_t> vec{0,1,2};
|
||||
kp::Tensor tensor(vec);
|
||||
REQUIRE( tensor.size() == vec.size() );
|
||||
REQUIRE( tensor.data() == vec );
|
||||
}
|
||||
|
||||
TEST_CASE("test_tensor_copy_from_other_tensor_host_data") {
|
||||
std::vector<uint32_t> vecA{0,1,2};
|
||||
std::vector<uint32_t> vecB{0,0,0};
|
||||
|
||||
std::shared_ptr<kp::Tensor> tensorA = std::make_shared<kp::Tensor>(
|
||||
vecA,
|
||||
kp::Tensor::TensorTypes::eStaging);
|
||||
std::shared_ptr<kp::Tensor> tensorB = std::make_shared<kp::Tensor>(
|
||||
vecA,
|
||||
kp::Tensor::TensorTypes::eStaging);
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
if(std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.getOrCreateManagedSequence("new").lock())
|
||||
{
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpCreateTensor>({tensorA, tensorB});
|
||||
|
||||
tensorA->mapDataIntoHostMemory();
|
||||
|
||||
tensorB->recordCopyFrom(tensorA, true);
|
||||
|
||||
sq->end();
|
||||
|
||||
sq->eval();
|
||||
|
||||
tensorB->mapDataFromHostMemory();
|
||||
}
|
||||
|
||||
REQUIRE(tensorA->data() == tensorB->data());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue