|
| 1 | +//==---------------- hardware_dispatch.cpp - ESIMD hardware dispatch 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 | +// UNSUPPORTED: esimd_emulator |
| 11 | +// RUN: %clangxx -fsycl -fsycl-targets=intel_gpu_bdw %s -o %t.out |
| 12 | +// RUN: %t.out |
| 13 | +// TODO: remove XFAIL when the fix in GPU RT is pulled into CI |
| 14 | +// XFAIL: * |
| 15 | +// This is basic test to test hardware dispatch functionality with ESIMD. |
| 16 | + |
| 17 | +#include <iostream> |
| 18 | +#include <sycl/ext/intel/esimd.hpp> |
| 19 | +#include <sycl/ext/intel/esimd/simd.hpp> |
| 20 | +#include <sycl/ext/oneapi/experimental/device_architecture.hpp> |
| 21 | +#include <sycl/sycl.hpp> |
| 22 | +#include <vector> |
| 23 | + |
| 24 | +using shared_allocator = sycl::usm_allocator<int32_t, sycl::usm::alloc::shared>; |
| 25 | +using shared_vector = std::vector<int32_t, shared_allocator>; |
| 26 | +using namespace sycl::ext::intel::esimd; |
| 27 | + |
| 28 | +int main() { |
| 29 | + sycl::queue q; |
| 30 | + shared_allocator allocator(q); |
| 31 | + |
| 32 | + shared_vector vec(4, allocator); |
| 33 | + { |
| 34 | + q.submit([&](sycl::handler &cgh) { |
| 35 | + int *output_ptr = vec.data(); |
| 36 | + cgh.single_task<class test1>([=]() SYCL_ESIMD_KERNEL { |
| 37 | + simd<int, 4> result; |
| 38 | + |
| 39 | + // test if_architecture_is |
| 40 | + sycl::ext::oneapi::experimental::if_architecture_is< |
| 41 | + sycl::ext::oneapi::experimental::architecture::intel_gpu_bdw>( |
| 42 | + [&]() { result[0] = 1; }) |
| 43 | + .otherwise([&]() { result[0] = 0; }); |
| 44 | + |
| 45 | + // test else_if_architecture_is |
| 46 | + sycl::ext::oneapi::experimental::if_architecture_is< |
| 47 | + sycl::ext::oneapi::experimental::architecture::intel_gpu_dg1>( |
| 48 | + [&]() { result[1] = 0; }) |
| 49 | + .else_if_architecture_is< |
| 50 | + sycl::ext::oneapi::experimental::architecture::intel_gpu_bdw>( |
| 51 | + [&]() { result[1] = 2; }) |
| 52 | + .otherwise([&]() { result[1] = 0; }); |
| 53 | + |
| 54 | + // test otherwise |
| 55 | + sycl::ext::oneapi::experimental::if_architecture_is< |
| 56 | + sycl::ext::oneapi::experimental::architecture::intel_gpu_dg1>( |
| 57 | + [&]() { result[2] = 0; }) |
| 58 | + .otherwise([&]() { result[2] = 3; }); |
| 59 | + |
| 60 | + // test more than one architecture template parameter is passed to |
| 61 | + // if_architecture_is |
| 62 | + sycl::ext::oneapi::experimental::if_architecture_is< |
| 63 | + sycl::ext::oneapi::experimental::architecture::intel_gpu_dg1, |
| 64 | + sycl::ext::oneapi::experimental::architecture::intel_gpu_bdw>( |
| 65 | + [&]() { result[3] = 4; }) |
| 66 | + .otherwise([&]() { result[3] = 0; }); |
| 67 | + result.copy_to(output_ptr); |
| 68 | + }); |
| 69 | + }); |
| 70 | + } |
| 71 | + q.wait(); |
| 72 | + |
| 73 | + for (int i = 0; i < 4; ++i) { |
| 74 | + if (vec[i] != i + 1) { |
| 75 | + std::cout << "Test failed for index " << i << std::endl; |
| 76 | + return 1; |
| 77 | + } |
| 78 | + } |
| 79 | + std::cout << "Pass" << std::endl; |
| 80 | + return 0; |
| 81 | +} |
0 commit comments