|
| 1 | +// REQUIRES: gpu |
| 2 | +// UNSUPPORTED: cuda || hip |
| 3 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 4 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 5 | + |
| 6 | +// This test checks that if specialization constant is set but not used, then |
| 7 | +// 1) The kernel still works properly; |
| 8 | +// 2) The kernel parameter holding the buffer for specialization constants is |
| 9 | +// optimized away. |
| 10 | +// TODO: the second part of the check should be added to this test when |
| 11 | +// DAE (Dead Arguments Elimination) optimization is enabled for ESIMD. |
| 12 | + |
| 13 | +#include <CL/sycl.hpp> |
| 14 | +#include <iostream> |
| 15 | +#include <sycl/ext/intel/esimd.hpp> |
| 16 | + |
| 17 | +constexpr sycl::specialization_id<int> Spec; |
| 18 | + |
| 19 | +int main() { |
| 20 | + sycl::queue Q; |
| 21 | + std::cout << "Running on: " |
| 22 | + << Q.get_device().get_info<sycl::info::device::name>() << std::endl; |
| 23 | + |
| 24 | + int *A = sycl::malloc_shared<int>(1, Q); |
| 25 | + *A = 123; |
| 26 | + Q.submit([&](sycl::handler &CGH) { |
| 27 | + CGH.set_specialization_constant<Spec>(42); |
| 28 | + CGH.single_task([=](sycl::kernel_handler KH) SYCL_ESIMD_KERNEL { |
| 29 | + // This use of get_specializaiton_constant is commented out. |
| 30 | + // Thus the device code doen't have info about it and cannot allocate |
| 31 | + // memory/buffer for it on device side. |
| 32 | + // The test checks that the unused kernel parameter is either |
| 33 | + // eliminated by DAE optimization OR nullptr is passed for that argument. |
| 34 | + |
| 35 | + // KH.get_specialization_constant<Spec>(); |
| 36 | + sycl::ext::intel::esimd::simd<int, 1> V(A); |
| 37 | + V += 2; |
| 38 | + V.copy_to(A); |
| 39 | + }); |
| 40 | + }).wait(); |
| 41 | + |
| 42 | + int AVal = *A; |
| 43 | + sycl::free(A, Q); |
| 44 | + |
| 45 | + if (AVal != 125) { |
| 46 | + std::cout << "Failed: " << AVal << " != 125" << std::endl; |
| 47 | + return 1; |
| 48 | + } |
| 49 | + std::cout << "Passed" << std::endl; |
| 50 | + return 0; |
| 51 | +} |
0 commit comments