|
| 1 | +// REQUIRES: gpu |
| 2 | +// UNSUPPORTED: gpu-intel-gen9 && windows |
| 3 | +// UNSUPPORTED: cuda || hip || esimd_emulator |
| 4 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 5 | +// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER |
| 6 | + |
| 7 | +//==----------- spec_const_redefine.cpp ------------------------------==// |
| 8 | +// |
| 9 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 10 | +// See https://llvm.org/LICENSE.txt for license information. |
| 11 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | +// The test checks that ESIMD kernels support specialization constants, |
| 15 | +// particularly: |
| 16 | +// - a specialization constant can be redifined and correct new value is used |
| 17 | +// after redefinition. |
| 18 | +// - the program is JITted only once per a unique set of specialization |
| 19 | +// constants values. |
| 20 | + |
| 21 | +#include "../esimd_test_utils.hpp" |
| 22 | + |
| 23 | +#include <sycl/ext/intel/esimd.hpp> |
| 24 | +#include <sycl/sycl.hpp> |
| 25 | + |
| 26 | +#include <iostream> |
| 27 | +#include <vector> |
| 28 | + |
| 29 | +using namespace sycl; |
| 30 | + |
| 31 | +int val = 0; |
| 32 | + |
| 33 | +// Fetch a value at runtime. |
| 34 | +int get_value() { return val; } |
| 35 | + |
| 36 | +constexpr specialization_id<int32_t> SC0; |
| 37 | +constexpr specialization_id<int32_t> SC1; |
| 38 | + |
| 39 | +int main(int argc, char **argv) { |
| 40 | + val = argc; |
| 41 | + |
| 42 | + queue q(esimd_test::ESIMDSelector, esimd_test::createExceptionHandler()); |
| 43 | + |
| 44 | + auto dev = q.get_device(); |
| 45 | + std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; |
| 46 | + auto ctxt = q.get_context(); |
| 47 | + |
| 48 | + bool passed = true; |
| 49 | + int x = get_value(); |
| 50 | + |
| 51 | + const int sc_vals[][2] = { |
| 52 | + {1 + x, 2 + x}, |
| 53 | + {2 + x, 3 + x}, |
| 54 | + {1 + x, 2 + x}, // same as first - program in cache must be used |
| 55 | + {2 + x, 3 + x} // same as second - program in cache must be used |
| 56 | + }; |
| 57 | + constexpr int n_sc_sets = sizeof(sc_vals) / sizeof(sc_vals[0]); |
| 58 | + std::vector<int> vec(n_sc_sets); |
| 59 | + |
| 60 | + for (int i = 0; i < n_sc_sets; i++) { |
| 61 | + const int *sc_set = &sc_vals[i][0]; |
| 62 | + try { |
| 63 | + sycl::buffer<int, 1> buf(vec.data(), vec.size()); |
| 64 | + |
| 65 | + q.submit([&](sycl::handler &cgh) { |
| 66 | + cgh.set_specialization_constant<SC0>(-500); |
| 67 | + cgh.set_specialization_constant<SC1>(9999); |
| 68 | + cgh.set_specialization_constant<SC0>(sc_set[0]); |
| 69 | + cgh.set_specialization_constant<SC1>(sc_set[1]); |
| 70 | + auto acc = buf.get_access<sycl::access::mode::write>(cgh); |
| 71 | + cgh.single_task<class KernelAAA>( |
| 72 | + [=](kernel_handler kh) SYCL_ESIMD_KERNEL { |
| 73 | + auto SC0Val = kh.get_specialization_constant<SC0>(); |
| 74 | + auto SC1Val = kh.get_specialization_constant<SC1>(); |
| 75 | + sycl::ext::intel::esimd::scalar_store(acc, i * sizeof(int), |
| 76 | + SC0Val + SC1Val); |
| 77 | + }); |
| 78 | + }); |
| 79 | + } catch (sycl::exception &e) { |
| 80 | + std::cout << "*** Exception caught: " << e.what() << "\n"; |
| 81 | + return 1; |
| 82 | + } |
| 83 | + int val = vec[i]; |
| 84 | + int gold = sc_set[0] + sc_set[1]; |
| 85 | + |
| 86 | + std::cout << "val = " << val << " gold = " << gold << "\n"; |
| 87 | + |
| 88 | + if (val != gold) { |
| 89 | + std::cout << "*** ERROR[" << i << "]: " << val << " != " << gold |
| 90 | + << "(gold)\n"; |
| 91 | + passed = false; |
| 92 | + } |
| 93 | + } |
| 94 | + std::cout << (passed ? "passed\n" : "FAILED\n"); |
| 95 | + return passed ? 0 : 1; |
| 96 | +} |
| 97 | + |
| 98 | +// --- Check that only two JIT compilation happened: |
| 99 | +// CHECK-COUNT-2: ---> piProgramBuild |
| 100 | +// CHECK-NOT: ---> piProgramBuild |
| 101 | +// --- Check that the test completed with expected results: |
| 102 | +// CHECK: passed |
0 commit comments