@@ -17,17 +17,14 @@ inline namespace _V1 {
1717namespace ext ::oneapi::experimental {
1818
1919enum class clock_scope : int {
20- // Aligned with SPIR-V Scope<id> values
20+ // Aligned with SPIR-V Scope<id> values.
2121 device = 1 ,
2222 work_group = 2 ,
2323 sub_group = 3
2424};
2525
26- #ifdef __SYCL_DEVICE_ONLY__
27- [[__sycl_detail__::__uses_aspects__(sycl::aspect::ext_oneapi_clock)]]
28- #endif // __SYCL_DEVICE_ONLY__
29- inline uint64_t
30- clock ([[maybe_unused]] clock_scope scope = clock_scope::sub_group) {
26+ namespace detail {
27+ inline uint64_t clock_impl (clock_scope scope) {
3128#ifdef __SYCL_DEVICE_ONLY__
3229#if defined(__NVPTX__) || defined(__AMDGCN__)
3330 // Currently clock() is not supported on NVPTX and AMDGCN.
@@ -37,10 +34,41 @@ clock([[maybe_unused]] clock_scope scope = clock_scope::sub_group) {
3734#endif // defined(__NVPTX__) || defined(__AMDGCN__)
3835#else
3936 throw sycl::exception (
40- make_error_code (errc::runtime),
41- " sycl::ext::oneapi::experimental::clock() is not supported on host." );
37+ make_error_code (errc::runtime),
38+ " sycl::ext::oneapi::experimental::clock() is not supported on host." );
4239#endif // __SYCL_DEVICE_ONLY__
4340}
41+ } // namespace detail
42+
43+ template <clock_scope Scope>
44+ inline uint64_t clock ();
45+
46+ // Specialization for device.
47+ template <>
48+ #ifdef __SYCL_DEVICE_ONLY__
49+ [[__sycl_detail__::__uses_aspects__(sycl::aspect::ext_oneapi_clock_device)]]
50+ #endif
51+ inline uint64_t clock<clock_scope::device>() {
52+ return detail::clock_impl (clock_scope::device);
53+ }
54+
55+ // Specialization for work-group.
56+ template <>
57+ #ifdef __SYCL_DEVICE_ONLY__
58+ [[__sycl_detail__::__uses_aspects__(sycl::aspect::ext_oneapi_clock_work_group)]]
59+ #endif
60+ inline uint64_t clock<clock_scope::work_group>() {
61+ return detail::clock_impl (clock_scope::work_group);
62+ }
63+
64+ // Specialization for sub-group.
65+ template <>
66+ #ifdef __SYCL_DEVICE_ONLY__
67+ [[__sycl_detail__::__uses_aspects__(sycl::aspect::ext_oneapi_clock_sub_group)]]
68+ #endif
69+ inline uint64_t clock<clock_scope::sub_group>() {
70+ return detail::clock_impl (clock_scope::sub_group);
71+ }
4472
4573} // namespace ext::oneapi::experimental
4674} // namespace _V1
0 commit comments