|
| 1 | +#include <simsycl/sycl/group.hh> |
| 2 | +#include <simsycl/sycl/nd_item.hh> |
| 3 | +#include <simsycl/sycl/sub_group.hh> |
| 4 | + |
| 5 | +namespace simsycl::sycl::khr { |
| 6 | + |
| 7 | +#if SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES |
| 8 | + |
| 9 | +namespace detail { |
| 10 | +template<int Dimensions> |
| 11 | +thread_local std::optional<simsycl::sycl::nd_item<Dimensions>> g_khr_wi_query_this_nd_item; |
| 12 | + |
| 13 | +template<int Dimensions> |
| 14 | +thread_local std::optional<simsycl::sycl::group<Dimensions>> g_khr_wi_query_this_group; |
| 15 | + |
| 16 | +inline thread_local std::optional<simsycl::sycl::sub_group> g_khr_wi_query_this_sub_group; |
| 17 | + |
| 18 | +inline void khr_wi_query_check(bool val, [[maybe_unused]] const char *query_name) { |
| 19 | + SIMSYCL_CHECK_MSG(val, |
| 20 | + "Work item query state '%s' is not available.\n" |
| 21 | + "Make sure that the query originated from a kernel launched with a sycl::nd_range argument", |
| 22 | + query_name); |
| 23 | +} |
| 24 | + |
| 25 | +} // namespace detail |
| 26 | + |
| 27 | +template<int Dimensions> |
| 28 | +simsycl::sycl::nd_item<Dimensions> this_nd_item() { |
| 29 | + detail::khr_wi_query_check(detail::g_khr_wi_query_this_nd_item<Dimensions>.has_value(), "this_nd_item"); |
| 30 | + return detail::g_khr_wi_query_this_nd_item<Dimensions>.value(); |
| 31 | +} |
| 32 | + |
| 33 | +template<int Dimensions> |
| 34 | +simsycl::sycl::group<Dimensions> this_group() { |
| 35 | + detail::khr_wi_query_check(detail::g_khr_wi_query_this_group<Dimensions>.has_value(), "this_group"); |
| 36 | + return detail::g_khr_wi_query_this_group<Dimensions>.value(); |
| 37 | +} |
| 38 | + |
| 39 | +inline simsycl::sycl::sub_group this_sub_group() { |
| 40 | + detail::khr_wi_query_check(detail::g_khr_wi_query_this_sub_group.has_value(), "this_sub_group"); |
| 41 | + return detail::g_khr_wi_query_this_sub_group.value(); |
| 42 | +} |
| 43 | + |
| 44 | +#endif // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES |
| 45 | + |
| 46 | +} // namespace simsycl::sycl::khr |
0 commit comments