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
/**
* \file dnn/src/x86/utils.h
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#include <cstddef>
#include <vector>
#include "src/common/utils.h"
#if MEGDNN_X86_WITH_MKL
#include <mkl.h>
//! As INTEL_MKL_VERSION >= 20190001 support SUPPORT_MKL_PACKED_GEMM
#if INTEL_MKL_VERSION >= 20190001
#define SUPPORT_MKL_PACKED_GEMM 1
#else
#define SUPPORT_MKL_PACKED_GEMM 0
#endif
#endif
namespace megdnn {
namespace x86 {
enum class SIMDType {
SSE,
SSE2,
SSE3,
SSE4_1,
SSE4_2,
AVX,
AVX2,
FMA,
VNNI,
NONE,
__NR_SIMD_TYPE //! total number of SIMD types; used for testing
};
bool is_supported(SIMDType type);
//! disable a particular and more advanced SIMD types, for testing
void disable_simd_type(SIMDType type);
template <typename T>
T find_nearest_elem(T val, const std::vector<T>& vec) {
megdnn_assert_internal(!vec.empty());
T res = vec[0];
typedef typename std::make_signed<T>::type S;
S opt_cost = (val - res > 0 ? val - res : res - val);
for (auto&& cand : vec) {
S cur_cost = (val - cand > 0 ? val - cand : cand - val);
if (cur_cost < opt_cost) {
opt_cost = cur_cost;
res = cand;
}
}
return res;
}
// Treat the denormalized numbers as zero.
void disable_denorm();
} // namespace x86
} // namespace megdnn
// vim: syntax=cpp.doxygen