|
| 1 | +//==---------- store_zero_const.cpp - 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 | +// REQUIRES: gpu |
| 9 | +// UNSUPPORTED: cuda |
| 10 | +// RUN: %clangxx -fsycl -fsycl-device-code-split=per_kernel -I%S/.. %s -o %t.out |
| 11 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 12 | +// XFAIL: * |
| 13 | + |
| 14 | +// This is a regression for vector BE bug: |
| 15 | +// storing a constant zero through an USM pointer causes BE crash with |
| 16 | +// "error: unsupported type for load/store" message. |
| 17 | +// Use -fsycl-device-code-split=per_kernel so that each kernel's compilation |
| 18 | +// does not affect others. |
| 19 | + |
| 20 | +#include "esimd_test_utils.hpp" |
| 21 | + |
| 22 | +#include <CL/sycl.hpp> |
| 23 | +#include <CL/sycl/INTEL/esimd.hpp> |
| 24 | + |
| 25 | +#include <cstdint> |
| 26 | +#include <iostream> |
| 27 | + |
| 28 | +using namespace cl::sycl; |
| 29 | + |
| 30 | +template <typename T> bool test(queue Q) { |
| 31 | + std::cout << " Testing " << typeid(T).name() << "...\n"; |
| 32 | + auto Ctx = Q.get_context(); |
| 33 | + auto Dev = Q.get_device(); |
| 34 | + |
| 35 | + constexpr unsigned Size = 1024; |
| 36 | + constexpr unsigned VL = 32; |
| 37 | + constexpr unsigned GroupSize = 8; |
| 38 | + |
| 39 | + T *A = malloc_shared<T>(Size * sizeof(T), Dev, Ctx); |
| 40 | + |
| 41 | + cl::sycl::range<1> GlobalRange{Size / VL}; |
| 42 | + cl::sycl::range<1> LocalRange{GroupSize}; |
| 43 | + cl::sycl::nd_range<1> Range(GlobalRange, LocalRange); |
| 44 | + |
| 45 | +#define GOLD_VAL 0 |
| 46 | + |
| 47 | + try { |
| 48 | + auto E = Q.submit([&](handler &CGH) { |
| 49 | + CGH.parallel_for<T>(Range, [=](nd_item<1> Ndi) SYCL_ESIMD_KERNEL { |
| 50 | + using namespace sycl::ext::intel::experimental::esimd; |
| 51 | + int I = Ndi.get_global_id(0); |
| 52 | + for (auto Ind = 0; Ind < VL; ++Ind) { |
| 53 | + A[I * VL + Ind] = static_cast<T>(GOLD_VAL); |
| 54 | + } |
| 55 | + }); |
| 56 | + }); |
| 57 | + E.wait(); |
| 58 | + } catch (cl::sycl::exception const &E) { |
| 59 | + std::cout << "SYCL exception caught: " << E.what() << '\n'; |
| 60 | + return E.get_cl_code(); |
| 61 | + } |
| 62 | + int ErrCnt = 0; |
| 63 | + |
| 64 | + for (unsigned I = 0; I < Size; ++I) { |
| 65 | + if (A[I] != GOLD_VAL) { |
| 66 | + if (++ErrCnt < 10) { |
| 67 | + std::cout << "failed at index " << I << ": " << A[I] << "\n"; |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + if (ErrCnt > 0) { |
| 72 | + std::cout << " pass rate: " |
| 73 | + << ((float)(Size - ErrCnt) / (float)Size) * 100.0f << "% (" |
| 74 | + << (Size - ErrCnt) << "/" << Size << ")\n"; |
| 75 | + } |
| 76 | + std::cout << (ErrCnt > 0 ? "FAILED\n" : "Passed\n"); |
| 77 | + sycl::free(A, Q); |
| 78 | + |
| 79 | + return ErrCnt == 0; |
| 80 | +} |
| 81 | + |
| 82 | +int main(void) { |
| 83 | + queue Q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler()); |
| 84 | + auto Dev = Q.get_device(); |
| 85 | + std::cout << "Running on " << Dev.get_info<info::device::name>() << "\n"; |
| 86 | + |
| 87 | + bool Passed = 1; |
| 88 | + Passed &= test<unsigned char>(Q); |
| 89 | + Passed &= test<char>(Q); |
| 90 | + Passed &= test<unsigned short>(Q); |
| 91 | + Passed &= test<short>(Q); |
| 92 | + Passed &= test<unsigned int>(Q); |
| 93 | + Passed &= test<uint64_t>(Q); |
| 94 | + Passed &= test<int64_t>(Q); |
| 95 | + Passed &= test<float>(Q); |
| 96 | + Passed &= test<double>(Q); |
| 97 | + |
| 98 | + std::cout << (Passed ? "Passed\n" : "FAILED\n"); |
| 99 | + return Passed ? 0 : 1; |
| 100 | +} |
0 commit comments