HIP: Heterogenous-computing Interface for Portability
amd_math_functions.h
1 /*
2 Copyright (c) 2015 - 2023 Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE 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__
45 namespace std {
46 template <>
47 struct __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__
66 inline
67 int amd_mixed_dot(short2 a, short2 b, int c, bool saturate) {
68  return __ockl_sdot2(a.data, b.data, c, saturate);
69 }
70 __DEVICE__
71 inline
72 uint amd_mixed_dot(ushort2 a, ushort2 b, uint c, bool saturate) {
73  return __ockl_udot2(a.data, b.data, c, saturate);
74 }
75 __DEVICE__
76 inline
77 int amd_mixed_dot(char4 a, char4 b, int c, bool saturate) {
78  return __ockl_sdot4(a.data, b.data, c, saturate);
79 }
80 __DEVICE__
81 inline
82 uint amd_mixed_dot(uchar4 a, uchar4 b, uint c, bool saturate) {
83  return __ockl_udot4(a.data, b.data, c, saturate);
84 }
85 __DEVICE__
86 inline
87 int amd_mixed_dot(int a, int b, int c, bool saturate) {
88  return __ockl_sdot8(a, b, c, saturate);
89 }
90 __DEVICE__
91 inline
92 uint 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