|
| 1 | +//==------- block_store.hpp - DPC++ ESIMD on-device test ----------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===-------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "common.hpp" |
| 10 | + |
| 11 | +using namespace sycl; |
| 12 | +using namespace sycl::ext::intel::esimd; |
| 13 | + |
| 14 | +template <typename T, uint16_t N, bool UseMask, bool UseProperties, |
| 15 | + typename StorePropertiesT> |
| 16 | +bool testUSM(queue Q, uint32_t Groups, uint32_t Threads, |
| 17 | + StorePropertiesT StoreProperties) { |
| 18 | + |
| 19 | + uint16_t Size = Groups * Threads * N; |
| 20 | + using Tuint = sycl::_V1::ext::intel::esimd::detail::uint_type_t<sizeof(T)>; |
| 21 | + |
| 22 | + std::cout << "USM case: T=" << esimd_test::type_name<T>() << ",N=" << N |
| 23 | + << ",UseMask=" << UseMask << ",UseProperties=" << UseProperties |
| 24 | + << std::endl; |
| 25 | + |
| 26 | + sycl::range<1> GlobalRange{Groups}; |
| 27 | + sycl::range<1> LocalRange{Threads}; |
| 28 | + sycl::nd_range<1> Range{GlobalRange * LocalRange, LocalRange}; |
| 29 | + constexpr size_t Alignment = getAlignment<T, N, UseMask>(StoreProperties); |
| 30 | + T *Out = sycl::aligned_alloc_shared<T>(Alignment, Size, Q); |
| 31 | + T Out_val = esimd_test::getRandomValue<T>(); |
| 32 | + for (int i = 0; i < Size; i++) |
| 33 | + Out[i] = Out_val; |
| 34 | + |
| 35 | + try { |
| 36 | + Q.submit([&](handler &cgh) { |
| 37 | + cgh.parallel_for(Range, [=](sycl::nd_item<1> ndi) SYCL_ESIMD_KERNEL { |
| 38 | + uint16_t GlobalID = ndi.get_global_id(0); |
| 39 | + uint32_t ElemOff = GlobalID * N; |
| 40 | + // TODO: these 2 lines work-around the problem with scalar |
| 41 | + // conversions to bfloat16. It could be just: "simd<T, N> |
| 42 | + // PassThru(ElemOffset, 1);" |
| 43 | + simd<uint32_t, N> PassThruInt(ElemOff, 1); |
| 44 | + simd<T, N> Vals = PassThruInt; |
| 45 | + if constexpr (UseMask) { |
| 46 | + simd_mask<1> Mask = (GlobalID + 1) % 1; |
| 47 | + block_store(Out + ElemOff, Vals, Mask, StorePropertiesT{}); |
| 48 | + Vals = block_load<T, N>(Out + ElemOff); |
| 49 | + Vals += 1; |
| 50 | + block_store(Out, ElemOff * sizeof(T), Vals, Mask, |
| 51 | + StorePropertiesT{}); |
| 52 | + Vals = block_load<T, N>(Out + ElemOff); |
| 53 | + Vals += 2; |
| 54 | + auto View = Vals.template select<N, 1>(); |
| 55 | + block_store<T, N>(Out, ElemOff * sizeof(T), View, Mask, |
| 56 | + StorePropertiesT{}); |
| 57 | + Vals = block_load<T, N>(Out + ElemOff); |
| 58 | + Vals += 3; |
| 59 | + View = Vals.template select<N, 1>(); |
| 60 | + block_store<T, N>(Out + ElemOff, View, Mask, StorePropertiesT{}); |
| 61 | + } else { |
| 62 | + if constexpr (UseProperties) |
| 63 | + block_store(Out + ElemOff, Vals, StorePropertiesT{}); |
| 64 | + |
| 65 | + else |
| 66 | + block_store(Out + ElemOff, Vals); |
| 67 | + |
| 68 | + Vals = block_load<T, N>(Out + ElemOff); |
| 69 | + Vals += 1; |
| 70 | + if constexpr (UseProperties) |
| 71 | + block_store(Out, ElemOff * sizeof(T), Vals, StorePropertiesT{}); |
| 72 | + else |
| 73 | + block_store(Out, ElemOff * sizeof(T), Vals); |
| 74 | + |
| 75 | + Vals = block_load<T, N>(Out + ElemOff); |
| 76 | + Vals += 2; |
| 77 | + auto View = Vals.template select<N, 1>(); |
| 78 | + if constexpr (UseProperties) |
| 79 | + block_store<T, N>(Out, ElemOff * sizeof(T), View, |
| 80 | + StorePropertiesT{}); |
| 81 | + else |
| 82 | + block_store<T, N>(Out, ElemOff * sizeof(T), View); |
| 83 | + |
| 84 | + Vals = block_load<T, N>(Out + ElemOff); |
| 85 | + Vals += 3; |
| 86 | + View = Vals.template select<N, 1>(); |
| 87 | + if constexpr (UseProperties) |
| 88 | + block_store<T, N>(Out + ElemOff, View, StorePropertiesT{}); |
| 89 | + else |
| 90 | + block_store<T, N>(Out + ElemOff, View); |
| 91 | + } |
| 92 | + }); |
| 93 | + }).wait(); |
| 94 | + } catch (sycl::exception const &e) { |
| 95 | + std::cout << "SYCL exception caught: " << e.what() << '\n'; |
| 96 | + sycl::free(Out, Q); |
| 97 | + return false; |
| 98 | + } |
| 99 | + |
| 100 | + bool Passed = true; |
| 101 | + |
| 102 | + for (int i = 0; i < Size; i++) { |
| 103 | + bool IsMaskSet = (i / N + 1) % 1; |
| 104 | + Tuint Expected = sycl::bit_cast<Tuint>(Out_val); |
| 105 | + if (!UseMask || IsMaskSet) |
| 106 | + Expected = sycl::bit_cast<Tuint>((T)(i + 6)); |
| 107 | + Tuint Computed = sycl::bit_cast<Tuint>(Out[i]); |
| 108 | + if (Computed != Expected) { |
| 109 | + Passed = false; |
| 110 | + std::cout << "Out[" << i << "] = " << std::to_string(Computed) << " vs " |
| 111 | + << std::to_string(Expected) << std::endl; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + sycl::free(Out, Q); |
| 116 | + |
| 117 | + return Passed; |
| 118 | +} |
| 119 | + |
| 120 | +template <typename T, bool TestPVCFeatures> bool test_block_store(queue Q) { |
| 121 | + constexpr bool CheckMask = true; |
| 122 | + constexpr bool CheckProperties = true; |
| 123 | + properties AlignOnlyProps{alignment<sizeof(T)>}; |
| 124 | + |
| 125 | + bool Passed = true; |
| 126 | + |
| 127 | + // Test block_store() that is available on Gen12 and PVC. |
| 128 | + Passed &= testUSM<T, 1, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 129 | + Passed &= testUSM<T, 2, !CheckMask, CheckProperties>(Q, 1, 4, AlignOnlyProps); |
| 130 | + Passed &= testUSM<T, 3, !CheckMask, CheckProperties>(Q, 2, 8, AlignOnlyProps); |
| 131 | + Passed &= testUSM<T, 4, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 132 | + Passed &= testUSM<T, 8, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 133 | + Passed &= |
| 134 | + testUSM<T, 16, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 135 | + Passed &= |
| 136 | + testUSM<T, 32, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 137 | + // Intentionally check non-power-of-2 simd size - it must work. |
| 138 | + Passed &= |
| 139 | + testUSM<T, 33, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 140 | + // TODO: Enable after failure fixed |
| 141 | + // Passed &= |
| 142 | + // testUSM<T, 67, !CheckMask, CheckProperties>(Q, 1, 4, AlignOnlyProps); |
| 143 | + // Intentionally check big simd size - it must work. |
| 144 | + Passed &= |
| 145 | + testUSM<T, 128, !CheckMask, CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 146 | + Passed &= |
| 147 | + testUSM<T, 256, !CheckMask, CheckProperties>(Q, 1, 4, AlignOnlyProps); |
| 148 | + |
| 149 | + // Test block_store() without passing compile-time properties argument. |
| 150 | + Passed &= |
| 151 | + testUSM<T, 16, !CheckMask, !CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 152 | + Passed &= |
| 153 | + testUSM<T, 32, !CheckMask, !CheckProperties>(Q, 2, 4, AlignOnlyProps); |
| 154 | + |
| 155 | + if constexpr (TestPVCFeatures) { |
| 156 | + // Using cache hints adds the requirement to run tests on PVC. |
| 157 | + // Also, PVC variant currently requires power-or-two elements and |
| 158 | + // the number of bytes loaded per call must not exceed 512. |
| 159 | + properties PVCProps{cache_hint_L1<cache_hint::write_back>, |
| 160 | + cache_hint_L2<cache_hint::write_back>, alignment<16>}; |
| 161 | + |
| 162 | + if constexpr (sizeof(T) >= 4) // only d/q words are supported now |
| 163 | + Passed &= testUSM<T, 1, !CheckMask, CheckProperties>(Q, 2, 4, PVCProps); |
| 164 | + if constexpr (sizeof(T) >= 2) // only d/q words are supported now |
| 165 | + Passed &= testUSM<T, 2, !CheckMask, CheckProperties>(Q, 5, 5, PVCProps); |
| 166 | + Passed &= testUSM<T, 4, !CheckMask, CheckProperties>(Q, 5, 5, PVCProps); |
| 167 | + Passed &= testUSM<T, 8, !CheckMask, CheckProperties>(Q, 5, 5, PVCProps); |
| 168 | + Passed &= testUSM<T, 16, CheckMask, CheckProperties>(Q, 5, 5, PVCProps); |
| 169 | + Passed &= testUSM<T, 32, !CheckMask, CheckProperties>(Q, 2, 4, PVCProps); |
| 170 | + Passed &= testUSM<T, 64, !CheckMask, CheckProperties>(Q, 7, 1, PVCProps); |
| 171 | + if constexpr (128 * sizeof(T) <= 512) |
| 172 | + Passed &= testUSM<T, 128, CheckMask, CheckProperties>(Q, 1, 4, PVCProps); |
| 173 | + if constexpr (256 * sizeof(T) <= 512) |
| 174 | + Passed &= testUSM<T, 256, CheckMask, CheckProperties>(Q, 1, 4, PVCProps); |
| 175 | + } // TestPVCFeatures |
| 176 | + |
| 177 | + return Passed; |
| 178 | +} |
0 commit comments