Skip to content

Commit dd6145e

Browse files
authored
[SYCL][ESIMD] Introduce an API to get thread ID and subdevice ID (#8569)
1 parent 67e63cf commit dd6145e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

sycl/include/CL/__spirv/spirv_ops.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,9 @@ __CLC_BF16_SCAL_VEC(uint32_t)
10511051
#undef __CLC_BF16_SCAL_VEC
10521052
#undef __CLC_BF16
10531053

1054+
extern __DPCPP_SYCL_EXTERNAL int32_t __spirv_BuiltInGlobalHWThreadIDINTEL();
1055+
extern __DPCPP_SYCL_EXTERNAL int32_t __spirv_BuiltInSubDeviceIDINTEL();
1056+
10541057
#else // if !__SYCL_DEVICE_ONLY__
10551058

10561059
template <typename dataT>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,31 @@ __ESIMD_API void lsc_fence(__ESIMD_NS::simd_mask<N> pred = 1) {
26692669

26702670
/// @} sycl_esimd_memory_lsc
26712671

2672+
/// @defgroup sycl_esimd_hw_thread_queries HW thread .
2673+
/// @ingroup sycl_esimd_memory
2674+
2675+
/// @addtogroup sycl_esimd_hw_thread_queries
2676+
/// @{
2677+
2678+
/// Get HW Thread ID
2679+
__ESIMD_API int32_t get_hw_thread_id() {
2680+
#ifdef __SYCL_DEVICE_ONLY__
2681+
return __spirv_BuiltInGlobalHWThreadIDINTEL();
2682+
#else
2683+
return std::rand();
2684+
#endif // __SYCL_DEVICE_ONLY__
2685+
}
2686+
/// Get subdevice ID
2687+
__ESIMD_API int32_t get_subdevice_id() {
2688+
#ifdef __SYCL_DEVICE_ONLY__
2689+
return __spirv_BuiltInSubDeviceIDINTEL();
2690+
#else
2691+
return 0;
2692+
#endif
2693+
}
2694+
2695+
/// @} sycl_esimd_hw_thread_queries
2696+
26722697
} // namespace experimental::esimd
26732698

26742699
namespace esimd {

0 commit comments

Comments
 (0)