From c577f2c6a3b4ddb6ba87a882723c53a248afbeba Mon Sep 17 00:00:00 2001 From: telsoa01 Date: Fri, 31 Aug 2018 09:22:23 +0100 Subject: Release 18.08 --- src/armnnOnnxParser/test/Addition.cpp | 311 ++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 src/armnnOnnxParser/test/Addition.cpp (limited to 'src/armnnOnnxParser/test/Addition.cpp') diff --git a/src/armnnOnnxParser/test/Addition.cpp b/src/armnnOnnxParser/test/Addition.cpp new file mode 100644 index 0000000000..25519447c6 --- /dev/null +++ b/src/armnnOnnxParser/test/Addition.cpp @@ -0,0 +1,311 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include +#include "armnnOnnxParser/IOnnxParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(OnnxParser) + +struct AddMainFixture : public armnnUtils::ParserPrototxtFixture +{ + AddMainFixture(const std::string& dataType) + { + m_Prototext = R"( + ir_version: 3 + producer_name: "CNTK" + producer_version: "2.5.1" + domain: "ai.cntk" + model_version: 1 + graph { + name: "CNTKGraph" + input { + name: "Input0" + type { + tensor_type { + elem_type: )" + dataType + R"( + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + input { + name: "Input1" + type { + tensor_type { + elem_type: )" + dataType + R"( + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + node { + input: "Input0" + input: "Input1" + output: "Output" + name: "addition" + op_type: "Add" + doc_string: "" + domain: "" + } + output { + name: "Output" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + } + opset_import { + version: 7 + })"; + } +}; + +struct AddValidFixture : AddMainFixture +{ + AddValidFixture() : AddMainFixture("FLOAT") { + Setup(); + } +}; + +struct AddInvalidFixture : AddMainFixture +{ + AddInvalidFixture() : AddMainFixture("INT32") { } +}; + +struct AddValidBroadcastFixture : public armnnUtils::ParserPrototxtFixture +{ + AddValidBroadcastFixture() { + + m_Prototext = R"( + ir_version: 3 + producer_name: "CNTK" + producer_version: "2.5.1" + domain: "ai.cntk" + model_version: 1 + graph { + name: "CNTKGraph" + input { + name: "Input0" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + } + } + } + } + input { + name: "Input1" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 4 + } + } + } + } + } + node { + input: "Input0" + input: "Input1" + output: "Output" + name: "addition" + op_type: "Add" + doc_string: "" + domain: "" + } + output { + name: "Output" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + } + } + } + } + } + opset_import { + version: 7 + })"; + Setup(); + } +}; + +struct AddInvalidBroadcastFixture : public armnnUtils::ParserPrototxtFixture +{ + AddInvalidBroadcastFixture() { + + m_Prototext = R"( + ir_version: 3 + producer_name: "CNTK" + producer_version: "2.5.1" + domain: "ai.cntk" + model_version: 1 + graph { + name: "CNTKGraph" + input { + name: "Input0" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 3 + } + } + } + } + } + input { + name: "Input1" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 4 + } + } + } + } + } + node { + input: "Input0" + input: "Input1" + output: "Output" + name: "addition" + op_type: "Add" + doc_string: "" + domain: "" + } + output { + name: "Output" + type { + tensor_type { + elem_type: FLOAT + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + } + } + } + } + } + opset_import { + version: 7 + })"; + } +}; + +BOOST_FIXTURE_TEST_CASE(ValidAddTest, AddValidFixture) +{ + RunTest<4>({{"Input0", {1.0f, 2.0f, -3.0f, -4.0f}}, + {"Input1", {1.0f, 2.0f, 3.0, 4.0f}}}, {{"Output", {2.0, 4.0, 0, 0.0}}}); +} + +BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeAdd, AddInvalidFixture) +{ + BOOST_CHECK_THROW(Setup(), armnn::ParseException); +} + +BOOST_FIXTURE_TEST_CASE(InvalidBroadcastAdd, AddInvalidBroadcastFixture) +{ + BOOST_CHECK_THROW(Setup(), armnn::ParseException); +} + +BOOST_FIXTURE_TEST_CASE(ValidBroadcastAdd, AddValidBroadcastFixture) +{ + RunTest<4>({{"Input0", {1.0f, 2.0f, -3.0f, -4.0f}}, + {"Input1", {1.0f, 2.0f, 3.0, 4.0f}}}, {{"Output", {2.0, 4.0, 0, 0.0}}}); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1