Skip to content

Commit 6f22951

Browse files
committed
Add simd check and set SSE3 as default compilation
1 parent eda350b commit 6f22951

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include(simd)
2929

3030
################################ Configurations #######################################
3131
option(WITH_GPU "Compile PaddlePaddle with NVIDIA GPU" ${CUDA_FOUND})
32-
option(WITH_AVX "Compile PaddlePaddle with AVX intrinsics" ${AVX_FOUND})
32+
option(WITH_AVX "Compile PaddlePaddle with AVX intrinsics" OFF)
3333
option(WITH_DSO "Compile PaddlePaddle with dynamic linked CUDA" ON)
3434
option(WITH_TESTING "Compile PaddlePaddle with unit testing" ON)
3535
option(WITH_SWIG_PY "Compile PaddlePaddle with inference api" ON)

paddle/utils/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License. */
1414

1515
#pragma once
1616

17+
#include "Error.h"
1718
#include "Excepts.h"
1819

1920
/**

paddle/utils/CpuId.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,37 @@ class SIMDFlags final {
9797
#define HAS_AVX512 HAS_SIMD(SIMD_AVX512)
9898
// clang-format on
9999

100+
/**
101+
* Invoke checkCPUFeature() before Paddle initialization to
102+
* check target machine whether support compiled instructions.
103+
* If not, simply throw out an error.
104+
*/
105+
inline Error __must_check checkCPUFeature() {
106+
Error err;
107+
#ifndef __AVX__
108+
if (HAS_AVX) {
109+
LOG(WARNING) << "PaddlePaddle wasn't compiled to use avx instructions, "
110+
<< "but these are available on your machine and could "
111+
<< "speed up CPU computations via CMAKE .. -DWITH_AVX=ON";
112+
}
113+
#else
114+
if (!HAS_AVX) {
115+
err = Errors(
116+
"PaddlePaddle was compiled to use avx instructions, "
117+
"but these aren't available on your machine, please "
118+
"disable it via CMAKE .. -DWITH_AVX=OFF");
119+
}
120+
#endif // __AVX__
121+
#ifdef __SSE3__
122+
if (!HAS_SSE3) {
123+
err = Error(
124+
"PaddlePaddle was compiled to use sse3 instructions, "
125+
"which is the minimum requirement of PaddlePaddle. "
126+
"But these aren't available on your current machine.");
127+
}
128+
#endif // __SSE3__
129+
130+
return err;
131+
}
132+
100133
} // 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)