|
| 1 | +//==--- iselect.cpp - DPC++ ESIMD feature 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 | +// This is basic test for testing proper intrinsics generation. |
| 9 | + |
| 10 | +// REQUIRES: gpu |
| 11 | +// UNSUPPORTED: cuda || hip |
| 12 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 13 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 14 | + |
| 15 | +#include <sycl/ext/intel/esimd.hpp> |
| 16 | +#include <sycl/sycl.hpp> |
| 17 | + |
| 18 | +#include <iostream> |
| 19 | +#include <typeinfo> |
| 20 | + |
| 21 | +namespace esimd = sycl::ext::intel::esimd; |
| 22 | +template <typename DataT> |
| 23 | +using shared_allocator = sycl::usm_allocator<DataT, sycl::usm::alloc::shared>; |
| 24 | +template <typename DataT> |
| 25 | +using shared_vector = std::vector<DataT, shared_allocator<DataT>>; |
| 26 | + |
| 27 | +int test(sycl::queue queue) { |
| 28 | + |
| 29 | + shared_allocator<int32_t> allocator1(queue); |
| 30 | + shared_vector<int32_t> input(16, allocator1); |
| 31 | + shared_vector<int32_t> output(16, allocator1); |
| 32 | + shared_allocator<uint16_t> allocator2(queue); |
| 33 | + shared_vector<uint16_t> offsets(8, allocator2); |
| 34 | + |
| 35 | + for (int i = 0; i < input.size(); ++i) { |
| 36 | + input[i] = i; |
| 37 | + } |
| 38 | + |
| 39 | + offsets[0] = 3; |
| 40 | + offsets[1] = 5; |
| 41 | + offsets[2] = 9; |
| 42 | + offsets[3] = 2; |
| 43 | + offsets[4] = 7; |
| 44 | + offsets[5] = 8; |
| 45 | + offsets[6] = 0; |
| 46 | + offsets[7] = 1; |
| 47 | + { |
| 48 | + queue |
| 49 | + .submit([&](sycl::handler &cgh) { |
| 50 | + int32_t *in_ptr = input.data(); |
| 51 | + int32_t *out_ptr = output.data(); |
| 52 | + uint16_t *off_ptr = offsets.data(); |
| 53 | + cgh.single_task([=]() SYCL_ESIMD_KERNEL { |
| 54 | + __ESIMD_NS::simd<int32_t, 16> input_load_vec; |
| 55 | + input_load_vec.copy_from(in_ptr); |
| 56 | + |
| 57 | + esimd::simd<uint16_t, 8> offset; |
| 58 | + offset.copy_from(off_ptr); |
| 59 | + |
| 60 | + esimd::simd<int, 8> data = input_load_vec.iselect(offset); |
| 61 | + data += 3; |
| 62 | + input_load_vec.template iupdate(offset, data, |
| 63 | + esimd::simd_mask<8>(1)); |
| 64 | + input_load_vec.copy_to(out_ptr); |
| 65 | + }); |
| 66 | + }) |
| 67 | + .wait_and_throw(); |
| 68 | + } |
| 69 | + int32_t expected_values[] = {3, 4, 5, 6, 4, 8, 6, 10, |
| 70 | + 11, 12, 10, 11, 12, 13, 14, 15}; |
| 71 | + int error = 0; |
| 72 | + for (int i = 0; i < 16; i++) { |
| 73 | + if (output[i] != expected_values[i]) { |
| 74 | + ++error; |
| 75 | + std::cout << "Output[" << i << "] = " << output[i] << ", expected " |
| 76 | + << expected_values[i] << std::endl; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + return error; |
| 81 | +} |
| 82 | + |
| 83 | +int main(int, char **) { |
| 84 | + sycl::queue queue; |
| 85 | + |
| 86 | + auto dev = queue.get_device(); |
| 87 | + std::cout << "Running on " << dev.get_info<sycl::info::device::name>() |
| 88 | + << "\n"; |
| 89 | + |
| 90 | + int test_result = 0; |
| 91 | + |
| 92 | + test_result = test(queue); |
| 93 | + |
| 94 | + if (test_result == 0) { |
| 95 | + std::cout << "Pass!!" << std::endl; |
| 96 | + } else { |
| 97 | + std::cout << "Fail!!" << std::endl; |
| 98 | + } |
| 99 | + |
| 100 | + return test_result; |
| 101 | +} |
0 commit comments