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 
21 #ifndef EIGEN_TYPE_CASTING_SYCL_H
22 #define EIGEN_TYPE_CASTING_SYCL_H
23 
24 #include "../../InternalHeaderCheck.h"
25 
26 namespace Eigen {
27 
28 namespace internal {
29 #ifdef SYCL_DEVICE_ONLY
30 template <>
31 struct type_casting_traits<float, int> {
32  enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
33 };
34 
35 template <>
36 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_int4
37 pcast<cl::sycl::cl_float4, cl::sycl::cl_int4>(const cl::sycl::cl_float4& a) {
38  return a
39  .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
49 pcast<cl::sycl::cl_int4, cl::sycl::cl_float4>(const cl::sycl::cl_int4& a) {
50  return a.template convert<cl::sycl::cl_float,
51  cl::sycl::rounding_mode::automatic>();
52 }
53 
54 template <>
55 struct type_casting_traits<double, float> {
56  enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
57 };
58 
59 template <>
60 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4
61 pcast<cl::sycl::cl_double2, cl::sycl::cl_float4>(
62  const cl::sycl::cl_double2& a, const cl::sycl::cl_double2& b) {
63  auto a1 = a.template convert<cl::sycl::cl_float,
64  cl::sycl::rounding_mode::automatic>();
65  auto b1 = b.template convert<cl::sycl::cl_float,
66  cl::sycl::rounding_mode::automatic>();
67  return cl::sycl::cl_float4(a1.x(), a1.y(), b1.x(), b1.y());
68 }
69 
70 template <>
71 struct type_casting_traits<float, double> {
72  enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
73 };
74 
75 template <>
76 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2
77 pcast<cl::sycl::cl_float4, cl::sycl::cl_double2>(const cl::sycl::cl_float4& a) {
78  // Simply discard the second half of the input
79  return cl::sycl::cl_double2(a.x(), a.y());
80 }
81 
82 #endif
83 } // end namespace internal
84 
85 } // end namespace Eigen
86 
87 #endif // EIGEN_TYPE_CASTING_SYCL_H
Array< int, 3, 1 > b
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:836
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
: InteropHeaders
Definition: Core:139