Skip to content

Commit 9ffc38e

Browse files
authored
Merge pull request #1666 from gangliao/sse_def
Add simd check and set SSE3 as default compilation
2 parents 24bdd9b + f6bf634 commit 9ffc38e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

paddle/utils/CpuId.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ limitations under the License. */
1212
#pragma once
1313

1414
#include "Common.h"
15+
#include "Error.h"
1516

1617
namespace paddle {
1718

@@ -97,4 +98,37 @@ class SIMDFlags final {
9798
#define HAS_AVX512 HAS_SIMD(SIMD_AVX512)
9899
// clang-format on
99100

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+
100134
} // namespace paddle

paddle/utils/Util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ limitations under the License. */
2626

2727
#include <gflags/gflags.h>
2828

29+
#include "CpuId.h"
2930
#include "CustomStackTrace.h"
3031
#include "Logging.h"
3132
#include "StringUtil.h"
@@ -185,6 +186,7 @@ void initMain(int argc, char** argv) {
185186
}
186187

187188
version::printVersion();
189+
checkCPUFeature().check();
188190
runInitFunctions();
189191
}
190192

0 commit comments

Comments
 (0)