|
| 1 | +//==---------------- wait.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 || hip |
| 10 | + |
| 11 | +// RUN: %clangxx -fsycl -fsycl-device-only -Xclang -emit-llvm -o %t.comp.ll %s |
| 12 | +// RUN: sycl-post-link -ir-output-only -lower-esimd -S %t.comp.ll -o %t.out.ll |
| 13 | +// RUN: FileCheck --input-file=%t.out.ll %s |
| 14 | + |
| 15 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 16 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 17 | + |
| 18 | +// This test verifies support of ext::intel::experimental::esimd::wait(). |
| 19 | +// The function is basically a NOP. It creates explicit scoreboard dependency |
| 20 | +// to avoid code motion across wait() and preserve the value computation even |
| 21 | +// if it is unused. |
| 22 | + |
| 23 | +#include "esimd_test_utils.hpp" |
| 24 | + |
| 25 | +#include <iostream> |
| 26 | +#include <sycl/ext/intel/esimd.hpp> |
| 27 | +#include <sycl/sycl.hpp> |
| 28 | + |
| 29 | +using namespace sycl; |
| 30 | +using namespace sycl::ext::intel::esimd; |
| 31 | +namespace iesimd = sycl::ext::intel::experimental::esimd; |
| 32 | + |
| 33 | +bool test(sycl::queue Q, int IArg = 128) { |
| 34 | + try { |
| 35 | + // Test case 1: check wait() with esimd::simd argument. |
| 36 | + Q.single_task([=]() SYCL_ESIMD_KERNEL { |
| 37 | + simd<int, 16> A = IArg; |
| 38 | + simd<int, 16> B = A * A; |
| 39 | + iesimd::wait(B); |
| 40 | + // CHECK: mul <16 x i32> |
| 41 | + // CHECK: llvm.genx.dummy.mov |
| 42 | + }).wait(); |
| 43 | + |
| 44 | + // Test case 2: check wait() with esimd::simd_view argument. |
| 45 | + Q.single_task([=]() SYCL_ESIMD_KERNEL { |
| 46 | + simd<int, 16> A = IArg; |
| 47 | + simd<int, 16> B = A * 17; |
| 48 | + auto BView = B.select<8, 2>(0); |
| 49 | + BView += 2; |
| 50 | + iesimd::wait(BView); |
| 51 | + // CHECK: mul <16 x i32> |
| 52 | + // CHECK: add <8 x i32> |
| 53 | + // CHECK: llvm.genx.dummy.mov |
| 54 | + }).wait(); |
| 55 | + |
| 56 | + // Test case 3: check wait() that prevesrves one simd and lets |
| 57 | + // optimize away the other/unused one. |
| 58 | + Q.single_task([=]() SYCL_ESIMD_KERNEL { |
| 59 | + simd<uint64_t, 8> A = IArg; |
| 60 | + auto B = A * 17; |
| 61 | + iesimd::wait(B); |
| 62 | + auto C = B * 17; |
| 63 | + // CHECK: mul <8 x i64> |
| 64 | + // CHECK-NOT: add <8 x i64> |
| 65 | + // CHECK: llvm.genx.dummy.mov |
| 66 | + // CHECK-NEXT: ret void |
| 67 | + }).wait(); |
| 68 | + } catch (sycl::exception const &e) { |
| 69 | + std::cout << "SYCL exception caught: " << e.what() << '\n'; |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + return true; |
| 74 | +} |
| 75 | + |
| 76 | +int main() { |
| 77 | + queue Q(esimd_test::ESIMDSelector, esimd_test::createExceptionHandler()); |
| 78 | + auto Dev = Q.get_device(); |
| 79 | + std::cout << "Running on " << Dev.get_info<info::device::name>() << std::endl; |
| 80 | + |
| 81 | + bool Passed = true; |
| 82 | + Passed &= test(Q); |
| 83 | + |
| 84 | + std::cout << (Passed ? "Test Passed\n" : "Test FAILED\n"); |
| 85 | + return Passed ? 0 : 1; |
| 86 | +} |
0 commit comments