diff --git a/SYCL/OptionalKernelFeatures/is_compatible.cpp b/SYCL/OptionalKernelFeatures/is_compatible.cpp new file mode 100644 index 0000000000..d1f17326b9 --- /dev/null +++ b/SYCL/OptionalKernelFeatures/is_compatible.cpp @@ -0,0 +1,46 @@ +// requires: cpu, gpu, accelerator +// RUN: %clangxx -fsycl -O0 %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +#include + +[[sycl::device_has(sycl::aspect::cpu)]] void foo(){}; +[[sycl::device_has(sycl::aspect::gpu)]] void bar(){}; +[[sycl::device_has(sycl::aspect::accelerator)]] void baz(){}; + +class KernelCPU; +class KernelGPU; +class KernelACC; + +int main() { + bool Compatible = true; + bool Called = false; + sycl::device Dev; + sycl::queue Q(Dev); + + if (sycl::is_compatible(Dev)) { + Q.submit( + [&](sycl::handler &h) { h.single_task([=]() { foo(); }); }); + Q.wait(); + Compatible &= Dev.is_cpu(); + Called = true; + } + if (sycl::is_compatible(Dev)) { + Q.submit( + [&](sycl::handler &h) { h.single_task([=]() { bar(); }); }); + Q.wait(); + Compatible &= Dev.is_gpu(); + Called = true; + } + if (sycl::is_compatible(Dev)) { + Q.submit( + [&](sycl::handler &h) { h.single_task([=]() { baz(); }); }); + Q.wait(); + Compatible &= Dev.is_accelerator(); + Called = true; + } + + return (Compatible && Called) ? 0 : 1; +}