Eigen  5.0.1
 
Loading...
Searching...
No Matches
MathFunctions.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Mehdi Goli Codeplay Software Ltd.
5// Ralph Potter Codeplay Software Ltd.
6// Luke Iwanski Codeplay Software Ltd.
7// Contact: <eigen@codeplay.com>
8//
9// This Source Code Form is subject to the terms of the Mozilla
10// Public License v. 2.0. If a copy of the MPL was not distributed
11// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
12// SPDX-FileCopyrightText: The Eigen Authors
13// SPDX-License-Identifier: MPL-2.0
14
15/*****************************************************************
16 * MathFunctions.h
17 *
18 * \brief:
19 * MathFunctions
20 *
21 *****************************************************************/
22
23#ifndef EIGEN_MATH_FUNCTIONS_SYCL_H
24#define EIGEN_MATH_FUNCTIONS_SYCL_H
25// IWYU pragma: private
26#include "../../InternalHeaderCheck.h"
27
28namespace Eigen {
29
30namespace internal {
31
32// Make sure this is only available when targeting a GPU: we don't want to
33// introduce conflicts between these packet_traits definitions and the ones
34// we'll use on the host side (SSE, AVX, ...)
35#if defined(SYCL_DEVICE_ONLY)
36
37// Generic macro for unary SYCL math functions.
38#define SYCL_PACKET_FUNCTION(EIGEN_FUNC, SYCL_FUNC, PACKET) \
39 template <> \
40 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PACKET EIGEN_FUNC<PACKET>(const PACKET& a) { \
41 return cl::sycl::SYCL_FUNC(a); \
42 }
43
44// Instantiate a unary function for the standard set of SYCL vector types.
45#define SYCL_UNARY_FUNCTION(EIGEN_FUNC, SYCL_FUNC) \
46 SYCL_PACKET_FUNCTION(EIGEN_FUNC, SYCL_FUNC, cl::sycl::cl_half8) \
47 SYCL_PACKET_FUNCTION(EIGEN_FUNC, SYCL_FUNC, cl::sycl::cl_float4) \
48 SYCL_PACKET_FUNCTION(EIGEN_FUNC, SYCL_FUNC, cl::sycl::cl_double2)
49
50SYCL_UNARY_FUNCTION(plog, log)
51SYCL_UNARY_FUNCTION(plog1p, log1p)
52SYCL_UNARY_FUNCTION(plog10, log10)
53SYCL_UNARY_FUNCTION(pexpm1, expm1)
54SYCL_UNARY_FUNCTION(psqrt, sqrt)
55SYCL_UNARY_FUNCTION(prsqrt, rsqrt)
56SYCL_UNARY_FUNCTION(psin, sin)
57SYCL_UNARY_FUNCTION(pcos, cos)
58SYCL_UNARY_FUNCTION(ptan, tan)
59SYCL_UNARY_FUNCTION(pasin, asin)
60SYCL_UNARY_FUNCTION(pacos, acos)
61SYCL_UNARY_FUNCTION(patan, atan)
62SYCL_UNARY_FUNCTION(psinh, sinh)
63SYCL_UNARY_FUNCTION(pcosh, cosh)
64SYCL_UNARY_FUNCTION(ptanh, tanh)
65SYCL_UNARY_FUNCTION(pround, round)
66SYCL_UNARY_FUNCTION(print, rint)
67SYCL_UNARY_FUNCTION(pfloor, floor)
68
69// pexp has additional scalar type instantiations.
70SYCL_UNARY_FUNCTION(pexp, exp)
71SYCL_PACKET_FUNCTION(pexp, exp, cl::sycl::cl_half)
72SYCL_PACKET_FUNCTION(pexp, exp, cl::sycl::cl_float)
73
74// pceil uses cl_half (scalar) instead of cl_half8 (vector) — preserving original behavior.
75SYCL_PACKET_FUNCTION(pceil, ceil, cl::sycl::cl_half)
76SYCL_PACKET_FUNCTION(pceil, ceil, cl::sycl::cl_float4)
77SYCL_PACKET_FUNCTION(pceil, ceil, cl::sycl::cl_double2)
78
79#undef SYCL_UNARY_FUNCTION
80#undef SYCL_PACKET_FUNCTION
81
82// Binary min/max functions.
83#define SYCL_BINARY_FUNCTION(EIGEN_FUNC, SYCL_FUNC, PACKET) \
84 template <> \
85 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PACKET EIGEN_FUNC<PACKET>(const PACKET& a, const PACKET& b) { \
86 return cl::sycl::SYCL_FUNC(a, b); \
87 }
88
89SYCL_BINARY_FUNCTION(pmin, fmin, cl::sycl::cl_half8)
90SYCL_BINARY_FUNCTION(pmin, fmin, cl::sycl::cl_float4)
91SYCL_BINARY_FUNCTION(pmin, fmin, cl::sycl::cl_double2)
92SYCL_BINARY_FUNCTION(pmax, fmax, cl::sycl::cl_half8)
93SYCL_BINARY_FUNCTION(pmax, fmax, cl::sycl::cl_float4)
94SYCL_BINARY_FUNCTION(pmax, fmax, cl::sycl::cl_double2)
95
96#undef SYCL_BINARY_FUNCTION
97
98// pldexp requires integer conversion of the exponent.
99#define SYCL_PLDEXP(packet_type) \
100 template <> \
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE packet_type pldexp(const packet_type& a, const packet_type& exponent) { \
102 return cl::sycl::ldexp(a, exponent.template convert<cl::sycl::cl_int, cl::sycl::rounding_mode::automatic>()); \
103 }
104
105SYCL_PLDEXP(cl::sycl::cl_half8)
106SYCL_PLDEXP(cl::sycl::cl_float4)
107SYCL_PLDEXP(cl::sycl::cl_double2)
108#undef SYCL_PLDEXP
109
110#endif
111} // end namespace internal
112
113} // end namespace Eigen
114
115#endif // EIGEN_MATH_FUNCTIONS_SYCL_H