This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[ESIMD] Add test for double GRF mode support. #1033
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| //==----------- double_grf.cpp - DPC++ ESIMD on-device test ---------------==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // This test verifies effect of | ||
| // set_kernel_properties(kernel_properties::use_double_grf); | ||
| // API call in device code: | ||
| // - ESIMD/SYCL splitting happens as usual | ||
| // - ESIMD module is further split into callgraphs for entry points requesting | ||
| // "double GRF" and callgraphs for entry points which are not | ||
| // - ESIMD device binary images requesting "double GRF" must be compiled with | ||
| // -doubleGRF option | ||
|
|
||
| // REQUIRES: gpu-intel-pvc | ||
| // UNSUPPORTED: cuda || hip | ||
| // TODO/FIXME: esimd_emulator does not support online compilation that | ||
| // invokes 'piProgramBuild'/'piKernelCreate' | ||
| // UNSUPPORTED: esimd_emulator | ||
| // RUN: %clangxx -fsycl %s -o %t.out | ||
| // RUN: env SYCL_PI_TRACE=-1 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER --check-prefixes=CHECK,CHECK-NO-VAR | ||
| // 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 | ||
|
|
||
| #include "esimd_test_utils.hpp" | ||
|
|
||
| #include <CL/sycl.hpp> | ||
| #include <iostream> | ||
| #include <sycl/ext/intel/esimd.hpp> | ||
|
|
||
| using namespace cl::sycl; | ||
| using namespace sycl::ext::intel::esimd; | ||
| using namespace sycl::ext::intel::experimental::esimd; | ||
|
|
||
| bool checkResult(const std::vector<float> &A, int Inc) { | ||
| int err_cnt = 0; | ||
| unsigned Size = A.size(); | ||
|
|
||
| for (unsigned i = 0; i < Size; ++i) { | ||
| if (A[i] != i + Inc) | ||
| if (++err_cnt < 10) | ||
| std::cerr << "failed at A[" << i << "]: " << A[i] << " != " << i + Inc | ||
| << "\n"; | ||
| } | ||
|
|
||
| if (err_cnt > 0) { | ||
| std::cout << " pass rate: " | ||
| << ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% (" | ||
| << (Size - err_cnt) << "/" << Size << ")\n"; | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| // Make the double GRF request from non-inlineable function - compiler should | ||
| // mark the caller kernel as "double GRF" anyway. | ||
| __attribute__((noinline)) void double_grf_marker() { | ||
| set_kernel_properties(kernel_properties::use_double_grf); | ||
| } | ||
|
|
||
| int main(void) { | ||
| constexpr unsigned Size = 32; | ||
| constexpr unsigned VL = 16; | ||
|
|
||
| std::vector<float> A(Size); | ||
|
|
||
| for (unsigned i = 0; i < Size; ++i) { | ||
| A[i] = i; | ||
| } | ||
|
|
||
| try { | ||
| buffer<float, 1> bufa(A.data(), range<1>(Size)); | ||
| queue q(gpu_selector{}, esimd_test::createExceptionHandler()); | ||
|
|
||
| auto dev = q.get_device(); | ||
| std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; | ||
|
|
||
| auto e = q.submit([&](handler &cgh) { | ||
| auto PA = bufa.get_access<access::mode::read_write>(cgh); | ||
| cgh.parallel_for<class SyclKernel>(Size, | ||
| [=](id<1> i) { PA[i] = PA[i] + 1; }); | ||
| }); | ||
| e.wait(); | ||
| } catch (cl::sycl::exception const &e) { | ||
| std::cout << "SYCL exception caught: " << e.what() << '\n'; | ||
| return 2; | ||
| } | ||
|
|
||
| if (checkResult(A, 1)) { | ||
| std::cout << "SYCL kernel passed\n"; | ||
| } else { | ||
| std::cout << "SYCL kernel failed\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| try { | ||
| buffer<float, 1> bufa(A.data(), range<1>(Size)); | ||
| queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler()); | ||
|
|
||
| auto dev = q.get_device(); | ||
| std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; | ||
|
|
||
| auto e = q.submit([&](handler &cgh) { | ||
| auto PA = bufa.get_access<access::mode::read_write>(cgh); | ||
| cgh.parallel_for<class EsimdKernel>(Size, [=](id<1> i) SYCL_ESIMD_KERNEL { | ||
| unsigned int offset = i * VL * sizeof(float); | ||
| simd<float, VL> va; | ||
| va.copy_from(PA, offset); | ||
| simd<float, VL> vc = va + 1; | ||
| vc.copy_to(PA, offset); | ||
| }); | ||
| }); | ||
| e.wait(); | ||
| } catch (cl::sycl::exception const &e) { | ||
| std::cout << "SYCL exception caught: " << e.what() << '\n'; | ||
| return 2; | ||
| } | ||
|
|
||
| if (checkResult(A, 2)) { | ||
| std::cout << "ESIMD kernel passed\n"; | ||
| } else { | ||
| std::cout << "ESIMD kernel failed\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| try { | ||
| buffer<float, 1> bufa(A.data(), range<1>(Size)); | ||
| queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler()); | ||
|
|
||
| auto dev = q.get_device(); | ||
| std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; | ||
|
|
||
| auto e = q.submit([&](handler &cgh) { | ||
| auto PA = bufa.get_access<access::mode::read_write>(cgh); | ||
| cgh.parallel_for<class EsimdKernelDoubleGRF>( | ||
| Size, [=](id<1> i) SYCL_ESIMD_KERNEL { | ||
| double_grf_marker(); | ||
| unsigned int offset = i * VL * sizeof(float); | ||
| simd<float, VL> va; | ||
| va.copy_from(PA, offset); | ||
| simd<float, VL> vc = va + 1; | ||
| vc.copy_to(PA, offset); | ||
| }); | ||
| }); | ||
| e.wait(); | ||
| } catch (cl::sycl::exception const &e) { | ||
| std::cout << "SYCL exception caught: " << e.what() << '\n'; | ||
| return 2; | ||
| } | ||
|
|
||
| if (checkResult(A, 3)) { | ||
| std::cout << "ESIMD double GRF kernel passed\n"; | ||
| } else { | ||
| std::cout << "ESIMD double GRF kernel failed\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| // Regular SYCL kernel is compiled without -vc-codegen option | ||
|
|
||
| // CHECK-LABEL: ---> piProgramBuild( | ||
| // CHECK-NOT: -vc-codegen | ||
| // CHECK-WITH-VAR: -g | ||
| // CHECK-NOT: -vc-codegen | ||
| // CHECK: ) ---> pi_result : PI_SUCCESS | ||
| // CHECK-LABEL: ---> piKernelCreate( | ||
| // CHECK: <const char *>: {{.*}}SyclKernel | ||
| // CHECK: ) ---> pi_result : PI_SUCCESS | ||
|
|
||
| // For ESIMD kernels, -vc-codegen option is always preserved, | ||
| // regardless of SYCL_PROGRAM_COMPILE_OPTIONS value. | ||
|
|
||
| // CHECK-LABEL: ---> piProgramBuild( | ||
| // CHECK-NO-VAR: -vc-codegen -disable-finalizer-msg | ||
| // CHECK-WITH-VAR: -g -vc-codegen -disable-finalizer-msg | ||
| // CHECK: ) ---> pi_result : PI_SUCCESS | ||
| // CHECK-LABEL: ---> piKernelCreate( | ||
| // CHECK: <const char *>: {{.*}}EsimdKernel | ||
| // CHECK: ) ---> pi_result : PI_SUCCESS | ||
|
|
||
| // Kernels requesting larger GRF are grouped into separate module and compiled | ||
| // with -doubleGRF regardless of SYCL_PROGRAM_COMPILE_OPTIONS value. | ||
|
|
||
| // CHECK-LABEL: ---> piProgramBuild( | ||
| // CHECK-NO-VAR: -vc-codegen -disable-finalizer-msg -doubleGRF | ||
| // CHECK-WITH-VAR: -g -vc-codegen -disable-finalizer-msg -doubleGRF | ||
| // CHECK: ) ---> pi_result : PI_SUCCESS | ||
| // CHECK-LABEL: ---> piKernelCreate( | ||
| // CHECK: <const char *>: {{.*}}EsimdKernelDoubleGRF | ||
| // CHECK: ) ---> pi_result : PI_SUCCESS | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor/non-blocking comment: