Commit 3e87ab9b authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

add unit tests for the two versions of Backend create_tensor (#2607)

* add unit tests for the two versions of Backend create_tensor

* disable new unit test on GPU until we have time to address it
parent 1eea5fe6
......@@ -92,7 +92,7 @@ all_2x2x3_eliminate_dims_0_2
all_2x2x3_eliminate_dims_1_2
all_2x2x3_eliminate_dims_0_1_2
# GPU backend uses floats to implement these ops for int32
# GPU backend uses floats to implement these ops for int32
floor_int32
divide_int32
one_hot_scalar_oob_in_3
......@@ -101,3 +101,6 @@ one_hot_scalar_oob_in_3
model_dequantize_linear
model_quantize_linear
model_quant_conv_linear
# This should be implemented
create_tensor_2
......@@ -131,6 +131,7 @@ set(MULTI_TEST_SRC
autodiff.in.cpp
backend_all.in.cpp
backend_any.in.cpp
backend_api.in.cpp
backend_binary_elementwise.in.cpp
backend_broadcast.in.cpp
backend_comparison.in.cpp
......
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#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"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
// This tests a backend's implementation of the two parameter version of create_tensor
NGRAPH_TEST(${BACKEND_NAME}, create_tensor_1)
{
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);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape);
copy_data(a, av);
copy_data(b, bv);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected = {6, 8, 10, 12};
EXPECT_EQ(read_vector<float>(result), expected);
}
// This tests a backend's implementation of the three parameter version of create_tensor
NGRAPH_TEST(${BACKEND_NAME}, create_tensor_2)
{
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, av.data());
shared_ptr<runtime::Tensor> b = backend->create_tensor(element::f32, shape, bv.data());
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};
EXPECT_EQ(read_vector<float>(result), expected);
}
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