Skip to content

Commit

Permalink
Add simd check and set SSE3 as default compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gangliao committed Mar 21, 2017
1 parent eda350b commit 6f22951
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include(simd)

################################ Configurations #######################################
option(WITH_GPU "Compile PaddlePaddle with NVIDIA GPU" ${CUDA_FOUND})
option(WITH_AVX "Compile PaddlePaddle with AVX intrinsics" ${AVX_FOUND})
option(WITH_AVX "Compile PaddlePaddle with AVX intrinsics" OFF)
option(WITH_DSO "Compile PaddlePaddle with dynamic linked CUDA" ON)
option(WITH_TESTING "Compile PaddlePaddle with unit testing" ON)
option(WITH_SWIG_PY "Compile PaddlePaddle with inference api" ON)
Expand Down
1 change: 1 addition & 0 deletions paddle/utils/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License. */

#pragma once

#include "Error.h"
#include "Excepts.h"

/**
Expand Down
33 changes: 33 additions & 0 deletions paddle/utils/CpuId.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,37 @@ class SIMDFlags final {
#define HAS_AVX512 HAS_SIMD(SIMD_AVX512)
// clang-format on

/**
* Invoke checkCPUFeature() before Paddle initialization to
* check target machine whether support compiled instructions.
* If not, simply throw out an error.
*/
inline Error __must_check checkCPUFeature() {
Error err;
#ifndef __AVX__
if (HAS_AVX) {
LOG(WARNING) << "PaddlePaddle wasn't compiled to use avx instructions, "
<< "but these are available on your machine and could "
<< "speed up CPU computations via CMAKE .. -DWITH_AVX=ON";
}
#else
if (!HAS_AVX) {
err = Errors(
"PaddlePaddle was compiled to use avx instructions, "
"but these aren't available on your machine, please "
"disable it via CMAKE .. -DWITH_AVX=OFF");
}
#endif // __AVX__
#ifdef __SSE3__
if (!HAS_SSE3) {
err = Error(
"PaddlePaddle was compiled to use sse3 instructions, "
"which is the minimum requirement of PaddlePaddle. "
"But these aren't available on your current machine.");
}
#endif // __SSE3__

return err;
}

} // namespace paddle
2 changes: 2 additions & 0 deletions paddle/utils/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ limitations under the License. */

#include <gflags/gflags.h>

#include "CpuId.h"
#include "CustomStackTrace.h"
#include "Logging.h"
#include "StringUtil.h"
Expand Down Expand Up @@ -185,6 +186,7 @@ void initMain(int argc, char** argv) {
}

version::printVersion();
checkCPUFeature().check();
runInitFunctions();
}

Expand Down

0 comments on commit 6f22951

Please sign in to comment.