File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ limitations under the License. */
12
12
#pragma once
13
13
14
14
#include " Common.h"
15
+ #include " Error.h"
15
16
16
17
namespace paddle {
17
18
@@ -97,4 +98,37 @@ class SIMDFlags final {
97
98
#define HAS_AVX512 HAS_SIMD (SIMD_AVX512)
98
99
// clang-format on
99
100
101
+ /* *
102
+ * Invoke checkCPUFeature() before Paddle initialization to
103
+ * check target machine whether support compiled instructions.
104
+ * If not, simply throw out an error.
105
+ */
106
+ inline Error __must_check checkCPUFeature() {
107
+ Error err;
108
+ #ifndef __AVX__
109
+ if (HAS_AVX) {
110
+ LOG (WARNING) << " PaddlePaddle wasn't compiled to use avx instructions, "
111
+ << " but these are available on your machine and could "
112
+ << " speed up CPU computations via CMAKE .. -DWITH_AVX=ON" ;
113
+ }
114
+ #else
115
+ if (!HAS_AVX) {
116
+ err = Error (
117
+ " PaddlePaddle was compiled to use avx instructions, "
118
+ " but these aren't available on your machine, please "
119
+ " disable it via CMAKE .. -DWITH_AVX=OFF" );
120
+ }
121
+ #endif // __AVX__
122
+ #ifdef __SSE3__
123
+ if (!HAS_SSE3) {
124
+ err = Error (
125
+ " PaddlePaddle was compiled to use sse3 instructions, "
126
+ " which is the minimum requirement of PaddlePaddle. "
127
+ " But these aren't available on your current machine." );
128
+ }
129
+ #endif // __SSE3__
130
+
131
+ return err;
132
+ }
133
+
100
134
} // namespace paddle
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ limitations under the License. */
26
26
27
27
#include < gflags/gflags.h>
28
28
29
+ #include " CpuId.h"
29
30
#include " CustomStackTrace.h"
30
31
#include " Logging.h"
31
32
#include " StringUtil.h"
@@ -185,6 +186,7 @@ void initMain(int argc, char** argv) {
185
186
}
186
187
187
188
version::printVersion ();
189
+ checkCPUFeature ().check ();
188
190
runInitFunctions ();
189
191
}
190
192
You can’t perform that action at this time.
0 commit comments