Welcome to mirror list, hosted at ThFree Co, Russian Federation.

downcast_test.cc « kernels « test - github.com/marian-nmt/intgemm/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f2ccd0edc3b31380d2ab5342bda507a175f8f24 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "../test.h"
#include "../../intgemm/aligned.h"
#include "../../intgemm/kernels.h"

#include <cstddef>
#include <numeric>

namespace intgemm {

template <CPUType CPUType_>
void kernel_downcast32to8_test() {
  if (kCPU < CPUType_)
    return;

  using vi = vector_t<CPUType_, int>;
  constexpr int LENGTH = sizeof(vi) / sizeof(int8_t);

  AlignedVector<int32_t> input(LENGTH);
  AlignedVector<int8_t> output(LENGTH);

  std::iota(input.begin(), input.end(), static_cast<int32_t>(-LENGTH / 2));

  *output.template as<vi>() = kernels::downcast32to8(
    input.template as<vi>()[0], input.template as<vi>()[1],
    input.template as<vi>()[2], input.template as<vi>()[3]);
  for (std::size_t i = 0; i < output.size(); ++i)
    CHECK(output[i] == int8_t(input[i]));
}

template INTGEMM_SSE2 void kernel_downcast32to8_test<CPUType::SSE2>();
KERNEL_TEST_CASE("downcast32to8 SSE2") { return kernel_downcast32to8_test<CPUType::SSE2>(); }

#ifdef INTGEMM_COMPILER_SUPPORTS_AVX2
template INTGEMM_AVX2 void kernel_downcast32to8_test<CPUType::AVX2>();
KERNEL_TEST_CASE("downcast32to8 AVX2") { return kernel_downcast32to8_test<CPUType::AVX2>(); }
#endif

#ifdef INTGEMM_COMPILER_SUPPORTS_AVX512BW
template INTGEMM_AVX512BW void kernel_downcast32to8_test<CPUType::AVX512BW>();
KERNEL_TEST_CASE("downcast32to8 AVX512BW") { return kernel_downcast32to8_test<CPUType::AVX512BW>(); }
#endif

template <CPUType CPUType_>
void kernel_downcast32to16_test() {
  if (kCPU < CPUType_)
    return;

  using vi = vector_t<CPUType_, int>;
  constexpr int LENGTH = sizeof(vi) / sizeof(int16_t);

  AlignedVector<int32_t> input(LENGTH);
  AlignedVector<int16_t> output(LENGTH);

  std::iota(input.begin(), input.end(), static_cast<int32_t>(-LENGTH / 2));

  *output.template as<vi>() = kernels::downcast32to16(
    input.template as<vi>()[0], input.template as<vi>()[1]);
  for (std::size_t i = 0; i < output.size(); ++i)
    CHECK(output[i] == int16_t(input[i]));
}

template INTGEMM_SSE2 void kernel_downcast32to16_test<CPUType::SSE2>();
KERNEL_TEST_CASE("downcast32to16 SSE2") { return kernel_downcast32to16_test<CPUType::SSE2>(); }

#ifdef INTGEMM_COMPILER_SUPPORTS_AVX2
template INTGEMM_AVX2 void kernel_downcast32to16_test<CPUType::AVX2>();
KERNEL_TEST_CASE("downcast32to16 AVX2") { return kernel_downcast32to16_test<CPUType::AVX2>(); }
#endif

#ifdef INTGEMM_COMPILER_SUPPORTS_AVX512BW
template INTGEMM_AVX512BW void kernel_downcast32to16_test<CPUType::AVX512BW>();
KERNEL_TEST_CASE("downcast32to16 AVX512BW") { return kernel_downcast32to16_test<CPUType::AVX512BW>(); }
#endif

template <CPUType CPUType_>
void kernel_downcast16to8_test() {
  if (kCPU < CPUType_)
    return;

  using vi = vector_t<CPUType_, int>;
  constexpr int LENGTH = sizeof(vi) / sizeof(int8_t);

  AlignedVector<int16_t> input(LENGTH);
  AlignedVector<int8_t> output(LENGTH);

  std::iota(input.begin(), input.end(), static_cast<int16_t>(-LENGTH / 2));

  *output.template as<vi>() = kernels::downcast16to8(
    input.template as<vi>()[0], input.template as<vi>()[1]);
  for (std::size_t i = 0; i < output.size(); ++i)
    CHECK(output[i] == int8_t(input[i]));
}

template INTGEMM_SSE2 void kernel_downcast16to8_test<CPUType::SSE2>();
KERNEL_TEST_CASE("downcast16to8 SSE2") { return kernel_downcast16to8_test<CPUType::SSE2>(); }

#ifdef INTGEMM_COMPILER_SUPPORTS_AVX2
template INTGEMM_AVX2 void kernel_downcast16to8_test<CPUType::AVX2>();
KERNEL_TEST_CASE("downcast16to8 AVX2") { return kernel_downcast16to8_test<CPUType::AVX2>(); }
#endif

#ifdef INTGEMM_COMPILER_SUPPORTS_AVX512BW
template INTGEMM_AVX512BW void kernel_downcast16to8_test<CPUType::AVX512BW>();
KERNEL_TEST_CASE("downcast16to8 AVX512BW") { return kernel_downcast16to8_test<CPUType::AVX512BW>(); }
#endif

}