|
| 1 | +//==---------------- frem.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-INTEL-DRIVER: lin: 30623 |
| 9 | +// RUN: %{build} -fsycl-device-code-split=per_kernel -o %t.out |
| 10 | +// RUN: %{run} %t.out |
| 11 | + |
| 12 | +#include "esimd_test_utils.hpp" |
| 13 | + |
| 14 | +#include <cmath> |
| 15 | +#include <sycl/ext/intel/experimental/esimd/math.hpp> |
| 16 | + |
| 17 | +using namespace sycl; |
| 18 | + |
| 19 | +template <typename T> bool test(queue q) { |
| 20 | + std::cout << "Running case: T=" << esimd_test::type_name<T>() << std::endl; |
| 21 | + constexpr unsigned Size = 16; |
| 22 | + constexpr unsigned VL = 16; |
| 23 | + |
| 24 | + T *A = new T[Size]; |
| 25 | + T *B = new T[Size]; |
| 26 | + T *C = new T[Size]; |
| 27 | + |
| 28 | + for (unsigned i = 0; i < Size; ++i) { |
| 29 | + A[i] = i + 500; |
| 30 | + B[i] = i + 1; |
| 31 | + C[i] = 0.0f; |
| 32 | + } |
| 33 | + |
| 34 | + try { |
| 35 | + buffer<T, 1> bufa(A, range<1>(Size)); |
| 36 | + buffer<T, 1> bufb(B, range<1>(Size)); |
| 37 | + buffer<T, 1> bufc(C, range<1>(Size)); |
| 38 | + |
| 39 | + auto e = q.submit([&](handler &cgh) { |
| 40 | + auto PA = bufa.template get_access<access::mode::read>(cgh); |
| 41 | + auto PB = bufb.template get_access<access::mode::read>(cgh); |
| 42 | + auto PC = bufc.template get_access<access::mode::write>(cgh); |
| 43 | + cgh.single_task([=]() SYCL_ESIMD_KERNEL { |
| 44 | + using namespace sycl::ext::intel::esimd; |
| 45 | + unsigned int offset = 0; |
| 46 | + simd<T, VL> va; |
| 47 | + va.copy_from(PA, offset); |
| 48 | + simd<T, VL> vb; |
| 49 | + vb.copy_from(PB, offset); |
| 50 | + simd<T, VL> vc = ext::intel::experimental::esimd::frem(va, vb); |
| 51 | + vc.copy_to(PC, offset); |
| 52 | + }); |
| 53 | + }); |
| 54 | + e.wait(); |
| 55 | + } catch (sycl::exception const &e) { |
| 56 | + std::cout << "SYCL exception caught: " << e.what() << '\n'; |
| 57 | + |
| 58 | + delete[] A; |
| 59 | + delete[] B; |
| 60 | + delete[] C; |
| 61 | + return 0; |
| 62 | + } |
| 63 | + |
| 64 | + int err_cnt = 0; |
| 65 | + |
| 66 | + for (unsigned i = 0; i < Size; ++i) { |
| 67 | + T expected = std::remainder(A[i], B[i]); |
| 68 | + if (C[i] != expected) { |
| 69 | + if (++err_cnt < 10) { |
| 70 | + std::cout << "failed at index " << i << ", " << std::to_string(C[i]) |
| 71 | + << " != " << std::to_string(expected) << "\n"; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + if (err_cnt > 0) { |
| 76 | + std::cout << " pass rate: " |
| 77 | + << ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% (" |
| 78 | + << (Size - err_cnt) << "/" << Size << ")\n"; |
| 79 | + } |
| 80 | + |
| 81 | + delete[] A; |
| 82 | + delete[] B; |
| 83 | + delete[] C; |
| 84 | + |
| 85 | + std::cout << (err_cnt > 0 ? "FAILED\n" : "Passed\n"); |
| 86 | + return err_cnt == 0; |
| 87 | +} |
| 88 | + |
| 89 | +int main() { |
| 90 | + auto q = queue{gpu_selector_v}; |
| 91 | + esimd_test::printTestLabel(q); |
| 92 | + bool passed = true; |
| 93 | + |
| 94 | + passed &= test<float>(q); |
| 95 | + // TODO: Enable when driver issue fixed |
| 96 | +#if 0 |
| 97 | + if (q.get_device().has(sycl::aspect::fp64)) |
| 98 | + passed &= test<double>(q); |
| 99 | +#endif |
| 100 | + return passed ? 0 : 1; |
| 101 | +} |
0 commit comments