Commit 0890cc86 authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

Add unit test for create_tensor passing in buffer to output tensor (#2711)

* add unit test for create_tensor passing in buffer to output tensor

* add comments

* disabled gpu create tensor unit test
parent 74447b2a
......@@ -119,7 +119,8 @@ model_quantize_linear
model_quant_conv_linear
# This should be implemented
create_tensor_2
create_tensor_2_input
create_tensor_2_output
# Not implemented
erf
......
......@@ -16,7 +16,6 @@
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/random.hpp"
......@@ -43,11 +42,11 @@ NGRAPH_TEST(${BACKEND_NAME}, create_tensor_1)
vector<float> bv = {5, 6, 7, 8};
shared_ptr<runtime::Tensor> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> b = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape);
copy_data(a, av);
copy_data(b, bv);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected = {6, 8, 10, 12};
......@@ -55,7 +54,8 @@ NGRAPH_TEST(${BACKEND_NAME}, create_tensor_1)
}
// This tests a backend's implementation of the three parameter version of create_tensor
NGRAPH_TEST(${BACKEND_NAME}, create_tensor_2)
// Testing using this tensor as a Function input
NGRAPH_TEST(${BACKEND_NAME}, create_tensor_2_input)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
......@@ -77,6 +77,34 @@ NGRAPH_TEST(${BACKEND_NAME}, create_tensor_2)
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
// This tests a backend's implementation of the three parameter version of create_tensor
// Testing using this tensor as a Function output
NGRAPH_TEST(${BACKEND_NAME}, create_tensor_2_output)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Add>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
vector<float> av = {1, 2, 3, 4};
vector<float> bv = {5, 6, 7, 8};
shared_ptr<runtime::Tensor> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> b = backend->create_tensor(element::f32, shape);
copy_data(a, av);
copy_data(b, bv);
vector<float> actual(4);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape, actual.data());
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected = {6, 8, 10, 12};
EXPECT_TRUE(test::all_close_f(actual, expected, MIN_FLOAT_TOLERANCE_BITS));
}
// This tests a backend's implementation of the copy_from for tensor
NGRAPH_TEST(${BACKEND_NAME}, tensor_copy_from)
{
......@@ -93,7 +121,7 @@ NGRAPH_TEST(${BACKEND_NAME}, tensor_copy_from)
copy_data(b, bv);
a->copy_from(*b);
EXPECT_TRUE(test::all_close(bv, read_vector<float>(a), 0.0f, 0.0f));
EXPECT_TRUE(test::all_close_f(bv, read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, get_parameters_and_results)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment