SYCL/TypeCasting.h
Go to the documentation of this file.
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 
13 /*****************************************************************
14  * TypeCasting.h
15  *
16  * \brief:
17  * TypeCasting
18  *
19  *****************************************************************/
20 
21 #ifndef EIGEN_TYPE_CASTING_SYCL_H
22 #define EIGEN_TYPE_CASTING_SYCL_H
23 
24 // IWYU pragma: private
25 #include "../../InternalHeaderCheck.h"
26 
27 namespace Eigen {
28 
29 namespace internal {
30 #ifdef SYCL_DEVICE_ONLY
31 template <>
32 struct type_casting_traits<float, int> {
33  enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
34 };
35 
36 template <>
37 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_int4 pcast<cl::sycl::cl_float4, cl::sycl::cl_int4>(
38  const cl::sycl::cl_float4& a) {
39  return a.template convert<cl::sycl::cl_int, cl::sycl::rounding_mode::automatic>();
40 }
41 
42 template <>
43 struct type_casting_traits<int, float> {
44  enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
45 };
46 
47 template <>
48 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 pcast<cl::sycl::cl_int4, cl::sycl::cl_float4>(
49  const cl::sycl::cl_int4& a) {
50  return a.template convert<cl::sycl::cl_float, cl::sycl::rounding_mode::automatic>();
51 }
52 
53 template <>
54 struct type_casting_traits<double, float> {
55  enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
56 };
57 
58 template <>
59 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 pcast<cl::sycl::cl_double2, cl::sycl::cl_float4>(
60  const cl::sycl::cl_double2& a, const cl::sycl::cl_double2& b) {
61  auto a1 = a.template convert<cl::sycl::cl_float, cl::sycl::rounding_mode::automatic>();
62  auto b1 = b.template convert<cl::sycl::cl_float, cl::sycl::rounding_mode::automatic>();
63  return cl::sycl::cl_float4(a1.x(), a1.y(), b1.x(), b1.y());
64 }
65 
66 template <>
67 struct type_casting_traits<float, double> {
68  enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
69 };
70 
71 template <>
72 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2 pcast<cl::sycl::cl_float4, cl::sycl::cl_double2>(
73  const cl::sycl::cl_float4& a) {
74  // Simply discard the second half of the input
75  return cl::sycl::cl_double2(a.x(), a.y());
76 }
77 
78 #endif
79 } // end namespace internal
80 
81 } // end namespace Eigen
82 
83 #endif // EIGEN_TYPE_CASTING_SYCL_H
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:845
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
Scalar * b
Definition: benchVecAdd.cpp:17
return int(ret)+1
const Scalar * a
Definition: level2_cplx_impl.h:32
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
Definition: Eigen_Colamd.h:49
@ TgtCoeffRatio
Definition: GenericPacketMath.h:206
@ VectorizedCast
Definition: GenericPacketMath.h:203
@ SrcCoeffRatio
Definition: GenericPacketMath.h:205