未验证 提交 587d99ae 编写于 作者: W wuhuanzhou 提交者: GitHub

update compilation with C++14 (#31815)

* update compilation with C++14, test=develop

* fix compilation error in eigen, test=develop
上级 b09c1ce0
...@@ -208,14 +208,11 @@ select_nvcc_arch_flags(NVCC_FLAGS_EXTRA) ...@@ -208,14 +208,11 @@ select_nvcc_arch_flags(NVCC_FLAGS_EXTRA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${NVCC_FLAGS_EXTRA}") set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${NVCC_FLAGS_EXTRA}")
message(STATUS "NVCC_FLAGS_EXTRA: ${NVCC_FLAGS_EXTRA}") message(STATUS "NVCC_FLAGS_EXTRA: ${NVCC_FLAGS_EXTRA}")
# Set C++11 support # Set C++14 support
set(CUDA_PROPAGATE_HOST_FLAGS OFF) set(CUDA_PROPAGATE_HOST_FLAGS OFF)
# Release/Debug flags set by cmake. Such as -O3 -g -DNDEBUG etc. # Release/Debug flags set by cmake. Such as -O3 -g -DNDEBUG etc.
# So, don't set these flags here. # So, don't set these flags here.
if (NOT WIN32) # windows msvc2015 support c++11 natively. set(CMAKE_CUDA_STANDARD 14)
# -std=c++11 -fPIC not recoginize by msvc, -Xcompiler will be added by cmake.
set(CMAKE_CUDA_STANDARD 11)
endif(NOT WIN32)
# (Note) For windows, if delete /W[1-4], /W1 will be added defaultly and conflic with -w # (Note) For windows, if delete /W[1-4], /W1 will be added defaultly and conflic with -w
# So replace /W[1-4] with /W0 # So replace /W[1-4] with /W0
......
...@@ -4,10 +4,10 @@ include(CheckCCompilerFlag) ...@@ -4,10 +4,10 @@ include(CheckCCompilerFlag)
include(CheckCXXSymbolExists) include(CheckCXXSymbolExists)
include(CheckTypeSize) include(CheckTypeSize)
function(CheckCompilerCXX11Flag) function(CheckCompilerCXX14Flag)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.8) if(${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 5.4)
message(FATAL_ERROR "Unsupported GCC version. GCC >= 4.8 required.") message(FATAL_ERROR "Unsupported GCC version. GCC >= 5.4 required.")
elseif(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 8.2) elseif(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 8.2)
message(WARNING "Found GCC ${CMAKE_CXX_COMPILER_VERSION} which is too high, recommended to use GCC 8.2") message(WARNING "Found GCC ${CMAKE_CXX_COMPILER_VERSION} which is too high, recommended to use GCC 8.2")
endif() endif()
...@@ -20,23 +20,15 @@ function(CheckCompilerCXX11Flag) ...@@ -20,23 +20,15 @@ function(CheckCompilerCXX11Flag)
message(FATAL_ERROR "Unsupported AppleClang version. AppleClang >= 5.1 required.") message(FATAL_ERROR "Unsupported AppleClang version. AppleClang >= 5.1 required.")
endif() endif()
else() else()
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.3) if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.4)
message(FATAL_ERROR "Unsupported Clang version. Clang >= 3.3 required.") message(FATAL_ERROR "Unsupported Clang version. Clang >= 3.4 required.")
endif() endif()
endif() endif()
endif() endif()
endfunction() endfunction()
CheckCompilerCXX11Flag() CheckCompilerCXX14Flag()
if (WITH_GPU) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
if (${CMAKE_CUDA_COMPILER_VERSION} GREATER_EQUAL 11.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
# safe_set_flag # safe_set_flag
# #
# Set a compile flag only if compiler is support # Set a compile flag only if compiler is support
......
...@@ -330,7 +330,10 @@ void BenchKernelSgd() { ...@@ -330,7 +330,10 @@ void BenchKernelSgd() {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
all.push_back(i); all.push_back(i);
} }
std::random_shuffle(all.begin(), all.end()); std::random_device rnd;
int64_t seed_tmp = rnd();
std::default_random_engine rng(seed_tmp);
std::shuffle(all.begin(), all.end(), rng);
out.insert(out.begin(), all.begin(), all.begin() + n); out.insert(out.begin(), all.begin(), all.begin() + n);
return out; return out;
}; };
......
...@@ -861,7 +861,10 @@ void TestKernelSgd() { ...@@ -861,7 +861,10 @@ void TestKernelSgd() {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
all.push_back(i); all.push_back(i);
} }
std::random_shuffle(all.begin(), all.end()); std::random_device rnd;
int64_t seed_tmp = rnd();
std::default_random_engine rng(seed_tmp);
std::shuffle(all.begin(), all.end(), rng);
out.insert(out.begin(), all.begin(), all.begin() + n); out.insert(out.begin(), all.begin(), all.begin() + n);
return out; return out;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册