Skip to content

Commit 33fceed

Browse files
authored
[SYCL] Update test for ext_sycl_oneapi_clock (#20141)
Add a test plan and update the test Spec: https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_clock.asciidoc
1 parent d1abb0c commit 33fceed

File tree

3 files changed

+104
-49
lines changed

3 files changed

+104
-49
lines changed

sycl/test-e2e/Clock/clock.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// REQUIRES-INTEL-DRIVER: cpu: 2026
2+
// REQUIRES: aspect-usm_shared_allocations
3+
// RUN: %{build} -o %t.out
4+
// RUN: %{run} %t.out
5+
6+
// UNSUPPORTED: spirv-backend
7+
// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/20146
8+
// UNSUPPORTED: target-native_cpu
9+
// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/20142
10+
11+
#include <sycl/detail/core.hpp>
12+
#include <sycl/ext/oneapi/experimental/clock.hpp>
13+
#include <sycl/usm.hpp>
14+
15+
namespace syclex = sycl::ext::oneapi::experimental;
16+
17+
template <syclex::clock_scope scope> void test(sycl::queue &q) {
18+
auto *data = sycl::malloc_shared<uint64_t>(3, q);
19+
20+
q.parallel_for(2, [=](sycl::id<1> idx) {
21+
if (idx == 0) {
22+
data[0] = syclex::clock<scope>();
23+
int sum = 0;
24+
for (int i = 0; i < 1e6; ++i)
25+
sum += i;
26+
data[1] = syclex::clock<scope>();
27+
sum = 0;
28+
for (int i = 0; i < 1e6; ++i)
29+
sum += i;
30+
data[2] = syclex::clock<scope>();
31+
}
32+
}).wait();
33+
34+
assert(data[1] > data[0]);
35+
assert(data[2] > data[1]);
36+
sycl::free(data, q);
37+
}
38+
39+
template <syclex::clock_scope scope>
40+
void test_if_supported(sycl::queue &q, sycl::aspect asp) {
41+
auto dev = q.get_device();
42+
if (dev.has(asp))
43+
test<scope>(q);
44+
else
45+
try {
46+
test<scope>(q);
47+
} catch (sycl::exception &e) {
48+
assert(e.code() == sycl::errc::kernel_not_supported && "Unexpected errc");
49+
}
50+
}
51+
52+
int main() {
53+
sycl::queue q;
54+
test_if_supported<syclex::clock_scope::sub_group>(
55+
q, sycl::aspect::ext_oneapi_clock_sub_group);
56+
test_if_supported<syclex::clock_scope::work_group>(
57+
q, sycl::aspect::ext_oneapi_clock_work_group);
58+
test_if_supported<syclex::clock_scope::device>(
59+
q, sycl::aspect::ext_oneapi_clock_device);
60+
return 0;
61+
}

sycl/test-e2e/Clock/test-plan.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
:sectnums:
2+
:xrefstyle: short
3+
4+
# Test plan for sycl_ext_oneapi_clock
5+
6+
This is a test plan for the APIs described in
7+
https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_clock.asciidoc[sycl_ext_oneapi_clock].
8+
9+
## Testing scope
10+
11+
### Device coverage
12+
13+
All of the tests described below are performed only on the default device that
14+
is selected on the CTS command line.
15+
16+
## Tests
17+
18+
### New aspects
19+
20+
The extension introduces the following aspects:
21+
22+
* `ext_oneapi_clock_sub_group`,
23+
* `ext_oneapi_clock_work_group`,
24+
* `ext_oneapi_clock_device`
25+
26+
Check if these aspects are defined by the implementation.
27+
28+
### New function
29+
30+
The extension introduces the following function:
31+
32+
* `uint64_t clock<clock_scope scope>()`
33+
34+
Check if the function:
35+
36+
* can be successfully called from a kernel,
37+
* accepts all possible values of `clock_scope` enum,
38+
* returns different values when called multiple times and these values are
39+
increasing (keep in mind an overflow).
40+
41+
When possible, check if the implementation throws an exception with the
42+
`errc::kernel_not_supported` error code when the kernel is submitted to a queue,
43+
but a device doesn't have a corresponding aspect.

sycl/test-e2e/Experimental/clock.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)