|
| 1 | +// REQUIRES: gpu |
| 2 | +// UNSUPPORTED: cuda || hip |
| 3 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 4 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 5 | +// XFAIL: esimd_emulator |
| 6 | +//==- abs_fix_test.cpp - Test for abs function -==// |
| 7 | +// |
| 8 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 9 | +// See https://llvm.org/LICENSE.txt for license information. |
| 10 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include <CL/sycl.hpp> |
| 15 | +#include <ext/intel/esimd.hpp> |
| 16 | +using namespace cl::sycl; |
| 17 | +using namespace sycl::ext::intel::experimental::esimd; |
| 18 | + |
| 19 | +#define SIMD 16 |
| 20 | +#define THREAD_NUM 512 |
| 21 | + |
| 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_abs(sycl::queue q, int32_t test_value) { |
| 28 | + |
| 29 | + shared_allocator<int32_t> allocator1(q); |
| 30 | + shared_vector<int32_t> input(THREAD_NUM * SIMD, allocator1); |
| 31 | + |
| 32 | + for (int i = 0; i < input.size(); ++i) { |
| 33 | + input[i] = test_value; |
| 34 | + } |
| 35 | + |
| 36 | + shared_allocator<uint32_t> allocator0(q); |
| 37 | + shared_vector<uint32_t> output(THREAD_NUM * SIMD, allocator0); |
| 38 | + shared_vector<uint32_t> scalar_output(1, allocator0); |
| 39 | + |
| 40 | + nd_range<1> Range((range<1>(THREAD_NUM)), (range<1>(SIMD))); |
| 41 | + auto e = q.submit([&](handler &cgh) { |
| 42 | + int32_t *in_ptr = input.data(); |
| 43 | + uint32_t *out_ptr = output.data(); |
| 44 | + uint32_t *scalar_ptr = scalar_output.data(); |
| 45 | + cgh.parallel_for(Range, [=](nd_item<1> it) SYCL_ESIMD_FUNCTION { |
| 46 | + __ESIMD_NS::simd<int32_t, SIMD> input_load_vec; |
| 47 | + input_load_vec.copy_from(in_ptr + it.get_global_id(0) * SIMD); |
| 48 | + |
| 49 | + __ESIMD_NS::simd<uint32_t, SIMD> result; |
| 50 | + __ESIMD_NS::simd<uint32_t, 1> scalar_result; |
| 51 | + result = __ESIMD_NS::abs<uint32_t, int32_t, SIMD>(input_load_vec); |
| 52 | + scalar_result = __ESIMD_NS::abs<uint32_t, int32_t, 1>(test_value); |
| 53 | + result.copy_to(out_ptr + it.get_global_id(0) * SIMD); |
| 54 | + scalar_result.copy_to(scalar_ptr); |
| 55 | + }); |
| 56 | + }); |
| 57 | + e.wait(); |
| 58 | + |
| 59 | + if (scalar_output[0] != std::abs(test_value)) { |
| 60 | + std::cout << "Test failed for scalar " << test_value << "." << std::endl; |
| 61 | + return 1; |
| 62 | + } |
| 63 | + for (int i = 0; i < THREAD_NUM * SIMD; ++i) { |
| 64 | + if (output[i] != std::abs(input[i])) { |
| 65 | + std::cout << "Test failed for " << input[i] << "." << std::endl; |
| 66 | + return 1; |
| 67 | + } |
| 68 | + } |
| 69 | + return 0; |
| 70 | +} |
| 71 | + |
| 72 | +int main(int argc, char *argv[]) { |
| 73 | + sycl::property_list properties{sycl::property::queue::enable_profiling()}; |
| 74 | + auto q = sycl::queue(properties); |
| 75 | + |
| 76 | + auto dev = q.get_device(); |
| 77 | + std::cout << "Running on " << dev.get_info<info::device::name>() << "\n"; |
| 78 | + |
| 79 | + int test_result = 0; |
| 80 | + test_result |= test_abs(q, 0xFFFFFFFF); |
| 81 | + |
| 82 | + if (!test_result) { |
| 83 | + std::cout << "Pass" << std::endl; |
| 84 | + } |
| 85 | + return test_result; |
| 86 | +} |
0 commit comments