__clang_hip_math.h
37.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
/*===---- __clang_hip_math.h - HIP math decls -------------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
#ifndef __CLANG_HIP_MATH_H__
#define __CLANG_HIP_MATH_H__
#include <algorithm>
#include <limits.h>
#include <limits>
#include <stdint.h>
#include <assert.h>
#pragma push_macro("__DEVICE__")
#pragma push_macro("__RETURN_TYPE")
// to be consistent with __clang_cuda_math_forward_declares
#define __DEVICE__ static __device__
#define __RETURN_TYPE bool
#if defined (__cplusplus) && __cplusplus < 201103L
//emulate static_assert on type sizes
template<bool>
struct __compare_result{};
template<>
struct __compare_result<true> {
static const bool valid;
};
__DEVICE__
inline void __suppress_unused_warning(bool b) {};
template<unsigned int S, unsigned int T>
__DEVICE__
inline void __static_assert_equal_size() {
__suppress_unused_warning(__compare_result<S==T>::valid);
}
#define __static_assert_type_size_equal(A, B) \
__static_assert_equal_size<A,B>()
#else
#define __static_assert_type_size_equal(A,B) \
static_assert((A) == (B), "")
#endif
__DEVICE__
inline uint64_t __make_mantissa_base8(const char *__tagp) {
uint64_t __r = 0;
while (__tagp) {
char __tmp = *__tagp;
if (__tmp >= '0' && __tmp <= '7')
__r = (__r * 8u) + __tmp - '0';
else
return 0;
++__tagp;
}
return __r;
}
__DEVICE__
inline uint64_t __make_mantissa_base10(const char *__tagp) {
uint64_t __r = 0;
while (__tagp) {
char __tmp = *__tagp;
if (__tmp >= '0' && __tmp <= '9')
__r = (__r * 10u) + __tmp - '0';
else
return 0;
++__tagp;
}
return __r;
}
__DEVICE__
inline uint64_t __make_mantissa_base16(const char *__tagp) {
uint64_t __r = 0;
while (__tagp) {
char __tmp = *__tagp;
if (__tmp >= '0' && __tmp <= '9')
__r = (__r * 16u) + __tmp - '0';
else if (__tmp >= 'a' && __tmp <= 'f')
__r = (__r * 16u) + __tmp - 'a' + 10;
else if (__tmp >= 'A' && __tmp <= 'F')
__r = (__r * 16u) + __tmp - 'A' + 10;
else
return 0;
++__tagp;
}
return __r;
}
__DEVICE__
inline uint64_t __make_mantissa(const char *__tagp) {
if (!__tagp)
return 0u;
if (*__tagp == '0') {
++__tagp;
if (*__tagp == 'x' || *__tagp == 'X')
return __make_mantissa_base16(__tagp);
else
return __make_mantissa_base8(__tagp);
}
return __make_mantissa_base10(__tagp);
}
// BEGIN FLOAT
#ifdef __cplusplus
__DEVICE__
inline float abs(float __x) { return __ocml_fabs_f32(__x); }
#endif
__DEVICE__
inline float acosf(float __x) { return __ocml_acos_f32(__x); }
__DEVICE__
inline float acoshf(float __x) { return __ocml_acosh_f32(__x); }
__DEVICE__
inline float asinf(float __x) { return __ocml_asin_f32(__x); }
__DEVICE__
inline float asinhf(float __x) { return __ocml_asinh_f32(__x); }
__DEVICE__
inline float atan2f(float __x, float __y) { return __ocml_atan2_f32(__x, __y); }
__DEVICE__
inline float atanf(float __x) { return __ocml_atan_f32(__x); }
__DEVICE__
inline float atanhf(float __x) { return __ocml_atanh_f32(__x); }
__DEVICE__
inline float cbrtf(float __x) { return __ocml_cbrt_f32(__x); }
__DEVICE__
inline float ceilf(float __x) { return __ocml_ceil_f32(__x); }
__DEVICE__
inline float copysignf(float __x, float __y) {
return __ocml_copysign_f32(__x, __y);
}
__DEVICE__
inline float cosf(float __x) { return __ocml_cos_f32(__x); }
__DEVICE__
inline float coshf(float __x) { return __ocml_cosh_f32(__x); }
__DEVICE__
inline float cospif(float __x) { return __ocml_cospi_f32(__x); }
__DEVICE__
inline float cyl_bessel_i0f(float __x) { return __ocml_i0_f32(__x); }
__DEVICE__
inline float cyl_bessel_i1f(float __x) { return __ocml_i1_f32(__x); }
__DEVICE__
inline float erfcf(float __x) { return __ocml_erfc_f32(__x); }
__DEVICE__
inline float erfcinvf(float __x) { return __ocml_erfcinv_f32(__x); }
__DEVICE__
inline float erfcxf(float __x) { return __ocml_erfcx_f32(__x); }
__DEVICE__
inline float erff(float __x) { return __ocml_erf_f32(__x); }
__DEVICE__
inline float erfinvf(float __x) { return __ocml_erfinv_f32(__x); }
__DEVICE__
inline float exp10f(float __x) { return __ocml_exp10_f32(__x); }
__DEVICE__
inline float exp2f(float __x) { return __ocml_exp2_f32(__x); }
__DEVICE__
inline float expf(float __x) { return __ocml_exp_f32(__x); }
__DEVICE__
inline float expm1f(float __x) { return __ocml_expm1_f32(__x); }
__DEVICE__
inline float fabsf(float __x) { return __ocml_fabs_f32(__x); }
__DEVICE__
inline float fdimf(float __x, float __y) { return __ocml_fdim_f32(__x, __y); }
__DEVICE__
inline float fdividef(float __x, float __y) { return __x / __y; }
__DEVICE__
inline float floorf(float __x) { return __ocml_floor_f32(__x); }
__DEVICE__
inline float fmaf(float __x, float __y, float __z) {
return __ocml_fma_f32(__x, __y, __z);
}
__DEVICE__
inline float fmaxf(float __x, float __y) { return __ocml_fmax_f32(__x, __y); }
__DEVICE__
inline float fminf(float __x, float __y) { return __ocml_fmin_f32(__x, __y); }
__DEVICE__
inline float fmodf(float __x, float __y) { return __ocml_fmod_f32(__x, __y); }
__DEVICE__
inline float frexpf(float __x, int *__nptr) {
int __tmp;
float __r =
__ocml_frexp_f32(__x, (__attribute__((address_space(5))) int *)&__tmp);
*__nptr = __tmp;
return __r;
}
__DEVICE__
inline float hypotf(float __x, float __y) { return __ocml_hypot_f32(__x, __y); }
__DEVICE__
inline int ilogbf(float __x) { return __ocml_ilogb_f32(__x); }
__DEVICE__
inline __RETURN_TYPE isfinite(float __x) { return __ocml_isfinite_f32(__x); }
__DEVICE__
inline __RETURN_TYPE isinf(float __x) { return __ocml_isinf_f32(__x); }
__DEVICE__
inline __RETURN_TYPE isnan(float __x) { return __ocml_isnan_f32(__x); }
__DEVICE__
inline float j0f(float __x) { return __ocml_j0_f32(__x); }
__DEVICE__
inline float j1f(float __x) { return __ocml_j1_f32(__x); }
__DEVICE__
inline float jnf(int __n,
float __x) { // TODO: we could use Ahmes multiplication
// and the Miller & Brown algorithm
// for linear recurrences to get O(log n) steps, but it's unclear if
// it'd be beneficial in this case.
if (__n == 0)
return j0f(__x);
if (__n == 1)
return j1f(__x);
float __x0 = j0f(__x);
float __x1 = j1f(__x);
for (int __i = 1; __i < __n; ++__i) {
float __x2 = (2 * __i) / __x * __x1 - __x0;
__x0 = __x1;
__x1 = __x2;
}
return __x1;
}
__DEVICE__
inline float ldexpf(float __x, int __e) { return __ocml_ldexp_f32(__x, __e); }
__DEVICE__
inline float lgammaf(float __x) { return __ocml_lgamma_f32(__x); }
__DEVICE__
inline long long int llrintf(float __x) { return __ocml_rint_f32(__x); }
__DEVICE__
inline long long int llroundf(float __x) { return __ocml_round_f32(__x); }
__DEVICE__
inline float log10f(float __x) { return __ocml_log10_f32(__x); }
__DEVICE__
inline float log1pf(float __x) { return __ocml_log1p_f32(__x); }
__DEVICE__
inline float log2f(float __x) { return __ocml_log2_f32(__x); }
__DEVICE__
inline float logbf(float __x) { return __ocml_logb_f32(__x); }
__DEVICE__
inline float logf(float __x) { return __ocml_log_f32(__x); }
__DEVICE__
inline long int lrintf(float __x) { return __ocml_rint_f32(__x); }
__DEVICE__
inline long int lroundf(float __x) { return __ocml_round_f32(__x); }
__DEVICE__
inline float modff(float __x, float *__iptr) {
float __tmp;
float __r =
__ocml_modf_f32(__x, (__attribute__((address_space(5))) float *)&__tmp);
*__iptr = __tmp;
return __r;
}
__DEVICE__
inline float nanf(const char *__tagp) {
union {
float val;
struct ieee_float {
uint32_t mantissa : 22;
uint32_t quiet : 1;
uint32_t exponent : 8;
uint32_t sign : 1;
} bits;
} __tmp;
__static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));
__tmp.bits.sign = 0u;
__tmp.bits.exponent = ~0u;
__tmp.bits.quiet = 1u;
__tmp.bits.mantissa = __make_mantissa(__tagp);
return __tmp.val;
}
__DEVICE__
inline float nearbyintf(float __x) { return __ocml_nearbyint_f32(__x); }
__DEVICE__
inline float nextafterf(float __x, float __y) {
return __ocml_nextafter_f32(__x, __y);
}
__DEVICE__
inline float norm3df(float __x, float __y, float __z) {
return __ocml_len3_f32(__x, __y, __z);
}
__DEVICE__
inline float norm4df(float __x, float __y, float __z, float __w) {
return __ocml_len4_f32(__x, __y, __z, __w);
}
__DEVICE__
inline float normcdff(float __x) { return __ocml_ncdf_f32(__x); }
__DEVICE__
inline float normcdfinvf(float __x) { return __ocml_ncdfinv_f32(__x); }
__DEVICE__
inline float
normf(int __dim,
const float *__a) { // TODO: placeholder until OCML adds support.
float __r = 0;
while (__dim--) {
__r += __a[0] * __a[0];
++__a;
}
return __ocml_sqrt_f32(__r);
}
__DEVICE__
inline float powf(float __x, float __y) { return __ocml_pow_f32(__x, __y); }
__DEVICE__
inline float powif(float __x, int __y) { return __ocml_pown_f32(__x, __y); }
__DEVICE__
inline float rcbrtf(float __x) { return __ocml_rcbrt_f32(__x); }
__DEVICE__
inline float remainderf(float __x, float __y) {
return __ocml_remainder_f32(__x, __y);
}
__DEVICE__
inline float remquof(float __x, float __y, int *__quo) {
int __tmp;
float __r = __ocml_remquo_f32(
__x, __y, (__attribute__((address_space(5))) int *)&__tmp);
*__quo = __tmp;
return __r;
}
__DEVICE__
inline float rhypotf(float __x, float __y) {
return __ocml_rhypot_f32(__x, __y);
}
__DEVICE__
inline float rintf(float __x) { return __ocml_rint_f32(__x); }
__DEVICE__
inline float rnorm3df(float __x, float __y, float __z) {
return __ocml_rlen3_f32(__x, __y, __z);
}
__DEVICE__
inline float rnorm4df(float __x, float __y, float __z, float __w) {
return __ocml_rlen4_f32(__x, __y, __z, __w);
}
__DEVICE__
inline float
rnormf(int __dim,
const float *__a) { // TODO: placeholder until OCML adds support.
float __r = 0;
while (__dim--) {
__r += __a[0] * __a[0];
++__a;
}
return __ocml_rsqrt_f32(__r);
}
__DEVICE__
inline float roundf(float __x) { return __ocml_round_f32(__x); }
__DEVICE__
inline float rsqrtf(float __x) { return __ocml_rsqrt_f32(__x); }
__DEVICE__
inline float scalblnf(float __x, long int __n) {
return (__n < INT_MAX) ? __ocml_scalbn_f32(__x, __n)
: __ocml_scalb_f32(__x, __n);
}
__DEVICE__
inline float scalbnf(float __x, int __n) { return __ocml_scalbn_f32(__x, __n); }
__DEVICE__
inline __RETURN_TYPE signbit(float __x) { return __ocml_signbit_f32(__x); }
__DEVICE__
inline void sincosf(float __x, float *__sinptr, float *__cosptr) {
float __tmp;
*__sinptr =
__ocml_sincos_f32(__x, (__attribute__((address_space(5))) float *)&__tmp);
*__cosptr = __tmp;
}
__DEVICE__
inline void sincospif(float __x, float *__sinptr, float *__cosptr) {
float __tmp;
*__sinptr = __ocml_sincospi_f32(
__x, (__attribute__((address_space(5))) float *)&__tmp);
*__cosptr = __tmp;
}
__DEVICE__
inline float sinf(float __x) { return __ocml_sin_f32(__x); }
__DEVICE__
inline float sinhf(float __x) { return __ocml_sinh_f32(__x); }
__DEVICE__
inline float sinpif(float __x) { return __ocml_sinpi_f32(__x); }
__DEVICE__
inline float sqrtf(float __x) { return __ocml_sqrt_f32(__x); }
__DEVICE__
inline float tanf(float __x) { return __ocml_tan_f32(__x); }
__DEVICE__
inline float tanhf(float __x) { return __ocml_tanh_f32(__x); }
__DEVICE__
inline float tgammaf(float __x) { return __ocml_tgamma_f32(__x); }
__DEVICE__
inline float truncf(float __x) { return __ocml_trunc_f32(__x); }
__DEVICE__
inline float y0f(float __x) { return __ocml_y0_f32(__x); }
__DEVICE__
inline float y1f(float __x) { return __ocml_y1_f32(__x); }
__DEVICE__
inline float ynf(int __n,
float __x) { // TODO: we could use Ahmes multiplication
// and the Miller & Brown algorithm
// for linear recurrences to get O(log n) steps, but it's unclear if
// it'd be beneficial in this case. Placeholder until OCML adds
// support.
if (__n == 0)
return y0f(__x);
if (__n == 1)
return y1f(__x);
float __x0 = y0f(__x);
float __x1 = y1f(__x);
for (int __i = 1; __i < __n; ++__i) {
float __x2 = (2 * __i) / __x * __x1 - __x0;
__x0 = __x1;
__x1 = __x2;
}
return __x1;
}
// BEGIN INTRINSICS
__DEVICE__
inline float __cosf(float __x) { return __ocml_native_cos_f32(__x); }
__DEVICE__
inline float __exp10f(float __x) { return __ocml_native_exp10_f32(__x); }
__DEVICE__
inline float __expf(float __x) { return __ocml_native_exp_f32(__x); }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fadd_rd(float __x, float __y) {
return __ocml_add_rtn_f32(__x, __y);
}
#endif
__DEVICE__
inline float __fadd_rn(float __x, float __y) { return __x + __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fadd_ru(float __x, float __y) {
return __ocml_add_rtp_f32(__x, __y);
}
__DEVICE__
inline float __fadd_rz(float __x, float __y) {
return __ocml_add_rtz_f32(__x, __y);
}
__DEVICE__
inline float __fdiv_rd(float __x, float __y) {
return __ocml_div_rtn_f32(__x, __y);
}
#endif
__DEVICE__
inline float __fdiv_rn(float __x, float __y) { return __x / __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fdiv_ru(float __x, float __y) {
return __ocml_div_rtp_f32(__x, __y);
}
__DEVICE__
inline float __fdiv_rz(float __x, float __y) {
return __ocml_div_rtz_f32(__x, __y);
}
#endif
__DEVICE__
inline float __fdividef(float __x, float __y) { return __x / __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fmaf_rd(float __x, float __y, float __z) {
return __ocml_fma_rtn_f32(__x, __y, __z);
}
#endif
__DEVICE__
inline float __fmaf_rn(float __x, float __y, float __z) {
return __ocml_fma_f32(__x, __y, __z);
}
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fmaf_ru(float __x, float __y, float __z) {
return __ocml_fma_rtp_f32(__x, __y, __z);
}
__DEVICE__
inline float __fmaf_rz(float __x, float __y, float __z) {
return __ocml_fma_rtz_f32(__x, __y, __z);
}
__DEVICE__
inline float __fmul_rd(float __x, float __y) {
return __ocml_mul_rtn_f32(__x, __y);
}
#endif
__DEVICE__
inline float __fmul_rn(float __x, float __y) { return __x * __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fmul_ru(float __x, float __y) {
return __ocml_mul_rtp_f32(__x, __y);
}
__DEVICE__
inline float __fmul_rz(float __x, float __y) {
return __ocml_mul_rtz_f32(__x, __y);
}
__DEVICE__
inline float __frcp_rd(float __x) { return __llvm_amdgcn_rcp_f32(__x); }
#endif
__DEVICE__
inline float __frcp_rn(float __x) { return __llvm_amdgcn_rcp_f32(__x); }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __frcp_ru(float __x) { return __llvm_amdgcn_rcp_f32(__x); }
__DEVICE__
inline float __frcp_rz(float __x) { return __llvm_amdgcn_rcp_f32(__x); }
#endif
__DEVICE__
inline float __frsqrt_rn(float __x) { return __llvm_amdgcn_rsq_f32(__x); }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fsqrt_rd(float __x) { return __ocml_sqrt_rtn_f32(__x); }
#endif
__DEVICE__
inline float __fsqrt_rn(float __x) { return __ocml_native_sqrt_f32(__x); }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fsqrt_ru(float __x) { return __ocml_sqrt_rtp_f32(__x); }
__DEVICE__
inline float __fsqrt_rz(float __x) { return __ocml_sqrt_rtz_f32(__x); }
__DEVICE__
inline float __fsub_rd(float __x, float __y) {
return __ocml_sub_rtn_f32(__x, __y);
}
#endif
__DEVICE__
inline float __fsub_rn(float __x, float __y) { return __x - __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline float __fsub_ru(float __x, float __y) {
return __ocml_sub_rtp_f32(__x, __y);
}
__DEVICE__
inline float __fsub_rz(float __x, float __y) {
return __ocml_sub_rtz_f32(__x, __y);
}
#endif
__DEVICE__
inline float __log10f(float __x) { return __ocml_native_log10_f32(__x); }
__DEVICE__
inline float __log2f(float __x) { return __ocml_native_log2_f32(__x); }
__DEVICE__
inline float __logf(float __x) { return __ocml_native_log_f32(__x); }
__DEVICE__
inline float __powf(float __x, float __y) { return __ocml_pow_f32(__x, __y); }
__DEVICE__
inline float __saturatef(float __x) {
return (__x < 0) ? 0 : ((__x > 1) ? 1 : __x);
}
__DEVICE__
inline void __sincosf(float __x, float *__sinptr, float *__cosptr) {
*__sinptr = __ocml_native_sin_f32(__x);
*__cosptr = __ocml_native_cos_f32(__x);
}
__DEVICE__
inline float __sinf(float __x) { return __ocml_native_sin_f32(__x); }
__DEVICE__
inline float __tanf(float __x) { return __ocml_tan_f32(__x); }
// END INTRINSICS
// END FLOAT
// BEGIN DOUBLE
#ifdef __cplusplus
__DEVICE__
inline double abs(double __x) { return __ocml_fabs_f64(__x); }
#endif
__DEVICE__
inline double acos(double __x) { return __ocml_acos_f64(__x); }
__DEVICE__
inline double acosh(double __x) { return __ocml_acosh_f64(__x); }
__DEVICE__
inline double asin(double __x) { return __ocml_asin_f64(__x); }
__DEVICE__
inline double asinh(double __x) { return __ocml_asinh_f64(__x); }
__DEVICE__
inline double atan(double __x) { return __ocml_atan_f64(__x); }
__DEVICE__
inline double atan2(double __x, double __y) {
return __ocml_atan2_f64(__x, __y);
}
__DEVICE__
inline double atanh(double __x) { return __ocml_atanh_f64(__x); }
__DEVICE__
inline double cbrt(double __x) { return __ocml_cbrt_f64(__x); }
__DEVICE__
inline double ceil(double __x) { return __ocml_ceil_f64(__x); }
__DEVICE__
inline double copysign(double __x, double __y) {
return __ocml_copysign_f64(__x, __y);
}
__DEVICE__
inline double cos(double __x) { return __ocml_cos_f64(__x); }
__DEVICE__
inline double cosh(double __x) { return __ocml_cosh_f64(__x); }
__DEVICE__
inline double cospi(double __x) { return __ocml_cospi_f64(__x); }
__DEVICE__
inline double cyl_bessel_i0(double __x) { return __ocml_i0_f64(__x); }
__DEVICE__
inline double cyl_bessel_i1(double __x) { return __ocml_i1_f64(__x); }
__DEVICE__
inline double erf(double __x) { return __ocml_erf_f64(__x); }
__DEVICE__
inline double erfc(double __x) { return __ocml_erfc_f64(__x); }
__DEVICE__
inline double erfcinv(double __x) { return __ocml_erfcinv_f64(__x); }
__DEVICE__
inline double erfcx(double __x) { return __ocml_erfcx_f64(__x); }
__DEVICE__
inline double erfinv(double __x) { return __ocml_erfinv_f64(__x); }
__DEVICE__
inline double exp(double __x) { return __ocml_exp_f64(__x); }
__DEVICE__
inline double exp10(double __x) { return __ocml_exp10_f64(__x); }
__DEVICE__
inline double exp2(double __x) { return __ocml_exp2_f64(__x); }
__DEVICE__
inline double expm1(double __x) { return __ocml_expm1_f64(__x); }
__DEVICE__
inline double fabs(double __x) { return __ocml_fabs_f64(__x); }
__DEVICE__
inline double fdim(double __x, double __y) { return __ocml_fdim_f64(__x, __y); }
__DEVICE__
inline double floor(double __x) { return __ocml_floor_f64(__x); }
__DEVICE__
inline double fma(double __x, double __y, double __z) {
return __ocml_fma_f64(__x, __y, __z);
}
__DEVICE__
inline double fmax(double __x, double __y) { return __ocml_fmax_f64(__x, __y); }
__DEVICE__
inline double fmin(double __x, double __y) { return __ocml_fmin_f64(__x, __y); }
__DEVICE__
inline double fmod(double __x, double __y) { return __ocml_fmod_f64(__x, __y); }
__DEVICE__
inline double frexp(double __x, int *__nptr) {
int __tmp;
double __r =
__ocml_frexp_f64(__x, (__attribute__((address_space(5))) int *)&__tmp);
*__nptr = __tmp;
return __r;
}
__DEVICE__
inline double hypot(double __x, double __y) {
return __ocml_hypot_f64(__x, __y);
}
__DEVICE__
inline int ilogb(double __x) { return __ocml_ilogb_f64(__x); }
__DEVICE__
inline __RETURN_TYPE isfinite(double __x) { return __ocml_isfinite_f64(__x); }
__DEVICE__
inline __RETURN_TYPE isinf(double __x) { return __ocml_isinf_f64(__x); }
__DEVICE__
inline __RETURN_TYPE isnan(double __x) { return __ocml_isnan_f64(__x); }
__DEVICE__
inline double j0(double __x) { return __ocml_j0_f64(__x); }
__DEVICE__
inline double j1(double __x) { return __ocml_j1_f64(__x); }
__DEVICE__
inline double jn(int __n,
double __x) { // TODO: we could use Ahmes multiplication
// and the Miller & Brown algorithm
// for linear recurrences to get O(log n) steps, but it's unclear if
// it'd be beneficial in this case. Placeholder until OCML adds
// support.
if (__n == 0)
return j0f(__x);
if (__n == 1)
return j1f(__x);
double __x0 = j0f(__x);
double __x1 = j1f(__x);
for (int __i = 1; __i < __n; ++__i) {
double __x2 = (2 * __i) / __x * __x1 - __x0;
__x0 = __x1;
__x1 = __x2;
}
return __x1;
}
__DEVICE__
inline double ldexp(double __x, int __e) { return __ocml_ldexp_f64(__x, __e); }
__DEVICE__
inline double lgamma(double __x) { return __ocml_lgamma_f64(__x); }
__DEVICE__
inline long long int llrint(double __x) { return __ocml_rint_f64(__x); }
__DEVICE__
inline long long int llround(double __x) { return __ocml_round_f64(__x); }
__DEVICE__
inline double log(double __x) { return __ocml_log_f64(__x); }
__DEVICE__
inline double log10(double __x) { return __ocml_log10_f64(__x); }
__DEVICE__
inline double log1p(double __x) { return __ocml_log1p_f64(__x); }
__DEVICE__
inline double log2(double __x) { return __ocml_log2_f64(__x); }
__DEVICE__
inline double logb(double __x) { return __ocml_logb_f64(__x); }
__DEVICE__
inline long int lrint(double __x) { return __ocml_rint_f64(__x); }
__DEVICE__
inline long int lround(double __x) { return __ocml_round_f64(__x); }
__DEVICE__
inline double modf(double __x, double *__iptr) {
double __tmp;
double __r =
__ocml_modf_f64(__x, (__attribute__((address_space(5))) double *)&__tmp);
*__iptr = __tmp;
return __r;
}
__DEVICE__
inline double nan(const char *__tagp) {
#if !_WIN32
union {
double val;
struct ieee_double {
uint64_t mantissa : 51;
uint32_t quiet : 1;
uint32_t exponent : 11;
uint32_t sign : 1;
} bits;
} __tmp;
__static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));
__tmp.bits.sign = 0u;
__tmp.bits.exponent = ~0u;
__tmp.bits.quiet = 1u;
__tmp.bits.mantissa = __make_mantissa(__tagp);
return __tmp.val;
#else
__static_assert_type_size_equal(sizeof(uint64_t), sizeof(double));
uint64_t val = __make_mantissa(__tagp);
val |= 0xFFF << 51;
return *reinterpret_cast<double *>(&val);
#endif
}
__DEVICE__
inline double nearbyint(double __x) { return __ocml_nearbyint_f64(__x); }
__DEVICE__
inline double nextafter(double __x, double __y) {
return __ocml_nextafter_f64(__x, __y);
}
__DEVICE__
inline double
norm(int __dim,
const double *__a) { // TODO: placeholder until OCML adds support.
double __r = 0;
while (__dim--) {
__r += __a[0] * __a[0];
++__a;
}
return __ocml_sqrt_f64(__r);
}
__DEVICE__
inline double norm3d(double __x, double __y, double __z) {
return __ocml_len3_f64(__x, __y, __z);
}
__DEVICE__
inline double norm4d(double __x, double __y, double __z, double __w) {
return __ocml_len4_f64(__x, __y, __z, __w);
}
__DEVICE__
inline double normcdf(double __x) { return __ocml_ncdf_f64(__x); }
__DEVICE__
inline double normcdfinv(double __x) { return __ocml_ncdfinv_f64(__x); }
__DEVICE__
inline double pow(double __x, double __y) { return __ocml_pow_f64(__x, __y); }
__DEVICE__
inline double powi(double __x, int __y) { return __ocml_pown_f64(__x, __y); }
__DEVICE__
inline double rcbrt(double __x) { return __ocml_rcbrt_f64(__x); }
__DEVICE__
inline double remainder(double __x, double __y) {
return __ocml_remainder_f64(__x, __y);
}
__DEVICE__
inline double remquo(double __x, double __y, int *__quo) {
int __tmp;
double __r = __ocml_remquo_f64(
__x, __y, (__attribute__((address_space(5))) int *)&__tmp);
*__quo = __tmp;
return __r;
}
__DEVICE__
inline double rhypot(double __x, double __y) {
return __ocml_rhypot_f64(__x, __y);
}
__DEVICE__
inline double rint(double __x) { return __ocml_rint_f64(__x); }
__DEVICE__
inline double
rnorm(int __dim,
const double *__a) { // TODO: placeholder until OCML adds support.
double __r = 0;
while (__dim--) {
__r += __a[0] * __a[0];
++__a;
}
return __ocml_rsqrt_f64(__r);
}
__DEVICE__
inline double rnorm3d(double __x, double __y, double __z) {
return __ocml_rlen3_f64(__x, __y, __z);
}
__DEVICE__
inline double rnorm4d(double __x, double __y, double __z, double __w) {
return __ocml_rlen4_f64(__x, __y, __z, __w);
}
__DEVICE__
inline double round(double __x) { return __ocml_round_f64(__x); }
__DEVICE__
inline double rsqrt(double __x) { return __ocml_rsqrt_f64(__x); }
__DEVICE__
inline double scalbln(double __x, long int __n) {
return (__n < INT_MAX) ? __ocml_scalbn_f64(__x, __n)
: __ocml_scalb_f64(__x, __n);
}
__DEVICE__
inline double scalbn(double __x, int __n) {
return __ocml_scalbn_f64(__x, __n);
}
__DEVICE__
inline __RETURN_TYPE signbit(double __x) { return __ocml_signbit_f64(__x); }
__DEVICE__
inline double sin(double __x) { return __ocml_sin_f64(__x); }
__DEVICE__
inline void sincos(double __x, double *__sinptr, double *__cosptr) {
double __tmp;
*__sinptr = __ocml_sincos_f64(
__x, (__attribute__((address_space(5))) double *)&__tmp);
*__cosptr = __tmp;
}
__DEVICE__
inline void sincospi(double __x, double *__sinptr, double *__cosptr) {
double __tmp;
*__sinptr = __ocml_sincospi_f64(
__x, (__attribute__((address_space(5))) double *)&__tmp);
*__cosptr = __tmp;
}
__DEVICE__
inline double sinh(double __x) { return __ocml_sinh_f64(__x); }
__DEVICE__
inline double sinpi(double __x) { return __ocml_sinpi_f64(__x); }
__DEVICE__
inline double sqrt(double __x) { return __ocml_sqrt_f64(__x); }
__DEVICE__
inline double tan(double __x) { return __ocml_tan_f64(__x); }
__DEVICE__
inline double tanh(double __x) { return __ocml_tanh_f64(__x); }
__DEVICE__
inline double tgamma(double __x) { return __ocml_tgamma_f64(__x); }
__DEVICE__
inline double trunc(double __x) { return __ocml_trunc_f64(__x); }
__DEVICE__
inline double y0(double __x) { return __ocml_y0_f64(__x); }
__DEVICE__
inline double y1(double __x) { return __ocml_y1_f64(__x); }
__DEVICE__
inline double yn(int __n,
double __x) { // TODO: we could use Ahmes multiplication
// and the Miller & Brown algorithm
// for linear recurrences to get O(log n) steps, but it's unclear if
// it'd be beneficial in this case. Placeholder until OCML adds
// support.
if (__n == 0)
return j0f(__x);
if (__n == 1)
return j1f(__x);
double __x0 = j0f(__x);
double __x1 = j1f(__x);
for (int __i = 1; __i < __n; ++__i) {
double __x2 = (2 * __i) / __x * __x1 - __x0;
__x0 = __x1;
__x1 = __x2;
}
return __x1;
}
// BEGIN INTRINSICS
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __dadd_rd(double __x, double __y) {
return __ocml_add_rtn_f64(__x, __y);
}
#endif
__DEVICE__
inline double __dadd_rn(double __x, double __y) { return __x + __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __dadd_ru(double __x, double __y) {
return __ocml_add_rtp_f64(__x, __y);
}
__DEVICE__
inline double __dadd_rz(double __x, double __y) {
return __ocml_add_rtz_f64(__x, __y);
}
__DEVICE__
inline double __ddiv_rd(double __x, double __y) {
return __ocml_div_rtn_f64(__x, __y);
}
#endif
__DEVICE__
inline double __ddiv_rn(double __x, double __y) { return __x / __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __ddiv_ru(double __x, double __y) {
return __ocml_div_rtp_f64(__x, __y);
}
__DEVICE__
inline double __ddiv_rz(double __x, double __y) {
return __ocml_div_rtz_f64(__x, __y);
}
__DEVICE__
inline double __dmul_rd(double __x, double __y) {
return __ocml_mul_rtn_f64(__x, __y);
}
#endif
__DEVICE__
inline double __dmul_rn(double __x, double __y) { return __x * __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __dmul_ru(double __x, double __y) {
return __ocml_mul_rtp_f64(__x, __y);
}
__DEVICE__
inline double __dmul_rz(double __x, double __y) {
return __ocml_mul_rtz_f64(__x, __y);
}
__DEVICE__
inline double __drcp_rd(double __x) { return __llvm_amdgcn_rcp_f64(__x); }
#endif
__DEVICE__
inline double __drcp_rn(double __x) { return __llvm_amdgcn_rcp_f64(__x); }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __drcp_ru(double __x) { return __llvm_amdgcn_rcp_f64(__x); }
__DEVICE__
inline double __drcp_rz(double __x) { return __llvm_amdgcn_rcp_f64(__x); }
__DEVICE__
inline double __dsqrt_rd(double __x) { return __ocml_sqrt_rtn_f64(__x); }
#endif
__DEVICE__
inline double __dsqrt_rn(double __x) { return __ocml_sqrt_f64(__x); }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __dsqrt_ru(double __x) { return __ocml_sqrt_rtp_f64(__x); }
__DEVICE__
inline double __dsqrt_rz(double __x) { return __ocml_sqrt_rtz_f64(__x); }
__DEVICE__
inline double __dsub_rd(double __x, double __y) {
return __ocml_sub_rtn_f64(__x, __y);
}
#endif
__DEVICE__
inline double __dsub_rn(double __x, double __y) { return __x - __y; }
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __dsub_ru(double __x, double __y) {
return __ocml_sub_rtp_f64(__x, __y);
}
__DEVICE__
inline double __dsub_rz(double __x, double __y) {
return __ocml_sub_rtz_f64(__x, __y);
}
__DEVICE__
inline double __fma_rd(double __x, double __y, double __z) {
return __ocml_fma_rtn_f64(__x, __y, __z);
}
#endif
__DEVICE__
inline double __fma_rn(double __x, double __y, double __z) {
return __ocml_fma_f64(__x, __y, __z);
}
#if defined OCML_BASIC_ROUNDED_OPERATIONS
__DEVICE__
inline double __fma_ru(double __x, double __y, double __z) {
return __ocml_fma_rtp_f64(__x, __y, __z);
}
__DEVICE__
inline double __fma_rz(double __x, double __y, double __z) {
return __ocml_fma_rtz_f64(__x, __y, __z);
}
#endif
// END INTRINSICS
// END DOUBLE
// BEGIN INTEGER
__DEVICE__
inline int abs(int __x) {
int __sgn = __x >> (sizeof(int) * CHAR_BIT - 1);
return (__x ^ __sgn) - __sgn;
}
__DEVICE__
inline long labs(long __x) {
long __sgn = __x >> (sizeof(long) * CHAR_BIT - 1);
return (__x ^ __sgn) - __sgn;
}
__DEVICE__
inline long long llabs(long long __x) {
long long __sgn = __x >> (sizeof(long long) * CHAR_BIT - 1);
return (__x ^ __sgn) - __sgn;
}
#if defined(__cplusplus)
__DEVICE__
inline long abs(long __x) { return labs(__x); }
__DEVICE__
inline long long abs(long long __x) { return llabs(__x); }
#endif
// END INTEGER
__DEVICE__
inline _Float16 fma(_Float16 __x, _Float16 __y, _Float16 __z) {
return __ocml_fma_f16(__x, __y, __z);
}
__DEVICE__
inline float fma(float __x, float __y, float __z) {
return fmaf(__x, __y, __z);
}
#pragma push_macro("__DEF_FUN1")
#pragma push_macro("__DEF_FUN2")
#pragma push_macro("__DEF_FUNI")
#pragma push_macro("__DEF_FLOAT_FUN2I")
#pragma push_macro("__HIP_OVERLOAD1")
#pragma push_macro("__HIP_OVERLOAD2")
// __hip_enable_if::type is a type function which returns __T if __B is true.
template <bool __B, class __T = void> struct __hip_enable_if {};
template <class __T> struct __hip_enable_if<true, __T> { typedef __T type; };
// __HIP_OVERLOAD1 is used to resolve function calls with integer argument to
// avoid compilation error due to ambibuity. e.g. floor(5) is resolved with
// floor(double).
#define __HIP_OVERLOAD1(__retty, __fn) \
template <typename __T> \
__DEVICE__ typename __hip_enable_if<std::numeric_limits<__T>::is_integer, \
__retty>::type \
__fn(__T __x) { \
return ::__fn((double)__x); \
}
// __HIP_OVERLOAD2 is used to resolve function calls with mixed float/double
// or integer argument to avoid compilation error due to ambibuity. e.g.
// max(5.0f, 6.0) is resolved with max(double, double).
#define __HIP_OVERLOAD2(__retty, __fn) \
template <typename __T1, typename __T2> \
__DEVICE__ \
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized && \
std::numeric_limits<__T2>::is_specialized, \
__retty>::type \
__fn(__T1 __x, __T2 __y) { \
return __fn((double)__x, (double)__y); \
}
// Define cmath functions with float argument and returns float.
#define __DEF_FUN1(__retty, __func) \
__DEVICE__ \
inline float __func(float __x) { return __func##f(__x); } \
__HIP_OVERLOAD1(__retty, __func)
// Define cmath functions with float argument and returns __retty.
#define __DEF_FUNI(__retty, __func) \
__DEVICE__ \
inline __retty __func(float __x) { return __func##f(__x); } \
__HIP_OVERLOAD1(__retty, __func)
// define cmath functions with two float arguments.
#define __DEF_FUN2(__retty, __func) \
__DEVICE__ \
inline float __func(float __x, float __y) { return __func##f(__x, __y); } \
__HIP_OVERLOAD2(__retty, __func)
__DEF_FUN1(double, acos)
__DEF_FUN1(double, acosh)
__DEF_FUN1(double, asin)
__DEF_FUN1(double, asinh)
__DEF_FUN1(double, atan)
__DEF_FUN2(double, atan2);
__DEF_FUN1(double, atanh)
__DEF_FUN1(double, cbrt)
__DEF_FUN1(double, ceil)
__DEF_FUN2(double, copysign);
__DEF_FUN1(double, cos)
__DEF_FUN1(double, cosh)
__DEF_FUN1(double, erf)
__DEF_FUN1(double, erfc)
__DEF_FUN1(double, exp)
__DEF_FUN1(double, exp2)
__DEF_FUN1(double, expm1)
__DEF_FUN1(double, fabs)
__DEF_FUN2(double, fdim);
__DEF_FUN1(double, floor)
__DEF_FUN2(double, fmax);
__DEF_FUN2(double, fmin);
__DEF_FUN2(double, fmod);
//__HIP_OVERLOAD1(int, fpclassify)
__DEF_FUN2(double, hypot);
__DEF_FUNI(int, ilogb)
__HIP_OVERLOAD1(bool, isfinite)
__HIP_OVERLOAD2(bool, isgreater);
__HIP_OVERLOAD2(bool, isgreaterequal);
__HIP_OVERLOAD1(bool, isinf);
__HIP_OVERLOAD2(bool, isless);
__HIP_OVERLOAD2(bool, islessequal);
__HIP_OVERLOAD2(bool, islessgreater);
__HIP_OVERLOAD1(bool, isnan);
//__HIP_OVERLOAD1(bool, isnormal)
__HIP_OVERLOAD2(bool, isunordered);
__DEF_FUN1(double, lgamma)
__DEF_FUN1(double, log)
__DEF_FUN1(double, log10)
__DEF_FUN1(double, log1p)
__DEF_FUN1(double, log2)
__DEF_FUN1(double, logb)
__DEF_FUNI(long long, llrint)
__DEF_FUNI(long long, llround)
__DEF_FUNI(long, lrint)
__DEF_FUNI(long, lround)
__DEF_FUN1(double, nearbyint);
__DEF_FUN2(double, nextafter);
__DEF_FUN2(double, pow);
__DEF_FUN2(double, remainder);
__DEF_FUN1(double, rint);
__DEF_FUN1(double, round);
__HIP_OVERLOAD1(bool, signbit)
__DEF_FUN1(double, sin)
__DEF_FUN1(double, sinh)
__DEF_FUN1(double, sqrt)
__DEF_FUN1(double, tan)
__DEF_FUN1(double, tanh)
__DEF_FUN1(double, tgamma)
__DEF_FUN1(double, trunc);
// define cmath functions with a float and an integer argument.
#define __DEF_FLOAT_FUN2I(__func) \
__DEVICE__ \
inline float __func(float __x, int __y) { return __func##f(__x, __y); }
__DEF_FLOAT_FUN2I(scalbn)
__DEF_FLOAT_FUN2I(ldexp)
template <class T> __DEVICE__ inline T min(T __arg1, T __arg2) {
return (__arg1 < __arg2) ? __arg1 : __arg2;
}
template <class T> __DEVICE__ inline T max(T __arg1, T __arg2) {
return (__arg1 > __arg2) ? __arg1 : __arg2;
}
__DEVICE__ inline int min(int __arg1, int __arg2) {
return (__arg1 < __arg2) ? __arg1 : __arg2;
}
__DEVICE__ inline int max(int __arg1, int __arg2) {
return (__arg1 > __arg2) ? __arg1 : __arg2;
}
__DEVICE__
inline float max(float __x, float __y) { return fmaxf(__x, __y); }
__DEVICE__
inline double max(double __x, double __y) { return fmax(__x, __y); }
__DEVICE__
inline float min(float __x, float __y) { return fminf(__x, __y); }
__DEVICE__
inline double min(double __x, double __y) { return fmin(__x, __y); }
__HIP_OVERLOAD2(double, max)
__HIP_OVERLOAD2(double, min)
__host__ inline static int min(int __arg1, int __arg2) {
return std::min(__arg1, __arg2);
}
__host__ inline static int max(int __arg1, int __arg2) {
return std::max(__arg1, __arg2);
}
#ifdef __cplusplus
__DEVICE__
inline float pow(float __base, int __iexp) { return powif(__base, __iexp); }
__DEVICE__
inline double pow(double __base, int __iexp) { return powi(__base, __iexp); }
__DEVICE__
inline _Float16 pow(_Float16 __base, int __iexp) {
return __ocml_pown_f16(__base, __iexp);
}
__DEVICE__
inline float remquo(float __x, float __y, int *__quo) {
return remquof(__x, __y, __quo);
}
template <typename __T1, typename __T2>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized &&
std::numeric_limits<__T2>::is_specialized,
double>::type
remquo(__T1 __x, __T2 __y, int *__quo) {
return remquo((double)__x, (double)__y, __quo);
}
__DEVICE__
inline float frexp(float __x, int *__nptr) { return frexpf(__x, __nptr); }
__DEVICE__
inline float modf(float __x, float *__iptr) { return modff(__x, __iptr); }
#endif
#pragma pop_macro("__DEF_FUN1")
#pragma pop_macro("__DEF_FUN2")
#pragma pop_macro("__DEF_FUNI")
#pragma pop_macro("__DEF_FLOAT_FUN2I")
#pragma pop_macro("__HIP_OVERLOAD1")
#pragma pop_macro("__HIP_OVERLOAD2")
#pragma pop_macro("__DEVICE__")
#pragma pop_macro("__RETURN_TYPE")
#endif // __CLANG_HIP_MATH_H__