From 66cc615679966a4dad4f6f6bc3a69353c6567ccc Mon Sep 17 00:00:00 2001 From: Lukas Mosimann Date: Thu, 25 Apr 2019 14:40:21 +0200 Subject: [PATCH] std::move, std::forward -> const_expr::move, const_expr::forward --- .../gridtools/c_bindings/function_wrapper.hpp | 4 ++-- include/gridtools/c_bindings/generator.hpp | 4 ++-- include/gridtools/common/any_moveable.hpp | 7 ++++--- include/gridtools/common/array.hpp | 2 +- include/gridtools/common/functional.hpp | 3 ++- .../common/generic_metafunctions/utility.hpp | 14 +++++--------- .../gridtools/common/hypercube_iterator.hpp | 4 ++-- include/gridtools/common/pair.hpp | 19 +++++++++++-------- include/gridtools/common/permute_to.hpp | 4 ++-- include/gridtools/common/split_args.hpp | 17 +++++++++-------- include/gridtools/common/timer/timer.hpp | 3 ++- include/gridtools/common/tuple.hpp | 7 ++++--- .../distributed_boundaries/bound_bc.hpp | 5 +++-- include/gridtools/stencil_composition/arg.hpp | 4 ++-- .../stencil_composition/computation.hpp | 6 +++--- .../intermediate_expand.hpp | 9 +++++---- .../make_computation.hpp | 11 ++++++----- .../backend_cuda/iterate_domain_cuda.hpp | 2 +- .../backend_naive/iterate_domain_naive.hpp | 2 +- .../backend_x86/iterate_domain_x86.hpp | 2 +- .../stencil_composition/intermediate.hpp | 2 +- .../stencil_composition/make_computation.hpp | 14 ++++++++------ .../stencil_composition/sid/as_const.hpp | 2 +- .../stencil_composition/sid/composite.hpp | 6 +++--- .../stencil_composition/sid/delegate.hpp | 2 +- .../stencil_composition/sid/synthetic.hpp | 13 +++++++------ .../backend_cuda/iterate_domain_cuda.hpp | 2 +- .../backend_naive/iterate_domain_naive.hpp | 2 +- .../backend_x86/iterate_domain_x86.hpp | 2 +- include/gridtools/storage/data_store.hpp | 2 +- include/gridtools/storage/sid.hpp | 4 ++-- .../gridtools/tools/computation_fixture.hpp | 8 ++++---- .../mpi_unit_test_driver/mpi_listener.hpp | 2 +- .../gridtools/tools/regression_fixture.hpp | 2 +- 34 files changed, 101 insertions(+), 91 deletions(-) diff --git a/include/gridtools/c_bindings/function_wrapper.hpp b/include/gridtools/c_bindings/function_wrapper.hpp index 8b71831f5a..ceb021885b 100644 --- a/include/gridtools/c_bindings/function_wrapper.hpp +++ b/include/gridtools/c_bindings/function_wrapper.hpp @@ -80,7 +80,7 @@ namespace gridtools { template ::type>::value, int>::type = 0> gt_handle *convert_to_c(T &&obj) { - return new gt_handle{std::forward(obj)}; + return new gt_handle{const_expr::forward(obj)}; } template @@ -161,7 +161,7 @@ namespace gridtools { /// Wrap the functor of type `Impl` to another functor that can be invoked with the 'wrapped_t' signature. template _impl::wrapped_f::type> wrap(Impl &&obj) { - return {std::forward(obj)}; + return {const_expr::forward(obj)}; } /// Specialization for function pointers. diff --git a/include/gridtools/c_bindings/generator.hpp b/include/gridtools/c_bindings/generator.hpp index 49d0c0c001..c1fb105777 100644 --- a/include/gridtools/c_bindings/generator.hpp +++ b/include/gridtools/c_bindings/generator.hpp @@ -96,7 +96,7 @@ namespace gridtools { void for_each_param(TypeToStr &&type_to_str, Fun &&fun) { int count = 0; for_each_type(for_each_param_helper_f{ - std::forward(type_to_str), std::forward(fun), count}); + const_expr::forward(type_to_str), const_expr::forward(fun), count}); }; template @@ -439,7 +439,7 @@ namespace gridtools { get_entities().add(name, std::bind(Traits::template generate_entity, std::placeholders::_1, - std::forward(params)...)); + const_expr::forward(params)...)); } template diff --git a/include/gridtools/common/any_moveable.hpp b/include/gridtools/common/any_moveable.hpp index 7f685b3590..b691cfec4e 100644 --- a/include/gridtools/common/any_moveable.hpp +++ b/include/gridtools/common/any_moveable.hpp @@ -15,6 +15,7 @@ #include #include "defs.hpp" +#include "generic_metafunctions/utility.hpp" namespace gridtools { @@ -36,7 +37,7 @@ namespace gridtools { struct impl : iface { T m_obj; impl(T const &obj) : m_obj(obj) {} - impl(T &&obj) : m_obj(std::move(obj)) {} + impl(T &&obj) : m_obj(const_expr::move(obj)) {} std::type_info const &type() const noexcept override { return typeid(T); } }; std::unique_ptr m_impl; @@ -45,12 +46,12 @@ namespace gridtools { any_moveable() = default; template ::type> - any_moveable(Arg &&arg) : m_impl(new impl(std::forward(arg))) {} + any_moveable(Arg &&arg) : m_impl(new impl(const_expr::forward(arg))) {} any_moveable(any_moveable &&) = default; template ::type> any_moveable &operator=(Arg &&obj) { - m_impl.reset(new impl(std::forward(obj))); + m_impl.reset(new impl(const_expr::forward(obj))); return *this; } any_moveable &operator=(any_moveable &&) = default; diff --git a/include/gridtools/common/array.hpp b/include/gridtools/common/array.hpp index 86ee9e312f..5cf9fbfde7 100644 --- a/include/gridtools/common/array.hpp +++ b/include/gridtools/common/array.hpp @@ -195,7 +195,7 @@ namespace gridtools { template GT_FUNCTION T &&get(array &&arr) noexcept { GT_STATIC_ASSERT(I < D, "index is out of bounds"); - return std::move(get(arr)); + return const_expr::move(get(arr)); } /** @} */ diff --git a/include/gridtools/common/functional.hpp b/include/gridtools/common/functional.hpp index c155840cc0..ac62a1dc38 100644 --- a/include/gridtools/common/functional.hpp +++ b/include/gridtools/common/functional.hpp @@ -24,6 +24,7 @@ #include +#include "./generic_metafunctions/utility.hpp" #include "./host_device.hpp" #define GT_FILENAME @@ -47,7 +48,7 @@ namespace gridtools { struct ctor { template GT_TARGET GT_FORCE_INLINE T operator()(Args &&... args) const { - return T{std::forward(args)...}; + return T{const_expr::forward(args)...}; } #ifndef BOOST_RESULT_OF_USE_DECLTYPE diff --git a/include/gridtools/common/generic_metafunctions/utility.hpp b/include/gridtools/common/generic_metafunctions/utility.hpp index e923405266..2083ad8498 100644 --- a/include/gridtools/common/generic_metafunctions/utility.hpp +++ b/include/gridtools/common/generic_metafunctions/utility.hpp @@ -13,32 +13,28 @@ #include #include +#include "../host_device.hpp" + namespace gridtools { /** * `std::forward`/`std::move` versions that are guarantied to be constexpr */ namespace const_expr { -// cuda < 9.2 doesn't have std::move/std::forward definded as `constexpr` -#if __CUDACC__ // defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ < 9 || __CUDACC_VER_MAJOR__ == 9 && // __CUDACC_VER_MINOR__ < 2) template - __device__ __host__ typename std::remove_reference::type &&move(T &&obj) noexcept { + GT_HOST_DEVICE typename std::remove_reference::type &&move(T &&obj) noexcept { return static_cast::type &&>(obj); } template - __device__ __host__ T &&forward(typename std::remove_reference::type &obj) noexcept { + GT_HOST_DEVICE T &&forward(typename std::remove_reference::type &obj) noexcept { return static_cast(obj); } template - __device__ __host__ T &&forward(typename std::remove_reference::type &&obj) noexcept { + GT_HOST_DEVICE T &&forward(typename std::remove_reference::type &&obj) noexcept { static_assert( !std::is_lvalue_reference::value, "Error: obj is instantiated with an lvalue reference type"); return static_cast(obj); } -#else - using std::forward; - using std::move; -#endif } // namespace const_expr } // namespace gridtools diff --git a/include/gridtools/common/hypercube_iterator.hpp b/include/gridtools/common/hypercube_iterator.hpp index a2170b860a..20e53ce428 100644 --- a/include/gridtools/common/hypercube_iterator.hpp +++ b/include/gridtools/common/hypercube_iterator.hpp @@ -82,7 +82,7 @@ namespace gridtools { size_t InnerD = tuple_size::type>::value, typename std::enable_if::type = 0> GT_FUNCTION impl_::hypercube_view make_hypercube_view(Container &&cube) { - auto &&transposed = tuple_util::host_device::transpose(std::forward(cube)); + auto &&transposed = tuple_util::host_device::transpose(const_expr::forward(cube)); return {tuple_util::host_device::convert_to(tuple_util::host_device::get<0>(transposed)), tuple_util::host_device::convert_to(tuple_util::host_device::get<1>(transposed))}; } @@ -107,6 +107,6 @@ namespace gridtools { typename std::enable_if::type>::value, int>::type = 0> GT_FUNCTION impl_::hypercube_view make_hypercube_view(Container &&sizes) { - return {tuple_util::host_device::convert_to(std::forward(sizes))}; + return {tuple_util::host_device::convert_to(const_expr::forward(sizes))}; } } // namespace gridtools diff --git a/include/gridtools/common/pair.hpp b/include/gridtools/common/pair.hpp index 1f3a3591ab..03de7bac86 100644 --- a/include/gridtools/common/pair.hpp +++ b/include/gridtools/common/pair.hpp @@ -36,16 +36,17 @@ namespace gridtools { GT_FUNCTION pair(const std::pair &p) : pair(p.first, p.second) {} template - GT_FUNCTION pair(std::pair &&p) : pair(std::move(p.first), std::move(p.second)) {} + GT_FUNCTION pair(std::pair &&p) : pair(const_expr::move(p.first), const_expr::move(p.second)) {} template - GT_FUNCTION pair(U1 &&t1_, U2 &&t2_) : first(std::forward(t1_)), second(std::forward(t2_)) {} + GT_FUNCTION pair(U1 &&t1_, U2 &&t2_) + : first(const_expr::forward(t1_)), second(const_expr::forward(t2_)) {} template , pair>::value, int>::type = 0> GT_FUNCTION pair(const pair &p) : first(p.first), second(p.second) {} template , pair>::value, int>::type = 0> - GT_FUNCTION pair(pair &&p) : first(std::move(p.first)), second(std::move(p.second)) {} + GT_FUNCTION pair(pair &&p) : first(const_expr::move(p.first)), second(const_expr::move(p.second)) {} template , pair>::value, int>::type = 0> GT_FUNCTION pair &operator=(pair &&other) noexcept { - first = std::move(other.first); - second = std::move(other.second); + first = const_expr::move(other.first); + second = const_expr::move(other.second); return *this; } @@ -141,7 +142,7 @@ namespace gridtools { } template static GT_FUNCTION T1 &&move_get(pair &&p) noexcept { - return std::move(p.first); + return const_expr::move(p.first); } }; template <> @@ -168,7 +169,8 @@ namespace gridtools { static GT_FUNCTION auto get(const pair &p) noexcept GT_AUTO_RETURN(pair_get::const_get(p)); template - static GT_FUNCTION auto get(pair &&p) noexcept GT_AUTO_RETURN(pair_get::move_get(std::move(p))); + static GT_FUNCTION auto get(pair &&p) noexcept GT_AUTO_RETURN( + pair_get::move_get(const_expr::move(p))); }; } // namespace pair_impl_ @@ -179,7 +181,8 @@ namespace gridtools { GT_FUNCTION auto get(const pair &p) noexcept GT_AUTO_RETURN(pair_impl_::pair_get::const_get(p)); template - GT_FUNCTION auto get(pair &&p) noexcept GT_AUTO_RETURN(pair_impl_::pair_get::move_get(std::move(p))); + GT_FUNCTION auto get(pair &&p) noexcept GT_AUTO_RETURN( + pair_impl_::pair_get::move_get(const_expr::move(p))); template pair_impl_::getter tuple_getter(pair const &); diff --git a/include/gridtools/common/permute_to.hpp b/include/gridtools/common/permute_to.hpp index 6923c024f3..2a4d378a81 100644 --- a/include/gridtools/common/permute_to.hpp +++ b/include/gridtools/common/permute_to.hpp @@ -28,7 +28,7 @@ namespace gridtools { Res operator()(Src &&src) { using src_t = decay_t; return Res{ - tuple_util::get::value>(std::forward(src))...}; + tuple_util::get::value>(const_expr::forward(src))...}; } }; } // namespace impl_ @@ -62,6 +62,6 @@ namespace gridtools { template Res permute_to(Src &&src) { - return impl_::permute_to_impl{}(std::forward(src)); + return impl_::permute_to_impl{}(const_expr::forward(src)); } } // namespace gridtools diff --git a/include/gridtools/common/split_args.hpp b/include/gridtools/common/split_args.hpp index 4b17ad350d..34247dc60c 100644 --- a/include/gridtools/common/split_args.hpp +++ b/include/gridtools/common/split_args.hpp @@ -23,6 +23,7 @@ #include "../meta/type_traits.hpp" #include "../meta/zip.hpp" #include "defs.hpp" +#include "generic_metafunctions/utility.hpp" namespace gridtools { namespace _impl { @@ -49,20 +50,20 @@ namespace gridtools { template class L, class... Is> auto get_part_helper(Args &&args, L *) - GT_AUTO_RETURN(std::forward_as_tuple(std::get(std::forward(args))...)); + GT_AUTO_RETURN(std::forward_as_tuple(std::get(const_expr::forward(args))...)); template