2 // Copyright 2016-2018 Intel Corporation.
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
19 #include <gtest/gtest.h>
20 #include <mock_icnn_network.hpp>
21 #include "gna_plugin/gna_plugin_config.hpp"
22 #include "gna_matcher.hpp"
23 #include "test_irs.hpp"
25 using namespace InferenceEngine;
26 using namespace GNAPluginNS;
27 using namespace ::testing;
29 class GNAConfigTest : public GNATest {
34 void SetUp() override {
38 TEST_F(GNAConfigTest, reportAnErrorIfConfigNotFound) {
40 Config c ({{TargetDevice :: eGNA, Precision::I16},
41 {TargetDevice :: eCPU, Precision::FP32}});
43 EXPECT_CALL(net, getPrecision()).WillRepeatedly(Return(Precision::FP32));
44 EXPECT_CALL(net, getTargetDevice()).WillRepeatedly(Return(TargetDevice::eGNA));
46 ASSERT_ANY_THROW(c.find_configuration(net));
49 TEST_F(GNAConfigTest, canFindConfiguration) {
51 Config c ({{TargetDevice :: eGNA, Precision::I16},
52 {TargetDevice :: eCPU, Precision::FP32}});
54 EXPECT_CALL(net, getPrecision()).WillRepeatedly(Return(Precision::FP32));
55 EXPECT_CALL(net, getTargetDevice()).WillRepeatedly(Return(TargetDevice::eCPU));
57 auto match = c.find_configuration(net);
59 EXPECT_EQ(match.device, TargetDevice::eCPU);
60 EXPECT_EQ(match.networkPrec, Precision::FP32);
63 TEST_F(GNAConfigTest, canPassTroughNetworkAfterFindConfiguration) {
65 Config c ({{TargetDevice :: eGNA, Precision::I16},
66 {TargetDevice :: eCPU, Precision::FP32}});
68 EXPECT_CALL(net, getPrecision()).WillRepeatedly(Return(Precision::FP32));
69 EXPECT_CALL(net, getTargetDevice()).WillRepeatedly(Return(TargetDevice::eCPU));
71 auto match = c.find_configuration(net);
73 auto net2 = match.convert(net);
75 EXPECT_EQ(net2->getTargetDevice(), TargetDevice::eCPU);
76 EXPECT_EQ(net2->getPrecision(), Precision::FP32);
79 TEST_F(GNAConfigTest, canNotMatchWithDefaultDevice) {
81 Config c ({{TargetDevice :: eGNA, Precision::I16},
82 {TargetDevice :: eCPU, Precision::FP32}});
84 c.setDefaultDevice(TargetDevice::eGNA);
86 EXPECT_CALL(net, getPrecision()).WillRepeatedly(Return(Precision::FP32));
87 EXPECT_CALL(net, getTargetDevice()).WillRepeatedly(Return(TargetDevice::eDefault));
89 EXPECT_ANY_THROW(c.find_configuration(net).convert(net));
92 TEST_F(GNAConfigTest, canMatchWithDefaultDevice) {
94 Config c ({{TargetDevice :: eGNA, Precision::I16},
95 {TargetDevice :: eCPU, Precision::FP32}});
97 c.setDefaultDevice(TargetDevice::eGNA);
99 EXPECT_CALL(net, getPrecision()).WillRepeatedly(Return(Precision::I16));
100 EXPECT_CALL(net, getTargetDevice()).WillRepeatedly(Return(TargetDevice::eDefault));
102 auto net2 = c.find_configuration(net).convert(net);
104 EXPECT_EQ(net2->getTargetDevice(), TargetDevice::eDefault);
105 EXPECT_EQ(net2->getPrecision(), Precision::I16);
108 TEST_F(GNAConfigTest, canMatchWith1AsyncThread) {
110 .onInferModel(GNATestIRs::Fc2DOutputModel())
112 .withAcceleratorThreadsNumber("1")
113 .gna().propagate_forward().called_without().pwl_inserted_into_nnet();
116 TEST_F(GNAConfigTest, canMatchWith4AsyncThreads) {
118 .onInferModel(GNATestIRs::Fc2DOutputModel())
120 .withAcceleratorThreadsNumber("4")
121 .gna().propagate_forward().called_without().pwl_inserted_into_nnet();
124 TEST_F(GNAConfigTest, canNOTMatchWith0AsyncThreads) {
126 .onInferModel(GNATestIRs::Fc2DOutputModel())
128 .withAcceleratorThreadsNumber("0")
129 .gna().propagate_forward().called_without().pwl_inserted_into_nnet()
133 TEST_F(GNAConfigTest, canNOTMatchWith128AsyncThreads) {
135 .onInferModel(GNATestIRs::Fc2DOutputModel())
137 .withAcceleratorThreadsNumber("128")
138 .gna().propagate_forward().called_without().pwl_inserted_into_nnet()
142 TEST_F(GNAConfigTest, canMatchWithSingleMultipleOMPThreads) {
144 .onInferModel(GNATestIRs::Fc2DOutputModel())
146 .enable_omp_multithreading()
147 .gna().propagate_forward().called_without().pwl_inserted_into_nnet();
150 TEST_F(GNAConfigTest, failToCreatePluginWithDifferentInputScaleFactors) {
151 assert_that().creating().gna_plugin()
152 .withGNAConfig(std::string(GNA_CONFIG_KEY(SCALE_FACTOR))+"_1", 1000)
153 .withGNAConfig(std::string(GNA_CONFIG_KEY(SCALE_FACTOR))+"_2", 2000).throws();