Skip to content

Commit 2a330cc

Browse files
author
Dmitry Sidorov
authored
[SYCL][ESIMD] Make get_hw_thread_id to return 0 (#19391)
Same for sub device id API. The appropriate SPIR-V extension used for them previously is deprecated. --------- Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
1 parent 164db6c commit 2a330cc

2 files changed

Lines changed: 88 additions & 106 deletions

File tree

sycl/include/sycl/ext/intel/experimental/esimd/memory.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,21 +2480,9 @@ lsc_atomic_update(AccessorTy acc, __ESIMD_NS::simd<uint32_t, N> offsets,
24802480
/// @{
24812481

24822482
/// Get HW Thread ID
2483-
__ESIMD_API int32_t get_hw_thread_id() {
2484-
#ifdef __SYCL_DEVICE_ONLY__
2485-
return __spirv_BuiltInGlobalHWThreadIDINTEL();
2486-
#else
2487-
return std::rand();
2488-
#endif // __SYCL_DEVICE_ONLY__
2489-
}
2483+
__ESIMD_API int32_t get_hw_thread_id() { return 0; }
24902484
/// Get subdevice ID
2491-
__ESIMD_API int32_t get_subdevice_id() {
2492-
#ifdef __SYCL_DEVICE_ONLY__
2493-
return __spirv_BuiltInSubDeviceIDINTEL();
2494-
#else
2495-
return 0;
2496-
#endif
2497-
}
2485+
__ESIMD_API int32_t get_subdevice_id() { return 0; }
24982486

24992487
/// @} sycl_esimd_hw_thread_queries
25002488

Lines changed: 86 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,86 @@
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

Comments
 (0)