Skip to content

Commit bcbce80

Browse files
committed
Revert "[HIP] fix host min/max in header (#82956)"
This reverts commit 55783bd. Due to regressions in hipCUB. hipCUB/hipcub/include/hipcub/backend/rocprim/device/device_spmv.hpp:142:33: error: call to 'min' is ambiguous https://github.com/ROCm/hipCUB/blob/develop/hipcub/include/hipcub/backend/rocprim/device/device_spmv.hpp#L142 The ambuguity seems due to missing min(int, unsigned int). Previously, there is only min(int, int). After the change, there are min(int, int) and min(unsigned int, unsigned int), therefore there is ambiguity.
1 parent f20ea05 commit bcbce80

File tree

1 file changed

+6
-66
lines changed

1 file changed

+6
-66
lines changed

clang/lib/Headers/__clang_hip_math.h

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,75 +1306,15 @@ float min(float __x, float __y) { return __builtin_fminf(__x, __y); }
13061306
__DEVICE__
13071307
double min(double __x, double __y) { return __builtin_fmin(__x, __y); }
13081308

1309-
// Define host min/max functions.
1310-
#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) && \
1311-
!defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
1312-
1313-
#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
1314-
#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
1315-
#define DEFINE_MIN_MAX_FUNCTIONS(ret_type, type1, type2) \
1316-
inline ret_type min(const type1 __a, const type2 __b) { \
1317-
return (__a < __b) ? __a : __b; \
1318-
} \
1319-
inline ret_type max(const type1 __a, const type2 __b) { \
1320-
return (__a > __b) ? __a : __b; \
1321-
}
1322-
1323-
// Define min and max functions for same type comparisons
1324-
DEFINE_MIN_MAX_FUNCTIONS(int, int, int)
1325-
DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, unsigned int)
1326-
DEFINE_MIN_MAX_FUNCTIONS(long, long, long)
1327-
DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, unsigned long)
1328-
DEFINE_MIN_MAX_FUNCTIONS(long long, long long, long long)
1329-
DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long,
1330-
unsigned long long)
1331-
1332-
// The host min/max functions below accept mixed signed/unsigned integer
1333-
// parameters and perform unsigned comparisons, which may produce unexpected
1334-
// results if a signed integer was passed unintentionally. To avoid this
1335-
// happening silently, these overloaded functions are not defined by default.
1336-
// However, for compatibility with CUDA, they will be defined if users define
1337-
// __HIP_DEFINE_MIXED_HOST_MIN_MAX__.
1338-
#ifdef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1339-
DEFINE_MIN_MAX_FUNCTIONS(unsigned int, int, unsigned int)
1340-
DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, int)
1341-
DEFINE_MIN_MAX_FUNCTIONS(unsigned long, long, unsigned long)
1342-
DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, long)
1343-
DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, long long, unsigned long long)
1344-
DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long, long long)
1345-
#endif // ifdef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1346-
1347-
// Floating-point comparisons using built-in functions
1348-
inline float min(float const __a, float const __b) {
1349-
return __builtin_fminf(__a, __b);
1350-
}
1351-
inline double min(double const __a, double const __b) {
1352-
return __builtin_fmin(__a, __b);
1353-
}
1354-
inline double min(float const __a, double const __b) {
1355-
return __builtin_fmin(__a, __b);
1356-
}
1357-
inline double min(double const __a, float const __b) {
1358-
return __builtin_fmin(__a, __b);
1309+
#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
1310+
__host__ inline static int min(int __arg1, int __arg2) {
1311+
return __arg1 < __arg2 ? __arg1 : __arg2;
13591312
}
13601313

1361-
inline float max(float const __a, float const __b) {
1362-
return __builtin_fmaxf(__a, __b);
1363-
}
1364-
inline double max(double const __a, double const __b) {
1365-
return __builtin_fmax(__a, __b);
1366-
}
1367-
inline double max(float const __a, double const __b) {
1368-
return __builtin_fmax(__a, __b);
1314+
__host__ inline static int max(int __arg1, int __arg2) {
1315+
return __arg1 > __arg2 ? __arg1 : __arg2;
13691316
}
1370-
inline double max(double const __a, float const __b) {
1371-
return __builtin_fmax(__a, __b);
1372-
}
1373-
1374-
#pragma pop_macro("DEFINE_MIN_MAX_FUNCTIONS")
1375-
1376-
#endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&
1377-
// !defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
1317+
#endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
13781318
#endif
13791319

13801320
#pragma pop_macro("__DEVICE__")

0 commit comments

Comments
 (0)