|  | 
|  | 1 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | 
|  | 2 | +// RUN: %HOST_RUN_PLACEHOLDER %t.out | 
|  | 3 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out | 
|  | 4 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out | 
|  | 5 | +// RUN: %ACC_RUN_PLACEHOLDER %t.out | 
|  | 6 | + | 
|  | 7 | +// OpenCL CPU driver does not support cl_khr_fp16 extension | 
|  | 8 | +// UNSUPPORTED: cpu && opencl | 
|  | 9 | + | 
|  | 10 | +#include <CL/sycl.hpp> | 
|  | 11 | +#include <cassert> | 
|  | 12 | + | 
|  | 13 | +template <typename T> void assert_out_of_bound(T val, T lower, T upper) { | 
|  | 14 | +  assert(sycl::all(lower < val && val < upper)); | 
|  | 15 | +} | 
|  | 16 | + | 
|  | 17 | +template <> | 
|  | 18 | +void assert_out_of_bound<float>(float val, float lower, float upper) { | 
|  | 19 | +  assert(lower < val && val < upper); | 
|  | 20 | +} | 
|  | 21 | + | 
|  | 22 | +template <> | 
|  | 23 | +void assert_out_of_bound<sycl::half>(sycl::half val, sycl::half lower, | 
|  | 24 | +                                     sycl::half upper) { | 
|  | 25 | +  assert(lower < val && val < upper); | 
|  | 26 | +} | 
|  | 27 | + | 
|  | 28 | +template <typename T> void native_tanh_tester() { | 
|  | 29 | +  T r{0}; | 
|  | 30 | + | 
|  | 31 | +#ifdef SYCL_EXT_ONEAPI_NATIVE_MATH | 
|  | 32 | +  { | 
|  | 33 | +    sycl::buffer<T, 1> BufR(&r, sycl::range<1>(1)); | 
|  | 34 | +    sycl::queue myQueue; | 
|  | 35 | +    myQueue.submit([&](sycl::handler &cgh) { | 
|  | 36 | +      auto AccR = BufR.template get_access<sycl::access::mode::write>(cgh); | 
|  | 37 | +      cgh.single_task([=]() { | 
|  | 38 | +        AccR[0] = sycl::ext::oneapi::experimental::native::tanh(T(1.0f)); | 
|  | 39 | +      }); | 
|  | 40 | +    }); | 
|  | 41 | +  } | 
|  | 42 | + | 
|  | 43 | +  assert_out_of_bound(r, T(0.75f), T(0.77f)); // 0.76159415595576488812 | 
|  | 44 | +#endif | 
|  | 45 | +} | 
|  | 46 | + | 
|  | 47 | +template <typename T> void native_exp2_tester() { | 
|  | 48 | +  T r{0}; | 
|  | 49 | + | 
|  | 50 | +#ifdef SYCL_EXT_ONEAPI_NATIVE_MATH | 
|  | 51 | +  { | 
|  | 52 | +    sycl::buffer<T, 1> BufR(&r, sycl::range<1>(1)); | 
|  | 53 | +    sycl::queue myQueue; | 
|  | 54 | +    myQueue.submit([&](sycl::handler &cgh) { | 
|  | 55 | +      auto AccR = BufR.template get_access<sycl::access::mode::write>(cgh); | 
|  | 56 | +      cgh.single_task([=]() { | 
|  | 57 | +        AccR[0] = sycl::ext::oneapi::experimental::native::exp2(T(0.5f)); | 
|  | 58 | +      }); | 
|  | 59 | +    }); | 
|  | 60 | +  } | 
|  | 61 | + | 
|  | 62 | +  assert_out_of_bound(r, T(1.30f), T(1.50f)); // 1.4142135623730950488 | 
|  | 63 | +#endif | 
|  | 64 | +} | 
|  | 65 | + | 
|  | 66 | +int main() { | 
|  | 67 | + | 
|  | 68 | +  native_tanh_tester<float>(); | 
|  | 69 | +  native_tanh_tester<sycl::float2>(); | 
|  | 70 | +  native_tanh_tester<sycl::float3>(); | 
|  | 71 | +  native_tanh_tester<sycl::float4>(); | 
|  | 72 | +  native_tanh_tester<sycl::float8>(); | 
|  | 73 | +  native_tanh_tester<sycl::float16>(); | 
|  | 74 | + | 
|  | 75 | +  native_tanh_tester<sycl::half>(); | 
|  | 76 | +  native_tanh_tester<sycl::half2>(); | 
|  | 77 | +  native_tanh_tester<sycl::half3>(); | 
|  | 78 | +  native_tanh_tester<sycl::half4>(); | 
|  | 79 | +  native_tanh_tester<sycl::half8>(); | 
|  | 80 | +  native_tanh_tester<sycl::half16>(); | 
|  | 81 | + | 
|  | 82 | +  native_exp2_tester<sycl::half>(); | 
|  | 83 | +  native_exp2_tester<sycl::half2>(); | 
|  | 84 | +  native_exp2_tester<sycl::half3>(); | 
|  | 85 | +  native_exp2_tester<sycl::half4>(); | 
|  | 86 | +  native_exp2_tester<sycl::half8>(); | 
|  | 87 | +  native_exp2_tester<sycl::half16>(); | 
|  | 88 | + | 
|  | 89 | +  return 0; | 
|  | 90 | +} | 
0 commit comments