|
| 1 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 2 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out |
| 3 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 4 | +// RUN: %ACC_RUN_PLACEHOLDER %t.out |
| 5 | +// |
| 6 | +// This test intends to check that no speculative compilation is happening, |
| 7 | +// i.e. there are no exceptions thrown about aspects fp16 or fp64 being |
| 8 | +// unsuppored on device. |
| 9 | + |
| 10 | +#include <sycl/sycl.hpp> |
| 11 | + |
| 12 | +void foo(sycl::half &value) { value += sycl::half(1.0f); } |
| 13 | + |
| 14 | +void foo(double &value) { value += 2.0; } |
| 15 | + |
| 16 | +void foo(float &value) { value += 3.0f; } |
| 17 | + |
| 18 | +int main() { |
| 19 | + sycl::queue q; |
| 20 | + |
| 21 | + sycl::half h = 0.0f; |
| 22 | + double d = 0.0; |
| 23 | + float f = 0.0f; |
| 24 | + |
| 25 | + sycl::buffer<sycl::half> buf_half(&h, sycl::range{1}); |
| 26 | + sycl::buffer<double> buf_double(&d, sycl::range{1}); |
| 27 | + sycl::buffer<float> buf_float(&f, sycl::range{1}); |
| 28 | + |
| 29 | + if (q.get_device().has(sycl::aspect::fp16)) { |
| 30 | + q.submit([&](sycl::handler &cgh) { |
| 31 | + auto acc = buf_half.get_access(cgh); |
| 32 | + cgh.single_task([=] { foo(acc[0]); }); |
| 33 | + }).wait(); |
| 34 | + |
| 35 | + auto host_acc = buf_half.get_host_access(); |
| 36 | + assert(host_acc[0] == 1.0f); |
| 37 | + } else if (q.get_device().has(sycl::aspect::fp64)) { |
| 38 | + q.submit([&](sycl::handler &cgh) { |
| 39 | + auto acc = buf_double.get_access(cgh); |
| 40 | + cgh.single_task([=] { foo(acc[0]); }); |
| 41 | + }).wait(); |
| 42 | + |
| 43 | + auto host_acc = buf_double.get_host_access(); |
| 44 | + assert(host_acc[0] == 2.0f); |
| 45 | + } else { |
| 46 | + q.submit([&](sycl::handler &cgh) { |
| 47 | + auto acc = buf_float.get_access(cgh); |
| 48 | + cgh.single_task([=] { foo(acc[0]); }); |
| 49 | + }).wait(); |
| 50 | + |
| 51 | + auto host_acc = buf_float.get_host_access(); |
| 52 | + assert(host_acc[0] == 3.0f); |
| 53 | + } |
| 54 | + |
| 55 | + return 0; |
| 56 | +} |
0 commit comments