1 #include "caffe2/core/common.h" 2 #include "caffe2/core/flags.h" 3 #include "caffe2/core/init.h" 4 #include "caffe2/core/logging.h" 5 #include "caffe2/utils/cpuid.h" 8 caffe2_quit_on_unsupported_cpu_feature,
10 "If set, when Caffe2 is built with a CPU feature (like avx2) but the " 11 "current CPU does not support it, quit early. If not set (by default), " 12 "log this as an error message and continue execution.");
16 static void QuitIfFeatureUnsupported(
17 const bool cpu_has_feature,
const string& feature) {
18 VLOG(1) <<
"Caffe2 built with " << feature <<
".";
19 if (!cpu_has_feature) {
21 "The Caffe2 binary is compiled with CPU feature " + feature +
22 ", but your CPU does not support it. This will lead to segfaults " 23 "on your machine, such as SIGILL 'illegal instructions' on Linux. " 24 "As a result Caffe2 will preemptively quit. Please install or " 25 "build a Caffe2 binary with the feature turned off.";
26 if (FLAGS_caffe2_quit_on_unsupported_cpu_feature) {
27 LOG(FATAL) << err_string;
29 LOG(ERROR) << err_string;
34 static void WarnIfFeatureUnused(
35 const bool cpu_has_feature,
const string& feature) {
36 VLOG(1) <<
"Caffe2 not built with " << feature <<
".";
37 if (cpu_has_feature) {
38 #ifdef CAFFE2_NO_CROSS_ARCH_WARNING 45 <<
"CPU feature " << feature
46 <<
" is present on your machine, " 47 "but the Caffe2 binary is not compiled with it. It means you " 48 "may not get the full speed of your CPU.";
52 bool Caffe2CheckIntrinsicsFeatures(
int*,
char***) {
55 QuitIfFeatureUnsupported(GetCpuId().avx(),
"avx");
57 WarnIfFeatureUnused(GetCpuId().avx(),
"avx");
61 QuitIfFeatureUnsupported(GetCpuId().avx2(),
"avx2");
63 WarnIfFeatureUnused(GetCpuId().avx2(),
"avx2");
67 QuitIfFeatureUnsupported(GetCpuId().fma(),
"fma");
69 WarnIfFeatureUnused(GetCpuId().fma(),
"fma");
75 REGISTER_CAFFE2_INIT_FUNCTION(
76 Caffe2CheckIntrinsicsFeatures,
77 &Caffe2CheckIntrinsicsFeatures,
78 "Check intrinsics compatibility between the CPU feature and the binary.");
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...