Skip to content

[ESIMD] Remove unused L1/L2 vars, add struct to add/replace align prop #13310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 16 additions & 81 deletions sycl/include/sycl/ext/intel/esimd/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,16 +1747,6 @@ block_load(AccessorT acc, detail::DeviceAccessorOffsetT byte_offset,
return block_load<T, N>(detail::accessorToPointer<T>(acc, byte_offset),
props);
#else // !__ESIMD_FORCE_STATELESS_MEM
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
"hint is cache_level::L2 now.");

// If the alignment property is not passed, then assume the pointer
// is element-aligned.
constexpr size_t DefaultAlignment = (sizeof(T) <= 4) ? 4 : sizeof(T);
Expand Down Expand Up @@ -1822,17 +1812,9 @@ __ESIMD_API std::enable_if_t<
block_load(AccessorT acc, PropertyListT /* props */ = {}) {
// Create new properties without the alignment property passed in 'props',
// and add alignment<16> as it is usable and most favourable in this case.
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
"hint is cache_level::L2 now.");
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
return block_load<T, N>(acc, 0, Props);
using NewPropertyListT =
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
return block_load<T, N>(acc, 0, NewPropertyListT{});
}

/// simd<T, N>
Expand Down Expand Up @@ -1877,18 +1859,8 @@ __ESIMD_API std::enable_if_t<
block_load(AccessorT acc, detail::DeviceAccessorOffsetT byte_offset,
simd_mask<1> pred, simd<T, N> pass_thru,
PropertyListT /* props */ = {}) {
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
"hint is cache_level::L2 now.");

// If the alignment property is not passed, then assume the byte_offset
// is element-aligned and is at leat 4-bytes.
// is element-aligned and is at least 4-bytes.
constexpr size_t DefaultAlignment = (sizeof(T) <= 4) ? 4 : sizeof(T);
using NewPropertyListT =
detail::add_alignment_property_t<PropertyListT, DefaultAlignment>;
Expand Down Expand Up @@ -1980,17 +1952,9 @@ block_load(AccessorT acc, simd_mask<1> pred, simd<T, N> pass_thru,
PropertyListT /* props */ = {}) {
// Create new properties without the alignment property passed in 'props',
// and add alignment<16> as it is usable and most favourable in this case.
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
"hint is cache_level::L2 now.");
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
return block_load<T, N>(acc, 0, pred, pass_thru, Props);
using NewPropertyListT =
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
return block_load<T, N>(acc, 0, pred, pass_thru, NewPropertyListT{});
}

/// simd<T, N>
Expand Down Expand Up @@ -2030,19 +1994,10 @@ __ESIMD_API std::enable_if_t<
block_load(AccessorT acc, simd_mask<1> pred, PropertyListT /* props */ = {}) {
// Create new properties without the alignment property passed in 'props',
// and add alignment<16> as it is usable and most favourable in this case.
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
"hint is cache_level::L2 now.");
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};

using NewPropertyListT =
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
simd<T, N> PassThru; // Intentionally uninitialized.
return block_load<T, N>(acc, 0, pred, PassThru, Props);
return block_load<T, N>(acc, 0, pred, PassThru, NewPropertyListT{});
}

/// Each of the following block store functions stores a contiguous memory block
Expand Down Expand Up @@ -2398,14 +2353,9 @@ __ESIMD_API std::enable_if_t<
block_store(AccessorT acc, simd<T, N> vals, PropertyListT props = {}) {
// Create new properties without the alignment property passed in 'props',
// and add alignment<16> as it is usable and most favourable in this case.
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
block_store<T, N>(acc, 0, vals, Props);
using NewPropertyListT =
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
block_store<T, N>(acc, 0, vals, NewPropertyListT{});
}

/// void block_store(AccessorT acc, OffsetT byte_offset, // (acc-bs-3)
Expand Down Expand Up @@ -2490,14 +2440,9 @@ block_store(AccessorT acc, simd<T, N> vals, simd_mask<1> pred,
PropertyListT props = {}) {
// Create new properties without the alignment property passed in 'props',
// and add alignment<16> as it is usable and most favourable in this case.
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
block_store<T, N>(acc, 0, vals, pred, Props);
using NewPropertyListT =
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
block_store<T, N>(acc, 0, vals, pred, NewPropertyListT{});
}

/// @} sycl_esimd_memory_block
Expand Down Expand Up @@ -7168,16 +7113,6 @@ atomic_update(AccessorTy acc, simd<Toffset, N> byte_offset, simd_mask<N> mask,
return atomic_update<Op, T, N>(__ESIMD_DNS::accessorToPointer<T>(acc),
byte_offset, mask, props);
#else
constexpr auto L1Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
cache_hint::none);
constexpr auto L2Hint =
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
cache_hint::none);
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
"hint is cache_level::L2 now.");

static_assert(std::is_integral_v<Toffset>, "Unsupported offset type");

if constexpr (detail::has_cache_hints<PropertyListT>() ||
Expand Down
32 changes: 32 additions & 0 deletions sycl/include/sycl/ext/intel/esimd/memory_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,38 @@ template <typename PropertyListT, size_t Alignment>
using add_alignment_property_t =
typename add_alignment_property<PropertyListT, Alignment>::type;

// Removes the 'alignment' property from 'PropertyListT' if it is there.
// Otherwise, keeps the 'PropertyListT' without changes.
template <typename PropertyListT> struct remove_alignment_property {
using type = PropertyListT;
};
template <size_t Alignment, typename... LastTs>
struct remove_alignment_property<
properties<std::tuple<alignment_key::value_t<Alignment>, LastTs...>>> {
using type = properties<std::tuple<LastTs...>>;
};
template <typename FirstT, size_t Alignment, typename... LastTs>
struct remove_alignment_property<properties<
std::tuple<FirstT, alignment_key::value_t<Alignment>, LastTs...>>> {
using type = properties<std::tuple<FirstT, LastTs...>>;
};
template <typename PropertyListT>
using remove_alignment_property_t =
typename remove_alignment_property<PropertyListT>::type;

// Creates and adds a compile-time property 'alignment<Alignment>' to the given
// property list 'PropertyListT'. If 'alignment' property was already in
// 'PropertyListT', then it is replaced with a new one - `alignment<Alignment>`.
template <typename PropertyListT, size_t Alignment>
struct add_or_replace_alignment_property {
using type =
add_alignment_property_t<remove_alignment_property_t<PropertyListT>,
Alignment>;
};
template <typename PropertyListT, size_t Alignment>
using add_or_replace_alignment_property_t =
typename add_or_replace_alignment_property<PropertyListT, Alignment>::type;

// Creates the type for the list of L1, L2, and alignment properties.
template <cache_hint L1H, cache_hint L2H, size_t Alignment>
struct make_L1_L2_alignment_properties {
Expand Down