Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions sycl/include/sycl/ext/oneapi/experimental/clock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//==-------- clock.hpp --- SYCL extension for clock() free function --------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <sycl/__spirv/spirv_ops.hpp>
#include <sycl/exception.hpp>

namespace sycl {
inline namespace _V1 {
namespace ext::oneapi::experimental {

enum class clock_scope : int {
// Aligned with SPIR-V Scope<id> values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Aligned with SPIR-V Scope<id> values
// Aligned with SPIR-V Scope<id> values.

device = 1,
work_group = 2,
sub_group = 3
};

#ifdef __SYCL_DEVICE_ONLY__
[[__sycl_detail__::__uses_aspects__(sycl::aspect::ext_oneapi_clock)]]
#endif // __SYCL_DEVICE_ONLY__
uint64_t clock(clock_scope scope = clock_scope::sub_group) {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_ReadClockKHR(static_cast<int>(scope));
#else
throw sycl::exception(
make_error_code(errc::runtime),
"sycl::ext::oneapi::experimental::clock() is not supported on host.");
#endif // __SYCL_DEVICE_ONLY__
}

} // namespace ext::oneapi::experimental
} // namespace _V1
} // namespace sycl
1 change: 1 addition & 0 deletions sycl/include/sycl/info/aspects.def
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ __SYCL_ASPECT(ext_oneapi_async_memory_alloc, 87)
__SYCL_ASPECT(ext_intel_device_info_luid, 88)
__SYCL_ASPECT(ext_intel_device_info_node_mask, 89)
__SYCL_ASPECT(ext_oneapi_exportable_device_mem, 90)
__SYCL_ASPECT(ext_oneapi_clock, 91)

1 change: 1 addition & 0 deletions sycl/source/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
UR_DEVICE_INFO_MEMORY_EXPORT_EXPORTABLE_DEVICE_MEM_EXP>()
.value_or(0);
}
CASE(ext_oneapi_clock) { return has_extension("cl_khr_kernel_clock"); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the UR adaptors under a new device info query. Could you please open a tracker to remind us to do that?

else {
return false; // This device aspect has not been implemented yet.
}
Expand Down
1 change: 1 addition & 0 deletions sycl/source/feature_test.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ inline namespace _V1 {
#define SYCL_KHR_FREE_FUNCTION_COMMANDS 1
#define SYCL_KHR_QUEUE_EMPTY_QUERY 1
#define SYCL_EXT_ONEAPI_MEMORY_EXPORT 1
#define SYCL_EXT_ONEAPI_CLOCK 1
// In progress yet
#define SYCL_EXT_ONEAPI_ATOMIC16 0
#define SYCL_KHR_DEFAULT_CONTEXT 1
Expand Down
40 changes: 40 additions & 0 deletions sycl/test-e2e/Experimental/clock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// REQUIRES: ext_oneapi_clock

#include <sycl/detail/core.hpp>
#include <sycl/ext/oneapi/experimental/clock.hpp>
#include <sycl/usm.hpp>

int main() {
sycl::queue q;
uint64_t *data = sycl::malloc_shared<uint64_t>(3, q);

q.single_task([=]() {
uint64_t sg_clock_start = sycl::ext::oneapi::experimental::clock(
sycl::ext::oneapi::experimental::clock_scope::sub_group);
uint64_t wg_clock_start = sycl::ext::oneapi::experimental::clock(
sycl::ext::oneapi::experimental::clock_scope::work_group);
uint64_t dev_clock_start = sycl::ext::oneapi::experimental::clock(
sycl::ext::oneapi::experimental::clock_scope::device);

int count = 0;
for (int i = 0; i < 1e6; ++i)
count++;

uint64_t sg_clock_end = sycl::ext::oneapi::experimental::clock(
sycl::ext::oneapi::experimental::clock_scope::sub_group);
uint64_t wg_clock_end = sycl::ext::oneapi::experimental::clock(
sycl::ext::oneapi::experimental::clock_scope::work_group);
uint64_t dev_clock_end = sycl::ext::oneapi::experimental::clock(
sycl::ext::oneapi::experimental::clock_scope::device);
data[0] = sg_clock_end - sg_clock_start;
data[1] = wg_clock_end - wg_clock_start;
data[2] = dev_clock_end - dev_clock_start;
});
q.wait();

assert(data[0] > 0);
assert(data[1] > 0);
assert(data[2] > 0);

return 0;
}
Loading