|
1 | | -// RUN: %{build} -o %t.out |
2 | | -// RUN: %{run} %t.out |
3 | | -//==- thread_id_test.cpp - Test to verify thread id functionlity-==// |
4 | | -// |
5 | | -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
6 | | -// See https://llvm.org/LICENSE.txt for license information. |
7 | | -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
8 | | -// |
9 | | -//===----------------------------------------------------------------------===// |
10 | | - |
11 | | -// This is basic test to validate thread id functions. |
12 | | - |
13 | | -#include <cmath> |
14 | | -#include <iostream> |
15 | | -#include <sycl/detail/core.hpp> |
16 | | -#include <sycl/ext/intel/esimd.hpp> |
17 | | -#include <sycl/ext/intel/esimd/simd.hpp> |
18 | | -#include <sycl/usm.hpp> |
19 | | -#include <sycl/usm/usm_allocator.hpp> |
20 | | -#include <vector> |
21 | | - |
22 | | -int ErrCnt = 0; |
23 | | -template <typename DataT> |
24 | | -using shared_allocator = sycl::usm_allocator<DataT, sycl::usm::alloc::shared>; |
25 | | -template <typename DataT> |
26 | | -using shared_vector = std::vector<DataT, shared_allocator<DataT>>; |
27 | | - |
28 | | -int test_thread_id() { |
29 | | - sycl::queue Queue; |
30 | | - shared_allocator<int32_t> Allocator(Queue); |
31 | | - constexpr int32_t SIZE = 32; |
32 | | - |
33 | | - shared_vector<int32_t> VectorOutputThreadId(SIZE, -1, Allocator); |
34 | | - shared_vector<int32_t> VectorOutputSubdeviceId(SIZE, -1, Allocator); |
35 | | - |
36 | | - auto GlobalRange = sycl::range<1>(SIZE); |
37 | | - sycl::range<1> LocalRange{1}; |
38 | | - sycl::nd_range<1> Range(GlobalRange, LocalRange); |
39 | | - |
40 | | - { |
41 | | - Queue.submit([&](sycl::handler &cgh) { |
42 | | - int32_t *VectorOutputThreadIdPtr = VectorOutputThreadId.data(); |
43 | | - int32_t *VectorOutputSubdeviceIdPtr = VectorOutputSubdeviceId.data(); |
44 | | - |
45 | | - auto Kernel = ([=](sycl::nd_item<1> ndi) [[intel::sycl_explicit_simd]] { |
46 | | - using namespace sycl::ext::intel::esimd; |
47 | | - auto Idx = ndi.get_global_id(0); |
48 | | - |
49 | | - simd<int32_t, 1> VectorResultThreadId = |
50 | | - sycl::ext::intel::experimental::esimd::get_hw_thread_id(); |
51 | | - simd<int32_t, 1> VectorResultSubdeviceId = |
52 | | - sycl::ext::intel::experimental::esimd::get_subdevice_id(); |
53 | | - |
54 | | - VectorResultThreadId.copy_to(VectorOutputThreadIdPtr + Idx); |
55 | | - VectorResultSubdeviceId.copy_to(VectorOutputSubdeviceIdPtr + Idx); |
56 | | - }); |
57 | | - |
58 | | - cgh.parallel_for(Range, Kernel); |
59 | | - }); |
60 | | - Queue.wait(); |
61 | | - } |
62 | | - |
63 | | - int Result = 0; |
64 | | - |
65 | | - // Check if all returned elements are non negative |
66 | | - Result |= |
67 | | - !std::all_of(VectorOutputSubdeviceId.begin(), |
68 | | - VectorOutputSubdeviceId.end(), [](int i) { return i >= 0; }); |
69 | | - Result |= |
70 | | - !std::all_of(VectorOutputThreadId.begin(), VectorOutputThreadId.end(), |
71 | | - [](int i) { return i >= 0; }); |
72 | | - |
73 | | - // Check if returned values are not the same |
74 | | - std::sort(VectorOutputThreadId.begin(), VectorOutputThreadId.end()); |
75 | | - Result |= |
76 | | - std::equal(VectorOutputThreadId.begin() + 1, VectorOutputThreadId.end(), |
77 | | - VectorOutputThreadId.begin()); |
78 | | - |
79 | | - return Result; |
80 | | -} |
81 | | - |
82 | | -int main() { |
83 | | - |
84 | | - int TestResult = 0; |
85 | | - |
86 | | - TestResult |= test_thread_id(); |
87 | | - |
88 | | - if (!TestResult) { |
89 | | - std::cout << "Pass" << std::endl; |
90 | | - } |
91 | | - return TestResult; |
92 | | -} |
| 1 | +// RUN: %{build} -o %t.out |
| 2 | +// RUN: %{run} %t.out |
| 3 | +//==- thread_id_test.cpp - Test to verify thread id functionlity-==// |
| 4 | +// |
| 5 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 6 | +// See https://llvm.org/LICENSE.txt for license information. |
| 7 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | + |
| 11 | +// This is basic test to validate thread id functions. |
| 12 | + |
| 13 | +#include <cmath> |
| 14 | +#include <iostream> |
| 15 | +#include <sycl/detail/core.hpp> |
| 16 | +#include <sycl/ext/intel/esimd.hpp> |
| 17 | +#include <sycl/ext/intel/esimd/simd.hpp> |
| 18 | +#include <sycl/usm.hpp> |
| 19 | +#include <sycl/usm/usm_allocator.hpp> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +int ErrCnt = 0; |
| 23 | +template <typename DataT> |
| 24 | +using shared_allocator = sycl::usm_allocator<DataT, sycl::usm::alloc::shared>; |
| 25 | +template <typename DataT> |
| 26 | +using shared_vector = std::vector<DataT, shared_allocator<DataT>>; |
| 27 | + |
| 28 | +int test_thread_id() { |
| 29 | + sycl::queue Queue; |
| 30 | + shared_allocator<int32_t> Allocator(Queue); |
| 31 | + constexpr int32_t SIZE = 32; |
| 32 | + |
| 33 | + shared_vector<int32_t> VectorOutputThreadId(SIZE, -1, Allocator); |
| 34 | + shared_vector<int32_t> VectorOutputSubdeviceId(SIZE, -1, Allocator); |
| 35 | + |
| 36 | + auto GlobalRange = sycl::range<1>(SIZE); |
| 37 | + sycl::range<1> LocalRange{1}; |
| 38 | + sycl::nd_range<1> Range(GlobalRange, LocalRange); |
| 39 | + |
| 40 | + { |
| 41 | + Queue.submit([&](sycl::handler &cgh) { |
| 42 | + int32_t *VectorOutputThreadIdPtr = VectorOutputThreadId.data(); |
| 43 | + int32_t *VectorOutputSubdeviceIdPtr = VectorOutputSubdeviceId.data(); |
| 44 | + |
| 45 | + auto Kernel = ([=](sycl::nd_item<1> ndi) [[intel::sycl_explicit_simd]] { |
| 46 | + using namespace sycl::ext::intel::esimd; |
| 47 | + auto Idx = ndi.get_global_id(0); |
| 48 | + |
| 49 | + simd<int32_t, 1> VectorResultThreadId = |
| 50 | + sycl::ext::intel::experimental::esimd::get_hw_thread_id(); |
| 51 | + simd<int32_t, 1> VectorResultSubdeviceId = |
| 52 | + sycl::ext::intel::experimental::esimd::get_subdevice_id(); |
| 53 | + |
| 54 | + VectorResultThreadId.copy_to(VectorOutputThreadIdPtr + Idx); |
| 55 | + VectorResultSubdeviceId.copy_to(VectorOutputSubdeviceIdPtr + Idx); |
| 56 | + }); |
| 57 | + |
| 58 | + cgh.parallel_for(Range, Kernel); |
| 59 | + }); |
| 60 | + Queue.wait(); |
| 61 | + } |
| 62 | + |
| 63 | + int Result = 0; |
| 64 | + |
| 65 | + // Check if all returned elements are zero |
| 66 | + Result |= |
| 67 | + !std::all_of(VectorOutputSubdeviceId.begin(), |
| 68 | + VectorOutputSubdeviceId.end(), [](int i) { return i == 0; }); |
| 69 | + Result |= |
| 70 | + !std::all_of(VectorOutputThreadId.begin(), VectorOutputThreadId.end(), |
| 71 | + [](int i) { return i == 0; }); |
| 72 | + |
| 73 | + return Result; |
| 74 | +} |
| 75 | + |
| 76 | +int main() { |
| 77 | + |
| 78 | + int TestResult = 0; |
| 79 | + |
| 80 | + TestResult |= test_thread_id(); |
| 81 | + |
| 82 | + if (!TestResult) { |
| 83 | + std::cout << "Pass" << std::endl; |
| 84 | + } |
| 85 | + return TestResult; |
| 86 | +} |
0 commit comments