Skip to content

Commit cdc6ba8

Browse files
authored
[SYCL][libdevice] Add __imf_llmax/min, __imf_ullmax/min, __imf_umax/min (#6811)
Signed-off-by: jinge90 <[email protected]>
1 parent 7e6f724 commit cdc6ba8

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

libdevice/device_imf.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ static inline TyFP __integral2FP_host(TyINT x, int rdMode) {
9292
}
9393
#endif // __LIBDEVICE_HOST_IMPL__
9494

95+
template <typename Ty> static inline Ty __imax(Ty x, Ty y) {
96+
static_assert(std::is_integral<Ty>::value,
97+
"__imax only accepts integral type.");
98+
return (x > y) ? x : y;
99+
}
100+
101+
template <typename Ty> static inline Ty __imin(Ty x, Ty y) {
102+
static_assert(std::is_integral<Ty>::value,
103+
"__imin only accepts integral type.");
104+
return (x < y) ? x : y;
105+
}
106+
95107
static inline float __fclamp(float x, float y, float z) {
96108
#if defined(__LIBDEVICE_HOST_IMPL__)
97109
return __builtin_fmin(__builtin_fmax(x, y), z);

libdevice/imf_utils/integer_misc.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,37 @@ unsigned long long int __devicelib_imf_umul64hi(unsigned long long int x,
173173
static_cast<uint64_t>(y));
174174
#endif
175175
}
176+
177+
DEVICE_EXTERN_C_INLINE
178+
long long int __devicelib_imf_llmax(long long int x, long long int y) {
179+
return __imax(x, y);
180+
;
181+
}
182+
183+
DEVICE_EXTERN_C_INLINE
184+
long long int __devicelib_imf_llmin(long long int x, long long int y) {
185+
return __imin(x, y);
186+
}
187+
188+
DEVICE_EXTERN_C_INLINE
189+
unsigned long long int __devicelib_imf_ullmax(unsigned long long int x,
190+
unsigned long long int y) {
191+
return __imax(x, y);
192+
}
193+
194+
DEVICE_EXTERN_C_INLINE
195+
unsigned long long int __devicelib_imf_ullmin(unsigned long long int x,
196+
unsigned long long int y) {
197+
return __imin(x, y);
198+
}
199+
200+
DEVICE_EXTERN_C_INLINE
201+
unsigned int __devicelib_imf_umax(unsigned int x, unsigned int y) {
202+
return __imax(x, y);
203+
}
204+
205+
DEVICE_EXTERN_C_INLINE
206+
unsigned int __devicelib_imf_umin(unsigned int x, unsigned int y) {
207+
return __imin(x, y);
208+
}
176209
#endif //__LIBDEVICE_IMF_ENABLED__

libdevice/imf_wrapper.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,58 @@ float __imf_half2float(_iml_half_internal x) {
292292
return __devicelib_imf_half2float(x);
293293
}
294294

295+
DEVICE_EXTERN_C_INLINE
296+
long long int __devicelib_imf_llmax(long long int, long long int);
297+
298+
DEVICE_EXTERN_C_INLINE
299+
long long int __devicelib_imf_llmin(long long int, long long int);
300+
301+
DEVICE_EXTERN_C_INLINE
302+
unsigned long long int __devicelib_imf_ullmax(unsigned long long int,
303+
unsigned long long int);
304+
305+
DEVICE_EXTERN_C_INLINE
306+
unsigned long long int __devicelib_imf_ullmin(unsigned long long int,
307+
unsigned long long int);
308+
309+
DEVICE_EXTERN_C_INLINE
310+
unsigned int __devicelib_imf_umax(unsigned int, unsigned int);
311+
312+
DEVICE_EXTERN_C_INLINE
313+
unsigned int __devicelib_imf_umin(unsigned int, unsigned int);
314+
315+
DEVICE_EXTERN_C_INLINE
316+
long long int __imf_llmax(long long int x, long long int y) {
317+
return __devicelib_imf_llmax(x, y);
318+
}
319+
320+
DEVICE_EXTERN_C_INLINE
321+
long long int __imf_llmin(long long int x, long long int y) {
322+
return __devicelib_imf_llmin(x, y);
323+
}
324+
325+
DEVICE_EXTERN_C_INLINE
326+
unsigned long long int __imf_ullmax(unsigned long long int x,
327+
unsigned long long int y) {
328+
return __devicelib_imf_ullmax(x, y);
329+
}
330+
331+
DEVICE_EXTERN_C_INLINE
332+
unsigned long long int __imf_ullmin(unsigned long long int x,
333+
unsigned long long int y) {
334+
return __devicelib_imf_ullmin(x, y);
335+
}
336+
337+
DEVICE_EXTERN_C_INLINE
338+
unsigned int __imf_umax(unsigned int x, unsigned int y) {
339+
return __devicelib_imf_umax(x, y);
340+
}
341+
342+
DEVICE_EXTERN_C_INLINE
343+
unsigned int __imf_umin(unsigned int x, unsigned int y) {
344+
return __devicelib_imf_umin(x, y);
345+
}
346+
295347
DEVICE_EXTERN_C_INLINE
296348
unsigned int __devicelib_imf_brev(unsigned int);
297349

llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ SYCLDeviceLibFuncMap SDLMap = {
171171
{"__devicelib_memcmp", DeviceLibExt::cl_intel_devicelib_cstring},
172172
{"__devicelib_assert_read", DeviceLibExt::cl_intel_devicelib_assert},
173173
{"__devicelib_assert_fail", DeviceLibExt::cl_intel_devicelib_assert},
174+
{"__devicelib_imf_llmax", DeviceLibExt::cl_intel_devicelib_imf},
175+
{"__devicelib_imf_llmin", DeviceLibExt::cl_intel_devicelib_imf},
176+
{"__devicelib_imf_ullmax", DeviceLibExt::cl_intel_devicelib_imf},
177+
{"__devicelib_imf_ullmin", DeviceLibExt::cl_intel_devicelib_imf},
178+
{"__devicelib_imf_umax", DeviceLibExt::cl_intel_devicelib_imf},
179+
{"__devicelib_imf_umin", DeviceLibExt::cl_intel_devicelib_imf},
174180
{"__devicelib_imf_brev", DeviceLibExt::cl_intel_devicelib_imf},
175181
{"__devicelib_imf_brevll", DeviceLibExt::cl_intel_devicelib_imf},
176182
{"__devicelib_imf_byte_perm", DeviceLibExt::cl_intel_devicelib_imf},

sycl/include/sycl/builtins.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,16 @@ extern SYCL_EXTERNAL double hypot(double x, double y);
17381738
extern SYCL_EXTERNAL void *memcpy(void *dest, const void *src, size_t n);
17391739
extern SYCL_EXTERNAL void *memset(void *dest, int c, size_t n);
17401740
extern SYCL_EXTERNAL int memcmp(const void *s1, const void *s2, size_t n);
1741+
extern SYCL_EXTERNAL long long int __imf_llmax(long long int x,
1742+
long long int y);
1743+
extern SYCL_EXTERNAL long long int __imf_llmin(long long int x,
1744+
long long int y);
1745+
extern SYCL_EXTERNAL unsigned long long int
1746+
__imf_ullmax(unsigned long long int x, unsigned long long int y);
1747+
extern SYCL_EXTERNAL unsigned long long int
1748+
__imf_ullmin(unsigned long long int x, unsigned long long int y);
1749+
extern SYCL_EXTERNAL unsigned int __imf_umax(unsigned int x, unsigned int y);
1750+
extern SYCL_EXTERNAL unsigned int __imf_umin(unsigned int x, unsigned int y);
17411751
extern SYCL_EXTERNAL unsigned int __imf_brev(unsigned int x);
17421752
extern SYCL_EXTERNAL unsigned long long int
17431753
__imf_brevll(unsigned long long int x);

0 commit comments

Comments
 (0)