Skip to content

Commit aa1cc9e

Browse files
committed
[SYCL] Implement sycl_ext_oneapi_clock
Spec: #19842
1 parent 09780f1 commit aa1cc9e

File tree

1 file changed

+37
-0
lines changed
  • sycl/include/sycl/ext/oneapi/experimental

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//==-------- clock.hpp --- SYCL extension for clock() free function --------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/__spirv/spirv_ops.hpp>
12+
#include <sycl/exception.hpp>
13+
14+
namespace sycl {
15+
inline namespace _V1 {
16+
namespace ext::oneapi::experimental {
17+
18+
enum class clock_scope : int {
19+
// Aligned with SPIR-V Scope<id> values
20+
device = 1,
21+
work_group = 2,
22+
sub_group = 3
23+
};
24+
25+
uint64_t clock(clock_scope scope = clock_scope::sub_group) {
26+
#ifdef __SYCL_DEVICE_ONLY__
27+
return __spirv_ReadClockKHR(static_cast<int>(scope));
28+
#else
29+
throw sycl::exception(
30+
make_error_code(errc::runtime),
31+
"sycl::ext::oneapi::experimental::clock() is not supported on host.");
32+
#endif // __SYCL_DEVICE_ONLY__
33+
}
34+
35+
} // namespace ext::oneapi::experimental
36+
} // namespace _V1
37+
} // namespace sycl

0 commit comments

Comments
 (0)