Ngraph unit tests refactoring: part 2 (#1518)

This commit is contained in:
Gabriele Galiero Casay
2020-08-04 11:56:46 +02:00
committed by GitHub
parent 80b6bf28c2
commit 19f798b084
9 changed files with 250 additions and 382 deletions

View File

@@ -32,19 +32,16 @@
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, log)
{
@@ -52,22 +49,18 @@ NGRAPH_TEST(${BACKEND_NAME}, log)
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Log>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.125f, 0.25f, 0.5f, 1.f, 2.f, 4.f, 8.f, 16.f};
std::vector<float> loga{-2.07944154f,
-1.38629436f,
-0.69314718f,
0.00000000f,
0.69314718f,
1.38629436f,
2.07944154f,
2.77258872f};
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{0.125f, 0.25f, 0.5f, 1.f, 2.f, 4.f, 8.f, 16.f});
vector<float> loga{-2.07944154f,
-1.38629436f,
-0.69314718f,
0.00000000f,
0.69314718f,
1.38629436f,
2.07944154f,
2.77258872f};
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(loga, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape, loga);
test_case.run();
}

View File

@@ -16,19 +16,15 @@
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "runtime/backend.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, logical_or)
{
@@ -37,16 +33,11 @@ NGRAPH_TEST(${BACKEND_NAME}, logical_or)
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}");
std::vector<char> a{1, 0, 1, 1, 1, 0, 1, 0};
std::vector<char> b{0, 0, 1, 0, 0, 1, 1, 0};
// 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));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_multiple_inputs<char>({a, b});
test_case.add_expected_output<char>(shape, {1, 0, 1, 1, 1, 1, 1, 0});
test_case.run();
}

View File

@@ -16,19 +16,15 @@
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "runtime/backend.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/known_element_types.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, logical_xor)
{
@@ -37,16 +33,11 @@ NGRAPH_TEST(${BACKEND_NAME}, logical_xor)
auto B = make_shared<op::Parameter>(element::boolean, shape);
auto f = make_shared<Function>(make_shared<op::Xor>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<char> a{1, 0, 1, 1, 1, 0, 1, 0};
std::vector<char> b{0, 0, 1, 0, 0, 1, 1, 0};
// 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, 0, 1, 1, 1, 0, 0}), read_vector<char>(result));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_multiple_inputs<char>({a, b});
test_case.add_expected_output<char>(shape, {1, 0, 0, 1, 1, 1, 0, 0});
test_case.run();
}

View File

@@ -27,19 +27,16 @@
#include <numeric>
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_channel)
{
@@ -53,29 +50,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_across_channel)
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}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.f,
0.3015113f,
0.4364357f,
0.5f,
0.8728715f,
0.8451542f,
0.5970223f,
0.6115928f,
0.5642765f,
0.5669467f,
0.7784989f,
0.7720487f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_h)
@@ -90,29 +82,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_across_h)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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.0f,
0.7071068f,
0.5345225f,
0.8017837f,
0.6172134f,
0.7715167f,
0.6469966f,
0.7548294f,
0.6620847f,
0.7448453f,
0.671156f,
0.7382717f};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0f,
0.7071068f,
0.5345225f,
0.8017837f,
0.6172134f,
0.7715167f,
0.6469966f,
0.7548294f,
0.6620847f,
0.7448453f,
0.671156f,
0.7382717f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_hw)
@@ -127,29 +114,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_across_hw)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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.0f,
0.7071068f,
0.5345225f,
0.8017837f,
0.6172134f,
0.7715167f,
0.6469966f,
0.7548294f,
0.6620847f,
0.7448453f,
0.671156f,
0.7382717f};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0f,
0.7071068f,
0.5345225f,
0.8017837f,
0.6172134f,
0.7715167f,
0.6469966f,
0.7548294f,
0.6620847f,
0.7448453f,
0.671156f,
0.7382717f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_all_dims)
@@ -164,30 +146,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_across_all_dims)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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.0f,
0.0638877f,
0.0888231f,
0.1332347f,
0.1949481f,
0.2436851f,
0.3833259f,
0.4472136f,
0.3552925f,
0.399704f,
0.4873702f,
0.5361072f};
EXPECT_TRUE(
test::all_close_f(expected, read_vector<float>(result), DEFAULT_FLOAT_TOLERANCE_BITS + 1));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0f,
0.0638877f,
0.0888231f,
0.1332347f,
0.1949481f,
0.2436851f,
0.3833259f,
0.4472136f,
0.3552925f,
0.399704f,
0.4873702f,
0.5361072f});
test_case.run(DEFAULT_FLOAT_TOLERANCE_BITS + 1);
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_nw)
@@ -202,29 +178,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_across_nw)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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.0f,
0.140028f,
0.2407717f,
0.3144855f,
0.3698001f,
0.4123931f,
0.9863939f,
0.9801961f,
0.9630868f,
0.9434564f,
0.9245003f,
0.9072647f};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0f,
0.140028f,
0.2407717f,
0.3144855f,
0.3698001f,
0.4123931f,
0.9863939f,
0.9801961f,
0.9630868f,
0.9434564f,
0.9245003f,
0.9072647f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_empty)
@@ -239,31 +210,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_across_empty)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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.0f,
0.7071068f,
0.8944272f,
0.9486833f,
0.9701425f,
0.9805807f,
0.9863939f,
0.9899495f,
0.9922779f,
0.9938837f,
0.9950372f,
0.9958932f,
};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0f,
0.7071068f,
0.8944272f,
0.9486833f,
0.9701425f,
0.9805807f,
0.9863939f,
0.9899495f,
0.9922779f,
0.9938837f,
0.9950372f,
0.9958932f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_6D_across_2_axes)
@@ -278,22 +242,17 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_6D_across_2_axes)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a(24);
std::iota(std::begin(a), std::end(a), 0);
vector<float> args(24);
std::iota(std::begin(args), std::end(args), 0);
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.0f, 0.2581989f, 0.5163978f, 0.7745967f, 0.3549426f, 0.4436783f,
0.5324139f, 0.6211495f, 0.4175966f, 0.4697962f, 0.5219957f, 0.5741953f,
0.4426267f, 0.4795122f, 0.5163978f, 0.5532833f, 0.4560274f, 0.4845291f,
0.5130308f, 0.5415326f, 0.4643635f, 0.4875816f, 0.5107998f, 0.534018f};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(
shape, {0.0f, 0.2581989f, 0.5163978f, 0.7745967f, 0.3549426f, 0.4436783f,
0.5324139f, 0.6211495f, 0.4175966f, 0.4697962f, 0.5219957f, 0.5741953f,
0.4426267f, 0.4795122f, 0.5163978f, 0.5532833f, 0.4560274f, 0.4845291f,
0.5130308f, 0.5415326f, 0.4643635f, 0.4875816f, 0.5107998f, 0.534018f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_2d_across_empty)
@@ -308,31 +267,24 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_2d_across_empty)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
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.0f,
0.7071068f,
0.8944272f,
0.9486833f,
0.9701425f,
0.9805807f,
0.9863939f,
0.9899495f,
0.9922779f,
0.9938837f,
0.9950372f,
0.9958932f,
};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0f,
0.7071068f,
0.8944272f,
0.9486833f,
0.9701425f,
0.9805807f,
0.9863939f,
0.9899495f,
0.9922779f,
0.9938837f,
0.9950372f,
0.9958932f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_2d_across_outermost_axis)
@@ -347,38 +299,33 @@ NGRAPH_TEST(${BACKEND_NAME}, lrn_2d_across_outermost_axis)
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{0.64915806f,
0.21213771f,
-1.48256505f,
-1.41040838f,
0.58189541f,
0.11432108f,
-0.22993855f,
-0.13325502f,
-0.03083259f,
-0.48450908f,
0.50342429f,
-0.99551708f};
vector<float> args{0.64915806f,
0.21213771f,
-1.48256505f,
-1.41040838f,
0.58189541f,
0.11432108f,
-0.22993855f,
-0.13325502f,
-0.03083259f,
-0.48450908f,
0.50342429f,
-0.99551708f};
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.45900404f,
0.14999892f,
-1.04828012f,
-0.99727529f,
0.41144446f,
0.08083449f,
-0.16259004f,
-0.09422511f,
-0.02180192f,
-0.34259823f,
0.35597473f,
-0.70393407f};
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result), 23));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.45900404f,
0.14999892f,
-1.04828012f,
-0.99727529f,
0.41144446f,
0.08083449f,
-0.16259004f,
-0.09422511f,
-0.02180192f,
-0.34259823f,
0.35597473f,
-0.70393407f});
test_case.run(23);
}

View File

@@ -32,19 +32,16 @@
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, multiply)
{
@@ -53,20 +50,13 @@ NGRAPH_TEST(${BACKEND_NAME}, multiply)
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Multiply>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{1, 2, 3, 4};
std::vector<float> b{5, 6, 7, 8};
// 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>({{5, 12}, {21, 32}})).get_vector()));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_multiple_inputs<float>({a, b});
test_case.add_expected_output<float>(shape, {5, 12, 21, 32});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, multiply_overload)
@@ -76,18 +66,11 @@ NGRAPH_TEST(${BACKEND_NAME}, multiply_overload)
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A * B, ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{1, 2, 3, 4};
std::vector<float> b{5, 6, 7, 8};
// 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>({{5, 12}, {21, 32}})).get_vector()));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_multiple_inputs<float>({a, b});
test_case.add_expected_output<float>(shape, {5, 12, 21, 32});
test_case.run();
}

View File

@@ -32,19 +32,16 @@
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, negative)
{
@@ -52,18 +49,12 @@ NGRAPH_TEST(${BACKEND_NAME}, negative)
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Negative>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{1, -2, 0, -4.75f, 8.75f, -8.75f};
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{1, -2, 0, -4.75f, 8.75f, -8.75f});
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, 0, 4.75f, -8.75f, 8.75f}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(a);
test_case.add_expected_output<float>(shape, {-1, 2, 0, 4.75f, -8.75f, 8.75f});
test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, negative_i32)
@@ -74,16 +65,12 @@ NGRAPH_TEST(${BACKEND_NAME}, negative_i32)
auto shape_rt = Shape{2, 5};
auto f = make_shared<Function>(relu, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<int32_t> a{1, 8, -8, 17, -2, 1, 8, -8, 17, -1};
auto a = backend->create_tensor(element::i32, shape_a);
copy_data(a, vector<int32_t>{1, 8, -8, 17, -2, 1, 8, -8, 17, -1});
auto result = backend->create_tensor(element::i32, shape_rt);
vector<int32_t> expected{-1, -8, 8, -17, 2, -1, -8, 8, -17, 1};
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ(expected, read_vector<int32_t>(result));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int32_t>(shape_a, a);
test_case.add_expected_output<int32_t>(shape_rt, {-1, -8, 8, -17, 2, -1, -8, 8, -17, 1});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, negative_f32)
@@ -94,16 +81,11 @@ NGRAPH_TEST(${BACKEND_NAME}, negative_f32)
auto shape_rt = Shape{2, 5};
auto f = make_shared<Function>(relu, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{1.35f, 8.76f, -8.0f, 17.234f, -2.121f, 1.0f, 8.7f, -8.92f, 17.0f, -1.0f};
auto a = backend->create_tensor(element::f32, shape_a);
copy_data(
a, vector<float>{1.35f, 8.76f, -8.0f, 17.234f, -2.121f, 1.0f, 8.7f, -8.92f, 17.0f, -1.0f});
auto result = backend->create_tensor(element::f32, shape_rt);
vector<float> expected{
-1.35f, -8.76f, 8.0f, -17.234f, 2.121f, -1.0f, -8.7f, 8.92f, -17.0f, 1.0f};
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ(expected, read_vector<float>(result));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape_a, a);
test_case.add_expected_output<float>(
shape_rt, {-1.35f, -8.76f, 8.0f, -17.234f, 2.121f, -1.0f, -8.7f, 8.92f, -17.0f, 1.0f});
test_case.run();
}

View File

@@ -32,19 +32,16 @@
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, not)
{
@@ -52,16 +49,12 @@ NGRAPH_TEST(${BACKEND_NAME}, not)
auto A = make_shared<op::Parameter>(element::boolean, shape);
auto f = make_shared<Function>(make_shared<op::Not>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<char> a{1, 0, 1, 0};
// Create some tensors for input/output
auto a = backend->create_tensor(element::boolean, shape);
copy_data(a, vector<char>{1, 0, 1, 0});
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, 0, 1}), read_vector<char>(result));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<char>(shape, a);
test_case.add_expected_output<char>(shape, {0, 1, 0, 1});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, not_i32)
@@ -70,14 +63,9 @@ NGRAPH_TEST(${BACKEND_NAME}, not_i32)
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Not>(A), ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<int32_t> a{1, 0, 2, 0};
// Create some tensors for input/output
auto a = backend->create_tensor(element::i32, shape);
copy_data(a, vector<int32_t>{1, 0, 2, 0});
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<int32_t>{0, 1, 0, 1}), read_vector<int32_t>(result));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int32_t>(shape, a);
test_case.add_expected_output<int32_t>(shape, {0, 1, 0, 1});
}

View File

@@ -32,19 +32,16 @@
// clang-format on
#include "gtest/gtest.h"
#include "runtime/backend.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
#include "util/test_tools.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, power)
{
@@ -53,16 +50,11 @@ NGRAPH_TEST(${BACKEND_NAME}, power)
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Power>(A, B), ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
std::vector<float> a{1, 2, 3, 5};
std::vector<float> b{2, 0, 6, 3};
// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{1, 2, 3, 5});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{2, 0, 6, 3});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close_f(vector<float>{1, 1, 729, 125}, read_vector<float>(result)));
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_multiple_inputs<float>({a, b});
test_case.add_expected_output<float>(shape, {1, 1, 729, 125});
test_case.run();
}

View File

@@ -231,5 +231,6 @@ namespace InferenceEngine
template class TBlob<bool>;
template class TBlob<ngraph::bfloat16>;
template class TBlob<ngraph::float16>;
template class TBlob<char>;
#endif
}