Skip to content

Commit

Permalink
Address inspect tool, check module cmakelists and spell check
Browse files Browse the repository at this point in the history
- missing includes
- prevent max/min being expanded as macros
- minor spell check correction
- remove pragma once in cpp file
- resolve implicit type conversions in rfa type to single and double

Signed-off-by: Shreyas Atre <[email protected]>
  • Loading branch information
SAtacker committed Dec 18, 2024
1 parent 520f161 commit 99b7ae9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 39 deletions.
3 changes: 3 additions & 0 deletions libs/core/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ set(algorithms_headers
hpx/parallel/algorithms/detail/parallel_stable_sort.hpp
hpx/parallel/algorithms/detail/pivot.hpp
hpx/parallel/algorithms/detail/reduce.hpp
hpx/parallel/algorithms/detail/reduce_deterministic.hpp
hpx/parallel/algorithms/detail/replace.hpp
hpx/parallel/algorithms/detail/rfa.hpp
hpx/parallel/algorithms/detail/rotate.hpp
hpx/parallel/algorithms/detail/sample_sort.hpp
hpx/parallel/algorithms/detail/search.hpp
Expand Down Expand Up @@ -72,6 +74,7 @@ set(algorithms_headers
hpx/parallel/algorithms/partition.hpp
hpx/parallel/algorithms/reduce_by_key.hpp
hpx/parallel/algorithms/reduce.hpp
hpx/parallel/algorithms/reduce_deterministic.hpp
hpx/parallel/algorithms/remove_copy.hpp
hpx/parallel/algorithms/remove.hpp
hpx/parallel/algorithms/replace.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <hpx/parallel/util/loop.hpp>

#include <cstddef>
#include <cstring>
#include <limits>
#include <type_traits>
#include <utility>
Expand All @@ -32,6 +33,8 @@ namespace hpx::parallel::detail {
sequential_reduce_deterministic_t, ExPolicy&&, InIterB first,
InIterE last, T init, Reduce&& r)
{
/// TODO: Put constraint on Reduce to be a binary plus operator
(void) r;
hpx::parallel::detail::rfa::RFA_bins<T> bins;
bins.initialize_bins();
std::memcpy(rfa::__rfa_bin_host_buffer__, &bins, sizeof(bins));
Expand Down
81 changes: 48 additions & 33 deletions libs/core/algorithms/include/hpx/parallel/algorithms/detail/rfa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <cmath>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <vector>

namespace hpx::parallel::detail::rfa {
template <typename F>
Expand Down Expand Up @@ -351,29 +353,29 @@ namespace hpx::parallel::detail::rfa {

///Get index of float-point precision
///The index of a non-binned type is the smallest index a binned type would
///need to have to sum it reproducibly. Higher indicies correspond to smaller
///need to have to sum it reproducibly. Higher indices correspond to smaller
///bins.
static inline constexpr int binned_dindex(const ftype x)
{
int exp = EXP(x);
if (exp == 0)
{
if (x == 0.0)
if (x == static_cast<ftype>(0.0))
{
return MAXINDEX;
}
else
{
std::frexp(x, &exp);
return std::max((MAX_EXP - exp) / BIN_WIDTH, MAXINDEX);
return (std::max)((MAX_EXP - exp) / BIN_WIDTH, MAXINDEX);
}
}
return ((MAX_EXP + EXP_BIAS) - exp) / BIN_WIDTH;
}

///Get index of manually specified binned double precision
///The index of a binned type is the bin that it corresponds to. Higher
///indicies correspond to smaller bins.
///indices correspond to smaller bins.
inline int binned_index() const
{
return ((MAX_EXP + MANT_DIG - BIN_WIDTH + 1 + EXP_BIAS) -
Expand Down Expand Up @@ -457,7 +459,7 @@ namespace hpx::parallel::detail::rfa {
if (binned_index0())
{
M = primary(0);
ftype qd = x * COMPRESSION;
ftype qd = x * static_cast<ftype>(COMPRESSION);
auto& ql = get_bits(qd);
ql |= 1;
qd += M;
Expand Down Expand Up @@ -550,7 +552,7 @@ namespace hpx::parallel::detail::rfa {
int i = 0;

if (ISNANINF(primary(0)))
return primary(0);
return (double) primary(0);
if (ISZERO(primary(0)))
return 0.0;

Expand All @@ -564,29 +566,36 @@ namespace hpx::parallel::detail::rfa {
{
scale_down = std::ldexp(0.5, 1 - (2 * MANT_DIG - BIN_WIDTH));
scale_up = std::ldexp(0.5, 1 + (2 * MANT_DIG - BIN_WIDTH));
scaled = std::max(
std::min(FOLD, (3 * MANT_DIG) / BIN_WIDTH - X_index), 0);
scaled = (std::max)(
(std::min)(FOLD, (3 * MANT_DIG) / BIN_WIDTH - X_index), 0);
if (X_index == 0)
{
Y += carry(0) * ((bins[0] / 6.0) * scale_down * EXPANSION);
Y += carry(inccarX) * ((bins[1] / 6.0) * scale_down);
Y += (primary(0) - bins[0]) * scale_down * EXPANSION;
Y += ((double) carry(0)) *
((((double) bins[0]) / 6.0) * scale_down * EXPANSION);
Y += ((double) carry(inccarX)) *
((((double) bins[1]) / 6.0) * scale_down);
Y += ((double) primary(0) - (double) bins[0]) * scale_down *
EXPANSION;
i = 2;
}
else
{
Y += carry(0) * ((bins[0] / 6.0) * scale_down);
Y += ((double) carry(0)) *
(((double) bins[0] / 6.0) * scale_down);
i = 1;
}
for (; i < scaled; i++)
{
Y += carry(i * inccarX) * ((bins[i] / 6.0) * scale_down);
Y +=
(primary((i - 1) * incpriX) - bins[i - 1]) * scale_down;
Y += ((double) carry(i * inccarX)) *
(((double) bins[i] / 6.0) * scale_down);
Y += ((double) primary((i - 1) * incpriX) -
(double) (bins[i - 1])) *
scale_down;
}
if (i == FOLD)
{
Y += (primary((FOLD - 1) * incpriX) - bins[FOLD - 1]) *
Y += ((double) primary((FOLD - 1) * incpriX) -
(double) (bins[FOLD - 1])) *
scale_down;
return Y * scale_up;
}
Expand All @@ -597,20 +606,23 @@ namespace hpx::parallel::detail::rfa {
Y *= scale_up;
for (; i < FOLD; i++)
{
Y += carry(i * inccarX) * (bins[i] / 6.0);
Y += primary((i - 1) * incpriX) - bins[i - 1];
Y += ((double) carry(i * inccarX)) *
((double) bins[i] / 6.0);
Y += (double) (primary((i - 1) * incpriX) - bins[i - 1]);
}
Y += primary((FOLD - 1) * incpriX) - bins[FOLD - 1];
Y += ((double) primary((FOLD - 1) * incpriX) -
((double) bins[FOLD - 1]));
}
else
{
Y += carry(0) * (bins[0] / 6.0);
Y += ((double) carry(0)) * ((double) bins[0] / 6.0);
for (i = 1; i < FOLD; i++)
{
Y += carry(i * inccarX) * (bins[i] / 6.0);
Y += (primary((i - 1) * incpriX) - bins[i - 1]);
Y += ((double) carry(i * inccarX)) *
((double) bins[i] / 6.0);
Y += (double) (primary((i - 1) * incpriX) - bins[i - 1]);
}
Y += (primary((FOLD - 1) * incpriX) - bins[FOLD - 1]);
Y += (double) (primary((FOLD - 1) * incpriX) - bins[FOLD - 1]);
}
return Y;
}
Expand All @@ -627,7 +639,7 @@ namespace hpx::parallel::detail::rfa {
if (ISNANINF(primary(0)))
return primary(0);
if (ISZERO(primary(0)))
return 0.0;
return 0.0f;

//Note that the following order of summation is in order of decreasing
//exponent. The following code is specific to SBWIDTH=13, FLT_MANT_DIG=24, and
Expand All @@ -636,20 +648,22 @@ namespace hpx::parallel::detail::rfa {
const auto* const bins = binned_bins(X_index);
if (X_index == 0)
{
Y += (double) carry(0) * (double) (bins[0] / 6.0) *
Y += (double) carry(0) * (double) (((double) bins[0]) / 6.0) *
(double) EXPANSION;
Y += (double) carry(inccarX) * (double) (bins[1] / 6.0);
Y += (double) carry(inccarX) *
(double) (((double) bins[1]) / 6.0);
Y += (double) (primary(0) - bins[0]) * (double) EXPANSION;
i = 2;
}
else
{
Y += (double) carry(0) * (double) (bins[0] / 6.0);
Y += (double) carry(0) * (double) (((double) bins[0]) / 6.0);
i = 1;
}
for (; i < FOLD; i++)
{
Y += (double) carry(i * inccarX) * (double) (bins[i] / 6.0);
Y += (double) carry(i * inccarX) *
(double) (((double) bins[i]) / 6.0);
Y += (double) (primary((i - 1) * incpriX) - bins[i - 1]);
}
Y += (double) (primary((FOLD - 1) * incpriX) - bins[FOLD - 1]);
Expand Down Expand Up @@ -867,11 +881,11 @@ namespace hpx::parallel::detail::rfa {
{
if (std::is_same_v<ftype, float>)
{
return binned_conv_single(1, 1);
return static_cast<ftype>(binned_conv_single(1, 1));
}
else
{
return binned_conv_double(1, 1);
return static_cast<ftype>(binned_conv_double(1, 1));
}
}

Expand All @@ -888,7 +902,8 @@ namespace hpx::parallel::detail::rfa {
{
const double X = std::abs(max_abs_val);
const double S = std::abs(binned_sum);
return static_cast<ftype>(max(X, std::ldexp(0.5, MIN_EXP - 1)) *
return static_cast<ftype>(
(std::max)(X, std::ldexp(0.5, MIN_EXP - 1)) *
std::ldexp(0.5, (1 - FOLD) * BIN_WIDTH + 1) * N +
((7.0 * EPSILON) /
(1.0 - 6.0 * std::sqrt(static_cast<double>(EPSILON)) -
Expand Down Expand Up @@ -973,7 +988,7 @@ namespace hpx::parallel::detail::rfa {
T max_abs_val = input[0];
for (size_t i = 0; i < N; i++)
{
max_abs_val = max(max_abs_val, std::abs(input[i]));
max_abs_val = (std::max)(max_abs_val, std::abs(input[i]));
}
add(input, N, max_abs_val);
}
Expand Down Expand Up @@ -1142,4 +1157,4 @@ namespace hpx::parallel::detail::rfa {
}
};

} // namespace hpx::parallel::detail::rfa
} // namespace hpx::parallel::detail::rfa
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/detail/rfa.hpp>
Expand All @@ -19,6 +17,7 @@
#include <limits>
#include <numeric>
#include <random>
#include <string>
#include <vector>

#include "test_utils.hpp"
Expand All @@ -27,8 +26,8 @@ int seed = std::random_device{}();
std::mt19937 gen(seed);

template <typename T>
T get_rand(
T LO = std::numeric_limits<T>::min(), T HI = std::numeric_limits<T>::max())
T get_rand(T LO = (std::numeric_limits<T>::min)(),
T HI = (std::numeric_limits<T>::max)())
{
return LO +
static_cast<T>(std::rand()) / (static_cast<T>(RAND_MAX / (HI - LO)));
Expand Down Expand Up @@ -75,8 +74,8 @@ void test_reduce1(IteratorTag)
FloatTypeNonDeterministic r3 = std::accumulate(
nondeterministic.begin(), nondeterministic.end(), val_non_det);

HPX_TEST_EQ(r1, r3);
HPX_TEST_EQ(r2, r3);
HPX_TEST_EQ(static_cast<FloatTypeNonDeterministic>(r1), r3);
HPX_TEST_EQ(static_cast<FloatTypeNonDeterministic>(r2), r3);
}

template <typename IteratorTag, typename FloatTypeDeterministic,
Expand Down

0 comments on commit 99b7ae9

Please sign in to comment.