|
| 1 | +//==------- fp_args_size_common.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 | +// The test checks that ESIMD kernels support use of function pointers from main |
| 10 | +// function with different total arguments size and retval size. |
| 11 | +// Cases: |
| 12 | +// Total arguments size < %arg register size (32 GRFs) |
| 13 | +// Total arguments size == %arg register size |
| 14 | +// Total arguments size > %arg register size (i.e. stack mem is required) |
| 15 | +// Return value size < %retval register size (12 GRFs) |
| 16 | +// Return value size == %retval register size |
| 17 | +// Return value size > %retval register size |
| 18 | + |
| 19 | +#include "esimd_test_utils.hpp" |
| 20 | + |
| 21 | +#include <CL/sycl.hpp> |
| 22 | +#include <CL/sycl/INTEL/esimd.hpp> |
| 23 | +#include <iostream> |
| 24 | + |
| 25 | +static_assert(SIZE >= VL, "Size must greater than or equal to VL"); |
| 26 | +static_assert(SIZE % VL == 0, "Size must be multiple of VL"); |
| 27 | +constexpr unsigned ROWS = SIZE / VL; |
| 28 | + |
| 29 | +using namespace cl::sycl; |
| 30 | + |
| 31 | +class KernelID; |
| 32 | + |
| 33 | +template <typename TA, typename TB, typename TC> |
| 34 | +ESIMD_NOINLINE TC add(TA A, TB B) { |
| 35 | + return (TC)A + (TC)B; |
| 36 | +} |
| 37 | + |
| 38 | +int main(void) { |
| 39 | + queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler()); |
| 40 | + |
| 41 | + auto dev = q.get_device(); |
| 42 | + std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; |
| 43 | + auto ctx = q.get_context(); |
| 44 | + |
| 45 | + a_data_t *A = static_cast<a_data_t *>( |
| 46 | + sycl::malloc_shared(SIZE * sizeof(a_data_t), dev, ctx)); |
| 47 | + for (int i = 0; i < SIZE; i++) |
| 48 | + A[i] = (a_data_t)1; |
| 49 | + |
| 50 | + b_data_t *B = static_cast<b_data_t *>( |
| 51 | + sycl::malloc_shared(SIZE * sizeof(b_data_t), dev, ctx)); |
| 52 | + for (int i = 0; i < SIZE; i++) |
| 53 | + B[i] = (b_data_t)i; |
| 54 | + |
| 55 | + c_data_t *C = static_cast<c_data_t *>( |
| 56 | + sycl::malloc_shared(SIZE * sizeof(c_data_t), dev, ctx)); |
| 57 | + memset(C, 0, SIZE * sizeof(c_data_t)); |
| 58 | + |
| 59 | + try { |
| 60 | + auto qq = q.submit([&](handler &cgh) { |
| 61 | + cgh.parallel_for<KernelID>( |
| 62 | + sycl::range<1>{1}, [=](id<1> i) SYCL_ESIMD_KERNEL { |
| 63 | + using namespace sycl::INTEL::gpu; |
| 64 | + |
| 65 | + simd<a_data_t, SIZE> va(0); |
| 66 | + simd<b_data_t, SIZE> vb(0); |
| 67 | + for (int j = 0; j < ROWS; j++) { |
| 68 | + va.select<VL, 1>(j * VL) = block_load<a_data_t, VL>(A + j * VL); |
| 69 | + vb.select<VL, 1>(j * VL) = block_load<b_data_t, VL>(B + j * VL); |
| 70 | + } |
| 71 | + |
| 72 | + auto foo = &add<simd<a_data_t, SIZE>, simd<b_data_t, SIZE>, |
| 73 | + simd<c_data_t, SIZE>>; |
| 74 | + auto vc = foo(va, vb); |
| 75 | + |
| 76 | + for (int j = 0; j < ROWS; j++) |
| 77 | + block_store<c_data_t, VL>(C + j * VL, vc.select<VL, 1>(j * VL)); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + qq.wait(); |
| 82 | + } catch (cl::sycl::exception const &e) { |
| 83 | + std::cout << "SYCL exception caught: " << e.what() << std::endl; |
| 84 | + sycl::free(A, ctx); |
| 85 | + sycl::free(B, ctx); |
| 86 | + sycl::free(C, ctx); |
| 87 | + return e.get_cl_code(); |
| 88 | + } |
| 89 | + |
| 90 | + unsigned err_cnt = 0; |
| 91 | + for (int i = 0; i < SIZE; i++) |
| 92 | + if (C[i] != A[i] + B[i]) |
| 93 | + err_cnt++; |
| 94 | + |
| 95 | + sycl::free(A, ctx); |
| 96 | + sycl::free(B, ctx); |
| 97 | + sycl::free(C, ctx); |
| 98 | + |
| 99 | + if (err_cnt > 0) { |
| 100 | + std::cout << "FAILED" << std::endl; |
| 101 | + return 1; |
| 102 | + } |
| 103 | + |
| 104 | + std::cout << "passed" << std::endl; |
| 105 | + return 0; |
| 106 | +} |
0 commit comments