gna_pwl_test.cpp 11.5 KB
Newer Older
1 2 3
// Copyright (C) 2018-2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

#include <vector>
#include <gtest/gtest.h>
#include "gna_matcher.hpp"

class PWLAproximationTest : public GNATest {
 protected:
    void SetUp() override  {
    }
};
using namespace GNATestIRs;

// Recursive Algorithm
// Precision Threshold

TEST_F(PWLAproximationTest, forTanhOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(TanhActivationModel())
	                            .inNotCompactMode()
22
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
23 24 25 26 27 28 29 30 31
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActTanh)
                                .pwl_quantization_precision_threshold(0.0053);
}

TEST_F(PWLAproximationTest, forSigmoidOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(SigmoidActivationModel())
                                .inNotCompactMode()
32
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
33 34 35 36 37 38 39 40 41
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActSigmoid)
                                .pwl_quantization_precision_threshold(0.0027);
}

TEST_F(PWLAproximationTest, forReLUonRecursiveAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(ReLUActivationModel())
                                .inNotCompactMode()
42
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
43 44 45 46 47 48 49 50 51
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActRelu)
                                .pwl_quantization_precision_threshold(0.0001);
}

TEST_F(PWLAproximationTest, forLeakyReLUonRecursiveAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(LeakyReLUActivationModel())
                                .inNotCompactMode()
52
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
53 54 55 56 57 58 59 60 61
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActLeakyRelu)
                                .pwl_quantization_precision_threshold(0.0003);
}

TEST_F(PWLAproximationTest, DISABLED_forIdentityOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(IdentityActivationModel())
                                .inNotCompactMode()
62
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
63 64 65 66 67 68 69 70 71
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActIdentity)
                                .pwl_quantization_precision_threshold(0.0003);
}

TEST_F(PWLAproximationTest, forClampOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(ClampActivationModel())
                                .inNotCompactMode()
72
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
73 74 75 76 77 78 79 80 81
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
                                .pwl_quantization_precision_threshold(0.0001);
}

TEST_F(PWLAproximationTest, forTanhOnUniformAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(TanhActivationModel())
                                .inNotCompactMode()
82
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
83 84 85 86 87 88 89 90 91 92
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActTanh)
                                .pwl_quantization_precision_threshold(0.0009);
}

TEST_F(PWLAproximationTest, forSigmoidOnUniformAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(SigmoidActivationModel())
                                .inNotCompactMode()
93
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
94 95 96 97 98 99 100 101 102 103
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActSigmoid)
                                .pwl_quantization_precision_threshold(0.0004);
}

TEST_F(PWLAproximationTest, DISABLED_forIdentityOnUniformAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(IdentityActivationModel())
                                .inNotCompactMode()
104
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
105 106 107 108 109 110 111 112 113 114
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActIdentity)
                                .pwl_quantization_precision_threshold(0.0003);
}

TEST_F(PWLAproximationTest, forClampOnUniformAlgoWithPrecisionThresholdIsSuccess) {
    assert_that().onInferModel(ClampActivationModel())
                                .inNotCompactMode()
115
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
116 117 118 119 120 121 122 123 124 125
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
                                .pwl_quantization_precision_threshold(0.0001);
}

TEST_F(PWLAproximationTest, forSigmoidonRecursiveAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(SigmoidActivationModel())
                                .inNotCompactMode()
126
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
127 128 129 130 131 132 133 134 135
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActSigmoid)
                                .pwl_quantization_segments_threshold(12);
}

TEST_F(PWLAproximationTest, forTanhonRecursiveAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(TanhActivationModel())
                                .inNotCompactMode()
136
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
137 138 139 140 141 142 143 144 145
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActTanh)
                                .pwl_quantization_segments_threshold(12);
}

TEST_F(PWLAproximationTest, forReLUonRecursiveAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(ReLUActivationModel())
                                .inNotCompactMode()
146
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
147 148 149 150 151 152 153 154 155
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActRelu)
                                .pwl_quantization_segments_threshold(2);
}

TEST_F(PWLAproximationTest, forLeakyReLUonRecursiveAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(LeakyReLUActivationModel())
                                .inNotCompactMode()
156
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
157 158 159 160 161 162 163 164 165
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActLeakyRelu)
                                .pwl_quantization_segments_threshold(2);
}

TEST_F(PWLAproximationTest, DISABLED_forIdentityOnRecursiveAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(IdentityActivationModel())
                                .inNotCompactMode()
166
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
167 168 169 170 171 172 173 174 175
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActIdentity)
                                .pwl_quantization_segments_threshold(3);
}

TEST_F(PWLAproximationTest, forClampOnRecursiveAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(ClampActivationModel())
                                .inNotCompactMode()
176
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
177 178 179 180 181 182 183 184 185
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
                                .pwl_quantization_segments_threshold(3);
}

TEST_F(PWLAproximationTest, forSigmoidonUniformAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(SigmoidActivationModel())
                                .inNotCompactMode()
186
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
187 188 189 190 191 192 193 194 195 196
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActSigmoid)
                                .pwl_quantization_segments_threshold(65);
}

TEST_F(PWLAproximationTest, forTanhonUniformAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(TanhActivationModel())
                                .inNotCompactMode()
197
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
198 199 200 201 202 203 204 205 206 207
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActTanh)
                                .pwl_quantization_segments_threshold(65);
}

TEST_F(PWLAproximationTest, DISABLED_forIdentityOnUniformAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(IdentityActivationModel())
                                .inNotCompactMode()
208
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
209 210 211 212 213 214 215 216 217 218
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActIdentity)
                                .pwl_quantization_segments_threshold(3);
}

TEST_F(PWLAproximationTest, forClampOnUniformAlgoWithSegmentThresholdIsSuccess) {
    assert_that().onInferModel(ClampActivationModel())
                                .inNotCompactMode()
219
                                .withGNAConfig(GNA_CONFIG_KEY(SCALE_FACTOR), 1.0f)
220 221 222 223 224 225
                                .withUniformPWLAlgo()
                                .propagate_forward()
                                .called_with()
                                .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
                                .pwl_quantization_segments_threshold(3);
}