XeTLA v0.3.6
IntelĀ® Xe Templates for Linear Algebra - API Definition Document
 
Loading...
Searching...
No Matches
explicit_conv.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (c) 2022-2023 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
19
20#pragma once
21
26
27namespace gpu::xetla {
28
31
32//template <typename T_dst, typename T_src, int N>
33//__XETLA_API xetla_vector<T_dst, N> xetla_cvt(xetla_vector<T_src, N> src) {}
34
39template <typename T_dst, typename T_src, int N>
40__XETLA_API typename std::enable_if_t<!(is_internal_type<T_dst>::value)
42 xetla_vector<T_dst, N>>
44 xetla_vector<T_dst, N> dst = src;
45 return dst;
46}
47
52template <typename T_dst, typename T_src, int N>
53__XETLA_API typename std::enable_if_t<std::is_same<T_dst, bf16>::value
54 && std::is_same<T_src, float>::value,
55 xetla_vector<T_dst, N>>
57 xetla_vector<T_dst, N> dst = src;
58 return dst;
59}
60
65template <typename T_dst, typename T_src, int N>
66__XETLA_API typename std::enable_if_t<std::is_same<T_dst, float>::value
67 && std::is_same<T_src, bf16>::value,
68 xetla_vector<T_dst, N>>
70 xetla_vector<T_dst, N> dst = src;
71 return dst;
72}
73
78template <typename T_dst, typename T_src, int N>
79__XETLA_API typename std::enable_if_t<std::is_same<T_dst, tf32>::value
80 && std::is_same<T_src, float>::value,
81 xetla_vector<T_dst, N>>
83 xetla_vector<T_dst, N> dst = src;
84 return dst;
85}
86
91template <typename T_dst, typename T_src, int N>
92__XETLA_API typename std::enable_if_t<std::is_same<T_dst, float>::value
93 && std::is_same<T_src, tf32>::value,
94 xetla_vector<T_dst, N>>
96 return src.xetla_format<float>();
97}
98
103template <typename T_dst, typename T_src, int N>
104__XETLA_API typename std::enable_if_t<std::is_same<T_dst, fp16>::value
105 && std::is_same<T_src, int32_t>::value,
106 xetla_vector<T_dst, N>>
107xetla_cvt(xetla_vector<T_src, N> src, float scaling_value) {
108 xetla_vector<T_dst, N> dst = scaling_value * src;
109 return dst;
110}
111
116template <typename T_dst, typename T_src, int N>
117__XETLA_API typename std::enable_if_t<std::is_same<T_dst, int8_t>::value
118 && std::is_same<T_src, int32_t>::value,
119 xetla_vector<T_dst, N>>
120xetla_cvt(xetla_vector<T_src, N> src, float scaling_value) {
121 auto tmp = xetla_rnde<float>(scaling_value * src);
122 auto dst = __ESIMD_NS::saturate<T_dst, float, N>(tmp);
123 return dst;
124}
125
130template <typename T_dst, typename T_src, int N>
131__XETLA_API typename std::enable_if_t<std::is_same<T_dst, int8_t>::value
132 && std::is_same<T_src, float>::value,
133 xetla_vector<T_dst, N>>
134xetla_cvt(xetla_vector<T_src, N> src, float scaling_value) {
135 auto tmp = xetla_rnde<float>(scaling_value * src);
136 auto dst = __ESIMD_NS::saturate<T_dst, float, N>(tmp);
137 return dst;
138}
139
144template <typename T_dst, typename T_src, int N>
145__XETLA_API typename std::enable_if_t<std::is_same<T_dst, T_src>::value
147 xetla_vector<T_dst, N>>
149 return src;
150}
151
153
154} // namespace gpu::xetla
C++ API.
C++ API.
#define __XETLA_API
Definition common.hpp:43
__ESIMD_NS::simd< native_type_t< Ty >, N > xetla_vector
wrapper for xetla_vector.
Definition base_types.hpp:149
__XETLA_API std::enable_if_t<!(is_internal_type< T_dst >::value) &&!(is_internal_type< T_src >::value), xetla_vector< T_dst, N > > xetla_cvt(xetla_vector< T_src, N > src)
xetla explicit data conversion for standard data types(integer,float,half)
Definition explicit_conv.hpp:43
Definition arch_config.hpp:24
static constexpr bool value
Definition base_types.hpp:68