|
| 1 | +// RUN: %clangxx %s -o %test.bc -ffp-accuracy=high:sin,sqrt -ffp-accuracy=medium:cos -ffp-accuracy=low:tan -ffp-accuracy=cuda:exp,acos -ffp-accuracy=sycl:log,asin -fno-math-errno -fsycl -fsycl-device-only |
| 2 | +// RUN: sycl-post-link -split=auto -symbols %test.bc -o %test.table |
| 3 | +// RUN: FileCheck %s -input-file=%test.table --check-prefixes CHECK-TABLE |
| 4 | +// RUN: FileCheck %s -input-file=%test_0.sym --check-prefixes CHECK-M0-SYMS |
| 5 | +// RUN: FileCheck %s -input-file=%test_1.sym --check-prefixes CHECK-M1-SYMS |
| 6 | +// RUN: FileCheck %s -input-file=%test_2.sym --check-prefixes CHECK-M2-SYMS |
| 7 | +// RUN: FileCheck %s -input-file=%test_3.sym --check-prefixes CHECK-M3-SYMS |
| 8 | +// RUN: FileCheck %s -input-file=%test_4.sym --check-prefixes CHECK-M4-SYMS |
| 9 | +// RUN: FileCheck %s -input-file=%test_5.sym --check-prefixes CHECK-M5-SYMS |
| 10 | + |
| 11 | +// Tests that kernels which use different fp-accuracy level end up in different |
| 12 | +// device images. |
| 13 | + |
| 14 | +// CHECK-TABLE: Code |
| 15 | +// CHECK-TABLE-NEXT: _0.sym |
| 16 | +// CHECK-TABLE-NEXT: _1.sym |
| 17 | +// CHECK-TABLE-NEXT: _2.sym |
| 18 | +// CHECK-TABLE-NEXT: _3.sym |
| 19 | +// CHECK-TABLE-NEXT: _4.sym |
| 20 | +// CHECK-TABLE-NEXT: _5.sym |
| 21 | +// CHECK-TABLE-NEXT: _6.sym |
| 22 | +// CHECK-TABLE-EMPTY: |
| 23 | + |
| 24 | +// CHECK-M0-SYMS: __pf_kernel_wrapper{{.*}}Kernel1 |
| 25 | +// CHECK-M0-SYMS-NEXT: Kernel1 |
| 26 | +// CHECK-M0-SYMS-NEXT: __pf_kernel_wrapper{{.*}}Kernel7 |
| 27 | +// CHECK-M0-SYMS-NEXT: Kernel7 |
| 28 | +// CHECK-M0-SYMS-EMPTY: |
| 29 | + |
| 30 | +// CHECK-M1-SYMS: __pf_kernel_wrapper{{.*}}Kernel2 |
| 31 | +// CHECK-M1-SYMS-NEXT: Kernel2 |
| 32 | +// CHECK-M1-SYMS-EMPTY: |
| 33 | + |
| 34 | +// CHECK-M2-SYMS: __pf_kernel_wrapper{{.*}}Kernel3 |
| 35 | +// CHECK-M2-SYMS-NEXT: Kernel3 |
| 36 | +// CHECK-M2-SYMS-EMPTY: |
| 37 | + |
| 38 | +// CHECK-M3-SYMS: __pf_kernel_wrapper{{.*}}Kernel6 |
| 39 | +// CHECK-M3-SYMS-NEXT: Kernel6 |
| 40 | +// CHECK-M3-SYMS-EMPTY: |
| 41 | + |
| 42 | +// CHECK-M4-SYMS: __pf_kernel_wrapper{{.*}}Kernel4 |
| 43 | +// CHECK-M4-SYMS-NEXT: Kernel4 |
| 44 | +// CHECK-M4-SYMS-EMPTY: |
| 45 | + |
| 46 | +// CHECK-M5-SYMS: __pf_kernel_wrapper{{.*}}Kernel5 |
| 47 | +// CHECK-M5-SYMS-NEXT: Kernel5 |
| 48 | +// CHECK-M5-SYMS-EMPTY: |
| 49 | + |
| 50 | +// CHECK-M6-SYMS: __pf_kernel_wrapper{{.*}}Kernel0 |
| 51 | +// CHECK-M6-SYMS-NEXT: Kernel0 |
| 52 | +// CHECK-M6-SYMS-EMPTY: |
| 53 | + |
| 54 | +#include <array> |
| 55 | +#include <cmath> |
| 56 | +#include <iostream> |
| 57 | +#include <sycl/sycl.hpp> |
| 58 | + |
| 59 | +using namespace sycl; |
| 60 | + |
| 61 | +constexpr access::mode sycl_read = access::mode::read; |
| 62 | +constexpr access::mode sycl_write = access::mode::write; |
| 63 | + |
| 64 | +int main() { |
| 65 | + const size_t array_size = 4; |
| 66 | + std::array<double, array_size> D = {{1., 2., 3., 4.}}, E; |
| 67 | + queue deviceQueue; |
| 68 | + range<1> numOfItems{array_size}; |
| 69 | + double Value = 5.; |
| 70 | + buffer<double, 1> bufferOut(E.data(), numOfItems); |
| 71 | + |
| 72 | + // Kernel0 doesn't use math functions. |
| 73 | + deviceQueue.submit([&](handler &cgh) { |
| 74 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 75 | + |
| 76 | + cgh.parallel_for<class Kernel0>( |
| 77 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = Value; }); |
| 78 | + }); |
| 79 | + |
| 80 | + // Kernel1 uses high-accuracy sin. |
| 81 | + deviceQueue.submit([&](handler &cgh) { |
| 82 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 83 | + |
| 84 | + cgh.parallel_for<class Kernel1>( |
| 85 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = std::sin(Value); }); |
| 86 | + }); |
| 87 | + |
| 88 | + // Kernel2 uses medium-accuracy cos. |
| 89 | + deviceQueue.submit([&](handler &cgh) { |
| 90 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 91 | + |
| 92 | + cgh.parallel_for<class Kernel2>( |
| 93 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = std::cos(Value); }); |
| 94 | + }); |
| 95 | + |
| 96 | + // Kernel3 uses low-accuracy tan. |
| 97 | + deviceQueue.submit([&](handler &cgh) { |
| 98 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 99 | + |
| 100 | + cgh.parallel_for<class Kernel3>( |
| 101 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = std::tan(Value); }); |
| 102 | + }); |
| 103 | + |
| 104 | + // Kernel4 uses cuda-accuracy exp and sycl-accuracy log. |
| 105 | + deviceQueue.submit([&](handler &cgh) { |
| 106 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 107 | + |
| 108 | + cgh.parallel_for<class Kernel4>(numOfItems, [=](id<1> wiID) { |
| 109 | + accessorOut[wiID] = std::log(std::exp(Value)); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + // Kernel5 uses cuda-accuracy acos. |
| 114 | + deviceQueue.submit([&](handler &cgh) { |
| 115 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 116 | + |
| 117 | + cgh.parallel_for<class Kernel5>( |
| 118 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = std::acos(Value); }); |
| 119 | + }); |
| 120 | + |
| 121 | + // Kernel6 uses sycl-accuracy asin. |
| 122 | + deviceQueue.submit([&](handler &cgh) { |
| 123 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 124 | + |
| 125 | + cgh.parallel_for<class Kernel6>( |
| 126 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = std::asin(Value); }); |
| 127 | + }); |
| 128 | + |
| 129 | + // Kernel7 uses high-accuracy sqrt. |
| 130 | + deviceQueue.submit([&](handler &cgh) { |
| 131 | + auto accessorOut = bufferOut.template get_access<sycl_write>(cgh); |
| 132 | + |
| 133 | + cgh.parallel_for<class Kernel7>( |
| 134 | + numOfItems, [=](id<1> wiID) { accessorOut[wiID] = std::sqrt(Value); }); |
| 135 | + }); |
| 136 | + |
| 137 | + return 0; |
| 138 | +} |
0 commit comments