blob: 8d60cff1bc7d1a6248071ea81be4b17cc0fb1876 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "3rd_party/catch.hpp"
#include "aligned.h"
#include "postprocess.h"
#include <numeric>
namespace intgemm {
INTGEMM_AVX2 TEST_CASE("PostprocessPipeline AVX2", "Unquantize-ReLU") {
if (kCPU < CPUType::AVX2)
return;
AlignedVector<int32_t> input(8);
AlignedVector<float> output(8);
std::iota(input.begin(), input.end(), -2);
auto pipeline = CreatePostprocessPipeline(Unquantize(0.5f), ReLU());
auto inited_pipeline = InitPostprocessPipeline<CPUType::AVX2>(pipeline);
*output.as<__m256>() = inited_pipeline.run(*input.as<__m256i>(), 0);
CHECK(output[0] == 0.0f); // input = -2
CHECK(output[1] == 0.0f); // input = -1
CHECK(output[2] == 0.0f); // input = 0
CHECK(output[3] == 0.5f); // input = 1
CHECK(output[4] == 1.0f); // input = 2
CHECK(output[5] == 1.5f); // input = 3
CHECK(output[6] == 2.0f); // input = 4
CHECK(output[7] == 2.5f); // input = 5
}
INTGEMM_AVX2 TEST_CASE("PostprocessPipeline AVX2 on whole buffer", "Unquantize-ReLU") {
if (kCPU < CPUType::AVX2)
return;
AlignedVector<int32_t> input(16);
AlignedVector<float> output(16);
std::iota(input.begin(), input.end(), -8);
auto pipeline = CreatePostprocessPipeline(Unquantize(0.5f), ReLU());
auto inited_pipeline = InitPostprocessPipeline<CPUType::AVX2>(pipeline);
inited_pipeline.run(input.as<__m256i>(), 2, output.as<__m256>());
CHECK(output[0] == 0.f); // input = -8
CHECK(output[1] == 0.f); // input = -7
CHECK(output[2] == 0.f); // input = -6
CHECK(output[3] == 0.f); // input = -5
CHECK(output[4] == 0.f); // input = -4
CHECK(output[5] == 0.f); // input = -3
CHECK(output[6] == 0.f); // input = -2
CHECK(output[7] == 0.f); // input = -1
CHECK(output[8] == 0.0f); // input = 0
CHECK(output[9] == 0.5f); // input = 1
CHECK(output[10] == 1.0f); // input = 2
CHECK(output[11] == 1.5f); // input = 3
CHECK(output[12] == 2.0f); // input = 4
CHECK(output[13] == 2.5f); // input = 5
CHECK(output[14] == 3.0f); // input = 6
CHECK(output[15] == 3.5f); // input = 7
}
}
|