Commit 5465677f authored by Adam Procter's avatar Adam Procter Committed by Scott Cyphers

Finish splitting backend_test.in.cpp (#3262)

* Split backend_test.in.cpp

* style

* Move backend_{graph_comparison,mlir}.in.cpp back

* Move backend_mlir.in.cpp into backend/ dir

* Disable some tests in PlaidML manifest
parent ea165a93
......@@ -45,6 +45,7 @@
#include "ngraph/builder/autobroadcast.hpp"
#include "ngraph/builder/numpy_transpose.hpp"
#include "ngraph/builder/quantized_conv_builder.hpp"
#include "ngraph/builder/reduce_ops.hpp"
#include "ngraph/builder/tensor_mask.hpp"
#include "ngraph/coordinate_transform.hpp"
......@@ -92,6 +93,7 @@
#include "ngraph/op/experimental/dyn_replace_slice.hpp"
#include "ngraph/op/experimental/dyn_reshape.hpp"
#include "ngraph/op/experimental/dyn_slice.hpp"
#include "ngraph/op/experimental/generate_mask.hpp"
#include "ngraph/op/experimental/range.hpp"
#include "ngraph/op/experimental/shape_of.hpp"
#include "ngraph/op/experimental/tile.hpp"
......
......@@ -315,3 +315,16 @@ avg_pool_3d_uneven_strided_padded
rnn_cell_activation_function
gru_cell_bias_clip
gru_cell_linear_before_reset
# After https://github.com/NervanaSystems/ngraph/pull/3262, these tests began
# failing with what appear to be precision issues. That PR simply split the
# old "backend_test.in.cpp" into multiple files. The only relevant side effect
# I can think of here is that the order of test execution changed as a result.
softmax_all
softmax_axis
softmax_underflow
softmax_overflow
sigmoid_n1c1h2w2
sigmoid_n1c1h4
sigmoid_bprop_n1c1h4
lrn
......@@ -215,25 +215,62 @@ add_subdirectory(util)
# such as ${BACKEND_NAME} with their values, such as CPU, GPU, or INTERPRETER.
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
backend_dot.in.cpp
backend_embedding_lookup.in.cpp
backend_fused_op.in.cpp
backend_gather.in.cpp
backend_one_hot.in.cpp
backend_pool.in.cpp
backend_reshape.in.cpp
backend_scatter.in.cpp
backend_sum.in.cpp
backend_topk.in.cpp
backend_arg_reduce.in.cpp
backend_test.in.cpp
backend_unary_elementwise.in.cpp
backend/abc.in.cpp
backend/aliased_output.in.cpp
backend/all.in.cpp
backend/any.in.cpp
backend/api.in.cpp
backend/arg_reduce.in.cpp
backend/batch_mat_mul.in.cpp
backend/batch_norm.in.cpp
backend/binary_elementwise.in.cpp
backend/broadcast.in.cpp
backend/comparison.in.cpp
backend/computation_reuse.in.cpp
backend/concat.in.cpp
backend/constant.in.cpp
backend/convert.in.cpp
backend/convolution.in.cpp
backend/dot.in.cpp
backend/embedding_lookup.in.cpp
backend/function_name.in.cpp
backend/fused_op.in.cpp
backend/gather.in.cpp
backend/generate_mask.in.cpp
backend/logical_and.in.cpp
backend/logical_or.in.cpp
backend/lrn.in.cpp
backend/max.in.cpp
backend/min.in.cpp
backend/multiple_backends.in.cpp
backend/multiple_result.in.cpp
backend/node_name.in.cpp
backend/numeric.in.cpp
backend/one_hot.in.cpp
backend/pad.in.cpp
backend/parameter_as_output.in.cpp
backend/pool.in.cpp
backend/product.in.cpp
backend/quantize_dequantize.in.cpp
backend/quantized_convolution.in.cpp
backend/relu.in.cpp
backend/replace_slice.in.cpp
backend/reshape.in.cpp
backend/reverse.in.cpp
backend/reverse_sequence.in.cpp
backend/scatter.in.cpp
backend/select.in.cpp
backend/shape_of.in.cpp
backend/sigmoid.in.cpp
backend/slice.in.cpp
backend/softmax.in.cpp
backend/sum.in.cpp
backend/tensorview_custom_mem.in.cpp
backend/topk.in.cpp
backend/unhandled_op.in.cpp
backend/unary_elementwise.in.cpp
backend/validate_call.in.cpp
backend/zero_sized.in.cpp
convolution_test.in.cpp
dyn_replace_slice_test.in.cpp
dyn_slice_test.in.cpp
......@@ -241,7 +278,7 @@ set(MULTI_TEST_SRC
)
if (NGRAPH_MLIR_ENABLE)
list(APPEND MULTI_TEST_SRC backend_mlir.in.cpp)
list(APPEND MULTI_TEST_SRC backend/mlir.in.cpp)
endif()
if(NGRAPH_DISTRIBUTED_ENABLE)
......
//*****************************************************************************
// 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_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, abc)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>((A + B) * C, ParameterVector{A, B, C});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
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> c = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape);
copy_data(a, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
copy_data(c, test::NDArray<float, 2>({{9, 10}, {11, 12}}).get_vector());
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector()));
handle->call_with_validate({result}, {b, a, c});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector()));
handle->call_with_validate({result}, {a, c, b});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{50, 72}, {98, 128}})).get_vector()));
}
NGRAPH_TEST(${BACKEND_NAME}, abc_int64)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::i64, shape);
auto B = make_shared<op::Parameter>(element::i64, shape);
auto C = make_shared<op::Parameter>(element::i64, shape);
auto f = make_shared<Function>((A + B) * C, ParameterVector{A, B, C});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i64, shape);
copy_data(a, vector<int64_t>{1, 2, 3, 4});
auto b = backend->create_tensor(element::i64, shape);
copy_data(b, vector<int64_t>{5, 6, 7, 8});
auto c = backend->create_tensor(element::i64, shape);
copy_data(c, vector<int64_t>{9, 10, 11, 12});
auto result = backend->create_tensor(element::i64, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c});
EXPECT_EQ((vector<int64_t>{54, 80, 110, 144}), read_vector<int64_t>(result));
handle->call_with_validate({result}, {b, a, c});
EXPECT_EQ((vector<int64_t>{54, 80, 110, 144}), read_vector<int64_t>(result));
handle->call_with_validate({result}, {a, c, b});
EXPECT_EQ((vector<int64_t>{50, 72, 98, 128}), read_vector<int64_t>(result));
}
//*****************************************************************************
// 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_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, aliased_output)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = A + B;
auto D = A * B;
auto E = op::Constant::create(element::f32, shape, {1, 2, 3, 4});
auto f = make_shared<Function>(NodeVector{C, C, D, D, C, E, E}, ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
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> out1 = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> out2 = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> out3 = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> out4 = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> out5 = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> out6 = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> out7 = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{0, 1, 2, 3});
copy_data(b, vector<float>{1, 2, 3, 4});
vector<float> expectedC{1, 3, 5, 7};
vector<float> expectedD{0, 2, 6, 12};
vector<float> expectedE{1, 2, 3, 4};
auto handle = backend->compile(f);
handle->call_with_validate({out1, out2, out3, out4, out5, out6, out7}, {a, b});
EXPECT_TRUE(test::all_close_f(expectedC, read_vector<float>(out1), MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(expectedC, read_vector<float>(out2), MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(expectedD, read_vector<float>(out3), MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(expectedD, read_vector<float>(out4), MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(expectedC, read_vector<float>(out5), MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(expectedE, read_vector<float>(out6), MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(expectedE, read_vector<float>(out7), MIN_FLOAT_TOLERANCE_BITS));
}
//*****************************************************************************
// 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/known_element_types.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 test operates against the INTERPRETER backend as a reference, so it is
// disabled if INTERPRETER is disabled.
#if NGRAPH_INTERPRETER_ENABLE
NGRAPH_TEST(${BACKEND_NAME}, batch_mat_mul_forward)
{
auto make_dot = [](ParameterVector& a_params, ParameterVector& b_params) {
Shape shape_a{2, 3};
Shape shape_b{3, 2};
auto A = make_shared<op::Parameter>(element::f32, shape_a);
auto B = make_shared<op::Parameter>(element::f32, shape_b);
a_params.push_back(A);
b_params.push_back(B);
return make_shared<op::Dot>(A, B);
};
ParameterVector dot_a_params;
ParameterVector dot_b_params;
auto dot1 = make_dot(dot_a_params, dot_b_params);
auto dot2 = make_dot(dot_a_params, dot_b_params);
auto dot3 = make_dot(dot_a_params, dot_b_params);
auto dot_concat = make_shared<op::Concat>(NodeVector{dot1, dot2, dot3}, 0);
ParameterVector dot_params(dot_a_params);
dot_params.insert(dot_params.end(), dot_b_params.begin(), dot_b_params.end());
auto ref_f = make_shared<Function>(dot_concat, dot_params);
auto make_batchmatmul = [](ParameterVector& params) {
Shape shape_a{3, 2, 3};
Shape shape_b{3, 3, 2};
auto A = make_shared<op::Parameter>(element::f32, shape_a);
auto B = make_shared<op::Parameter>(element::f32, shape_b);
params.push_back(A);
params.push_back(B);
return make_shared<op::BatchMatMul>(A, B);
};
ParameterVector batchmatmul_params;
auto batchmatmul = make_batchmatmul(batchmatmul_params);
auto backend_f = make_shared<Function>(batchmatmul, batchmatmul_params);
test::Uniform<float> dot_rng(-1.0f, 1.0f);
vector<vector<float>> dot_args;
for (shared_ptr<op::Parameter> param : dot_params)
{
vector<float> tensor_val(shape_size(param->get_shape()));
dot_rng.initialize(tensor_val);
dot_args.push_back(tensor_val);
}
test::Uniform<float> batchmatmul_rng(-1.0f, 1.0f);
vector<vector<float>> batchmatmul_args;
for (shared_ptr<op::Parameter> param : batchmatmul_params)
{
vector<float> tensor_val(shape_size(param->get_shape()));
batchmatmul_rng.initialize(tensor_val);
batchmatmul_args.push_back(tensor_val);
}
auto ref_results = execute(ref_f, dot_args, "INTERPRETER");
auto backend_results = execute(backend_f, batchmatmul_args, "${BACKEND_NAME}");
for (size_t i = 0; i < ref_results.size(); i++)
{
EXPECT_TRUE(test::all_close(ref_results.at(i), backend_results.at(i), 1.0e-4f, 1.0e-4f));
}
}
#endif
This diff is collapsed.
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, computation_reuse)
{
Shape shape_a{1, 16, 2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape_a);
Shape shape_b{32, 16, 1, 1};
auto B = make_shared<op::Parameter>(element::f32, shape_b, true);
Shape shape_r{1, 32, 2, 2};
auto conv = make_shared<op::Convolution>(A,
B,
Strides{1, 1},
Strides{1, 1},
CoordinateDiff{0, 0},
CoordinateDiff{0, 0},
Strides{1, 1});
Shape pool_shape{1, 1};
auto pool = make_shared<op::AvgPool>(conv, pool_shape);
auto bias = make_shared<op::Broadcast>(
op::Constant::create(element::f32, Shape{}, {2.14}), shape_r, AxisSet{0, 1, 2, 3});
auto result_op = make_shared<op::Result>(pool + bias);
auto f = make_shared<Function>(ResultVector{result_op}, ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
vector<float> input(64, 1.0f);
vector<float> weights(512, 0.5f);
vector<float> rv(128);
auto a = backend->create_tensor(element::f32, shape_a, input.data());
auto b = backend->create_tensor(element::f32, shape_b, weights.data());
auto result = backend->create_tensor(element::f32, shape_r, rv.data());
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> rv_saved(rv);
b->set_stale(false);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f(rv_saved, rv));
}
This diff is collapsed.
//*****************************************************************************
// 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/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, tensor_constant)
{
Shape shape{2, 2, 2};
auto A = op::Constant::create(element::f32, shape, {1, 2, 3, 4, 5, 6, 7, 8});
auto f = make_shared<Function>(A, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, tensor_2constant)
{
Shape shape{2, 2, 2};
auto A = op::Constant::create(element::f32, shape, {1, 2, 3, 4, 5, 6, 7, 8});
auto f = make_shared<Function>(NodeVector{A, A}, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result0 = backend->create_tensor(element::f32, shape);
auto result1 = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result0, result1}, {});
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8}),
read_vector<float>(result0),
MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8}),
read_vector<float>(result1),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, tensor_constant_with_op)
{
Shape shape{2, 2, 2};
auto A = op::Constant::create(element::f32, shape, {-1, 2, 3, -4, 5, -6, -7, 8});
auto f = make_shared<Function>(make_shared<op::Abs>(A), ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, constant_multi_use)
{
auto A = make_shared<op::Constant>(element::i32, Shape{}, std::vector<std::string>{"388"});
auto f = make_shared<Function>(A, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::shared_ptr<runtime::Tensor> r1 = backend->create_tensor(element::i32, Shape{});
auto handle = backend->compile(f);
handle->call_with_validate({r1}, std::vector<std::shared_ptr<runtime::Tensor>>{});
EXPECT_EQ(read_vector<int>(r1), std::vector<int>{388});
std::shared_ptr<runtime::Tensor> r2 = backend->create_tensor(element::i32, Shape{});
handle->call_with_validate({r2}, std::vector<std::shared_ptr<runtime::Tensor>>{});
EXPECT_EQ(read_vector<int>(r2), std::vector<int>{388});
}
NGRAPH_TEST(${BACKEND_NAME}, scalar_constant_float32)
{
auto r = op::Constant::create(element::f32, Shape{}, {4.75});
auto f = make_shared<Function>(r, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::f32, Shape{});
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_TRUE(test::all_close_f(
vector<float>{4.75f}, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, scalar_constant_int64)
{
auto r = op::Constant::create(element::i64, Shape{}, {0x4000000000000001});
auto f = make_shared<Function>(r, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::i64, Shape{});
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ(vector<int64_t>{0x4000000000000001}, read_vector<int64_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, tensor_constant_float32)
{
Shape shape{2, 2};
auto r = op::Constant::create(element::f32, shape, {4.75, 4.5, -5.25, 0.0});
auto f = make_shared<Function>(r, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_TRUE(test::all_close_f((vector<float>{4.75f, 4.5f, -5.25f, 0.0f}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, tensor_constant_int64)
{
Shape shape{2};
auto r = op::Constant::create(element::i64, shape, {0x4000000000000001, 0x4000000000000002});
auto f = make_shared<Function>(r, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::i64, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ((vector<int64_t>{0x4000000000000001, 0x4000000000000002}),
read_vector<int64_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, constant_equality_bool)
{
Shape shape{4};
// auto A = make_shared<op::Parameter>(element::boolean, shape);
// auto B = make_shared<op::Parameter>(element::boolean, shape);
// auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{A, B});
auto A = op::Constant::create(element::boolean, shape, {true, false, true, false});
auto B = op::Constant::create(element::boolean, shape, {true, true, true, true});
auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ((vector<char>{true, false, true, false}), read_vector<char>(result));
}
//*****************************************************************************
// 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/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, convert_int32_float32)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Convert>(A, element::f32), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{281, 2, 3, 4});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_TRUE(test::all_close_f((vector<float>{281, 2, 3, 4}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, convert_uint16_float32)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::u16, shape);
auto f = make_shared<Function>(make_shared<op::Convert>(A, element::f32), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::u16, shape);
copy_data(a, vector<uint16_t>{1, 2, 3, 4});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_TRUE(test::all_close_f(
(vector<float>{1, 2, 3, 4}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, convert_int32_bool)
{
Shape shape{2, 3};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f =
make_shared<Function>(make_shared<op::Convert>(A, element::boolean), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
int32_t lowest = std::numeric_limits<int32_t>::lowest();
int32_t max = std::numeric_limits<int32_t>::max();
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{0, 12, 23, 0, lowest, max});
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<char>{0, 1, 1, 0, 1, 1}), read_vector<char>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, convert_float32_bool)
{
Shape shape{3, 3};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f =
make_shared<Function>(make_shared<op::Convert>(A, element::boolean), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
float lowest = std::numeric_limits<float>::lowest();
float max = std::numeric_limits<float>::max();
float min = std::numeric_limits<float>::min();
float pos_inf = std::numeric_limits<float>::infinity();
float neg_inf = -std::numeric_limits<float>::infinity();
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{0.f, 1.5745f, 0.12352f, 0.f, lowest, max, min, pos_inf, neg_inf});
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<char>{0, 1, 1, 0, 1, 1, 1, 1, 1}), read_vector<char>(result));
}
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, convolution_outlining)
{
Shape shape_a{1, 2, 2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape_a);
Shape shape_b{2, 2, 1, 1};
auto B = make_shared<op::Parameter>(element::f32, shape_b);
Shape shape_r{1, 2, 2, 2};
auto conv1 = make_shared<op::Convolution>(A,
B,
Strides{1, 1},
Strides{1, 1},
CoordinateDiff{0, 0},
CoordinateDiff{0, 0},
Strides{1, 1});
auto conv2 = make_shared<op::Convolution>(conv1,
B,
Strides{1, 1},
Strides{1, 1},
CoordinateDiff{0, 0},
CoordinateDiff{0, 0},
Strides{1, 1});
auto f = make_shared<Function>(conv2, ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape_a);
copy_data(a, vector<float>{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f});
auto b = backend->create_tensor(element::f32, shape_b);
copy_data(b, vector<float>{1.0f, 1.0f, 1.0f, 1.0f});
auto result = backend->create_tensor(element::f32, shape_r);
vector<float> expected_result{4.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f};
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f(vector<float>{expected_result}, read_vector<float>(result)));
}
//*****************************************************************************
// 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_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, function_name)
{
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>(A + B, ParameterVector{A, B}, "funky func name");
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::Tensor> a = backend->create_tensor<float>(shape);
shared_ptr<runtime::Tensor> b = backend->create_tensor<float>(shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor<float>(shape);
copy_data(a, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector()));
}
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, generate_mask)
{
Shape scalar{};
Shape result_shape{1, 128};
const unsigned int seed = 777;
auto training = op::Constant::create(element::f32, Shape{}, {1});
auto gen_mask =
make_shared<op::GenerateMask>(training, result_shape, element::f32, seed, 0.5, false);
auto gen_mask2 =
make_shared<op::GenerateMask>(training, result_shape, element::f32, seed, 0.5, false);
auto f = make_shared<Function>(NodeVector{gen_mask, gen_mask2}, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto is_not_zero_or_one = [](float num) { return num != 0.f && num != 1.f; };
auto result_tv1 = backend->create_tensor<float>(result_shape);
auto result_tv2 = backend->create_tensor<float>(result_shape);
auto handle = backend->compile(f);
handle->call_with_validate({result_tv1, result_tv2}, {});
auto result1 = read_vector<float>(result_tv1);
auto result2 = read_vector<float>(result_tv2);
ASSERT_TRUE(test::all_close_f(result1, result2));
ASSERT_FALSE(std::any_of(result1.begin(), result1.end(), is_not_zero_or_one));
handle->call_with_validate({result_tv1, result_tv2}, {});
auto result1_2 = read_vector<float>(result_tv1);
auto result2_2 = read_vector<float>(result_tv2);
ASSERT_FALSE(test::all_close_f(result1, result1_2));
ASSERT_FALSE(std::any_of(result1_2.begin(), result1_2.end(), is_not_zero_or_one));
ASSERT_FALSE(test::all_close_f(result2, result2_2));
ASSERT_FALSE(std::any_of(result2_2.begin(), result2_2.end(), is_not_zero_or_one));
}
NGRAPH_TEST(${BACKEND_NAME}, generate_mask2)
{
Shape scalar{};
Shape result_shape{1, 128};
const unsigned int seed = 777;
auto training = op::Constant::create(element::f32, Shape{}, {1});
auto gen_mask =
make_shared<op::GenerateMask>(training, result_shape, element::f32, seed, 0.5, true);
auto gen_mask2 =
make_shared<op::GenerateMask>(training, result_shape, element::f32, seed, 0.5, true);
auto f = make_shared<Function>(NodeVector{gen_mask, gen_mask2}, ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto is_not_zero_or_one = [](float num) { return num != 0.f && num != 1.f; };
auto result_tv1 = backend->create_tensor<float>(result_shape);
auto result_tv2 = backend->create_tensor<float>(result_shape);
auto handle = backend->compile(f);
handle->call_with_validate({result_tv1, result_tv2}, {});
auto result1 = read_vector<float>(result_tv1);
auto result2 = read_vector<float>(result_tv2);
ASSERT_TRUE(test::all_close_f(result1, result2));
ASSERT_FALSE(std::any_of(result1.begin(), result1.end(), is_not_zero_or_one));
auto result_tv1_2 = backend->create_tensor<float>(result_shape);
auto result_tv2_2 = backend->create_tensor<float>(result_shape);
handle->call_with_validate({result_tv1_2, result_tv2_2}, {});
auto result1_2 = read_vector<float>(result_tv1_2);
auto result2_2 = read_vector<float>(result_tv2_2);
ASSERT_TRUE(test::all_close_f(result1, result1_2));
ASSERT_FALSE(std::any_of(result1_2.begin(), result1_2.end(), is_not_zero_or_one));
ASSERT_TRUE(test::all_close_f(result2, result2_2));
ASSERT_FALSE(std::any_of(result2_2.begin(), result2_2.end(), is_not_zero_or_one));
}
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, logical_and)
{
Shape shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::boolean, shape);
auto B = make_shared<op::Parameter>(element::boolean, shape);
auto f = make_shared<Function>(make_shared<op::And>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::boolean, shape);
copy_data(a, vector<char>{1, 0, 1, 1, 1, 0, 1, 0});
auto b = backend->create_tensor(element::boolean, shape);
copy_data(b, vector<char>{0, 0, 1, 0, 0, 1, 1, 0});
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<char>{0, 0, 1, 0, 0, 0, 1, 0}), read_vector<char>(result));
}
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, logical_or)
{
Shape shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::boolean, shape);
auto B = make_shared<op::Parameter>(element::boolean, shape);
auto f = make_shared<Function>(make_shared<op::Or>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::boolean, shape);
copy_data(a, vector<char>{1, 0, 1, 1, 1, 0, 1, 0});
auto b = backend->create_tensor(element::boolean, shape);
copy_data(b, vector<char>{0, 0, 1, 0, 0, 1, 1, 0});
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<char>{1, 0, 1, 1, 1, 1, 1, 0}), read_vector<char>(result));
}
//*****************************************************************************
// 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/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, lrn)
{
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
vector<float> args{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, args);
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
vector<float> expected{0.f,
0.3015113f,
0.4364357f,
0.5f,
0.8728715f,
0.8451542f,
0.5970223f,
0.6115928f,
0.5642765f,
0.5669467f,
0.7784989f,
0.7720487f};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
}
This diff is collapsed.
This diff is collapsed.
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, multiple_backends)
{
Shape shape{2, 2};
auto A1 = make_shared<op::Parameter>(element::f32, shape);
auto B1 = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A1 + B1, ParameterVector{A1, B1});
auto A2 = make_shared<op::Parameter>(element::f32, shape);
auto B2 = make_shared<op::Parameter>(element::f32, shape);
auto g = make_shared<Function>(A2 * B2, ParameterVector{A2, B2});
auto backend1 = runtime::Backend::create("${BACKEND_NAME}");
auto backend2 = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::Tensor> a1 = backend1->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> b1 = backend1->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> result1 = backend1->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> a2 = backend2->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> b2 = backend2->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> result2 = backend2->create_tensor(element::f32, shape);
copy_data(a1, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b1, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
copy_data(a2, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b2, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
auto handle1 = backend1->compile(f);
handle1->call_with_validate({result1}, {a1, b1});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result1),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector()));
auto handle2 = backend2->compile(g);
handle2->call_with_validate({result2}, {a2, b2});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result2),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector()));
}
//*****************************************************************************
// 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_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
// Multiple retrive values
NGRAPH_TEST(${BACKEND_NAME}, multiple_result)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = make_shared<op::Parameter>(element::f32, shape);
auto A_add_B = make_shared<op::Add>(A, B);
auto A_add_B_mul_C = make_shared<op::Multiply>(A_add_B, C);
auto f = make_shared<Function>(NodeVector{A_add_B, A_add_B_mul_C}, ParameterVector{A, B, C});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{1, 2, 3, 4});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{5, 6, 7, 8});
auto c = backend->create_tensor(element::f32, shape);
copy_data(c, vector<float>{9, 10, 11, 12});
auto r0 = backend->create_tensor(element::f32, shape);
auto r1 = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({r0, r1}, {a, b, c});
EXPECT_TRUE(test::all_close_f((vector<float>{6, 8, 10, 12}), read_vector<float>(r0)));
EXPECT_TRUE(test::all_close_f((vector<float>{54, 80, 110, 144}), read_vector<float>(r1)));
}
//*****************************************************************************
// 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_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, node_name)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = A + B;
C->set_friendly_name("a node name");
auto f = make_shared<Function>(C, ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
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, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector()));
}
//*****************************************************************************
// 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/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, numeric_float_nan)
{
Shape shape{5};
auto A = op::Constant::create(element::f32, shape, {-2.5f, 25.5f, 2.25f, NAN, 6.0f});
auto B = op::Constant::create(element::f32, shape, {10.0f, 5.0f, 2.25f, 10.0f, NAN});
auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, numeric_double_nan)
{
Shape shape{5};
auto A = op::Constant::create(element::f64, shape, {-2.5f, 25.5f, 2.25f, NAN, 6.0f});
auto B = op::Constant::create(element::f64, shape, {10.0f, 5.0f, 2.25f, 10.0f, NAN});
auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, numeric_float_inf)
{
Shape shape{5};
auto A = op::Constant::create(element::f32, shape, {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f});
auto B = op::Constant::create(element::f32, shape, {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY});
auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, numeric_double_inf)
{
Shape shape{5};
auto A = op::Constant::create(element::f64, shape, {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f});
auto B = op::Constant::create(element::f64, shape, {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY});
auto f = make_shared<Function>(make_shared<op::Equal>(A, B), ParameterVector{});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto result = backend->create_tensor(element::boolean, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {});
EXPECT_EQ((vector<char>{false, false, true, false, false}), read_vector<char>(result));
}
This diff is collapsed.
//*****************************************************************************
// 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_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, parameter_as_output)
{
Shape shape{3, 4};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::Tensor> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape);
vector<float> expected{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
vector<float> zero(shape_size(shape), 0);
copy_data(a, expected);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
This diff is collapsed.
This diff is collapsed.
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, quantized_convolution)
{
Shape shape_a{1, 1, 3, 4};
Shape shape_b{1, 1, 3, 3};
Shape shape_r{1, 1, 3, 4};
vector<uint8_t> a_data = {1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4};
vector<int8_t> b_data = {1, 2, 3, 4, 5, 0, 0, 1, 2};
auto A = make_shared<op::Parameter>(element::u8, shape_a);
auto B = make_shared<op::Parameter>(element::i8, shape_b);
auto C = make_shared<op::Parameter>(element::f32, Shape{});
auto D = make_shared<op::Parameter>(element::f32, Shape{});
auto E = make_shared<op::Parameter>(element::f32, Shape{});
auto F = make_shared<op::Parameter>(element::f32, Shape{});
auto G = make_shared<op::Parameter>(element::f32, Shape{});
auto H = make_shared<op::Parameter>(element::f32, Shape{});
auto CV = ngraph::builder::QuantizedConvolutionBuilder(A,
B,
Strides{1, 1},
Strides{1, 1},
CoordinateDiff{1, 1},
CoordinateDiff{1, 1},
Strides{1, 1},
C,
D,
E,
F,
G,
H,
element::i8);
auto f = make_shared<Function>(NodeVector{CV}, ParameterVector{A, B, C, D, E, F, G, H});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::u8, shape_a);
copy_data(a, a_data);
auto b = backend->create_tensor(element::i8, shape_b);
copy_data(b, b_data);
auto d = backend->create_tensor(element::f32, Shape{});
copy_data(d, vector<float>{0.0f});
auto e = backend->create_tensor(element::f32, Shape{});
copy_data(e, vector<float>{255.0f});
auto e_a = backend->create_tensor(element::f32, Shape{});
copy_data(e_a, vector<float>{-127.0f});
auto g = backend->create_tensor(element::f32, Shape{});
copy_data(g, vector<float>{127.0f});
auto h = backend->create_tensor(element::f32, Shape{});
copy_data(h, vector<float>{22.0f});
auto i = backend->create_tensor(element::f32, Shape{});
copy_data(i, vector<float>{90.0f});
auto result = backend->create_tensor(element::i8, shape_r);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, d, e, e_a, g, h, i});
EXPECT_EQ((vector<int8_t>{31, 48, 42, 45, 54, 102, 127, 61, 47, 73, 61, 55}),
read_vector<int8_t>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, quantized_conv_int32_output)
{
Shape shape_a{1, 1, 3, 4};
Shape shape_b{1, 1, 3, 3};
Shape shape_r{1, 1, 3, 4};
vector<uint8_t> a_data = {1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4};
vector<uint8_t> b_data = {1, 2, 3, 4, 5, 0, 0, 1, 2};
auto A = make_shared<op::Parameter>(element::u8, shape_a);
auto B = make_shared<op::Parameter>(element::u8, shape_b);
auto C = make_shared<op::Parameter>(element::f32, Shape{});
auto D = op::Constant::create(element::u8, Shape{}, {0});
auto E = make_shared<op::Parameter>(element::f32, Shape{});
auto F = op::Constant::create(element::u8, Shape{}, {0});
auto G = make_shared<op::Parameter>(element::f32, Shape{});
auto H = op::Constant::create(element::i32, Shape{}, {0});
auto CV = make_shared<op::QuantizedConvolution>(A,
B,
Strides{1, 1},
Strides{1, 1},
CoordinateDiff{1, 1},
CoordinateDiff{1, 1},
Strides{1, 1},
C,
D,
E,
F,
G,
H,
element::i32);
auto f = make_shared<Function>(NodeVector{CV}, ParameterVector{A, B, C, E, G});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::u8, shape_a);
copy_data(a, a_data);
auto b = backend->create_tensor(element::u8, shape_b);
copy_data(b, b_data);
auto c = backend->create_tensor(element::f32, Shape{});
copy_data(c, vector<float>{1.0f});
auto d = backend->create_tensor(element::f32, Shape{});
copy_data(d, vector<float>{1.0f});
auto e = backend->create_tensor(element::f32, Shape{});
copy_data(e, vector<float>{1.0f});
auto result = backend->create_tensor(element::i32, shape_r);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c, d, e});
EXPECT_EQ((vector<int32_t>{22, 34, 30, 32, 38, 72, 90, 43, 33, 52, 43, 39}),
read_vector<int32_t>(result));
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
//*****************************************************************************
// 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/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, select)
{
Shape shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::boolean, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Select>(A, B, C), ParameterVector{A, B, C});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::boolean, shape);
copy_data(a, vector<char>{0, 1, 1, 0, 0, 1, 0, 1});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{1, 2, 3, 4, 5, 6, 7, 8});
auto c = backend->create_tensor(element::f32, shape);
copy_data(c, vector<float>{11, 12, 13, 14, 15, 16, 17, 18});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c});
EXPECT_TRUE(test::all_close_f((vector<float>{11, 2, 3, 14, 15, 6, 17, 8}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, select_double)
{
Shape shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::boolean, shape);
auto B = make_shared<op::Parameter>(element::f64, shape);
auto C = make_shared<op::Parameter>(element::f64, shape);
auto f = make_shared<Function>(make_shared<op::Select>(A, B, C), ParameterVector{A, B, C});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
auto a = backend->create_tensor(element::boolean, shape);
copy_data(a, vector<char>{0, 1, 1, 0, 0, 1, 0, 1});
auto b = backend->create_tensor(element::f64, shape);
copy_data(b, vector<double>{1, 2, 3, 4, 5, 6, 7, 8});
auto c = backend->create_tensor(element::f64, shape);
copy_data(c, vector<double>{11, 12, 13, 14, 15, 16, 17, 18});
auto result = backend->create_tensor(element::f64, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c});
EXPECT_TRUE(test::all_close_f((vector<double>{11, 2, 3, 14, 15, 6, 17, 8}),
read_vector<double>(result)));
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
//*****************************************************************************
// 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/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, tensorview_custom_mem)
{
auto backend = runtime::Backend::create("${BACKEND_NAME}");
Shape shape{2, 2};
auto make_external = [&]() {
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::Divide>(A, B), ParameterVector{A, B});
return f;
};
auto f = make_external();
vector<float> av{2, 4, 8, 16};
vector<float> bv{1, 2, 4, 8};
// use custom mem with tensorview, no need to copy data
auto a = backend->create_tensor(element::f32, shape, av.data());
auto b = backend->create_tensor(element::f32, shape, bv.data());
// use custom mem with result tensorview
vector<float> rv{0, 0, 0, 0};
auto result = backend->create_tensor(element::f32, shape, rv.data());
// result should be in memory without needing explict read
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f((vector<float>{2, 2, 2, 2}), rv, MIN_FLOAT_TOLERANCE_BITS));
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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