Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit 84bd5f3

Browse files
Anusha GodavarthySuryazhang2amd
authored andcommitted
SWDEV-362611 - Added hmax and hmin
Change-Id: I133a80e997e39357693df7ab969425c0d5585607 (cherry picked from commit 16edfa7)
1 parent 56b3642 commit 84bd5f3

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

include/hip/amd_detail/amd_hip_fp16.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,38 @@ THE SOFTWARE.
12501250
inline
12511251
__HOST_DEVICE__
12521252
bool __hbgtu2(__half2 x, __half2 y) { return __hbgt2(x, y); }
1253+
inline
1254+
__device__
1255+
__half __hmax(const __half x, const __half y) {
1256+
return __half_raw{__ocml_fmax_f16(static_cast<__half_raw>(x).data,
1257+
static_cast<__half_raw>(y).data)};
1258+
}
1259+
inline
1260+
__device__
1261+
__half __hmax_nan(const __half x, const __half y) {
1262+
if(__ocml_isnan_f16(x)) {
1263+
return x;
1264+
} else if (__ocml_isnan_f16(y)) {
1265+
return y;
1266+
}
1267+
return __hmax(x, y);
1268+
}
1269+
inline
1270+
__device__
1271+
__half __hmin(const __half x, const __half y) {
1272+
return __half_raw{__ocml_fmin_f16(static_cast<__half_raw>(x).data,
1273+
static_cast<__half_raw>(y).data)};
1274+
}
1275+
inline
1276+
__device__
1277+
__half __hmin_nan(const __half x, const __half y) {
1278+
if(__ocml_isnan_f16(x)) {
1279+
return x;
1280+
} else if (__ocml_isnan_f16(y)) {
1281+
return y;
1282+
}
1283+
return __hmin(x, y);
1284+
}
12531285

12541286
// Arithmetic
12551287
inline

include/hip/amd_detail/hip_fp16_math_fwd.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ THE SOFTWARE.
2525
// /*
2626
// Half Math Functions
2727
// */
28-
2928
#include "host_defines.h"
3029
#if !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__
3130
extern "C"
@@ -51,6 +50,8 @@ extern "C"
5150
__device__ _Float16 __ocml_sin_f16(_Float16);
5251
__device__ __attribute__((const)) _Float16 __ocml_sqrt_f16(_Float16);
5352
__device__ __attribute__((const)) _Float16 __ocml_trunc_f16(_Float16);
53+
__device__ __attribute__((const)) _Float16 __ocml_fmax_f16(_Float16, _Float16);
54+
__device__ __attribute__((const)) _Float16 __ocml_fmin_f16(_Float16, _Float16);
5455

5556
typedef _Float16 __2f16 __attribute__((ext_vector_type(2)));
5657
typedef short __2i16 __attribute__((ext_vector_type(2)));
@@ -84,3 +85,8 @@ extern "C"
8485
__device__ __attribute__((const)) __2f16 __ocml_trunc_2f16(__2f16);
8586
}
8687
#endif // !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__
88+
//TODO: remove these after they get into clang header __clang_hip_libdevice_declares.h'
89+
extern "C" {
90+
__device__ __attribute__((const)) _Float16 __ocml_fmax_f16(_Float16, _Float16);
91+
__device__ __attribute__((const)) _Float16 __ocml_fmin_f16(_Float16, _Float16);
92+
}

0 commit comments

Comments
 (0)