Skip to content

Commit b49d27f

Browse files
authored
[ESIMD] Remove unused L1/L2 vars, add struct to add/replace align prop (#13310)
Signed-off-by: Klochkov, Vyacheslav N <[email protected]>
1 parent 27a3990 commit b49d27f

File tree

2 files changed

+48
-81
lines changed

2 files changed

+48
-81
lines changed

sycl/include/sycl/ext/intel/esimd/memory.hpp

Lines changed: 16 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,16 +1747,6 @@ block_load(AccessorT acc, detail::DeviceAccessorOffsetT byte_offset,
17471747
return block_load<T, N>(detail::accessorToPointer<T>(acc, byte_offset),
17481748
props);
17491749
#else // !__ESIMD_FORCE_STATELESS_MEM
1750-
constexpr auto L1Hint =
1751-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
1752-
cache_hint::none);
1753-
constexpr auto L2Hint =
1754-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
1755-
cache_hint::none);
1756-
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
1757-
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
1758-
"hint is cache_level::L2 now.");
1759-
17601750
// If the alignment property is not passed, then assume the pointer
17611751
// is element-aligned.
17621752
constexpr size_t DefaultAlignment = (sizeof(T) <= 4) ? 4 : sizeof(T);
@@ -1822,17 +1812,9 @@ __ESIMD_API std::enable_if_t<
18221812
block_load(AccessorT acc, PropertyListT /* props */ = {}) {
18231813
// Create new properties without the alignment property passed in 'props',
18241814
// and add alignment<16> as it is usable and most favourable in this case.
1825-
constexpr auto L1Hint =
1826-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
1827-
cache_hint::none);
1828-
constexpr auto L2Hint =
1829-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
1830-
cache_hint::none);
1831-
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
1832-
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
1833-
"hint is cache_level::L2 now.");
1834-
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
1835-
return block_load<T, N>(acc, 0, Props);
1815+
using NewPropertyListT =
1816+
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
1817+
return block_load<T, N>(acc, 0, NewPropertyListT{});
18361818
}
18371819

18381820
/// simd<T, N>
@@ -1877,18 +1859,8 @@ __ESIMD_API std::enable_if_t<
18771859
block_load(AccessorT acc, detail::DeviceAccessorOffsetT byte_offset,
18781860
simd_mask<1> pred, simd<T, N> pass_thru,
18791861
PropertyListT /* props */ = {}) {
1880-
constexpr auto L1Hint =
1881-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
1882-
cache_hint::none);
1883-
constexpr auto L2Hint =
1884-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
1885-
cache_hint::none);
1886-
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
1887-
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
1888-
"hint is cache_level::L2 now.");
1889-
18901862
// If the alignment property is not passed, then assume the byte_offset
1891-
// is element-aligned and is at leat 4-bytes.
1863+
// is element-aligned and is at least 4-bytes.
18921864
constexpr size_t DefaultAlignment = (sizeof(T) <= 4) ? 4 : sizeof(T);
18931865
using NewPropertyListT =
18941866
detail::add_alignment_property_t<PropertyListT, DefaultAlignment>;
@@ -1980,17 +1952,9 @@ block_load(AccessorT acc, simd_mask<1> pred, simd<T, N> pass_thru,
19801952
PropertyListT /* props */ = {}) {
19811953
// Create new properties without the alignment property passed in 'props',
19821954
// and add alignment<16> as it is usable and most favourable in this case.
1983-
constexpr auto L1Hint =
1984-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
1985-
cache_hint::none);
1986-
constexpr auto L2Hint =
1987-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
1988-
cache_hint::none);
1989-
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
1990-
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
1991-
"hint is cache_level::L2 now.");
1992-
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
1993-
return block_load<T, N>(acc, 0, pred, pass_thru, Props);
1955+
using NewPropertyListT =
1956+
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
1957+
return block_load<T, N>(acc, 0, pred, pass_thru, NewPropertyListT{});
19941958
}
19951959

19961960
/// simd<T, N>
@@ -2030,19 +1994,10 @@ __ESIMD_API std::enable_if_t<
20301994
block_load(AccessorT acc, simd_mask<1> pred, PropertyListT /* props */ = {}) {
20311995
// Create new properties without the alignment property passed in 'props',
20321996
// and add alignment<16> as it is usable and most favourable in this case.
2033-
constexpr auto L1Hint =
2034-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
2035-
cache_hint::none);
2036-
constexpr auto L2Hint =
2037-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
2038-
cache_hint::none);
2039-
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
2040-
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
2041-
"hint is cache_level::L2 now.");
2042-
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
2043-
1997+
using NewPropertyListT =
1998+
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
20441999
simd<T, N> PassThru; // Intentionally uninitialized.
2045-
return block_load<T, N>(acc, 0, pred, PassThru, Props);
2000+
return block_load<T, N>(acc, 0, pred, PassThru, NewPropertyListT{});
20462001
}
20472002

20482003
/// Each of the following block store functions stores a contiguous memory block
@@ -2398,14 +2353,9 @@ __ESIMD_API std::enable_if_t<
23982353
block_store(AccessorT acc, simd<T, N> vals, PropertyListT props = {}) {
23992354
// Create new properties without the alignment property passed in 'props',
24002355
// and add alignment<16> as it is usable and most favourable in this case.
2401-
constexpr auto L1Hint =
2402-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
2403-
cache_hint::none);
2404-
constexpr auto L2Hint =
2405-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
2406-
cache_hint::none);
2407-
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
2408-
block_store<T, N>(acc, 0, vals, Props);
2356+
using NewPropertyListT =
2357+
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
2358+
block_store<T, N>(acc, 0, vals, NewPropertyListT{});
24092359
}
24102360

24112361
/// void block_store(AccessorT acc, OffsetT byte_offset, // (acc-bs-3)
@@ -2490,14 +2440,9 @@ block_store(AccessorT acc, simd<T, N> vals, simd_mask<1> pred,
24902440
PropertyListT props = {}) {
24912441
// Create new properties without the alignment property passed in 'props',
24922442
// and add alignment<16> as it is usable and most favourable in this case.
2493-
constexpr auto L1Hint =
2494-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
2495-
cache_hint::none);
2496-
constexpr auto L2Hint =
2497-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
2498-
cache_hint::none);
2499-
properties Props{cache_hint_L1<L1Hint>, cache_hint_L2<L2Hint>, alignment<16>};
2500-
block_store<T, N>(acc, 0, vals, pred, Props);
2443+
using NewPropertyListT =
2444+
detail::add_or_replace_alignment_property_t<PropertyListT, 16>;
2445+
block_store<T, N>(acc, 0, vals, pred, NewPropertyListT{});
25012446
}
25022447

25032448
/// @} sycl_esimd_memory_block
@@ -7168,16 +7113,6 @@ atomic_update(AccessorTy acc, simd<Toffset, N> byte_offset, simd_mask<N> mask,
71687113
return atomic_update<Op, T, N>(__ESIMD_DNS::accessorToPointer<T>(acc),
71697114
byte_offset, mask, props);
71707115
#else
7171-
constexpr auto L1Hint =
7172-
detail::getPropertyValue<PropertyListT, cache_hint_L1_key>(
7173-
cache_hint::none);
7174-
constexpr auto L2Hint =
7175-
detail::getPropertyValue<PropertyListT, cache_hint_L2_key>(
7176-
cache_hint::none);
7177-
static_assert(!PropertyListT::template has_property<cache_hint_L3_key>(),
7178-
"L3 cache hint is reserved. The old/experimental L3 LSC cache "
7179-
"hint is cache_level::L2 now.");
7180-
71817116
static_assert(std::is_integral_v<Toffset>, "Unsupported offset type");
71827117

71837118
if constexpr (detail::has_cache_hints<PropertyListT>() ||

sycl/include/sycl/ext/intel/esimd/memory_properties.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,38 @@ template <typename PropertyListT, size_t Alignment>
230230
using add_alignment_property_t =
231231
typename add_alignment_property<PropertyListT, Alignment>::type;
232232

233+
// Removes the 'alignment' property from 'PropertyListT' if it is there.
234+
// Otherwise, keeps the 'PropertyListT' without changes.
235+
template <typename PropertyListT> struct remove_alignment_property {
236+
using type = PropertyListT;
237+
};
238+
template <size_t Alignment, typename... LastTs>
239+
struct remove_alignment_property<
240+
properties<std::tuple<alignment_key::value_t<Alignment>, LastTs...>>> {
241+
using type = properties<std::tuple<LastTs...>>;
242+
};
243+
template <typename FirstT, size_t Alignment, typename... LastTs>
244+
struct remove_alignment_property<properties<
245+
std::tuple<FirstT, alignment_key::value_t<Alignment>, LastTs...>>> {
246+
using type = properties<std::tuple<FirstT, LastTs...>>;
247+
};
248+
template <typename PropertyListT>
249+
using remove_alignment_property_t =
250+
typename remove_alignment_property<PropertyListT>::type;
251+
252+
// Creates and adds a compile-time property 'alignment<Alignment>' to the given
253+
// property list 'PropertyListT'. If 'alignment' property was already in
254+
// 'PropertyListT', then it is replaced with a new one - `alignment<Alignment>`.
255+
template <typename PropertyListT, size_t Alignment>
256+
struct add_or_replace_alignment_property {
257+
using type =
258+
add_alignment_property_t<remove_alignment_property_t<PropertyListT>,
259+
Alignment>;
260+
};
261+
template <typename PropertyListT, size_t Alignment>
262+
using add_or_replace_alignment_property_t =
263+
typename add_or_replace_alignment_property<PropertyListT, Alignment>::type;
264+
233265
// Creates the type for the list of L1, L2, and alignment properties.
234266
template <cache_hint L1H, cache_hint L2H, size_t Alignment>
235267
struct make_L1_L2_alignment_properties {

0 commit comments

Comments
 (0)