Eigen  5.0.1
 
Loading...
Searching...
No Matches
TypeCasting.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 * TypeCasting.h
17 *
18 * \brief:
19 * TypeCasting
20 *
21 *****************************************************************/
22
23#ifndef EIGEN_TYPE_CASTING_SYCL_H
24#define EIGEN_TYPE_CASTING_SYCL_H
25
26// IWYU pragma: private
27#include "../../InternalHeaderCheck.h"
28
29namespace Eigen {
30
31namespace internal {
32#ifdef SYCL_DEVICE_ONLY
33template <>
34struct type_casting_traits<float, int> {
35 enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
36};
37
38template <>
39EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_int4 pcast<cl::sycl::cl_float4, cl::sycl::cl_int4>(
40 const cl::sycl::cl_float4& a) {
41 return a.template convert<cl::sycl::cl_int, cl::sycl::rounding_mode::automatic>();
42}
43
44template <>
45struct type_casting_traits<int, float> {
46 enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 1 };
47};
48
49template <>
50EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 pcast<cl::sycl::cl_int4, cl::sycl::cl_float4>(
51 const cl::sycl::cl_int4& a) {
52 return a.template convert<cl::sycl::cl_float, cl::sycl::rounding_mode::automatic>();
53}
54
55template <>
56struct type_casting_traits<double, float> {
57 enum { VectorizedCast = 1, SrcCoeffRatio = 2, TgtCoeffRatio = 1 };
58};
59
60template <>
61EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_float4 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, cl::sycl::rounding_mode::automatic>();
64 auto b1 = b.template convert<cl::sycl::cl_float, cl::sycl::rounding_mode::automatic>();
65 return cl::sycl::cl_float4(a1.x(), a1.y(), b1.x(), b1.y());
66}
67
68template <>
69struct type_casting_traits<float, double> {
70 enum { VectorizedCast = 1, SrcCoeffRatio = 1, TgtCoeffRatio = 2 };
71};
72
73template <>
74EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE cl::sycl::cl_double2 pcast<cl::sycl::cl_float4, cl::sycl::cl_double2>(
75 const cl::sycl::cl_float4& a) {
76 // Simply discard the second half of the input
77 return cl::sycl::cl_double2(a.x(), a.y());
78}
79
80#endif
81} // end namespace internal
82
83} // end namespace Eigen
84
85#endif // EIGEN_TYPE_CASTING_SYCL_H