|
| 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 | +} |
0 commit comments