未验证 提交 38a3746d 编写于 作者: T Twice 提交者: GitHub

c++ standard: bump version to 14 (#6252)

* c++ standard: bump to 14

* remove cplusplus_14.h & use cxx14

* fix python test

* fix .clang-format
Co-authored-by: Noneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
上级 9ed5706f
......@@ -89,7 +89,7 @@ SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
Standard: Auto
TabWidth: 8
UseTab: Never
...
......@@ -120,7 +120,7 @@ endif()
add_definitions(-DRPC_BACKEND_LOCAL)
message(STATUS "RPC backend enabled: local")
enable_testing()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(THIRD_PARTY_DIR "${PROJECT_BINARY_DIR}/third_party_install"
......@@ -148,7 +148,7 @@ if(WIN32)
#set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /DEBUG:FASTLINK")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_ITERATOR_DEBUG_LEVEL=0")
else()
set(EXTRA_CXX_FLAGS "-std=c++11 -Wall -Wno-sign-compare -Wno-unused-function -fPIC")
set(EXTRA_CXX_FLAGS "-std=c++14 -Wall -Wno-sign-compare -Wno-unused-function -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_CXX_FLAGS}")
......
......@@ -98,7 +98,7 @@ if (BUILD_CUDA)
# add a cache entry if want to use a ccache/sccache wrapped nvcc
set(CMAKE_CUDA_COMPILER ${CUDAToolkit_NVCC_EXECUTABLE} CACHE STRING "")
message(STATUS "CMAKE_CUDA_COMPILER: ${CMAKE_CUDA_COMPILER}")
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD 14)
find_package(CUDNN REQUIRED)
endif()
......
......@@ -19,11 +19,11 @@ limitations under the License.
#include "oneflow/api/python/functional/python_arg.h"
#include <tuple>
#include <utility>
#include "oneflow/api/python/framework/throw.h"
#include "oneflow/core/framework/tensor.h"
#include "oneflow/core/framework/tensor_tuple.h"
#include "oneflow/core/common/function_traits.h"
#include "oneflow/core/common/cplusplus_14.h"
namespace oneflow {
namespace one {
......
/*
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef ONEFLOW_CORE_COMMON_CPLUSPLUS_14_H_
#define ONEFLOW_CORE_COMMON_CPLUSPLUS_14_H_
#if __cplusplus < 201402L
#include <memory>
namespace std {
template<class T>
struct unique_if {
typedef unique_ptr<T> single_object;
};
template<class T>
struct unique_if<T[]> {
typedef unique_ptr<T[]> unknown_bound;
};
template<class T, size_t N>
struct unique_if<T[N]> {
typedef void known_bound;
};
template<class T, class... Args>
typename unique_if<T>::single_object make_unique(Args&&... args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
}
template<class T>
typename unique_if<T>::unknown_bound make_unique(size_t n) {
typedef typename remove_extent<T>::type U;
return unique_ptr<T>(new U[n]());
}
template<class T, class... Args>
typename unique_if<T>::known_bound make_unique(Args&&...) = delete;
template<size_t... Ints>
struct index_sequence {
using type = index_sequence;
using value_type = size_t;
static constexpr std::size_t size() noexcept { return sizeof...(Ints); }
};
// --------------------------------------------------------------
template<class Sequence1, class Sequence2>
struct _merge_and_renumber;
template<size_t... I1, size_t... I2>
struct _merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
: index_sequence<I1..., (sizeof...(I1) + I2)...> {};
// --------------------------------------------------------------
template<size_t N>
struct make_index_sequence : _merge_and_renumber<typename make_index_sequence<N / 2>::type,
typename make_index_sequence<N - N / 2>::type> {};
template<>
struct make_index_sequence<0> : index_sequence<> {};
template<>
struct make_index_sequence<1> : index_sequence<0> {};
template<typename... T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;
template<bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;
template<typename T>
using remove_const_t = typename remove_const<T>::type;
template<typename T>
using remove_reference_t = typename remove_reference<T>::type;
template<typename T>
using decay_t = typename decay<T>::type;
template<typename T>
using make_unsigned_t = typename std::make_unsigned<T>::type;
template<typename T>
using remove_cv_t = typename remove_cv<T>::type;
template<typename F, typename Tuple, size_t... Idx>
auto apply_helper(F&& f, Tuple&& tp, std::index_sequence<Idx...>)
-> decltype(std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(tp))...)) {
return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(tp))...);
}
template<typename F, typename Tuple>
auto apply(F&& f, Tuple&& tp)
-> decltype(apply_helper(std::forward<F>(f), std::forward<Tuple>(tp),
std::make_index_sequence<std::tuple_size<decay_t<Tuple>>::value>{})) {
return apply_helper(std::forward<F>(f), std::forward<Tuple>(tp),
std::make_index_sequence<std::tuple_size<decay_t<Tuple>>::value>{});
}
template<typename F, typename... Args>
auto invoke(F&& f, Args&&... args) -> decltype(std::forward<F>(f)(std::forward<Args>(args)...)) {
return std::forward<F>(f)(std::forward<Args>(args)...);
}
template<bool B, typename T, typename F>
using conditional_t = typename conditional<B, T, F>::type;
template<typename...>
struct conjunction : std::true_type {};
template<typename B1>
struct conjunction<B1> : B1 {};
template<typename B1, typename... Bn>
struct conjunction<B1, Bn...> : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
} // namespace std
#endif
#endif // ONEFLOW_CORE_COMMON_CPLUSPLUS_14_H_
......@@ -16,7 +16,8 @@ limitations under the License.
#ifndef ONEFLOW_CORE_COMMON_META_UTIL_HPP_
#define ONEFLOW_CORE_COMMON_META_UTIL_HPP_
#include "oneflow/core/common/cplusplus_14.h"
#include <utility>
#include <tuple>
namespace oneflow {
......@@ -34,14 +35,13 @@ void for_each_i(const std::tuple<Args...>& t, Func&& f, std::index_sequence<Idx.
template<typename T>
using remove_const_reference_t = std::remove_const_t<std::remove_reference_t<T>>;
template<size_t... Is>
auto make_tuple_from_sequence(std::index_sequence<Is...>) -> decltype(std::make_tuple(Is...)) {
std::make_tuple(Is...);
template<std::size_t... Is>
auto make_tuple_from_sequence(std::index_sequence<Is...>) {
return std::make_tuple(Is...);
}
template<size_t N>
constexpr auto make_tuple_from_sequence()
-> decltype(make_tuple_from_sequence(std::make_index_sequence<N>{})) {
template<std::size_t N>
constexpr auto make_tuple_from_sequence() {
return make_tuple_from_sequence(std::make_index_sequence<N>{});
}
......
......@@ -341,20 +341,19 @@ class Optional final : private internal::OptionalBase<T> {
Optional& operator=(Optional&& rhs) noexcept = default;
template<typename U>
auto value_or(U&& other) const& -> decltype(base::value_or(std::forward<U>(other))) {
decltype(auto) value_or(U&& other) const& {
return base::value_or(std::forward<U>(other));
}
template<typename U>
auto value_or(U&& other) && -> decltype(std::move(*this).base::value_or(std::forward<U>(other))) {
decltype(auto) value_or(U&& other) && {
return std::move(*this).base::value_or(std::forward<U>(other));
}
bool has_value() const { return base::has_value(); }
explicit operator bool() const { return has_value(); }
auto Data_YouAreNotAllowedToCallThisFuncOutsideThisFile() && -> decltype(
std::move(*this).base::value()) {
decltype(auto) Data_YouAreNotAllowedToCallThisFuncOutsideThisFile() && {
return std::move(*this).base::value();
}
......
......@@ -21,7 +21,7 @@ limitations under the License.
#include <utility>
template<typename... Args>
auto SwitchCase(Args&&... args) -> decltype(std::make_tuple(std::forward<Args>(args)...)) {
auto SwitchCase(Args&&... args) {
return std::make_tuple(std::forward<Args>(args)...);
}
......
......@@ -17,8 +17,7 @@ limitations under the License.
#define ONEFLOW_CORE_COMMON_TUPLE_HASH_H_
#include <tuple>
#include <functional>
#include "oneflow/core/common/cplusplus_14.h"
#include <utility>
#include "oneflow/core/common/util.h"
namespace std {
......
......@@ -119,7 +119,7 @@ class CustomOpModule(object):
return self
def cpp_def(self):
flags = "-std=c++11 -c -fPIC -O2 " + get_cflags()
flags = "-std=c++14 -c -fPIC -O2 " + get_cflags()
compile(
"g++",
flags,
......@@ -144,7 +144,7 @@ class CustomOpModule(object):
return self
def cpp_kernel(self):
flags = "-std=c++11 -c -fPIC -O2 " + get_cflags()
flags = "-std=c++14 -c -fPIC -O2 " + get_cflags()
compile(
"g++",
flags,
......@@ -161,7 +161,7 @@ class CustomOpModule(object):
def build_load(self):
if len(self.objs_) > 0:
flags = "-std=c++11 -shared -fPIC " + get_cflags()
flags = "-std=c++14 -shared -fPIC " + get_cflags()
compile(
"g++", flags, get_lflags(), self.objs_, "{}.so".format(self.out_prefix_)
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册