DPC++ Runtime
Runtime libraries for oneAPI DPC++
half_precision_math_functions.cpp
Go to the documentation of this file.
1 //==------------------- half_precision_math_functions.cpp ------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "host_helper_macros.hpp"
12 
13 #include <cmath>
14 
15 namespace sycl {
16 inline namespace _V1 {
17 namespace half_precision {
18 #define BUILTIN_HALF_CUSTOM(NUM_ARGS, NAME, IMPL) \
19  HOST_IMPL(NAME, IMPL) \
20  EXPORT_SCALAR_AND_VEC_1_16_NS(NUM_ARGS, NAME, half_precision, float)
21 
22 #define BUILTIN_HALF(NUM_ARGS, NAME) \
23  BUILTIN_HALF_CUSTOM(NUM_ARGS, NAME, std::NAME)
24 
25 BUILTIN_HALF(ONE_ARG, cos)
26 BUILTIN_HALF_CUSTOM(TWO_ARGS, divide, [](auto x, auto y) { return x / y; })
27 BUILTIN_HALF(ONE_ARG, exp)
28 BUILTIN_HALF(ONE_ARG, exp2)
29 BUILTIN_HALF_CUSTOM(ONE_ARG, exp10, [](auto x) { return std::pow(10.0f, x); })
30 BUILTIN_HALF(ONE_ARG, log)
31 BUILTIN_HALF(ONE_ARG, log2)
32 BUILTIN_HALF(ONE_ARG, log10)
33 BUILTIN_HALF_CUSTOM(TWO_ARGS, powr, [](auto x, auto y) {
34  return (x >= 0 ? std::pow(x, y) : x);
35 })
36 BUILTIN_HALF_CUSTOM(ONE_ARG, recip, [](auto x) { return 1.0f / x; })
37 BUILTIN_HALF_CUSTOM(ONE_ARG, rsqrt, [](auto x) { return 1.0f / std::sqrt(x); })
38 BUILTIN_HALF(ONE_ARG, sin)
39 BUILTIN_HALF(ONE_ARG, sqrt)
40 BUILTIN_HALF(ONE_ARG, tan)
41 } // namespace half_precision
42 } // namespace _V1
43 } // namespace sycl
__ESIMD_API simd< T, N > sqrt(simd< T, N > src, Sat sat={})
Square root.
Definition: math.hpp:389
__ESIMD_API simd< T, N > rsqrt(simd< T, N > src, Sat sat={})
Square root reciprocal - calculates 1/sqrt(x).
Definition: math.hpp:397
__ESIMD_API simd< T, N > pow(simd< T, N > src0, simd< U, N > src1, Sat sat={})
Power - calculates src0 in power of src1.
Definition: math.hpp:442
__ESIMD_API simd< T, N > log2(simd< T, N > src, Sat sat={})
Logarithm base 2.
Definition: math.hpp:381
__ESIMD_API simd< T, N > exp2(simd< T, N > src, Sat sat={})
Exponent base 2.
Definition: math.hpp:385
#define BUILTIN_HALF(NUM_ARGS, NAME)
__DPCPP_SYCL_EXTERNAL _SYCL_EXT_CPLX_INLINE_VISIBILITY std::enable_if_t< is_genfloat< _Tp >::value, complex< _Tp > > tan(const complex< _Tp > &__x)
__DPCPP_SYCL_EXTERNAL _SYCL_EXT_CPLX_INLINE_VISIBILITY std::enable_if_t< is_genfloat< _Tp >::value, complex< _Tp > > log10(const complex< _Tp > &__x)
BUILTIN_HALF_CUSTOM(ONE_ARG, exp10, [](auto x) { return std::pow(10.0f, x);}) BUILTIN_HALF_CUSTOM(TWO_ARGS
ESIMD_NODEBUG ESIMD_INLINE sycl::ext::intel::esimd::simd< float, SZ > log(sycl::ext::intel::esimd::simd< float, SZ > x) __NOEXC
ESIMD_NODEBUG ESIMD_INLINE sycl::ext::intel::esimd::simd< float, SZ > sin(sycl::ext::intel::esimd::simd< float, SZ > x) __NOEXC
ESIMD_NODEBUG ESIMD_INLINE sycl::ext::intel::esimd::simd< float, SZ > cos(sycl::ext::intel::esimd::simd< float, SZ > x) __NOEXC
ESIMD_NODEBUG ESIMD_INLINE sycl::ext::intel::esimd::simd< float, SZ > exp(sycl::ext::intel::esimd::simd< float, SZ > x) __NOEXC
Definition: access.hpp:18