HIP: Heterogenous-computing Interface for Portability
Loading...
Searching...
No Matches
amd_math_functions.h
1/*
2Copyright (c) 2015 - 2023 Advanced Micro Devices, Inc. All rights reserved.
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22
23#pragma once
24
25#if !defined(__HIPCC_RTC__)
26#include "hip_fp16_math_fwd.h"
27#include "amd_hip_vector_types.h"
28#include "math_fwd.h"
29
31
32#include <algorithm>
33// assert.h is only for the host version of assert.
34// The device version of assert is implemented in hip/amd_detail/hip_runtime.h.
35// Users should include hip_runtime.h for the device version of assert.
36#if !__HIP_DEVICE_COMPILE__
37#include <assert.h>
38#endif
39#include <limits.h>
40#include <limits>
41#include <stdint.h>
42#endif // !defined(__HIPCC_RTC__)
43
44#if _LIBCPP_VERSION && __HIP__
45namespace std {
46template <>
47struct __numeric_type<_Float16>
48{
49 static _Float16 __test(_Float16);
50
51 typedef _Float16 type;
52 static const bool value = true;
53};
54}
55#endif // _LIBCPP_VERSION
56
57#pragma push_macro("__DEVICE__")
58#pragma push_macro("__RETURN_TYPE")
59
60#define __DEVICE__ static __device__
61#define __RETURN_TYPE bool
62
63// DOT FUNCTIONS
64#if defined(__clang__) && defined(__HIP__)
65__DEVICE__
66inline
67int amd_mixed_dot(short2 a, short2 b, int c, bool saturate) {
68 return __ockl_sdot2(a.data, b.data, c, saturate);
69}
70__DEVICE__
71inline
72uint amd_mixed_dot(ushort2 a, ushort2 b, uint c, bool saturate) {
73 return __ockl_udot2(a.data, b.data, c, saturate);
74}
75__DEVICE__
76inline
77int amd_mixed_dot(char4 a, char4 b, int c, bool saturate) {
78 return __ockl_sdot4(a.data, b.data, c, saturate);
79}
80__DEVICE__
81inline
82uint amd_mixed_dot(uchar4 a, uchar4 b, uint c, bool saturate) {
83 return __ockl_udot4(a.data, b.data, c, saturate);
84}
85__DEVICE__
86inline
87int amd_mixed_dot(int a, int b, int c, bool saturate) {
88 return __ockl_sdot8(a, b, c, saturate);
89}
90__DEVICE__
91inline
92uint amd_mixed_dot(uint a, uint b, uint c, bool saturate) {
93 return __ockl_udot8(a, b, c, saturate);
94}
95#endif
96
97#pragma pop_macro("__DEVICE__")
98#pragma pop_macro("__RETURN_TYPE")
99// For backward compatibility.
100// There are HIP applications e.g. TensorFlow, expecting __HIP_ARCH_* macros
101// defined after including math_functions.h.
102#if !defined(__HIPCC_RTC__)
103#include <hip/amd_detail/amd_hip_runtime.h>
104#endif
Definition amd_hip_vector_types.h:1672
Definition amd_hip_vector_types.h:1709
Definition amd_hip_vector_types.h:1739
Definition amd_hip_vector_types.h:1776