Skip to content

Commit

Permalink
compress copy (scalar) (#1663)
Browse files Browse the repository at this point in the history
* compress copy tests
* compress copy scalar
  • Loading branch information
DenisYaroshevskiy authored Sep 5, 2023
1 parent 64441ad commit 1e3aed8
Show file tree
Hide file tree
Showing 16 changed files with 733 additions and 260 deletions.
7 changes: 3 additions & 4 deletions include/eve/detail/function/simd/common/to_logical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ to_logical(C c, eve::as<T>) noexcept
// represented. We then use an unsigned version of the index type.
// We don't just use unsigned indexes all the time cause on most cases,
// signed comparisons are faster and this will lead to pessimisation.
using i_t = std::conditional_t< (T::size()>=128 && sizeof(element_type_t<T>) == 1)
, as_integer_t<typename as_logical_t<T>::mask_type,unsigned>
, as_integer_t<typename as_logical_t<T>::mask_type>
>;
using i_t = std::conditional_t<(T::size() >= 128 && sizeof(element_type_t<l_t>) == 1),
typename l_t::bits_type,
as_integer_t<typename l_t::bits_type, signed>>;

if constexpr( std::same_as<C, ignore_all_> ) return l_t {false};
else if constexpr( std::same_as<C, ignore_none_> ) return l_t {true};
Expand Down
14 changes: 8 additions & 6 deletions include/eve/module/core/compress/compress_copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ namespace eve
//! * the ignored elements can are not loaded (same as load[ignore])
//! * they are treated as not selected, regardless of the mask value
//! 2nd is the output side ignore:
//! * elements that are ignored, will not be written. Example:
//! if the ignore_first(1) is passed, the first selected element
//! will not appear anywhere in the output and the 2nd selected
//! element will be written in (out + 1)
//! * elements that are ignored, will not be written.
//! having initial offset is equvialent to offeting the `o + offset`.
//! followed by keep_first(count)
//! Example:
//! if the `eve::ignore_extrema(1, L::size() - 2)` is passed,
//` the first selected element will be written at o + 1.
//! Defaults to 1st ignore.
//!
//! If the mask == true this and it's `unsafe` variation, this is the same behaviour as
Expand Down Expand Up @@ -95,7 +97,7 @@ namespace eve
//! typename I,
//! logical_simd_value L,
//! typename O>
//! autoo compress_copy
//! auto compress_copy
//! [safe/unsafe][sparse/dense]
//! [C1 ignore_in][C2 ignore_out](
//! I in,
Expand All @@ -107,7 +109,7 @@ namespace eve
//! typename I,
//! logical_simd_value L,
//! typename O>
//! autoo compress_copy
//! auto compress_copy
//! [safe/unsafe][sparse/dense]
//! [C1 ignore_in][C2 ignore_out](
//! I in,
Expand Down
94 changes: 94 additions & 0 deletions include/eve/module/core/compress/compress_copy_scalar.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/arch.hpp>
#include <eve/detail/overload.hpp>

namespace eve
{
EVE_REGISTER_CALLABLE(compress_copy_scalar_impl_)
EVE_DECLARE_CALLABLE(compress_copy_scalar_impl_, compress_copy_scalar_impl)

namespace detail
{
EVE_ALIAS_CALLABLE(compress_copy_scalar_impl_, compress_copy_scalar_impl);
}

EVE_CALLABLE_API(compress_copy_scalar_impl_, compress_copy_scalar_impl)
}

//================================================================================================
//! @addtogroup core_compress
//! @{
//! @var compress_copy_scalar
//! @brief One of the implementations for eve::compress_copy that relies on
//! only scalar reads/writes
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! @warning you should probably use eve::compress_copy.
//!
//! eve::compress_copy will either call this or eve::compress_copy_simd.
//! We believe eve::compress_copy makes correct selection of which one to use
//! but this is exposed in case we didn't.
//!
//! Api completly matches eve::compress_copy.
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace eve
//! {
//!
//! template <relative_conditional_expr C1,
//! relative_conditional_expr C2,
//! typename I,
//! logical_simd_value L,
//! typename O>
//! auto compress_copy_scalar
//! [safe/unsafe][sparse/dense]
//! [C1 ignore_in][C2 ignore_out](
//! I in,
//! L mask,
//! O out) -> unaligned_t<O>; // (1)
//!
//! template <relative_conditional_expr C1,
//! relative_conditional_expr C2,
//! typename I,
//! logical_simd_value L,
//! typename O>
//! auto compress_copy_scalar
//! [safe/unsafe][sparse/dense]
//! [C1 ignore_in][C2 ignore_out](
//! I in,
//! wide<value_type_t<I>, fixed<L::size()>> preloaded,
//! L mask,
//! O out) -> unaligned_t<O>; // (2)
//! }
//! @endcode
//!
//! **Parameters**
//!
//! @see eve::compress_copy
//!
//! **Return value**
//!
//! @see eve::compress_copy
//! @}
//================================================================================================

#include <eve/module/core/compress/simd/common/compress_copy_scalar.hpp>

#if defined(EVE_INCLUDE_SVE_HEADER)
# include <eve/module/core/compress/simd/arm/sve/compress_copy_scalar.hpp>
#endif
27 changes: 0 additions & 27 deletions include/eve/module/core/compress/detail/compress_copy_scalar.hpp

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/module/core/regular/logical_andnot.hpp>

namespace eve::detail
{

template <typename I, typename L, typename O>
EVE_FORCEINLINE O
compress_copy_sparse_sve_no_limits(I f, L m, O o)
{
if constexpr( has_aggregated_abi_v<L> )
{
auto [lo, hi] = m.slice();
o = compress_copy_sparse_sve_no_limits(f, lo, o);
return compress_copy_sparse_sve_no_limits(f + (L::size() / 2), hi, o);
}
else
{
while( any(m) )
{
L ignored_before = svbrka_z(sve_true<element_type_t<L>>(), m);
m = svbic_z(sve_true<element_type_t<L>>(), m, ignored_before);
auto cur = f + count_true(ignored_before) - 1;
eve::write(eve::read(cur), o++);
}
return o;
}
}

template <typename I, typename L, typename O>
EVE_FORCEINLINE O
compress_copy_sparse_sve_limited(I f, L m, O o, O limit)
{
if constexpr( has_aggregated_abi_v<L> )
{
auto [lo, hi] = m.slice();
o = compress_copy_sparse_sve_limited(f, lo, o, limit);
return compress_copy_sparse_sve_limited(f + (L::size() / 2), hi, o, limit);
}
else
{
while( any(m) )
{
if (o == limit) return o;
L ignored_before = svbrka_z(sve_true<element_type_t<L>>(), m);
m = svbic_z(sve_true<element_type_t<L>>(), m, ignored_before);
auto cur = f + count_true(ignored_before) - 1;
eve::write(eve::read(cur), o++);
}
return o;
}
}

template<typename Settings, typename I, typename L, typename O>
EVE_FORCEINLINE auto
compress_copy_scalar_impl_(EVE_SUPPORTS(sve_), Settings settings, I f, L m, O o) -> O
requires(Settings::is_sparse) //
{
using IC = typename Settings::cond_in_t;
using OC = typename Settings::cond_out_t;

if constexpr( L::size() < 4 )
{
return compress_copy_scalar_impl(
compress_callable_settings(settings.safety, dense, settings.c_in, settings.c_out), f, m, o);
}
else if constexpr( !IC::is_complete )
{
return compress_copy_scalar_impl(
compress_callable_settings(settings.safety, settings.density, ignore_none, settings.c_out),
f,
m && to_logical(settings.c_in, as(m)),
o);
}
else if constexpr ( !OC::is_complete )
{
o += settings.c_out.offset(eve::as(m));
O limit = o + settings.c_out.count(eve::as(m));
return compress_copy_sparse_sve_limited(f, m, o, limit);
}
else
{
return compress_copy_sparse_sve_no_limits(f, m, o);
}
}

}
Loading

0 comments on commit 1e3aed8

Please sign in to comment.