|
| 1 | +//==----------- double-grf.cpp - DPC++ SYCL 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 | +// This test verifies effect of |
| 9 | +// set_kernel_properties(kernel_properties::use_double_grf); |
| 10 | +// API call in device code: |
| 11 | +// - ESIMD/SYCL splitting happens as usual |
| 12 | +// - SYCL module is further split into callgraphs for entry points requesting |
| 13 | +// "double GRF" and callgraphs for entry points which are not |
| 14 | +// - SYCL device binary images requesting "double GRF" must be compiled with |
| 15 | +// -ze-opt-large-register-file option |
| 16 | + |
| 17 | +// REQUIRES: gpu-intel-pvc |
| 18 | +// UNSUPPORTED: cuda || hip |
| 19 | +// TODO/FIXME: esimd_emulator does not support online compilation that |
| 20 | +// invokes 'piProgramBuild'/'piKernelCreate' |
| 21 | +// UNSUPPORTED: esimd_emulator |
| 22 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 23 | +// RUN: env SYCL_PI_TRACE=-1 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER --check-prefixes=CHECK,CHECK-NO-VAR |
| 24 | +// RUN: env SYCL_PROGRAM_COMPILE_OPTIONS="-g" SYCL_PI_TRACE=-1 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER --check-prefixes=CHECK,CHECK-WITH-VAR |
| 25 | + |
| 26 | +#include "../helpers.hpp" |
| 27 | +#include <iostream> |
| 28 | +#include <sycl/ext/intel/experimental/kernel_properties.hpp> |
| 29 | +#include <sycl/sycl.hpp> |
| 30 | + |
| 31 | +using namespace sycl; |
| 32 | +using namespace sycl::ext::intel::experimental; |
| 33 | + |
| 34 | +bool checkResult(const std::vector<float> &A, int Inc) { |
| 35 | + int err_cnt = 0; |
| 36 | + unsigned Size = A.size(); |
| 37 | + |
| 38 | + for (unsigned i = 0; i < Size; ++i) { |
| 39 | + if (A[i] != i + Inc) |
| 40 | + if (++err_cnt < 10) |
| 41 | + std::cerr << "failed at A[" << i << "]: " << A[i] << " != " << i + Inc |
| 42 | + << "\n"; |
| 43 | + } |
| 44 | + |
| 45 | + if (err_cnt > 0) { |
| 46 | + std::cout << " pass rate: " |
| 47 | + << ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% (" |
| 48 | + << (Size - err_cnt) << "/" << Size << ")\n"; |
| 49 | + return false; |
| 50 | + } |
| 51 | + return true; |
| 52 | +} |
| 53 | + |
| 54 | +// Make the double GRF request from non-inlineable function - compiler should |
| 55 | +// mark the caller kernel as "double GRF" anyway. |
| 56 | +__attribute__((noinline)) void double_grf_marker() { |
| 57 | + set_kernel_properties(kernel_properties::use_double_grf); |
| 58 | +} |
| 59 | + |
| 60 | +int main(void) { |
| 61 | + constexpr unsigned Size = 32; |
| 62 | + constexpr unsigned VL = 16; |
| 63 | + |
| 64 | + std::vector<float> A(Size); |
| 65 | + |
| 66 | + for (unsigned i = 0; i < Size; ++i) { |
| 67 | + A[i] = i; |
| 68 | + } |
| 69 | + |
| 70 | + try { |
| 71 | + buffer<float, 1> bufa(A.data(), range<1>(Size)); |
| 72 | + queue q(sycl::gpu_selector_v, exceptionHandlerHelper); |
| 73 | + |
| 74 | + auto dev = q.get_device(); |
| 75 | + std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; |
| 76 | + |
| 77 | + auto e = q.submit([&](handler &cgh) { |
| 78 | + auto PA = bufa.get_access<access::mode::read_write>(cgh); |
| 79 | + cgh.parallel_for<class SYCLKernelSingleGRF>(Size, |
| 80 | + [=](id<1> i) { PA[i] += 2; }); |
| 81 | + }); |
| 82 | + e.wait(); |
| 83 | + } catch (sycl::exception const &e) { |
| 84 | + std::cout << "SYCL exception caught: " << e.what() << '\n'; |
| 85 | + return 2; |
| 86 | + } |
| 87 | + |
| 88 | + if (checkResult(A, 2)) { |
| 89 | + std::cout << "SingleGRF kernel passed\n"; |
| 90 | + } else { |
| 91 | + std::cout << "SingleGRF kernel failed\n"; |
| 92 | + return 1; |
| 93 | + } |
| 94 | + |
| 95 | + try { |
| 96 | + buffer<float, 1> bufa(A.data(), range<1>(Size)); |
| 97 | + queue q(sycl::gpu_selector_v, exceptionHandlerHelper); |
| 98 | + |
| 99 | + auto dev = q.get_device(); |
| 100 | + std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; |
| 101 | + |
| 102 | + auto e = q.submit([&](handler &cgh) { |
| 103 | + auto PA = bufa.get_access<access::mode::read_write>(cgh); |
| 104 | + cgh.parallel_for<class SYCLKernelDoubleGRF>(Size, [=](id<1> i) { |
| 105 | + double_grf_marker(); |
| 106 | + PA[i] += 2; |
| 107 | + }); |
| 108 | + }); |
| 109 | + e.wait(); |
| 110 | + } catch (sycl::exception const &e) { |
| 111 | + std::cout << "SYCL exception caught: " << e.what() << '\n'; |
| 112 | + return 2; |
| 113 | + } |
| 114 | + |
| 115 | + if (checkResult(A, 4)) { |
| 116 | + std::cout << "DoubleGRF kernel passed\n"; |
| 117 | + } else { |
| 118 | + std::cout << "DoubleGRF kernel failed\n"; |
| 119 | + return 1; |
| 120 | + } |
| 121 | + |
| 122 | + return 0; |
| 123 | +} |
| 124 | + |
| 125 | +// CHECK-LABEL: ---> piProgramBuild( |
| 126 | +// CHECK-NOT: -ze-opt-large-register-file |
| 127 | +// CHECK-WITH-VAR: -g |
| 128 | +// CHECK: ) ---> pi_result : PI_SUCCESS |
| 129 | +// CHECK-LABEL: ---> piKernelCreate( |
| 130 | +// CHECK: <const char *>: {{.*}}SingleGRF |
| 131 | +// CHECK: ) ---> pi_result : PI_SUCCESS |
| 132 | + |
| 133 | +// CHECK-LABEL: ---> piProgramBuild( |
| 134 | +// CHECK-NO-VAR: -ze-opt-large-register-file |
| 135 | +// CHECK-WITH-VAR: -g -ze-opt-large-register-file |
| 136 | +// CHECK: ) ---> pi_result : PI_SUCCESS |
| 137 | +// CHECK-LABEL: ---> piKernelCreate( |
| 138 | +// CHECK: <const char *>: {{.*}}DoubleGRF |
| 139 | +// CHECK: ) ---> pi_result : PI_SUCCESS |
0 commit comments