|
1 | 1 | /// |
2 | | -/// Check if bfloat16 example works using fallback libraries |
| 2 | +/// Checks a simple case of bfloat16, also employed for AOT library fallback. |
3 | 3 | /// |
4 | 4 |
|
5 | | -// REQUIRES: opencl-aot, ocloc, gpu-intel-gen9 |
6 | | - |
7 | 5 | // CUDA is not compatible with SPIR. |
8 | 6 | // UNSUPPORTED: cuda |
9 | 7 |
|
10 | 8 | // RUN: %clangxx -fsycl %s -o %t.out |
11 | 9 | // RUN: %{run} %t.out |
12 | 10 |
|
13 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64 %s -o %t.out |
14 | | -// RUN: %{run} %t.out |
15 | | - |
16 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend "-device gen9" %s -o %t.out |
17 | | -// RUN: %{run} %t.out |
18 | | - |
19 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend "-device *" %s -o %t.out |
20 | | -// RUN: %if gpu %{ %{run} %t.out %} |
21 | | - |
22 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64,spir64_gen -Xsycl-target-backend=spir64_gen "-device gen9" %s -o %t.out |
23 | | -// RUN: %{run} %t.out |
24 | | - |
25 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64,spir64_gen -Xsycl-target-backend=spir64_gen "-device gen9" %s -o %t.out |
26 | | -// RUN: %{run} %t.out |
27 | | - |
28 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64,spir64_gen -Xsycl-target-backend=spir64_gen "-device pvc" %s -o %t.out |
29 | | -// RUN: %if cpu %{ %{run} %t.out %} |
30 | | - |
31 | | -// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64,spir64_gen -Xsycl-target-backend=spir64_gen "-device pvc" %s -o %t.out |
32 | | -// RUN: %if cpu %{ %{run} %t.out %} |
33 | | - |
34 | | -#include <sycl/detail/core.hpp> |
35 | | -#include <sycl/ext/oneapi/bfloat16.hpp> |
36 | | - |
37 | | -using namespace sycl; |
38 | | -using sycl::ext::oneapi::bfloat16; |
39 | | - |
40 | | -float foo(float a, float b) { |
41 | | - // Convert from float to bfloat16. |
42 | | - bfloat16 A{a}; |
43 | | - bfloat16 B{b}; |
44 | | - |
45 | | - // Convert A and B from bfloat16 to float, do addition on floating-point |
46 | | - // numbers, then convert the result to bfloat16 and store it in C. |
47 | | - bfloat16 C = A + B; |
48 | | - |
49 | | - // Return the result converted from bfloat16 to float. |
50 | | - return C; |
51 | | -} |
52 | | - |
53 | | -int main(int argc, char *argv[]) { |
54 | | - float data[3] = {7.0f, 8.1f, 0.0f}; |
55 | | - |
56 | | - float result_host = foo(7.0f, 8.1f); |
57 | | - std::cout << "CPU Result = " << result_host << std::endl; |
58 | | - if (std::abs(15.1f - result_host) > 0.1f) { |
59 | | - std::cout << "Test failed. Expected CPU Result ~= 15.1" << std::endl; |
60 | | - return 1; |
61 | | - } |
62 | | - |
63 | | - queue deviceQueue; |
64 | | - buffer<float, 1> buf{data, 3}; |
65 | | - |
66 | | - deviceQueue.submit([&](handler &cgh) { |
67 | | - accessor numbers{buf, cgh, read_write}; |
68 | | - cgh.single_task([=]() { numbers[2] = foo(numbers[0], numbers[1]); }); |
69 | | - }); |
70 | | - |
71 | | - host_accessor hostOutAcc{buf, read_only}; |
72 | | - float result_device = hostOutAcc[2]; |
73 | | - std::cout << "GPU Result = " << result_device << std::endl; |
74 | | - if (std::abs(result_host - result_device) > 0.1f) { |
75 | | - std::cout << "Test failed. CPU Result !~= GPU result" << std::endl; |
76 | | - return 1; |
77 | | - } |
| 11 | +#include "bfloat16_example.hpp" |
78 | 12 |
|
79 | | - return 0; |
| 13 | +int main() { |
| 14 | + return runTest(); |
80 | 15 | } |
0 commit comments