forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DispatchStub.cpp
44 lines (37 loc) · 1.02 KB
/
DispatchStub.cpp
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
#include <ATen/native/DispatchStub.h>
#include <c10/util/Exception.h>
#include <cpuinfo.h>
#include <cstdlib>
#include <cstring>
namespace at { namespace native {
static CPUCapability compute_cpu_capability() {
auto envar = std::getenv("ATEN_CPU_CAPABILITY");
if (envar) {
if (strcmp(envar, "avx2") == 0) {
return CPUCapability::AVX2;
}
if (strcmp(envar, "avx") == 0) {
return CPUCapability::AVX;
}
if (strcmp(envar, "default") == 0) {
return CPUCapability::DEFAULT;
}
AT_WARN("ignoring invalid value for ATEN_CPU_CAPABILITY: ", envar);
}
#if !defined(__powerpc__) && !defined(__s390x__)
if (cpuinfo_initialize()) {
if (cpuinfo_has_x86_avx2() && cpuinfo_has_x86_fma3()) {
return CPUCapability::AVX2;
}
if (cpuinfo_has_x86_avx()) {
return CPUCapability::AVX;
}
}
#endif
return CPUCapability::DEFAULT;
}
CPUCapability get_cpu_capability() {
static CPUCapability capability = compute_cpu_capability();
return capability;
}
}} // namespace at::native