Skip to content

Commit

Permalink
Minor fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jan 4, 2025
1 parent 64b1c0d commit c141de4
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 115 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,9 @@ if(WIN32)
# Silence C++20 deprecation warnings
hpx_add_config_cond_define(_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS)

# Silence C++23 deprecation warnings
hpx_add_config_cond_define(_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS)

# ASan is available in Visual Studion starting V16.8
if((MSVC_VERSION GREATER_EQUAL 1928) AND HPX_WITH_SANITIZERS)
hpx_add_target_compile_option(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -30,7 +30,7 @@ namespace hpx::parallel::util::detail {
template <typename Iter>
struct is_data_aligned_impl
{
static HPX_FORCEINLINE bool call(Iter const& it) noexcept
static HPX_FORCEINLINE bool call(Iter& it) noexcept
{
using value_type = typename std::iterator_traits<Iter>::value_type;
using pack_type = traits::vector_pack_type_t<value_type>;
Expand All @@ -42,7 +42,7 @@ namespace hpx::parallel::util::detail {
};

template <typename Iter>
HPX_FORCEINLINE bool is_data_aligned(Iter const& it) noexcept
HPX_FORCEINLINE bool is_data_aligned(Iter& it) noexcept
{
return is_data_aligned_impl<Iter>::call(it);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace hpx::parallel::traits {
struct vector_pack_load
{
template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static V aligned(Iter const& iter)
HPX_HOST_DEVICE HPX_FORCEINLINE static V aligned(Iter& iter)
{
return V(
eve::as_aligned(std::addressof(*iter), eve::cardinal_t<V>{}));
}

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static V unaligned(Iter const& iter)
HPX_HOST_DEVICE HPX_FORCEINLINE static V unaligned(Iter& iter)
{
return *iter;
}
Expand All @@ -42,15 +42,15 @@ namespace hpx::parallel::traits {
{
template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static void aligned(
V& value, Iter const& iter)
V& value, Iter& iter)
{
eve::store(value,
eve::as_aligned(std::addressof(*iter), eve::cardinal_t<V>{}));
}

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static void unaligned(
V& value, Iter const& iter)
V& value, Iter& iter)
{
*iter = value;
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2021 Srinivas Yadav
// Copyright (c) 2016-2017 Hartmut Kaiser
// Copyright (c) 2016-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -25,14 +25,14 @@ namespace hpx::parallel::traits {
struct vector_pack_load
{
template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static V aligned(Iter const& iter)
HPX_HOST_DEVICE HPX_FORCEINLINE static V aligned(Iter& iter)
{
return V(
std::addressof(*iter), datapar::experimental::vector_aligned);
}

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static V unaligned(Iter const& iter)
HPX_HOST_DEVICE HPX_FORCEINLINE static V unaligned(Iter& iter)
{
return *iter;
}
Expand All @@ -44,15 +44,15 @@ namespace hpx::parallel::traits {
{
template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static void aligned(
V& value, Iter const& iter)
V& value, Iter& iter)
{
value.copy_to(
std::addressof(*iter), datapar::experimental::vector_aligned);
}

template <typename Iter>
HPX_HOST_DEVICE HPX_FORCEINLINE static void unaligned(
V& value, Iter const& iter)
V& value, Iter& iter)
{
*iter = value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016-2025 Hartmut Kaiser
// Copyright (c) 2016 Matthias Kretz
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -69,13 +69,13 @@ namespace hpx::parallel::traits {
using value_type = typename rebind_pack<V, ValueType>::type;

template <typename Iter>
static value_type aligned(Iter const& iter)
static value_type aligned(Iter& iter)
{
return value_type(std::addressof(*iter), Vc::Aligned);
}

template <typename Iter>
static value_type unaligned(Iter const& iter)
static value_type unaligned(Iter& iter)
{
return value_type(std::addressof(*iter), Vc::Unaligned);
}
Expand All @@ -87,13 +87,13 @@ namespace hpx::parallel::traits {
using value_type = typename rebind_pack<V, Vc::Vector<T, Abi>>::type;

template <typename Iter>
static value_type aligned(Iter const& iter)
static value_type aligned(Iter& iter)
{
return *iter;
}

template <typename Iter>
static value_type unaligned(Iter const& iter)
static value_type unaligned(Iter& iter)
{
return *iter;
}
Expand All @@ -107,13 +107,13 @@ namespace hpx::parallel::traits {
typename rebind_pack<Value, Vc::SimdArray<T, N, V, W>>::type;

template <typename Iter>
static value_type aligned(Iter const& iter)
static value_type aligned(Iter& iter)
{
return *iter;
}

template <typename Iter>
static value_type unaligned(Iter const& iter)
static value_type unaligned(Iter& iter)
{
return *iter;
}
Expand All @@ -124,13 +124,13 @@ namespace hpx::parallel::traits {
struct vector_pack_store
{
template <typename Iter>
static void aligned(V const& value, Iter const& iter)
static void aligned(V& value, Iter& iter)
{
value.store(std::addressof(*iter), Vc::Aligned);
}

template <typename Iter>
static void unaligned(V const& value, Iter const& iter)
static void unaligned(V& value, Iter& iter)
{
value.store(std::addressof(*iter), Vc::Unaligned);
}
Expand All @@ -140,13 +140,13 @@ namespace hpx::parallel::traits {
struct vector_pack_store<V, Vc::Vector<T, Abi>>
{
template <typename Iter>
static void aligned(V const& value, Iter const& iter)
static void aligned(V& value, Iter& iter)
{
*iter = value;
}

template <typename Iter>
static void unaligned(V const& value, Iter const& iter)
static void unaligned(V& value, Iter& iter)
{
*iter = value;
}
Expand All @@ -157,13 +157,13 @@ namespace hpx::parallel::traits {
struct vector_pack_store<Value, Vc::SimdArray<T, N, V, W>>
{
template <typename Iter>
static void aligned(Value const& value, Iter const& iter)
static void aligned(Value& value, Iter& iter)
{
*iter = value;
}

template <typename Iter>
static void unaligned(Value const& value, Iter const& iter)
static void unaligned(Value& value, Iter& iter)
{
*iter = value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016-2025 Hartmut Kaiser
// Copyright (c) 2016 Matthias Kretz
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace hpx::parallel::traits {
////////////////////////////////////////////////////////////////////
template <typename T>
struct vector_pack_mask_type<T,
typename std::enable_if_t<Vc::Traits::is_simd_vector<T>::value>>
std::enable_if_t<Vc::Traits::is_simd_vector<T>::value>>
{
using type = typename T::mask_type;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2019-2020 ETH Zurich
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2025 Hartmut Kaiser
// Copyright (c) 2019 Agustin Berge
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace hpx::parallel::execution::detail {
bool const allow_stealing;

template <std::size_t... Is, typename F, typename T, typename Ts>
static constexpr void bulk_invoke_helper(
HPX_FORCEINLINE static constexpr void bulk_invoke_helper(
hpx::util::index_pack<Is...>, F&& f, T&& t, Ts&& ts)
{
HPX_INVOKE(HPX_FORWARD(F, f), HPX_FORWARD(T, t),
Expand All @@ -63,7 +63,8 @@ namespace hpx::parallel::execution::detail {
// Perform the work in one element indexed by index. The index
// represents a range of indices (iterators) in the given shape.
template <typename F, typename Ts>
void do_work_chunk(F&& f, Ts&& ts, std::uint32_t const index) const
HPX_FORCEINLINE void do_work_chunk(
F&& f, Ts&& ts, std::uint32_t const index) const
{
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
static hpx::util::itt::event notify_event(
Expand Down Expand Up @@ -104,7 +105,7 @@ namespace hpx::parallel::execution::detail {
if (allow_stealing)
{
// Then steal from the opposite end of the neighboring queues
static constexpr auto opposite_end =
constexpr auto opposite_end =
hpx::concurrency::detail::opposite_end_v<Which>;

for (std::uint32_t offset = 1; offset != state->num_threads;
Expand All @@ -123,20 +124,6 @@ namespace hpx::parallel::execution::detail {
}
}

// Execute task function
void do_work() const
{
// schedule chunks from the end, if needed
if (reverse_placement)
{
do_work<hpx::concurrency::detail::queue_end::right>();
}
else
{
do_work<hpx::concurrency::detail::queue_end::left>();
}
}

// Store an exception and mark that an exception was thrown in the
// operation state. This function assumes that there is a current
// exception.
Expand All @@ -150,7 +137,7 @@ namespace hpx::parallel::execution::detail {
// Finish the work for one worker thread. If this is not the last worker
// thread to finish, it will only decrement the counter. If it is the
// last thread it will call set_exception if there is an exception.
// Otherwise it will call set_value on the shared state.
// Otherwise, it will call set_value on the shared state.
void finish() const
{
if (--(state->tasks_remaining.data_) == 0)
Expand Down Expand Up @@ -186,7 +173,16 @@ namespace hpx::parallel::execution::detail {
{
try
{
do_work();
// Execute task function
if (reverse_placement)
{
// schedule chunks from the end, if needed
do_work<hpx::concurrency::detail::queue_end::right>();
}
else
{
do_work<hpx::concurrency::detail::queue_end::left>();
}
}
catch (std::bad_alloc const&)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Hartmut Kaiser
// Copyright (c) 2020-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace hpx::util {

using type = iterator_adaptor<counting_iterator<Incrementable,
CategoryOrTraversal, Difference>,
Incrementable, Incrementable, traversal, Incrementable const&,
Incrementable, Incrementable, traversal, Incrementable&,
difference>;
};
} // namespace detail
Expand Down Expand Up @@ -122,6 +122,11 @@ namespace hpx::util {
{
return this->base_reference();
}

HPX_HOST_DEVICE constexpr typename base_type::reference dereference()
{
return this->base_reference();
}
};

template <typename Incrementable, typename CategoryOrTraversal,
Expand Down Expand Up @@ -175,8 +180,12 @@ namespace hpx::util {
static_cast<typename base_type::base_type>(n);
}

HPX_HOST_DEVICE constexpr typename base_type::reference dereference()
const noexcept
HPX_HOST_DEVICE constexpr decltype(auto) dereference() const noexcept
{
return this->base_reference();
}

HPX_HOST_DEVICE constexpr decltype(auto) dereference() noexcept
{
return this->base_reference();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2023 Hartmut Kaiser
// Copyright (c) 2016-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -106,7 +106,7 @@ namespace hpx::util {
//
// Reference - the reference type of the resulting iterator, and in
// particular, the result type of operator*(). If not supplied but
// Value is supplied, Value& is used. Otherwise
// Value is supplied, Value& is used. Otherwise,
// iterator_traits<Base>::reference is used.
//
// Difference - the difference_type of the resulting iterator. If not
Expand Down Expand Up @@ -149,13 +149,13 @@ namespace hpx::util {
Category, Reference, Difference, Pointer>;

// lvalue access to the Base object for Derived
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Base const& base_reference()
const noexcept
HPX_HOST_DEVICE HPX_FORCEINLINE Base& base_reference() noexcept
{
return iterator_;
}

HPX_HOST_DEVICE HPX_FORCEINLINE Base& base_reference() noexcept
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Base const& base_reference()
const noexcept
{
return iterator_;
}
Expand Down
Loading

0 comments on commit c141de4

Please sign in to comment.