triton-windows 3.3.0.post19__cp312-cp312-win_amd64.whl → 3.3.1.post21__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of triton-windows might be problematic. Click here for more details.
- triton/_C/libtriton.pyd +0 -0
- triton/__init__.py +1 -1
- triton/backends/amd/driver.py +6 -1
- triton/backends/nvidia/compiler.py +1 -3
- triton/backends/nvidia/driver.py +7 -3
- triton/runtime/autotuner.py +2 -2
- triton/runtime/build.py +5 -5
- triton/runtime/tcc/lib/python310.def +1610 -0
- triton/runtime/tcc/lib/python311.def +1633 -0
- triton/runtime/tcc/lib/python312.def +1703 -0
- triton/runtime/tcc/lib/python313.def +1651 -0
- triton/runtime/tcc/lib/python313t.def +1656 -0
- triton/runtime/tcc/lib/python39.def +1644 -0
- triton/runtime/tcc/lib/python3t.def +905 -0
- triton/windows_utils.py +11 -4
- {triton_windows-3.3.0.post19.dist-info → triton_windows-3.3.1.post21.dist-info}/METADATA +1 -1
- {triton_windows-3.3.0.post19.dist-info → triton_windows-3.3.1.post21.dist-info}/RECORD +19 -109
- {triton_windows-3.3.0.post19.dist-info → triton_windows-3.3.1.post21.dist-info}/WHEEL +1 -1
- triton/backends/amd/include/hip/amd_detail/amd_channel_descriptor.h +0 -358
- triton/backends/amd/include/hip/amd_detail/amd_device_functions.h +0 -1010
- triton/backends/amd/include/hip/amd_detail/amd_hip_atomic.h +0 -1638
- triton/backends/amd/include/hip/amd_detail/amd_hip_bf16.h +0 -1814
- triton/backends/amd/include/hip/amd_detail/amd_hip_bfloat16.h +0 -293
- triton/backends/amd/include/hip/amd_detail/amd_hip_common.h +0 -32
- triton/backends/amd/include/hip/amd_detail/amd_hip_complex.h +0 -174
- triton/backends/amd/include/hip/amd_detail/amd_hip_cooperative_groups.h +0 -835
- triton/backends/amd/include/hip/amd_detail/amd_hip_fp16.h +0 -1809
- triton/backends/amd/include/hip/amd_detail/amd_hip_fp8.h +0 -1391
- triton/backends/amd/include/hip/amd_detail/amd_hip_gl_interop.h +0 -108
- triton/backends/amd/include/hip/amd_detail/amd_hip_math_constants.h +0 -124
- triton/backends/amd/include/hip/amd_detail/amd_hip_runtime.h +0 -405
- triton/backends/amd/include/hip/amd_detail/amd_hip_runtime_pt_api.h +0 -196
- triton/backends/amd/include/hip/amd_detail/amd_hip_unsafe_atomics.h +0 -565
- triton/backends/amd/include/hip/amd_detail/amd_hip_vector_types.h +0 -2226
- triton/backends/amd/include/hip/amd_detail/amd_math_functions.h +0 -104
- triton/backends/amd/include/hip/amd_detail/amd_surface_functions.h +0 -244
- triton/backends/amd/include/hip/amd_detail/amd_warp_functions.h +0 -538
- triton/backends/amd/include/hip/amd_detail/amd_warp_sync_functions.h +0 -288
- triton/backends/amd/include/hip/amd_detail/concepts.hpp +0 -30
- triton/backends/amd/include/hip/amd_detail/device_library_decls.h +0 -133
- triton/backends/amd/include/hip/amd_detail/functional_grid_launch.hpp +0 -218
- triton/backends/amd/include/hip/amd_detail/grid_launch.h +0 -67
- triton/backends/amd/include/hip/amd_detail/grid_launch.hpp +0 -50
- triton/backends/amd/include/hip/amd_detail/grid_launch_GGL.hpp +0 -26
- triton/backends/amd/include/hip/amd_detail/helpers.hpp +0 -137
- triton/backends/amd/include/hip/amd_detail/hip_api_trace.hpp +0 -1446
- triton/backends/amd/include/hip/amd_detail/hip_assert.h +0 -101
- triton/backends/amd/include/hip/amd_detail/hip_cooperative_groups_helper.h +0 -242
- triton/backends/amd/include/hip/amd_detail/hip_fp16_gcc.h +0 -254
- triton/backends/amd/include/hip/amd_detail/hip_fp16_math_fwd.h +0 -96
- triton/backends/amd/include/hip/amd_detail/hip_ldg.h +0 -100
- triton/backends/amd/include/hip/amd_detail/hip_prof_str.h +0 -10570
- triton/backends/amd/include/hip/amd_detail/hip_runtime_prof.h +0 -78
- triton/backends/amd/include/hip/amd_detail/host_defines.h +0 -184
- triton/backends/amd/include/hip/amd_detail/hsa_helpers.hpp +0 -102
- triton/backends/amd/include/hip/amd_detail/macro_based_grid_launch.hpp +0 -798
- triton/backends/amd/include/hip/amd_detail/math_fwd.h +0 -698
- triton/backends/amd/include/hip/amd_detail/ockl_image.h +0 -177
- triton/backends/amd/include/hip/amd_detail/program_state.hpp +0 -107
- triton/backends/amd/include/hip/amd_detail/texture_fetch_functions.h +0 -491
- triton/backends/amd/include/hip/amd_detail/texture_indirect_functions.h +0 -478
- triton/backends/amd/include/hip/channel_descriptor.h +0 -39
- triton/backends/amd/include/hip/device_functions.h +0 -38
- triton/backends/amd/include/hip/driver_types.h +0 -468
- triton/backends/amd/include/hip/hip_bf16.h +0 -36
- triton/backends/amd/include/hip/hip_bfloat16.h +0 -44
- triton/backends/amd/include/hip/hip_common.h +0 -100
- triton/backends/amd/include/hip/hip_complex.h +0 -38
- triton/backends/amd/include/hip/hip_cooperative_groups.h +0 -46
- triton/backends/amd/include/hip/hip_deprecated.h +0 -95
- triton/backends/amd/include/hip/hip_ext.h +0 -161
- triton/backends/amd/include/hip/hip_fp16.h +0 -36
- triton/backends/amd/include/hip/hip_fp8.h +0 -33
- triton/backends/amd/include/hip/hip_gl_interop.h +0 -32
- triton/backends/amd/include/hip/hip_hcc.h +0 -24
- triton/backends/amd/include/hip/hip_math_constants.h +0 -36
- triton/backends/amd/include/hip/hip_profile.h +0 -27
- triton/backends/amd/include/hip/hip_runtime.h +0 -75
- triton/backends/amd/include/hip/hip_runtime_api.h +0 -9261
- triton/backends/amd/include/hip/hip_texture_types.h +0 -29
- triton/backends/amd/include/hip/hip_vector_types.h +0 -41
- triton/backends/amd/include/hip/hip_version.h +0 -17
- triton/backends/amd/include/hip/hiprtc.h +0 -421
- triton/backends/amd/include/hip/library_types.h +0 -78
- triton/backends/amd/include/hip/math_functions.h +0 -42
- triton/backends/amd/include/hip/surface_types.h +0 -63
- triton/backends/amd/include/hip/texture_types.h +0 -194
- triton/backends/amd/include/hsa/Brig.h +0 -1131
- triton/backends/amd/include/hsa/amd_hsa_common.h +0 -91
- triton/backends/amd/include/hsa/amd_hsa_elf.h +0 -462
- triton/backends/amd/include/hsa/amd_hsa_kernel_code.h +0 -269
- triton/backends/amd/include/hsa/amd_hsa_queue.h +0 -109
- triton/backends/amd/include/hsa/amd_hsa_signal.h +0 -80
- triton/backends/amd/include/hsa/hsa.h +0 -5738
- triton/backends/amd/include/hsa/hsa_amd_tool.h +0 -91
- triton/backends/amd/include/hsa/hsa_api_trace.h +0 -579
- triton/backends/amd/include/hsa/hsa_api_trace_version.h +0 -68
- triton/backends/amd/include/hsa/hsa_ext_amd.h +0 -3146
- triton/backends/amd/include/hsa/hsa_ext_finalize.h +0 -531
- triton/backends/amd/include/hsa/hsa_ext_image.h +0 -1454
- triton/backends/amd/include/hsa/hsa_ven_amd_aqlprofile.h +0 -488
- triton/backends/amd/include/hsa/hsa_ven_amd_loader.h +0 -667
- triton/backends/amd/include/hsa/hsa_ven_amd_pc_sampling.h +0 -416
- triton/backends/amd/include/roctracer/ext/prof_protocol.h +0 -107
- triton/backends/amd/include/roctracer/hip_ostream_ops.h +0 -4515
- triton/backends/amd/include/roctracer/hsa_ostream_ops.h +0 -1727
- triton/backends/amd/include/roctracer/hsa_prof_str.h +0 -3059
- triton/backends/amd/include/roctracer/roctracer.h +0 -779
- triton/backends/amd/include/roctracer/roctracer_ext.h +0 -81
- triton/backends/amd/include/roctracer/roctracer_hcc.h +0 -24
- triton/backends/amd/include/roctracer/roctracer_hip.h +0 -37
- triton/backends/amd/include/roctracer/roctracer_hsa.h +0 -112
- triton/backends/amd/include/roctracer/roctracer_plugin.h +0 -137
- triton/backends/amd/include/roctracer/roctracer_roctx.h +0 -67
- triton/backends/amd/include/roctracer/roctx.h +0 -229
- {triton_windows-3.3.0.post19.dist-info → triton_windows-3.3.1.post21.dist-info}/top_level.txt +0 -0
|
@@ -1,1814 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2019 - 2024 Advanced Micro Devices, Inc. All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in
|
|
14
|
-
* all copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* \file
|
|
27
|
-
* \brief hip_bf16.h provides struct for __hip_bfloat16 types
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16 bfloat16 Precision Intrinsics
|
|
32
|
-
* This section describes hip_bfloat16 precision intrinsic functions.
|
|
33
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16_ARITH Bfloat16 Arithmetic Functions
|
|
38
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
39
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16_COMP Bfloat16 Comparision Functions
|
|
44
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
45
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* \defgroup HIP_INTRINSIC_BFLOAT162_COMP Bfloat162 Comparision Functions
|
|
50
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
51
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* \defgroup HIP_INTRINSIC_BFLOAT162_ARITH Bfloat162 Arithmetic Functions
|
|
56
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
57
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16_CONV Bfloat16 Conversion Functions
|
|
62
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
63
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* \defgroup HIP_INTRINSIC_BFLOAT162_CONV Bfloat162 Conversion Functions
|
|
68
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
69
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16_MATH Bfloat16 Math Functions
|
|
74
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
75
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* \defgroup HIP_INTRINSIC_BFLOAT162_MATH Bfloat162 Math Functions
|
|
80
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
81
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16_RAW Bfloat16 Raw Struct
|
|
86
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
87
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* \defgroup HIP_INTRINSIC_BFLOAT162_RAW Bfloat162 Raw Struct
|
|
92
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
93
|
-
* To use these functions, include the header file \p hip_bf16.h in your program.
|
|
94
|
-
*/
|
|
95
|
-
|
|
96
|
-
#ifndef _HIP_INCLUDE_HIP_AMD_DETAIL_HIP_BF16_H_
|
|
97
|
-
#define _HIP_INCLUDE_HIP_AMD_DETAIL_HIP_BF16_H_
|
|
98
|
-
|
|
99
|
-
#if !defined(__HIPCC_RTC__)
|
|
100
|
-
#include <hip/amd_detail/amd_hip_common.h>
|
|
101
|
-
#endif // !defined(__HIPCC_RTC__)
|
|
102
|
-
|
|
103
|
-
#include "amd_hip_vector_types.h" // float2 etc
|
|
104
|
-
#include "device_library_decls.h" // ocml conversion functions
|
|
105
|
-
#include "math_fwd.h" // ocml device functions
|
|
106
|
-
|
|
107
|
-
#define __BF16_DEVICE__ __device__
|
|
108
|
-
#if defined(__HIPCC_RTC__)
|
|
109
|
-
#define __BF16_HOST_DEVICE__ __BF16_DEVICE__
|
|
110
|
-
#else
|
|
111
|
-
#include <algorithm>
|
|
112
|
-
#include <climits>
|
|
113
|
-
#include <cmath>
|
|
114
|
-
#define __BF16_HOST_DEVICE__ __host__ __BF16_DEVICE__
|
|
115
|
-
#endif
|
|
116
|
-
#define __BF16_DEVICE_STATIC__ __BF16_DEVICE__ static inline
|
|
117
|
-
#define __BF16_HOST_DEVICE_STATIC__ __BF16_HOST_DEVICE__ static inline
|
|
118
|
-
|
|
119
|
-
#if defined(__AVX512VL__) and defined(__AVX512BF16__) and not defined(__HIP_DEVICE_COMPILE__)
|
|
120
|
-
// Enable with -mavx512vl -mavx512bf16
|
|
121
|
-
#if defined(__MINGW64__)
|
|
122
|
-
#include <intrin.h>
|
|
123
|
-
#else
|
|
124
|
-
#include <immintrin.h>
|
|
125
|
-
#endif
|
|
126
|
-
#define HIP_BF16_AVX512_OP 1
|
|
127
|
-
static_assert(sizeof(__bf16) == sizeof(unsigned short),
|
|
128
|
-
"sizeof __bf16 should match sizeof unsigned short");
|
|
129
|
-
#else
|
|
130
|
-
#define HIP_BF16_AVX512_OP 0
|
|
131
|
-
#endif
|
|
132
|
-
|
|
133
|
-
#define HIPRT_ONE_BF16 __float2bfloat16(1.0f)
|
|
134
|
-
#define HIPRT_ZERO_BF16 __float2bfloat16(0.0f)
|
|
135
|
-
#define HIPRT_INF_BF16 __ushort_as_bfloat16((unsigned short)0x7F80U)
|
|
136
|
-
#define HIPRT_MAX_NORMAL_BF16 __ushort_as_bfloat16((unsigned short)0x7F7FU)
|
|
137
|
-
#define HIPRT_MIN_DENORM_BF16 __ushort_as_bfloat16((unsigned short)0x0001U)
|
|
138
|
-
#define HIPRT_NAN_BF16 __ushort_as_bfloat16((unsigned short)0x7FFFU)
|
|
139
|
-
#define HIPRT_NEG_ZERO_BF16 __ushort_as_bfloat16((unsigned short)0x8000U)
|
|
140
|
-
|
|
141
|
-
// Since we are using unsigned short to represent data in bfloat16, it can be of different sizes on
|
|
142
|
-
// different machines. These naive checks should prevent some undefined behavior on systems which
|
|
143
|
-
// have different sizes for basic types.
|
|
144
|
-
#if !defined(__HIPCC_RTC__)
|
|
145
|
-
static_assert(CHAR_BIT == 8, "byte size should be of 8 bits");
|
|
146
|
-
#endif
|
|
147
|
-
static_assert(sizeof(unsigned short) == 2, "size of unsigned short should be 2 bytes");
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_RAW
|
|
151
|
-
* \brief represents raw bfloat16 type
|
|
152
|
-
*/
|
|
153
|
-
typedef struct __attribute__((aligned(2))) {
|
|
154
|
-
unsigned short x;
|
|
155
|
-
} __hip_bfloat16_raw;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_RAW
|
|
159
|
-
* \brief represents raw bfloat16x2 vector type
|
|
160
|
-
*/
|
|
161
|
-
typedef struct __attribute__((aligned(4))) {
|
|
162
|
-
unsigned short x;
|
|
163
|
-
unsigned short y;
|
|
164
|
-
} __hip_bfloat162_raw;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* \defgroup HIP_INTRINSIC_BFLOAT16_STRUCT
|
|
168
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
169
|
-
* \brief Struct to represent a 16 bit brain floating point number.
|
|
170
|
-
* @{
|
|
171
|
-
*/
|
|
172
|
-
struct __attribute__((aligned(2))) __hip_bfloat16 {
|
|
173
|
-
private:
|
|
174
|
-
__BF16_HOST_DEVICE_STATIC__ float bfloatraw_2_float(unsigned short val) {
|
|
175
|
-
#if HIP_BF16_AVX512_OP
|
|
176
|
-
union {
|
|
177
|
-
unsigned short us;
|
|
178
|
-
__bf16 bf16;
|
|
179
|
-
} u = {val};
|
|
180
|
-
return _mm_cvtsbh_ss(u.bf16);
|
|
181
|
-
#else
|
|
182
|
-
unsigned int uval = val << 16;
|
|
183
|
-
union {
|
|
184
|
-
unsigned int u32;
|
|
185
|
-
float fp32;
|
|
186
|
-
} u = {uval};
|
|
187
|
-
return u.fp32;
|
|
188
|
-
#endif
|
|
189
|
-
}
|
|
190
|
-
__BF16_HOST_DEVICE_STATIC__ unsigned short float_2_bfloatraw(float f) {
|
|
191
|
-
#if HIP_BF16_AVX512_OP
|
|
192
|
-
union {
|
|
193
|
-
__bf16 bf16;
|
|
194
|
-
unsigned short us;
|
|
195
|
-
} u = {_mm_cvtness_sbh(f)};
|
|
196
|
-
return u.us;
|
|
197
|
-
#else
|
|
198
|
-
union {
|
|
199
|
-
float fp32;
|
|
200
|
-
unsigned int u32;
|
|
201
|
-
} u = {f};
|
|
202
|
-
if (~u.u32 & 0x7f800000) {
|
|
203
|
-
// When the exponent bits are not all 1s, then the value is zero, normal,
|
|
204
|
-
// or subnormal. We round the bfloat16 mantissa up by adding 0x7FFF, plus
|
|
205
|
-
// 1 if the least significant bit of the bfloat16 mantissa is 1 (odd).
|
|
206
|
-
// This causes the bfloat16's mantissa to be incremented by 1 if the 16
|
|
207
|
-
// least significant bits of the float mantissa are greater than 0x8000,
|
|
208
|
-
// or if they are equal to 0x8000 and the least significant bit of the
|
|
209
|
-
// bfloat16 mantissa is 1 (odd). This causes it to be rounded to even when
|
|
210
|
-
// the lower 16 bits are exactly 0x8000. If the bfloat16 mantissa already
|
|
211
|
-
// has the value 0x7f, then incrementing it causes it to become 0x00 and
|
|
212
|
-
// the exponent is incremented by one, which is the next higher FP value
|
|
213
|
-
// to the unrounded bfloat16 value. When the bfloat16 value is subnormal
|
|
214
|
-
// with an exponent of 0x00 and a mantissa of 0x7F, it may be rounded up
|
|
215
|
-
// to a normal value with an exponent of 0x01 and a mantissa of 0x00.
|
|
216
|
-
// When the bfloat16 value has an exponent of 0xFE and a mantissa of 0x7F,
|
|
217
|
-
// incrementing it causes it to become an exponent of 0xFF and a mantissa
|
|
218
|
-
// of 0x00, which is Inf, the next higher value to the unrounded value.
|
|
219
|
-
u.u32 += 0x7fff + ((u.u32 >> 16) & 1); // Round to nearest, round to even
|
|
220
|
-
} else if (u.u32 & 0xffff) {
|
|
221
|
-
// When all of the exponent bits are 1, the value is Inf or NaN.
|
|
222
|
-
// Inf is indicated by a zero mantissa. NaN is indicated by any nonzero
|
|
223
|
-
// mantissa bit. Quiet NaN is indicated by the most significant mantissa
|
|
224
|
-
// bit being 1. Signaling NaN is indicated by the most significant
|
|
225
|
-
// mantissa bit being 0 but some other bit(s) being 1. If any of the
|
|
226
|
-
// lower 16 bits of the mantissa are 1, we set the least significant bit
|
|
227
|
-
// of the bfloat16 mantissa, in order to preserve signaling NaN in case
|
|
228
|
-
// the bloat16's mantissa bits are all 0.
|
|
229
|
-
u.u32 |= 0x10000; // Preserve signaling NaN
|
|
230
|
-
}
|
|
231
|
-
return static_cast<unsigned short>(u.u32 >> 16);
|
|
232
|
-
#endif
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
__BF16_HOST_DEVICE_STATIC__ unsigned short double_2_bfloatraw(double d_in) {
|
|
236
|
-
union {
|
|
237
|
-
float fp32;
|
|
238
|
-
unsigned int u32;
|
|
239
|
-
} u = {static_cast<float>(d_in)};
|
|
240
|
-
double d = u.fp32;
|
|
241
|
-
|
|
242
|
-
// Round to odd
|
|
243
|
-
if ((d_in > 0.0 && d > d_in) || (d_in < 0.0 && d < d_in)) {
|
|
244
|
-
u.u32--;
|
|
245
|
-
u.u32 |= 1;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return float_2_bfloatraw(u.fp32);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
protected:
|
|
252
|
-
/*! \brief raw representation of bfloat16 */
|
|
253
|
-
unsigned short __x;
|
|
254
|
-
|
|
255
|
-
public:
|
|
256
|
-
// TODO: SWDEV-452411
|
|
257
|
-
// Need to add constructor of __hip_bfloat16 from
|
|
258
|
-
// unsigned long long
|
|
259
|
-
// long long
|
|
260
|
-
// long
|
|
261
|
-
// unsigned long
|
|
262
|
-
// Casting directly to double might lead to double rounding.
|
|
263
|
-
|
|
264
|
-
/*! \brief create __hip_bfloat16 from an unsigned int */
|
|
265
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(unsigned int val)
|
|
266
|
-
: __x(double_2_bfloatraw(static_cast<double>(val))) {}
|
|
267
|
-
|
|
268
|
-
/*! \brief create __hip_bfloat16 from a int */
|
|
269
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(int val)
|
|
270
|
-
: __x(double_2_bfloatraw(static_cast<double>(val))) {}
|
|
271
|
-
|
|
272
|
-
/*! \brief create __hip_bfloat16 from an unsigned short */
|
|
273
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(unsigned short val)
|
|
274
|
-
: __x(float_2_bfloatraw(static_cast<float>(val))) {}
|
|
275
|
-
|
|
276
|
-
/*! \brief create __hip_bfloat16 from a short */
|
|
277
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(short val)
|
|
278
|
-
: __x(float_2_bfloatraw(static_cast<float>(val))) {}
|
|
279
|
-
|
|
280
|
-
/*! \brief create __hip_bfloat16 from a double */
|
|
281
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(const double val) : __x(double_2_bfloatraw(val)) {}
|
|
282
|
-
|
|
283
|
-
/*! \brief create __hip_bfloat16 from a float */
|
|
284
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(const float val) : __x(float_2_bfloatraw(val)) {}
|
|
285
|
-
|
|
286
|
-
/*! \brief create __hip_bfloat16 from a __hip_bfloat16_raw */
|
|
287
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16(const __hip_bfloat16_raw& val) : __x(val.x) {}
|
|
288
|
-
|
|
289
|
-
/*! \brief default constructor */
|
|
290
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16() = default;
|
|
291
|
-
|
|
292
|
-
/*! \brief return a __hip_bfloat16_raw */
|
|
293
|
-
__BF16_HOST_DEVICE__ operator __hip_bfloat16_raw() const { return __hip_bfloat16_raw{__x}; }
|
|
294
|
-
|
|
295
|
-
/*! \brief return a __hip_bfloat16_raw cv qualifier */
|
|
296
|
-
__BF16_HOST_DEVICE__ operator __hip_bfloat16_raw() const volatile {
|
|
297
|
-
return __hip_bfloat16_raw{__x};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/*! \brief return false if bfloat value is +0.0 or -0.0, returns true otherwise */
|
|
301
|
-
__BF16_HOST_DEVICE__ operator bool() const {
|
|
302
|
-
auto val = bfloatraw_2_float(__x);
|
|
303
|
-
return val != 0.0f && val != -0.0f;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/*! \brief return a casted char from underlying float val */
|
|
307
|
-
__BF16_HOST_DEVICE__ operator char() const { return static_cast<char>(bfloatraw_2_float(__x)); }
|
|
308
|
-
|
|
309
|
-
/*! \brief return a float */
|
|
310
|
-
__BF16_HOST_DEVICE__ operator float() const { return bfloatraw_2_float(__x); }
|
|
311
|
-
|
|
312
|
-
/*! \brief return a casted int casted from float of underlying bfloat16 value */
|
|
313
|
-
__BF16_HOST_DEVICE__ operator int() const { return static_cast<int>(bfloatraw_2_float(__x)); }
|
|
314
|
-
|
|
315
|
-
/*! \brief return a casted long casted from float of underlying bfloat16 value */
|
|
316
|
-
__BF16_HOST_DEVICE__ operator long() const { return static_cast<long>(bfloatraw_2_float(__x)); }
|
|
317
|
-
|
|
318
|
-
/*! \brief return a casted long long casted from float of underlying bfloat16 value */
|
|
319
|
-
__BF16_HOST_DEVICE__ operator long long() const {
|
|
320
|
-
return static_cast<long long>(bfloatraw_2_float(__x));
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/*! \brief return a casted short casted from float of underlying bfloat16 value */
|
|
324
|
-
__BF16_HOST_DEVICE__ operator short() const { return static_cast<short>(bfloatraw_2_float(__x)); }
|
|
325
|
-
|
|
326
|
-
/*! \brief return a casted signed char from float of underlying bfloat16 value */
|
|
327
|
-
__BF16_HOST_DEVICE__ operator signed char() const {
|
|
328
|
-
return static_cast<signed char>(bfloatraw_2_float(__x));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/*! \brief return a casted unsigned char casted from float of underlying bfloat16 value */
|
|
332
|
-
__BF16_HOST_DEVICE__ operator unsigned char() const {
|
|
333
|
-
return static_cast<unsigned char>(bfloatraw_2_float(__x));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/*! \brief return a casted unsigned int casted from float of underlying bfloat16 value */
|
|
337
|
-
__BF16_HOST_DEVICE__ operator unsigned int() const {
|
|
338
|
-
return static_cast<unsigned int>(bfloatraw_2_float(__x));
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/*! \brief return a casted unsigned from float of underlying bfloat16 value */
|
|
342
|
-
__BF16_HOST_DEVICE__ operator unsigned long() const {
|
|
343
|
-
return static_cast<unsigned long>(bfloatraw_2_float(__x));
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/*! \brief return a casted unsigned long long from float of underlying bfloat16 value */
|
|
347
|
-
__BF16_HOST_DEVICE__ operator unsigned long long() const {
|
|
348
|
-
return static_cast<unsigned long long>(bfloatraw_2_float(__x));
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/*! \brief return a casted unsigned short from float of underlying bfloat16 value */
|
|
352
|
-
__BF16_HOST_DEVICE__ operator unsigned short() const {
|
|
353
|
-
return static_cast<unsigned short>(bfloatraw_2_float(__x));
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// TODO: SWDEV-452411 add operator which converts unsigned long long and long long to bfloat
|
|
357
|
-
|
|
358
|
-
/*! \brief assign value from an unsigned int */
|
|
359
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(unsigned int val) {
|
|
360
|
-
__x = float_2_bfloatraw(static_cast<float>(val));
|
|
361
|
-
return *this;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/*! \brief assign value from a int */
|
|
365
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(int val) {
|
|
366
|
-
__x = float_2_bfloatraw(static_cast<float>(val));
|
|
367
|
-
return *this;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/*! \brief assign value from an unsigned short */
|
|
371
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(unsigned short val) {
|
|
372
|
-
__x = float_2_bfloatraw(static_cast<float>(val));
|
|
373
|
-
return *this;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/*! \brief assign value from a short int */
|
|
377
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(short val) {
|
|
378
|
-
__x = float_2_bfloatraw(static_cast<float>(val));
|
|
379
|
-
return *this;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/*! \brief assign value from a double */
|
|
383
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(const double f) {
|
|
384
|
-
__x = float_2_bfloatraw(static_cast<float>(f));
|
|
385
|
-
return *this;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/*! \brief assign value from a float */
|
|
389
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(const float f) {
|
|
390
|
-
__x = float_2_bfloatraw(f);
|
|
391
|
-
return *this;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/*! \brief assign value from a __hip_bfloat16_raw */
|
|
395
|
-
__BF16_HOST_DEVICE__ __hip_bfloat16& operator=(const __hip_bfloat16_raw& hr) {
|
|
396
|
-
__x = hr.x;
|
|
397
|
-
return *this;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/*! \brief assign value from a __hip_bfloat16_raw volatile */
|
|
401
|
-
__BF16_HOST_DEVICE__ volatile __hip_bfloat16& operator=(const __hip_bfloat16_raw& hr) volatile {
|
|
402
|
-
__x = hr.x;
|
|
403
|
-
return *this;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/*! \brief assign value from a __hip_bfloat16_raw cv qualifier */
|
|
407
|
-
__BF16_HOST_DEVICE__ volatile __hip_bfloat16& operator=(
|
|
408
|
-
const volatile __hip_bfloat16_raw& hr) volatile {
|
|
409
|
-
__x = hr.x;
|
|
410
|
-
return *this;
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
/**@}*/
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* \defgroup HIP_INTRINSIC_BFLOAT162_STRUCT
|
|
417
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16
|
|
418
|
-
* \brief Struct to represent a two 16 bit brain floating point number.
|
|
419
|
-
* @{
|
|
420
|
-
*/
|
|
421
|
-
struct __attribute__((aligned(4))) __hip_bfloat162 {
|
|
422
|
-
public:
|
|
423
|
-
__hip_bfloat16 x; /*! \brief raw representation of bfloat16 */
|
|
424
|
-
__hip_bfloat16 y; /*! \brief raw representation of bfloat16 */
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
public:
|
|
428
|
-
/*! \brief create __hip_bfloat162 from __hip_bfloat162_raw */
|
|
429
|
-
__BF16_HOST_DEVICE__ __hip_bfloat162(const __hip_bfloat162_raw& h2r)
|
|
430
|
-
: x(__hip_bfloat16(__hip_bfloat16_raw{h2r.x})),
|
|
431
|
-
y(__hip_bfloat16(__hip_bfloat16_raw{h2r.y})) {}
|
|
432
|
-
|
|
433
|
-
/*! \brief copy constructor of __hip_bfloat162 */
|
|
434
|
-
__BF16_HOST_DEVICE__ __hip_bfloat162(const __hip_bfloat162& val) {
|
|
435
|
-
__hip_bfloat162_raw hr = val;
|
|
436
|
-
x = __hip_bfloat16_raw{hr.x};
|
|
437
|
-
y = __hip_bfloat16_raw{hr.y};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/*! \brief create __hip_bfloat162 from two __hip_bfloat16 */
|
|
441
|
-
__BF16_HOST_DEVICE__ __hip_bfloat162(const __hip_bfloat16& a, const __hip_bfloat16& b)
|
|
442
|
-
: x(a), y(b) {}
|
|
443
|
-
|
|
444
|
-
/*! \brief default constructor of __hip_bfloat162 */
|
|
445
|
-
__BF16_HOST_DEVICE__ __hip_bfloat162() = default;
|
|
446
|
-
|
|
447
|
-
/*! \brief return a __hip_bfloat162_raw */
|
|
448
|
-
__BF16_HOST_DEVICE__ operator __hip_bfloat162_raw() const {
|
|
449
|
-
__hip_bfloat16_raw l = x;
|
|
450
|
-
__hip_bfloat16_raw r = y;
|
|
451
|
-
return __hip_bfloat162_raw{l.x, r.x};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/*! \brief return a float2 */
|
|
455
|
-
__BF16_HOST_DEVICE__ operator float2() const {
|
|
456
|
-
#if HIP_BF16_AVX512_OP
|
|
457
|
-
union {
|
|
458
|
-
__hip_bfloat162_raw raw2;
|
|
459
|
-
__bf16 bf162[2];
|
|
460
|
-
static_assert(sizeof(__bf16[2]) == sizeof(__hip_bfloat162_raw));
|
|
461
|
-
} u;
|
|
462
|
-
u.raw2 = *this;
|
|
463
|
-
__m128bh pbf16{u.bf162[0], u.bf162[1], 0, 0};
|
|
464
|
-
__m128 pf32 = _mm_cvtpbh_ps(pbf16);
|
|
465
|
-
float2 ret(pf32[0], pf32[1]);
|
|
466
|
-
#else
|
|
467
|
-
float2 ret(x, y);
|
|
468
|
-
#endif
|
|
469
|
-
return ret;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/*! \brief assign value from __hip_bfloat162_raw */
|
|
473
|
-
__BF16_HOST_DEVICE__ __hip_bfloat162& operator=(const __hip_bfloat162_raw& h2r) {
|
|
474
|
-
x = __hip_bfloat16(__hip_bfloat16_raw{h2r.x});
|
|
475
|
-
y = __hip_bfloat16(__hip_bfloat16_raw{h2r.y});
|
|
476
|
-
return *this;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/*! \brief assign value from __hip_bfloat162 */
|
|
480
|
-
__BF16_HOST_DEVICE__ __hip_bfloat162& operator=(const __hip_bfloat162& src) {
|
|
481
|
-
__hip_bfloat162_raw hr = src;
|
|
482
|
-
x = __hip_bfloat16(__hip_bfloat16_raw{hr.x});
|
|
483
|
-
y = __hip_bfloat16(__hip_bfloat16_raw{hr.y});
|
|
484
|
-
return *this;
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
/**@}*/
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_CONV
|
|
491
|
-
* \brief Converts bfloat16 to float
|
|
492
|
-
*/
|
|
493
|
-
__BF16_HOST_DEVICE_STATIC__ float __bfloat162float(__hip_bfloat16 a) {
|
|
494
|
-
float ret = a;
|
|
495
|
-
return ret;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_CONV
|
|
500
|
-
* \brief Converts float to bfloat16
|
|
501
|
-
*/
|
|
502
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __float2bfloat16(float f) {
|
|
503
|
-
__hip_bfloat16 ret{f};
|
|
504
|
-
return ret;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
509
|
-
* \brief Converts and moves bfloat162 to float2
|
|
510
|
-
*/
|
|
511
|
-
__BF16_HOST_DEVICE_STATIC__ float2 __bfloat1622float2(const __hip_bfloat162 a) {
|
|
512
|
-
float2 ret = a;
|
|
513
|
-
return ret;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
518
|
-
* \brief Moves bfloat16 value to bfloat162
|
|
519
|
-
*/
|
|
520
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __bfloat162bfloat162(const __hip_bfloat16 a) {
|
|
521
|
-
return __hip_bfloat162(a, a);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
526
|
-
* \brief Reinterprets bits in a __hip_bfloat16 as a signed short integer
|
|
527
|
-
*/
|
|
528
|
-
__BF16_HOST_DEVICE_STATIC__ short int __bfloat16_as_short(const __hip_bfloat16 h) {
|
|
529
|
-
short ret = h;
|
|
530
|
-
return ret;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
535
|
-
* \brief Reinterprets bits in a __hip_bfloat16 as an unsigned signed short integer
|
|
536
|
-
*/
|
|
537
|
-
__BF16_HOST_DEVICE_STATIC__ unsigned short int __bfloat16_as_ushort(const __hip_bfloat16 h) {
|
|
538
|
-
unsigned short ret = h;
|
|
539
|
-
return ret;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
544
|
-
* \brief Convert double to __hip_bfloat16
|
|
545
|
-
*/
|
|
546
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __double2bfloat16(const double a) {
|
|
547
|
-
__hip_bfloat16 ret{a};
|
|
548
|
-
return ret;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
553
|
-
* \brief Convert float2 to __hip_bfloat162
|
|
554
|
-
*/
|
|
555
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __float22bfloat162_rn(const float2 a) {
|
|
556
|
-
return __hip_bfloat162{__float2bfloat16(a.x), __float2bfloat16(a.y)};
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
561
|
-
* \brief Combine two __hip_bfloat16 to __hip_bfloat162
|
|
562
|
-
*/
|
|
563
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __halves2bfloat162(const __hip_bfloat16 a,
|
|
564
|
-
const __hip_bfloat16 b) {
|
|
565
|
-
return __hip_bfloat162(a, b);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
570
|
-
* \brief Returns high 16 bits of __hip_bfloat162
|
|
571
|
-
*/
|
|
572
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __high2bfloat16(const __hip_bfloat162 a) {
|
|
573
|
-
__hip_bfloat162_raw hr = a;
|
|
574
|
-
return __hip_bfloat16(__hip_bfloat16_raw{hr.y});
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
579
|
-
* \brief Returns high 16 bits of __hip_bfloat162
|
|
580
|
-
*/
|
|
581
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __high2bfloat162(const __hip_bfloat162 a) {
|
|
582
|
-
__hip_bfloat162_raw hr = a;
|
|
583
|
-
return __hip_bfloat162(__hip_bfloat16_raw{hr.y}, __hip_bfloat16_raw{hr.y});
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
588
|
-
* \brief Converts high 16 bits of __hip_bfloat162 to float and returns the result
|
|
589
|
-
*/
|
|
590
|
-
__BF16_HOST_DEVICE_STATIC__ float __high2float(const __hip_bfloat162 a) {
|
|
591
|
-
__hip_bfloat162_raw hr = a;
|
|
592
|
-
return __bfloat162float(__hip_bfloat16(__hip_bfloat16_raw{hr.y}));
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
597
|
-
* \brief Extracts high 16 bits from each and combines them
|
|
598
|
-
*/
|
|
599
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __highs2bfloat162(const __hip_bfloat162 a,
|
|
600
|
-
const __hip_bfloat162 b) {
|
|
601
|
-
__hip_bfloat162_raw hr_a = a;
|
|
602
|
-
__hip_bfloat162_raw hr_b = b;
|
|
603
|
-
return __hip_bfloat162(__hip_bfloat162_raw{hr_a.y, hr_b.y});
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
608
|
-
* \brief Returns low 16 bits of __hip_bfloat162
|
|
609
|
-
*/
|
|
610
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __low2bfloat16(const __hip_bfloat162 a) {
|
|
611
|
-
__hip_bfloat162_raw hr = a;
|
|
612
|
-
return __hip_bfloat16(hr.x);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
617
|
-
* \brief Returns low 16 bits of __hip_bfloat162
|
|
618
|
-
*/
|
|
619
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __low2bfloat162(const __hip_bfloat162 a) {
|
|
620
|
-
__hip_bfloat162_raw hr = a;
|
|
621
|
-
return __hip_bfloat162(hr.x, hr.x);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
626
|
-
* \brief Converts low 16 bits of __hip_bfloat162 to float and returns the result
|
|
627
|
-
*/
|
|
628
|
-
__BF16_HOST_DEVICE_STATIC__ float __low2float(const __hip_bfloat162 a) {
|
|
629
|
-
__hip_bfloat162_raw hr = a;
|
|
630
|
-
return __bfloat162float(__hip_bfloat16(__hip_bfloat16_raw{hr.x}));
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
635
|
-
* \brief Swaps both halves
|
|
636
|
-
*/
|
|
637
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __lowhigh2highlow(const __hip_bfloat162 a) {
|
|
638
|
-
__hip_bfloat162_raw hr = a;
|
|
639
|
-
return __hip_bfloat162(__hip_bfloat162_raw{hr.y, hr.x});
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
/**
|
|
643
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
644
|
-
* \brief Extracts low 16 bits from each and combines them
|
|
645
|
-
*/
|
|
646
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __lows2bfloat162(const __hip_bfloat162 a,
|
|
647
|
-
const __hip_bfloat162 b) {
|
|
648
|
-
__hip_bfloat162_raw hr_a = a;
|
|
649
|
-
__hip_bfloat162_raw hr_b = b;
|
|
650
|
-
return __hip_bfloat162(__hip_bfloat162_raw{hr_a.x, hr_b.x});
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
655
|
-
* \brief Reinterprets short int into a bfloat16
|
|
656
|
-
*/
|
|
657
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __short_as_bfloat16(const short int a) {
|
|
658
|
-
return __hip_bfloat16(a);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_CONV
|
|
663
|
-
* \brief Reinterprets unsigned short int into a bfloat16
|
|
664
|
-
*/
|
|
665
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __ushort_as_bfloat16(const unsigned short int a) {
|
|
666
|
-
return __hip_bfloat16(a);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
671
|
-
* \brief Adds two bfloat16 values
|
|
672
|
-
*/
|
|
673
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hadd(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
674
|
-
return __float2bfloat16(__bfloat162float(a) + __bfloat162float(b));
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
679
|
-
* \brief Subtracts two bfloat16 values
|
|
680
|
-
*/
|
|
681
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hsub(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
682
|
-
return __float2bfloat16(__bfloat162float(a) - __bfloat162float(b));
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
687
|
-
* \brief Divides two bfloat16 values
|
|
688
|
-
*/
|
|
689
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hdiv(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
690
|
-
return __float2bfloat16(__bfloat162float(a) / __bfloat162float(b));
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
695
|
-
* \brief Performs FMA of given bfloat16 values
|
|
696
|
-
*/
|
|
697
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 __hfma(const __hip_bfloat16 a, const __hip_bfloat16 b,
|
|
698
|
-
const __hip_bfloat16 c) {
|
|
699
|
-
return __float2bfloat16(
|
|
700
|
-
__ocml_fma_f32(__bfloat162float(a), __bfloat162float(b), __bfloat162float(c)));
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
705
|
-
* \brief Multiplies two bfloat16 values
|
|
706
|
-
*/
|
|
707
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hmul(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
708
|
-
return __float2bfloat16(__bfloat162float(a) * __bfloat162float(b));
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
713
|
-
* \brief Negate a bfloat16 value
|
|
714
|
-
*/
|
|
715
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hneg(const __hip_bfloat16 a) {
|
|
716
|
-
__hip_bfloat16_raw hr = a;
|
|
717
|
-
hr.x ^= 0x8000;
|
|
718
|
-
return __hip_bfloat16(hr);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/**
|
|
722
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
723
|
-
* \brief Returns absolute of a bfloat16
|
|
724
|
-
*/
|
|
725
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __habs(const __hip_bfloat16 a) {
|
|
726
|
-
__hip_bfloat16_raw hr = a;
|
|
727
|
-
hr.x &= 0x7FFF;
|
|
728
|
-
return __hip_bfloat16(hr);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
733
|
-
* \brief Divides bfloat162 values
|
|
734
|
-
*/
|
|
735
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __h2div(const __hip_bfloat162 a,
|
|
736
|
-
const __hip_bfloat162 b) {
|
|
737
|
-
__hip_bfloat162_raw hr_a = a;
|
|
738
|
-
__hip_bfloat162_raw hr_b = b;
|
|
739
|
-
return __hip_bfloat162(__float2bfloat16(__bfloat162float(__hip_bfloat16_raw{hr_a.x}) /
|
|
740
|
-
__bfloat162float(__hip_bfloat16_raw{hr_b.x})),
|
|
741
|
-
__float2bfloat16(__bfloat162float(__hip_bfloat16_raw{hr_a.y}) /
|
|
742
|
-
__bfloat162float(__hip_bfloat16_raw{hr_b.y})));
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
747
|
-
* \brief Returns absolute of a bfloat162
|
|
748
|
-
*/
|
|
749
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __habs2(const __hip_bfloat162 a) {
|
|
750
|
-
__hip_bfloat162_raw hr_a = a;
|
|
751
|
-
return __hip_bfloat162(__habs(__hip_bfloat16_raw{hr_a.x}), __habs(__hip_bfloat16_raw{hr_a.y}));
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
/**
|
|
755
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
756
|
-
* \brief Adds two bfloat162 values
|
|
757
|
-
*/
|
|
758
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hadd2(const __hip_bfloat162 a,
|
|
759
|
-
const __hip_bfloat162 b) {
|
|
760
|
-
__hip_bfloat162_raw hr_a = a;
|
|
761
|
-
__hip_bfloat162_raw hr_b = b;
|
|
762
|
-
return __hip_bfloat162(__hadd(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}),
|
|
763
|
-
__hadd(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}));
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
768
|
-
* \brief Performs FMA of given bfloat162 values
|
|
769
|
-
*/
|
|
770
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 __hfma2(const __hip_bfloat162 a, const __hip_bfloat162 b,
|
|
771
|
-
const __hip_bfloat162 c) {
|
|
772
|
-
__hip_bfloat162_raw hr_a = a;
|
|
773
|
-
__hip_bfloat162_raw hr_b = b;
|
|
774
|
-
__hip_bfloat162_raw hr_c = c;
|
|
775
|
-
return __hip_bfloat162(
|
|
776
|
-
__hfma(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}, __hip_bfloat16_raw{hr_c.x}),
|
|
777
|
-
__hfma(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}, __hip_bfloat16_raw{hr_c.y}));
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
782
|
-
* \brief Multiplies two bfloat162 values
|
|
783
|
-
*/
|
|
784
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hmul2(const __hip_bfloat162 a,
|
|
785
|
-
const __hip_bfloat162 b) {
|
|
786
|
-
__hip_bfloat162_raw hr_a = a;
|
|
787
|
-
__hip_bfloat162_raw hr_b = b;
|
|
788
|
-
return __hip_bfloat162(__hmul(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}),
|
|
789
|
-
__hmul(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}));
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
/**
|
|
793
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
794
|
-
* \brief Converts a bfloat162 into negative
|
|
795
|
-
*/
|
|
796
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hneg2(const __hip_bfloat162 a) {
|
|
797
|
-
__hip_bfloat162_raw hr_a = a;
|
|
798
|
-
return __hip_bfloat162(__hneg(__hip_bfloat16_raw{hr_a.x}), __hneg(__hip_bfloat16_raw{hr_a.y}));
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
803
|
-
* \brief Subtracts two bfloat162 values
|
|
804
|
-
*/
|
|
805
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hsub2(const __hip_bfloat162 a,
|
|
806
|
-
const __hip_bfloat162 b) {
|
|
807
|
-
__hip_bfloat162_raw hr_a = a;
|
|
808
|
-
__hip_bfloat162_raw hr_b = b;
|
|
809
|
-
return __hip_bfloat162(__hsub(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}),
|
|
810
|
-
__hsub(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}));
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
/**
|
|
814
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
815
|
-
* \brief Operator to multiply two __hip_bfloat16 numbers
|
|
816
|
-
*/
|
|
817
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator*(const __hip_bfloat16& l,
|
|
818
|
-
const __hip_bfloat16& r) {
|
|
819
|
-
return __hmul(l, r);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
824
|
-
* \brief Operator to multiply-assign two __hip_bfloat16 numbers
|
|
825
|
-
*/
|
|
826
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16& operator*=(__hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
827
|
-
l = __hmul(l, r);
|
|
828
|
-
return l;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
833
|
-
* \brief Operator to unary+ on a __hip_bfloat16 number
|
|
834
|
-
*/
|
|
835
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator+(const __hip_bfloat16& l) { return l; }
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
839
|
-
* \brief Operator to add two __hip_bfloat16 numbers
|
|
840
|
-
*/
|
|
841
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator+(const __hip_bfloat16& l,
|
|
842
|
-
const __hip_bfloat16& r) {
|
|
843
|
-
return __hadd(l, r);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
/**
|
|
847
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
848
|
-
* \brief Operator to negate a __hip_bfloat16 number
|
|
849
|
-
*/
|
|
850
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator-(const __hip_bfloat16& l) { return __hneg(l); }
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
854
|
-
* \brief Operator to subtract two __hip_bfloat16 numbers
|
|
855
|
-
*/
|
|
856
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator-(const __hip_bfloat16& l,
|
|
857
|
-
const __hip_bfloat16& r) {
|
|
858
|
-
return __hsub(l, r);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
863
|
-
* \brief Operator to post increment a __hip_bfloat16 number
|
|
864
|
-
*/
|
|
865
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator++(__hip_bfloat16& l, const int) {
|
|
866
|
-
auto ret = l;
|
|
867
|
-
l = __hadd(l, HIPRT_ONE_BF16);
|
|
868
|
-
return ret;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
873
|
-
* \brief Operator to pre increment a __hip_bfloat16 number
|
|
874
|
-
*/
|
|
875
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16& operator++(__hip_bfloat16& l) {
|
|
876
|
-
l = __hadd(l, HIPRT_ONE_BF16);
|
|
877
|
-
return l;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
882
|
-
* \brief Operator to post decrement a __hip_bfloat16 number
|
|
883
|
-
*/
|
|
884
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator--(__hip_bfloat16& l, const int) {
|
|
885
|
-
auto ret = l;
|
|
886
|
-
l = __hsub(l, HIPRT_ONE_BF16);
|
|
887
|
-
return ret;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
/**
|
|
891
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
892
|
-
* \brief Operator to pre decrement a __hip_bfloat16 number
|
|
893
|
-
*/
|
|
894
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16& operator--(__hip_bfloat16& l) {
|
|
895
|
-
l = __hsub(l, HIPRT_ONE_BF16);
|
|
896
|
-
return l;
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
901
|
-
* \brief Operator to add-assign two __hip_bfloat16 numbers
|
|
902
|
-
*/
|
|
903
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16& operator+=(__hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
904
|
-
l = __hadd(l, r);
|
|
905
|
-
return l;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
/**
|
|
909
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
910
|
-
* \brief Operator to subtract-assign two __hip_bfloat16 numbers
|
|
911
|
-
*/
|
|
912
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16& operator-=(__hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
913
|
-
l = __hsub(l, r);
|
|
914
|
-
return l;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
/**
|
|
918
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
919
|
-
* \brief Operator to divide two __hip_bfloat16 numbers
|
|
920
|
-
*/
|
|
921
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 operator/(const __hip_bfloat16& l,
|
|
922
|
-
const __hip_bfloat16& r) {
|
|
923
|
-
return __hdiv(l, r);
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/**
|
|
927
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_ARITH
|
|
928
|
-
* \brief Operator to divide-assign two __hip_bfloat16 numbers
|
|
929
|
-
*/
|
|
930
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16& operator/=(__hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
931
|
-
l = __hdiv(l, r);
|
|
932
|
-
return l;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
/**
|
|
936
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
937
|
-
* \brief Operator to multiply two __hip_bfloat162 numbers
|
|
938
|
-
*/
|
|
939
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator*(const __hip_bfloat162& l,
|
|
940
|
-
const __hip_bfloat162& r) {
|
|
941
|
-
return __hmul2(l, r);
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
946
|
-
* \brief Operator to multiply-assign two __hip_bfloat162 numbers
|
|
947
|
-
*/
|
|
948
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162& operator*=(__hip_bfloat162& l,
|
|
949
|
-
const __hip_bfloat162& r) {
|
|
950
|
-
l = __hmul2(l, r);
|
|
951
|
-
return l;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
/**
|
|
955
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
956
|
-
* \brief Operator to unary+ on a __hip_bfloat162 number
|
|
957
|
-
*/
|
|
958
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator+(const __hip_bfloat162& l) { return l; }
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
962
|
-
* \brief Operator to add two __hip_bfloat162 numbers
|
|
963
|
-
*/
|
|
964
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator+(const __hip_bfloat162& l,
|
|
965
|
-
const __hip_bfloat162& r) {
|
|
966
|
-
return __hadd2(l, r);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
/**
|
|
970
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
971
|
-
* \brief Operator to negate a __hip_bfloat162 number
|
|
972
|
-
*/
|
|
973
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator-(const __hip_bfloat162& l) {
|
|
974
|
-
return __hneg2(l);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
979
|
-
* \brief Operator to subtract two __hip_bfloat162 numbers
|
|
980
|
-
*/
|
|
981
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator-(const __hip_bfloat162& l,
|
|
982
|
-
const __hip_bfloat162& r) {
|
|
983
|
-
return __hsub2(l, r);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
/**
|
|
987
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
988
|
-
* \brief Operator to post increment a __hip_bfloat162 number
|
|
989
|
-
*/
|
|
990
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator++(__hip_bfloat162& l, const int) {
|
|
991
|
-
auto ret = l;
|
|
992
|
-
l = __hadd2(l, {HIPRT_ONE_BF16, HIPRT_ONE_BF16});
|
|
993
|
-
return ret;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
998
|
-
* \brief Operator to pre increment a __hip_bfloat162 number
|
|
999
|
-
*/
|
|
1000
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162& operator++(__hip_bfloat162& l) {
|
|
1001
|
-
l = __hadd2(l, {HIPRT_ONE_BF16, HIPRT_ONE_BF16});
|
|
1002
|
-
return l;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
1007
|
-
* \brief Operator to post decrement a __hip_bfloat162 number
|
|
1008
|
-
*/
|
|
1009
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator--(__hip_bfloat162& l, const int) {
|
|
1010
|
-
auto ret = l;
|
|
1011
|
-
l = __hsub2(l, {HIPRT_ONE_BF16, HIPRT_ONE_BF16});
|
|
1012
|
-
return ret;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
/**
|
|
1016
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
1017
|
-
* \brief Operator to pre decrement a __hip_bfloat162 number
|
|
1018
|
-
*/
|
|
1019
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162& operator--(__hip_bfloat162& l) {
|
|
1020
|
-
l = __hsub2(l, {HIPRT_ONE_BF16, HIPRT_ONE_BF16});
|
|
1021
|
-
return l;
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
/**
|
|
1025
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
1026
|
-
* \brief Operator to add-assign two __hip_bfloat162 numbers
|
|
1027
|
-
*/
|
|
1028
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162& operator+=(__hip_bfloat162& l,
|
|
1029
|
-
const __hip_bfloat162& r) {
|
|
1030
|
-
l = __hadd2(l, r);
|
|
1031
|
-
return l;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
/**
|
|
1035
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
1036
|
-
* \brief Operator to subtract-assign two __hip_bfloat162 numbers
|
|
1037
|
-
*/
|
|
1038
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162& operator-=(__hip_bfloat162& l,
|
|
1039
|
-
const __hip_bfloat162& r) {
|
|
1040
|
-
l = __hsub2(l, r);
|
|
1041
|
-
return l;
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
/**
|
|
1045
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
1046
|
-
* \brief Operator to divide two __hip_bfloat162 numbers
|
|
1047
|
-
*/
|
|
1048
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 operator/(const __hip_bfloat162& l,
|
|
1049
|
-
const __hip_bfloat162& r) {
|
|
1050
|
-
return __h2div(l, r);
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
/**
|
|
1054
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_ARITH
|
|
1055
|
-
* \brief Operator to divide-assign two __hip_bfloat162 numbers
|
|
1056
|
-
*/
|
|
1057
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162& operator/=(__hip_bfloat162& l,
|
|
1058
|
-
const __hip_bfloat162& r) {
|
|
1059
|
-
l = __h2div(l, r);
|
|
1060
|
-
return l;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
/**
|
|
1064
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1065
|
-
* \brief Compare two bfloat162 values
|
|
1066
|
-
*/
|
|
1067
|
-
__BF16_HOST_DEVICE_STATIC__ bool __heq(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1068
|
-
return __bfloat162float(a) == __bfloat162float(b);
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
/**
|
|
1072
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1073
|
-
* \brief Compare two bfloat162 values - unordered equal
|
|
1074
|
-
*/
|
|
1075
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hequ(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1076
|
-
return !(__bfloat162float(a) < __bfloat162float(b)) &&
|
|
1077
|
-
!(__bfloat162float(a) > __bfloat162float(b));
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
/**
|
|
1081
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1082
|
-
* \brief Compare two bfloat162 values - greater than
|
|
1083
|
-
*/
|
|
1084
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hgt(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1085
|
-
return __bfloat162float(a) > __bfloat162float(b);
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
/**
|
|
1089
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1090
|
-
* \brief Compare two bfloat162 values - unordered greater than
|
|
1091
|
-
*/
|
|
1092
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hgtu(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1093
|
-
return !(__bfloat162float(a) <= __bfloat162float(b));
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1098
|
-
* \brief Compare two bfloat162 values - greater than equal
|
|
1099
|
-
*/
|
|
1100
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hge(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1101
|
-
return __bfloat162float(a) >= __bfloat162float(b);
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
/**
|
|
1105
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1106
|
-
* \brief Compare two bfloat162 values - unordered greater than equal
|
|
1107
|
-
*/
|
|
1108
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hgeu(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1109
|
-
return !(__bfloat162float(a) < __bfloat162float(b));
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
/**
|
|
1113
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1114
|
-
* \brief Compare two bfloat162 values - not equal
|
|
1115
|
-
*/
|
|
1116
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hne(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1117
|
-
return __bfloat162float(a) != __bfloat162float(b);
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
/**
|
|
1121
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1122
|
-
* \brief Compare two bfloat162 values - unordered not equal
|
|
1123
|
-
*/
|
|
1124
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hneu(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1125
|
-
return !(__bfloat162float(a) == __bfloat162float(b));
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
/**
|
|
1129
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1130
|
-
* \brief Compare two bfloat162 values - return max
|
|
1131
|
-
*/
|
|
1132
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hmax(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1133
|
-
#if __HIP_DEVICE_COMPILE__
|
|
1134
|
-
return __float2bfloat16(__ocml_fmax_f32(__bfloat162float(a), __bfloat162float(b)));
|
|
1135
|
-
#else
|
|
1136
|
-
return __float2bfloat16(std::max(__bfloat162float(a), __bfloat162float(b)));
|
|
1137
|
-
#endif
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
/**
|
|
1141
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1142
|
-
* \brief Compare two bfloat162 values - return min
|
|
1143
|
-
*/
|
|
1144
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __hmin(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1145
|
-
#if __HIP_DEVICE_COMPILE__
|
|
1146
|
-
return __float2bfloat16(__ocml_fmin_f32(__bfloat162float(a), __bfloat162float(b)));
|
|
1147
|
-
#else
|
|
1148
|
-
return __float2bfloat16(std::min(__bfloat162float(a), __bfloat162float(b)));
|
|
1149
|
-
#endif
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
/**
|
|
1153
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1154
|
-
* \brief Compare two bfloat162 values - less than operator
|
|
1155
|
-
*/
|
|
1156
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hlt(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1157
|
-
return __bfloat162float(a) < __bfloat162float(b);
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
/**
|
|
1161
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1162
|
-
* \brief Compare two bfloat162 values - unordered less than
|
|
1163
|
-
*/
|
|
1164
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hltu(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1165
|
-
return !(__bfloat162float(a) >= __bfloat162float(b));
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
/**
|
|
1169
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1170
|
-
* \brief Compare two bfloat162 values - less than equal
|
|
1171
|
-
*/
|
|
1172
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hle(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1173
|
-
return __bfloat162float(a) <= __bfloat162float(b);
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
/**
|
|
1177
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1178
|
-
* \brief Compare two bfloat162 values - unordered less than equal
|
|
1179
|
-
*/
|
|
1180
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hleu(const __hip_bfloat16 a, const __hip_bfloat16 b) {
|
|
1181
|
-
return !(__bfloat162float(a) > __bfloat162float(b));
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
/**
|
|
1185
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1186
|
-
* \brief Checks if number is inf
|
|
1187
|
-
*/
|
|
1188
|
-
__BF16_HOST_DEVICE_STATIC__ int __hisinf(const __hip_bfloat16 a) {
|
|
1189
|
-
__hip_bfloat16_raw hr = a;
|
|
1190
|
-
return !(~hr.x & 0x7f80) && !(hr.x & 0x7f);
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
/**
|
|
1194
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1195
|
-
* \brief Checks if number is nan
|
|
1196
|
-
*/
|
|
1197
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hisnan(const __hip_bfloat16 a) {
|
|
1198
|
-
__hip_bfloat16_raw hr = a;
|
|
1199
|
-
return !(~hr.x & 0x7f80) && +(hr.x & 0x7f);
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
/**
|
|
1203
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1204
|
-
* \brief Checks if two numbers are equal
|
|
1205
|
-
*/
|
|
1206
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbeq2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1207
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1208
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1209
|
-
return __heq(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1210
|
-
__heq(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
/**
|
|
1214
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1215
|
-
* \brief Checks if two numbers are equal - unordered
|
|
1216
|
-
*/
|
|
1217
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbequ2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1218
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1219
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1220
|
-
return __hequ(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1221
|
-
__hequ(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
/**
|
|
1225
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1226
|
-
* \brief Check for a >= b
|
|
1227
|
-
*/
|
|
1228
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbge2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1229
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1230
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1231
|
-
return __hge(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1232
|
-
__hge(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
/**
|
|
1236
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1237
|
-
* \brief Check for a >= b - unordered
|
|
1238
|
-
*/
|
|
1239
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbgeu2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1240
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1241
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1242
|
-
return __hgeu(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1243
|
-
__hgeu(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
/**
|
|
1247
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1248
|
-
* \brief Check for a > b
|
|
1249
|
-
*/
|
|
1250
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbgt2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1251
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1252
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1253
|
-
return __hgt(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1254
|
-
__hgt(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
/**
|
|
1258
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1259
|
-
* \brief Check for a > b - unordered
|
|
1260
|
-
*/
|
|
1261
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbgtu2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1262
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1263
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1264
|
-
return __hgtu(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1265
|
-
__hgtu(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
/**
|
|
1269
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1270
|
-
* \brief Check for a <= b
|
|
1271
|
-
*/
|
|
1272
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hble2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1273
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1274
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1275
|
-
return __hle(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1276
|
-
__hle(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
/**
|
|
1280
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1281
|
-
* \brief Check for a <= b - unordered
|
|
1282
|
-
*/
|
|
1283
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbleu2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1284
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1285
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1286
|
-
return __hleu(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1287
|
-
__hleu(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
/**
|
|
1291
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1292
|
-
* \brief Check for a < b
|
|
1293
|
-
*/
|
|
1294
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hblt2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1295
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1296
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1297
|
-
return __hlt(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1298
|
-
__hlt(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
/**
|
|
1302
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1303
|
-
* \brief Check for a < b - unordered
|
|
1304
|
-
*/
|
|
1305
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbltu2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1306
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1307
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1308
|
-
return __hltu(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) &&
|
|
1309
|
-
__hltu(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
/**
|
|
1313
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1314
|
-
* \brief Check for a != b
|
|
1315
|
-
*/
|
|
1316
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbne2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1317
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1318
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1319
|
-
return __hne(__hip_bfloat16(__hip_bfloat16_raw{hr_a.x}),
|
|
1320
|
-
__hip_bfloat16(__hip_bfloat16_raw{hr_b.x})) &&
|
|
1321
|
-
__hne(__hip_bfloat16(__hip_bfloat16_raw{hr_a.y}), __hip_bfloat16(__hip_bfloat16_raw{hr_b.y}));
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
/**
|
|
1325
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1326
|
-
* \brief Check for a != b
|
|
1327
|
-
*/
|
|
1328
|
-
__BF16_HOST_DEVICE_STATIC__ bool __hbneu2(const __hip_bfloat162 a, const __hip_bfloat162 b) {
|
|
1329
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1330
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1331
|
-
return __hneu(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ||
|
|
1332
|
-
__hneu(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y});
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
/**
|
|
1336
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1337
|
-
* \brief Check for a != b, returns 1.0 if equal, otherwise 0.0
|
|
1338
|
-
*/
|
|
1339
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __heq2(const __hip_bfloat162 a,
|
|
1340
|
-
const __hip_bfloat162 b) {
|
|
1341
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1342
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1343
|
-
return __hip_bfloat162{
|
|
1344
|
-
{__heq(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ? HIPRT_ONE_BF16
|
|
1345
|
-
: HIPRT_ZERO_BF16},
|
|
1346
|
-
{__heq(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}) ? HIPRT_ONE_BF16
|
|
1347
|
-
: HIPRT_ZERO_BF16}};
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
/**
|
|
1351
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1352
|
-
* \brief Check for a >= b, returns 1.0 if greater than equal, otherwise 0.0
|
|
1353
|
-
*/
|
|
1354
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hge2(const __hip_bfloat162 a,
|
|
1355
|
-
const __hip_bfloat162 b) {
|
|
1356
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1357
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1358
|
-
return __hip_bfloat162{
|
|
1359
|
-
{__hge(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ? HIPRT_ONE_BF16
|
|
1360
|
-
: HIPRT_ZERO_BF16},
|
|
1361
|
-
{__hge(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}) ? HIPRT_ONE_BF16
|
|
1362
|
-
: HIPRT_ZERO_BF16}};
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
/**
|
|
1366
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1367
|
-
* \brief Check for a > b, returns 1.0 if greater than equal, otherwise 0.0
|
|
1368
|
-
*/
|
|
1369
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hgt2(const __hip_bfloat162 a,
|
|
1370
|
-
const __hip_bfloat162 b) {
|
|
1371
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1372
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1373
|
-
return __hip_bfloat162{
|
|
1374
|
-
{__hgt(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ? HIPRT_ONE_BF16
|
|
1375
|
-
: HIPRT_ZERO_BF16},
|
|
1376
|
-
{__hgt(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}) ? HIPRT_ONE_BF16
|
|
1377
|
-
: HIPRT_ONE_BF16}};
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
/**
|
|
1381
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1382
|
-
* \brief Check for a is NaN, returns 1.0 if NaN, otherwise 0.0
|
|
1383
|
-
*/
|
|
1384
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hisnan2(const __hip_bfloat162 a) {
|
|
1385
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1386
|
-
return __hip_bfloat162{{__hisnan(__hip_bfloat16_raw{hr_a.x}) ? HIPRT_ONE_BF16 : HIPRT_ZERO_BF16},
|
|
1387
|
-
{__hisnan(__hip_bfloat16_raw{hr_a.y}) ? HIPRT_ONE_BF16 : HIPRT_ONE_BF16}};
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
/**
|
|
1391
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1392
|
-
* \brief Check for a <= b, returns 1.0 if greater than equal, otherwise 0.0
|
|
1393
|
-
*/
|
|
1394
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hle2(const __hip_bfloat162 a,
|
|
1395
|
-
const __hip_bfloat162 b) {
|
|
1396
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1397
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1398
|
-
return __hip_bfloat162{
|
|
1399
|
-
{__hle(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ? HIPRT_ONE_BF16
|
|
1400
|
-
: HIPRT_ZERO_BF16},
|
|
1401
|
-
{__hle(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}) ? HIPRT_ONE_BF16
|
|
1402
|
-
: HIPRT_ZERO_BF16}};
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
/**
|
|
1406
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1407
|
-
* \brief Check for a < b, returns 1.0 if greater than equal, otherwise 0.0
|
|
1408
|
-
*/
|
|
1409
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hlt2(const __hip_bfloat162 a,
|
|
1410
|
-
const __hip_bfloat162 b) {
|
|
1411
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1412
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1413
|
-
return __hip_bfloat162{
|
|
1414
|
-
{__hlt(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ? HIPRT_ONE_BF16
|
|
1415
|
-
: HIPRT_ZERO_BF16},
|
|
1416
|
-
{__hlt(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}) ? HIPRT_ONE_BF16
|
|
1417
|
-
: HIPRT_ZERO_BF16}};
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
/**
|
|
1421
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1422
|
-
* \brief Returns max of two elements
|
|
1423
|
-
*/
|
|
1424
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hmax2(const __hip_bfloat162 a,
|
|
1425
|
-
const __hip_bfloat162 b) {
|
|
1426
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1427
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1428
|
-
return __hip_bfloat162(__hmax(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}),
|
|
1429
|
-
__hmax(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}));
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
/**
|
|
1433
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1434
|
-
* \brief Returns min of two elements
|
|
1435
|
-
*/
|
|
1436
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hmin2(const __hip_bfloat162 a,
|
|
1437
|
-
const __hip_bfloat162 b) {
|
|
1438
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1439
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1440
|
-
return __hip_bfloat162(__hmin(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}),
|
|
1441
|
-
__hmin(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}));
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
/**
|
|
1445
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1446
|
-
* \brief Checks for not equal to
|
|
1447
|
-
*/
|
|
1448
|
-
__BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __hne2(const __hip_bfloat162 a,
|
|
1449
|
-
const __hip_bfloat162 b) {
|
|
1450
|
-
__hip_bfloat162_raw hr_a = a;
|
|
1451
|
-
__hip_bfloat162_raw hr_b = b;
|
|
1452
|
-
return __hip_bfloat162{
|
|
1453
|
-
{__hne(__hip_bfloat16_raw{hr_a.x}, __hip_bfloat16_raw{hr_b.x}) ? HIPRT_ONE_BF16
|
|
1454
|
-
: HIPRT_ZERO_BF16},
|
|
1455
|
-
{__hne(__hip_bfloat16_raw{hr_a.y}, __hip_bfloat16_raw{hr_b.y}) ? HIPRT_ONE_BF16
|
|
1456
|
-
: HIPRT_ZERO_BF16}};
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
/**
|
|
1460
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1461
|
-
* \brief Operator to perform an equal compare on two __hip_bfloat16 numbers
|
|
1462
|
-
*/
|
|
1463
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator==(const __hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
1464
|
-
return __heq(l, r);
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
/**
|
|
1468
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1469
|
-
* \brief Operator to perform a not equal on two __hip_bfloat16 numbers
|
|
1470
|
-
*/
|
|
1471
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator!=(const __hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
1472
|
-
return __hne(l, r);
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
/**
|
|
1476
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1477
|
-
* \brief Operator to perform a less than on two __hip_bfloat16 numbers
|
|
1478
|
-
*/
|
|
1479
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator<(const __hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
1480
|
-
return __hlt(l, r);
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
/**
|
|
1484
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1485
|
-
* \brief Operator to perform a less than equal on two __hip_bfloat16 numbers
|
|
1486
|
-
*/
|
|
1487
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator<=(const __hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
1488
|
-
return __hle(l, r);
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
/**
|
|
1492
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1493
|
-
* \brief Operator to perform a greater than on two __hip_bfloat16 numbers
|
|
1494
|
-
*/
|
|
1495
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator>(const __hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
1496
|
-
return __hgt(l, r);
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
/**
|
|
1500
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1501
|
-
* \brief Operator to perform a greater than equal on two __hip_bfloat16 numbers
|
|
1502
|
-
*/
|
|
1503
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator>=(const __hip_bfloat16& l, const __hip_bfloat16& r) {
|
|
1504
|
-
return __hge(l, r);
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
/**
|
|
1508
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1509
|
-
* \brief Operator to perform an equal compare on two __hip_bfloat16 numbers
|
|
1510
|
-
*/
|
|
1511
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator==(const __hip_bfloat162& l, const __hip_bfloat162& r) {
|
|
1512
|
-
float2 ret = __heq2(l, r);
|
|
1513
|
-
return ret.x != 0.0f && ret.y != 0.0f;
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
/**
|
|
1517
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1518
|
-
* \brief Operator to perform a not equal on two __hip_bfloat16 numbers
|
|
1519
|
-
*/
|
|
1520
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator!=(const __hip_bfloat162& l, const __hip_bfloat162& r) {
|
|
1521
|
-
return !(l == r);
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
/**
|
|
1525
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1526
|
-
* \brief Operator to perform a less than on two __hip_bfloat16 numbers
|
|
1527
|
-
*/
|
|
1528
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator<(const __hip_bfloat162& l, const __hip_bfloat162& r) {
|
|
1529
|
-
float2 fl = l, fr = r;
|
|
1530
|
-
return fl.x < fr.x && fl.x < fr.y;
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
/**
|
|
1534
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1535
|
-
* \brief Operator to perform a less than equal on two __hip_bfloat16 numbers
|
|
1536
|
-
*/
|
|
1537
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator<=(const __hip_bfloat162& l, const __hip_bfloat162& r) {
|
|
1538
|
-
float2 fl = l, fr = r;
|
|
1539
|
-
return fl.x <= fr.x && fl.x <= fr.y;
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
/**
|
|
1543
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_COMP
|
|
1544
|
-
* \brief Operator to perform a greater than on two __hip_bfloat16 numbers
|
|
1545
|
-
*/
|
|
1546
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator>(const __hip_bfloat162& l, const __hip_bfloat162& r) {
|
|
1547
|
-
float2 fl = l, fr = r;
|
|
1548
|
-
return fl.x > fr.x && fl.x > fr.y;
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
/**
|
|
1552
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_COMP
|
|
1553
|
-
* \brief Operator to perform a greater than equal on two __hip_bfloat16 numbers
|
|
1554
|
-
*/
|
|
1555
|
-
__BF16_HOST_DEVICE_STATIC__ bool operator>=(const __hip_bfloat162& l, const __hip_bfloat162& r) {
|
|
1556
|
-
float2 fl = l, fr = r;
|
|
1557
|
-
return fl.x >= fr.x && fl.x >= fr.y;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
/**
|
|
1561
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1562
|
-
* \brief Calculate ceil of bfloat16
|
|
1563
|
-
*/
|
|
1564
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hceil(const __hip_bfloat16 h) {
|
|
1565
|
-
return __float2bfloat16(__ocml_ceil_f32(__bfloat162float(h)));
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1570
|
-
* \brief Calculate cosine of bfloat16
|
|
1571
|
-
*/
|
|
1572
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hcos(const __hip_bfloat16 h) {
|
|
1573
|
-
return __float2bfloat16(__ocml_cos_f32(__bfloat162float(h)));
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
/**
|
|
1577
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1578
|
-
* \brief Calculate exponential of bfloat16
|
|
1579
|
-
*/
|
|
1580
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hexp(const __hip_bfloat16 h) {
|
|
1581
|
-
return __float2bfloat16(__ocml_exp_f32(__bfloat162float(h)));
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
/**
|
|
1585
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1586
|
-
* \brief Calculate exponential 10 of bfloat16
|
|
1587
|
-
*/
|
|
1588
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hexp10(const __hip_bfloat16 h) {
|
|
1589
|
-
return __float2bfloat16(__ocml_exp10_f32(__bfloat162float(h)));
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
/**
|
|
1593
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1594
|
-
* \brief Calculate exponential 2 of bfloat16
|
|
1595
|
-
*/
|
|
1596
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hexp2(const __hip_bfloat16 h) {
|
|
1597
|
-
return __float2bfloat16(__ocml_exp2_f32(__bfloat162float(h)));
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
/**
|
|
1601
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1602
|
-
* \brief Calculate floor of bfloat16
|
|
1603
|
-
*/
|
|
1604
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hfloor(const __hip_bfloat16 h) {
|
|
1605
|
-
return __float2bfloat16(__ocml_floor_f32(__bfloat162float(h)));
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
/**
|
|
1609
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1610
|
-
* \brief Calculate natural log of bfloat16
|
|
1611
|
-
*/
|
|
1612
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hlog(const __hip_bfloat16 h) {
|
|
1613
|
-
return __float2bfloat16(__ocml_log_f32(__bfloat162float(h)));
|
|
1614
|
-
}
|
|
1615
|
-
|
|
1616
|
-
/**
|
|
1617
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1618
|
-
* \brief Calculate log 10 of bfloat16
|
|
1619
|
-
*/
|
|
1620
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hlog10(const __hip_bfloat16 h) {
|
|
1621
|
-
return __float2bfloat16(__ocml_log10_f32(__bfloat162float(h)));
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
/**
|
|
1625
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1626
|
-
* \brief Calculate log 2 of bfloat16
|
|
1627
|
-
*/
|
|
1628
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hlog2(const __hip_bfloat16 h) {
|
|
1629
|
-
return __float2bfloat16(__ocml_log2_f32(__bfloat162float(h)));
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
/**
|
|
1633
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1634
|
-
* \brief Calculate reciprocal
|
|
1635
|
-
*/
|
|
1636
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hrcp(const __hip_bfloat16 h) {
|
|
1637
|
-
return __float2bfloat16(1.0f / (__bfloat162float(h)));
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
/**
|
|
1641
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1642
|
-
* \brief Round to nearest int
|
|
1643
|
-
*/
|
|
1644
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hrint(const __hip_bfloat16 h) {
|
|
1645
|
-
return __float2bfloat16(__ocml_rint_f32(__bfloat162float(h)));
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
/**
|
|
1649
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1650
|
-
* \brief Reciprocal square root
|
|
1651
|
-
*/
|
|
1652
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hrsqrt(const __hip_bfloat16 h) {
|
|
1653
|
-
return __float2bfloat16(__ocml_rsqrt_f32(__bfloat162float(h)));
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
/**
|
|
1657
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1658
|
-
* \brief Calculate sin of bfloat16
|
|
1659
|
-
*/
|
|
1660
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hsin(const __hip_bfloat16 h) {
|
|
1661
|
-
return __float2bfloat16(__ocml_sin_f32(__bfloat162float(h)));
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
/**
|
|
1665
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1666
|
-
* \brief Calculate sqrt of bfloat16
|
|
1667
|
-
*/
|
|
1668
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 hsqrt(const __hip_bfloat16 h) {
|
|
1669
|
-
return __float2bfloat16(__ocml_sqrt_f32(__bfloat162float(h)));
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
/**
|
|
1673
|
-
* \ingroup HIP_INTRINSIC_BFLOAT16_MATH
|
|
1674
|
-
* \brief Calculate truncate of bfloat16
|
|
1675
|
-
*/
|
|
1676
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat16 htrunc(const __hip_bfloat16 h) {
|
|
1677
|
-
return __float2bfloat16(__ocml_trunc_f32(__bfloat162float(h)));
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
/**
|
|
1681
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1682
|
-
* \brief Calculate ceil of bfloat162
|
|
1683
|
-
*/
|
|
1684
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2ceil(const __hip_bfloat162 h) {
|
|
1685
|
-
__hip_bfloat162_raw hr = h;
|
|
1686
|
-
return __hip_bfloat162(hceil(__hip_bfloat16_raw{hr.x}), hceil(__hip_bfloat16_raw{hr.y}));
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
/**
|
|
1690
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1691
|
-
* \brief Calculate cosine of bfloat162
|
|
1692
|
-
*/
|
|
1693
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2cos(const __hip_bfloat162 h) {
|
|
1694
|
-
__hip_bfloat162_raw hr = h;
|
|
1695
|
-
return __hip_bfloat162(hcos(__hip_bfloat16_raw{hr.x}), hcos(__hip_bfloat16_raw{hr.y}));
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
/**
|
|
1699
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1700
|
-
* \brief Calculate exponential of bfloat162
|
|
1701
|
-
*/
|
|
1702
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2exp(const __hip_bfloat162 h) {
|
|
1703
|
-
__hip_bfloat162_raw hr = h;
|
|
1704
|
-
return __hip_bfloat162(hexp(__hip_bfloat16_raw{hr.x}), hexp(__hip_bfloat16_raw{hr.y}));
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
/**
|
|
1708
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1709
|
-
* \brief Calculate exponential 10 of bfloat162
|
|
1710
|
-
*/
|
|
1711
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2exp10(const __hip_bfloat162 h) {
|
|
1712
|
-
__hip_bfloat162_raw hr = h;
|
|
1713
|
-
return __hip_bfloat162(hexp10(__hip_bfloat16_raw{hr.x}), hexp10(__hip_bfloat16_raw{hr.y}));
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
/**
|
|
1717
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1718
|
-
* \brief Calculate exponential 2 of bfloat162
|
|
1719
|
-
*/
|
|
1720
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2exp2(const __hip_bfloat162 h) {
|
|
1721
|
-
__hip_bfloat162_raw hr = h;
|
|
1722
|
-
return __hip_bfloat162(hexp2(__hip_bfloat16_raw{hr.x}), hexp2(__hip_bfloat16_raw{hr.y}));
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
/**
|
|
1726
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1727
|
-
* \brief Calculate floor of bfloat162
|
|
1728
|
-
*/
|
|
1729
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2floor(const __hip_bfloat162 h) {
|
|
1730
|
-
__hip_bfloat162_raw hr = h;
|
|
1731
|
-
return __hip_bfloat162(hfloor(__hip_bfloat16_raw{hr.x}), hfloor(__hip_bfloat16_raw{hr.y}));
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
/**
|
|
1735
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1736
|
-
* \brief Calculate natural log of bfloat162
|
|
1737
|
-
*/
|
|
1738
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2log(const __hip_bfloat162 h) {
|
|
1739
|
-
__hip_bfloat162_raw hr = h;
|
|
1740
|
-
return __hip_bfloat162(hlog(__hip_bfloat16_raw{hr.x}), hlog(__hip_bfloat16_raw{hr.y}));
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
/**
|
|
1744
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1745
|
-
* \brief Calculate log 10 of bfloat162
|
|
1746
|
-
*/
|
|
1747
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2log10(const __hip_bfloat162 h) {
|
|
1748
|
-
__hip_bfloat162_raw hr = h;
|
|
1749
|
-
return __hip_bfloat162(hlog10(__hip_bfloat16_raw{hr.x}), hlog10(__hip_bfloat16_raw{hr.y}));
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
/**
|
|
1753
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1754
|
-
* \brief Calculate log 2 of bfloat162
|
|
1755
|
-
*/
|
|
1756
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2log2(const __hip_bfloat162 h) {
|
|
1757
|
-
__hip_bfloat162_raw hr = h;
|
|
1758
|
-
return __hip_bfloat162(hlog2(__hip_bfloat16_raw{hr.x}), hlog2(__hip_bfloat16_raw{hr.y}));
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
|
-
/**
|
|
1762
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1763
|
-
* \brief Calculate vector reciprocal
|
|
1764
|
-
*/
|
|
1765
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2rcp(const __hip_bfloat162 h) {
|
|
1766
|
-
__hip_bfloat162_raw hr = h;
|
|
1767
|
-
return __hip_bfloat162(hrcp(__hip_bfloat16_raw{hr.x}), hrcp(__hip_bfloat16_raw{hr.y}));
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
/**
|
|
1771
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1772
|
-
* \brief Calculate vector round to nearest int
|
|
1773
|
-
*/
|
|
1774
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2rint(const __hip_bfloat162 h) {
|
|
1775
|
-
__hip_bfloat162_raw hr = h;
|
|
1776
|
-
return __hip_bfloat162(hrint(__hip_bfloat16_raw{hr.x}), hrint(__hip_bfloat16_raw{hr.y}));
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
/**
|
|
1780
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1781
|
-
* \brief Calculate vector reciprocal square root
|
|
1782
|
-
*/
|
|
1783
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2rsqrt(const __hip_bfloat162 h) {
|
|
1784
|
-
__hip_bfloat162_raw hr = h;
|
|
1785
|
-
return __hip_bfloat162(hrsqrt(__hip_bfloat16_raw{hr.x}), hrsqrt(__hip_bfloat16_raw{hr.y}));
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
/**
|
|
1789
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1790
|
-
* \brief Calculate sin of bfloat162
|
|
1791
|
-
*/
|
|
1792
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2sin(const __hip_bfloat162 h) {
|
|
1793
|
-
__hip_bfloat162_raw hr = h;
|
|
1794
|
-
return __hip_bfloat162(hsin(__hip_bfloat16_raw{hr.x}), hsin(__hip_bfloat16_raw{hr.y}));
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
/**
|
|
1798
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1799
|
-
* \brief Calculate sqrt of bfloat162
|
|
1800
|
-
*/
|
|
1801
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2sqrt(const __hip_bfloat162 h) {
|
|
1802
|
-
__hip_bfloat162_raw hr = h;
|
|
1803
|
-
return __hip_bfloat162(hsqrt(__hip_bfloat16_raw{hr.x}), hsqrt(__hip_bfloat16_raw{hr.y}));
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
/**
|
|
1807
|
-
* \ingroup HIP_INTRINSIC_BFLOAT162_MATH
|
|
1808
|
-
* \brief Calculate truncate of bfloat162
|
|
1809
|
-
*/
|
|
1810
|
-
__BF16_DEVICE_STATIC__ __hip_bfloat162 h2trunc(const __hip_bfloat162 h) {
|
|
1811
|
-
__hip_bfloat162_raw hr = h;
|
|
1812
|
-
return __hip_bfloat162(htrunc(__hip_bfloat16_raw{hr.x}), htrunc(__hip_bfloat16_raw{hr.y}));
|
|
1813
|
-
}
|
|
1814
|
-
#endif
|