-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathlibdevice.txt
5788 lines (5786 loc) · 187 KB
/
libdevice.txt
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
LIBDEVICE USER'S GUIDE
Part 000 _v8.0 | February 2016TABLE OF CONTENTS
Chapter 1. Introduction.........................................................................................1
1.1. What Is libdevice?........................................................................................1
Chapter 2. Basic Usage..........................................................................................2
2.1. Linking with libdevice................................................................................... 2
2.2. Selecting Library Version................................................................................3
Chapter 3. Function Reference...............................................................................4
3.1. __nv_abs....................................................................................................4
3.2. __nv_acos..................................................................................................4
3.3. __nv_acosf.................................................................................................5
3.4. __nv_acosh.................................................................................................5
3.5. __nv_acoshf................................................................................................6
3.6. __nv_asin...................................................................................................7
3.7. __nv_asinf..................................................................................................7
3.8. __nv_asinh................................................................................................. 8
3.9. __nv_asinhf................................................................................................ 8
3.10. __nv_atan.................................................................................................9
3.11. __nv_atan2............................................................................................... 9
3.12. __nv_atan2f.............................................................................................10
3.13. __nv_atanf.............................................................................................. 10
3.14. __nv_atanh..............................................................................................11
3.15. __nv_atanhf.............................................................................................11
3.16. __nv_brev............................................................................................... 12
3.17. __nv_brevll..............................................................................................12
3.18. __nv_byte_perm........................................................................................13
3.19. __nv_cbrt................................................................................................14
3.20. __nv_cbrtf...............................................................................................14
3.21. __nv_ceil................................................................................................ 15
3.22. __nv_ceilf............................................................................................... 15
3.23. __nv_clz................................................................................................. 16
3.24. __nv_clzll................................................................................................16
3.25. __nv_copysign.......................................................................................... 17
3.26. __nv_copysignf......................................................................................... 17
3.27. __nv_cos.................................................................................................17
3.28. __nv_cosf................................................................................................18
3.29. __nv_cosh............................................................................................... 19
3.30. __nv_coshf.............................................................................................. 19
3.31. __nv_cospi...............................................................................................20
3.32. __nv_cospif..............................................................................................20
3.33. __nv_dadd_rd...........................................................................................21
3.34. __nv_dadd_rn...........................................................................................21
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | ii3.35. __nv_dadd_ru...........................................................................................22
3.36. __nv_dadd_rz...........................................................................................22
3.37. __nv_ddiv_rd............................................................................................23
3.38. __nv_ddiv_rn............................................................................................23
3.39. __nv_ddiv_ru............................................................................................24
3.40. __nv_ddiv_rz............................................................................................24
3.41. __nv_dmul_rd...........................................................................................25
3.42. __nv_dmul_rn...........................................................................................25
3.43. __nv_dmul_ru...........................................................................................26
3.44. __nv_dmul_rz...........................................................................................26
3.45. __nv_double2float_rd................................................................................. 27
3.46. __nv_double2float_rn................................................................................. 27
3.47. __nv_double2float_ru................................................................................. 28
3.48. __nv_double2float_rz..................................................................................28
3.49. __nv_double2hiint......................................................................................29
3.50. __nv_double2int_rd....................................................................................29
3.51. __nv_double2int_rn....................................................................................30
3.52. __nv_double2int_ru....................................................................................30
3.53. __nv_double2int_rz....................................................................................31
3.54. __nv_double2ll_rd......................................................................................31
3.55. __nv_double2ll_rn......................................................................................32
3.56. __nv_double2ll_ru......................................................................................32
3.57. __nv_double2ll_rz......................................................................................33
3.58. __nv_double2loint......................................................................................33
3.59. __nv_double2uint_rd..................................................................................34
3.60. __nv_double2uint_rn.................................................................................. 34
3.61. __nv_double2uint_ru.................................................................................. 35
3.62. __nv_double2uint_rz...................................................................................35
3.63. __nv_double2ull_rd....................................................................................36
3.64. __nv_double2ull_rn....................................................................................36
3.65. __nv_double2ull_ru....................................................................................37
3.66. __nv_double2ull_rz....................................................................................37
3.67. __nv_double_as_longlong.............................................................................38
3.68. __nv_drcp_rd........................................................................................... 38
3.69. __nv_drcp_rn........................................................................................... 39
3.70. __nv_drcp_ru........................................................................................... 39
3.71. __nv_drcp_rz............................................................................................40
3.72. __nv_dsqrt_rd...........................................................................................40
3.73. __nv_dsqrt_rn...........................................................................................41
3.74. __nv_dsqrt_ru...........................................................................................41
3.75. __nv_dsqrt_rz...........................................................................................42
3.76. __nv_erf.................................................................................................42
3.77. __nv_erfc................................................................................................43
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | iii3.78. __nv_erfcf...............................................................................................43
3.79. __nv_erfcinv............................................................................................44
3.80. __nv_erfcinvf...........................................................................................44
3.81. __nv_erfcx...............................................................................................45
3.82. __nv_erfcxf..............................................................................................46
3.83. __nv_erff................................................................................................46
3.84. __nv_erfinv..............................................................................................47
3.85. __nv_erfinvf.............................................................................................47
3.86. __nv_exp................................................................................................ 48
3.87. __nv_exp10..............................................................................................48
3.88. __nv_exp10f.............................................................................................49
3.89. __nv_exp2...............................................................................................49
3.90. __nv_exp2f..............................................................................................50
3.91. __nv_expf............................................................................................... 50
3.92. __nv_expm1.............................................................................................51
3.93. __nv_expm1f............................................................................................51
3.94. __nv_fabs................................................................................................52
3.95. __nv_fabsf...............................................................................................52
3.96. __nv_fadd_rd...........................................................................................53
3.97. __nv_fadd_rn........................................................................................... 53
3.98. __nv_fadd_ru........................................................................................... 54
3.99. __nv_fadd_rz............................................................................................54
3.100. __nv_fast_cosf........................................................................................ 55
3.101. __nv_fast_exp10f.....................................................................................56
3.102. __nv_fast_expf........................................................................................56
3.103. __nv_fast_fdividef....................................................................................57
3.104. __nv_fast_log10f......................................................................................57
3.105. __nv_fast_log2f.......................................................................................58
3.106. __nv_fast_logf.........................................................................................58
3.107. __nv_fast_powf....................................................................................... 59
3.108. __nv_fast_sincosf.....................................................................................59
3.109. __nv_fast_sinf.........................................................................................60
3.110. __nv_fast_tanf........................................................................................ 61
3.111. __nv_fdim..............................................................................................61
3.112. __nv_fdimf.............................................................................................62
3.113. __nv_fdiv_rd...........................................................................................62
3.114. __nv_fdiv_rn...........................................................................................63
3.115. __nv_fdiv_ru...........................................................................................63
3.116. __nv_fdiv_rz...........................................................................................64
3.117. __nv_ffs................................................................................................64
3.118. __nv_ffsll...............................................................................................65
3.119. __nv_finitef............................................................................................65
3.120. __nv_float2half_rn................................................................................... 66
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | iv3.121. __nv_float2int_rd.....................................................................................66
3.122. __nv_float2int_rn.....................................................................................67
3.123. __nv_float2int_ru.....................................................................................67
3.124. __nv_float2int_rz.....................................................................................68
3.125. __nv_float2ll_rd.......................................................................................68
3.126. __nv_float2ll_rn.......................................................................................69
3.127. __nv_float2ll_ru.......................................................................................69
3.128. __nv_float2ll_rz.......................................................................................70
3.129. __nv_float2uint_rd................................................................................... 70
3.130. __nv_float2uint_rn................................................................................... 71
3.131. __nv_float2uint_ru................................................................................... 71
3.132. __nv_float2uint_rz....................................................................................72
3.133. __nv_float2ull_rd.....................................................................................72
3.134. __nv_float2ull_rn.....................................................................................73
3.135. __nv_float2ull_ru.....................................................................................73
3.136. __nv_float2ull_rz.....................................................................................74
3.137. __nv_float_as_int.....................................................................................74
3.138. __nv_floor..............................................................................................74
3.139. __nv_floorf.............................................................................................75
3.140. __nv_fma...............................................................................................76
3.141. __nv_fma_rd...........................................................................................76
3.142. __nv_fma_rn...........................................................................................77
3.143. __nv_fma_ru...........................................................................................77
3.144. __nv_fma_rz...........................................................................................78
3.145. __nv_fmaf..............................................................................................79
3.146. __nv_fmaf_rd..........................................................................................79
3.147. __nv_fmaf_rn..........................................................................................80
3.148. __nv_fmaf_ru..........................................................................................81
3.149. __nv_fmaf_rz..........................................................................................81
3.150. __nv_fmax.............................................................................................82
3.151. __nv_fmaxf............................................................................................82
3.152. __nv_fmin..............................................................................................83
3.153. __nv_fminf.............................................................................................84
3.154. __nv_fmod.............................................................................................84
3.155. __nv_fmodf............................................................................................85
3.156. __nv_fmul_rd..........................................................................................86
3.157. __nv_fmul_rn..........................................................................................86
3.158. __nv_fmul_ru..........................................................................................87
3.159. __nv_fmul_rz..........................................................................................87
3.160. __nv_frcp_rd.......................................................................................... 88
3.161. __nv_frcp_rn.......................................................................................... 88
3.162. __nv_frcp_ru.......................................................................................... 89
3.163. __nv_frcp_rz...........................................................................................89
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | v3.164. __nv_frexp.............................................................................................90
3.165. __nv_frexpf............................................................................................90
3.166. __nv_frsqrt_rn.........................................................................................91
3.167. __nv_fsqrt_rd..........................................................................................92
3.168. __nv_fsqrt_rn..........................................................................................92
3.169. __nv_fsqrt_ru..........................................................................................93
3.170. __nv_fsqrt_rz..........................................................................................93
3.171. __nv_fsub_rd..........................................................................................94
3.172. __nv_fsub_rn..........................................................................................94
3.173. __nv_fsub_ru..........................................................................................95
3.174. __nv_fsub_rz.......................................................................................... 95
3.175. __nv_hadd............................................................................................. 96
3.176. __nv_half2float....................................................................................... 96
3.177. __nv_hiloint2double..................................................................................97
3.178. __nv_hypot............................................................................................ 97
3.179. __nv_hypotf........................................................................................... 98
3.180. __nv_ilogb............................................................................................. 98
3.181. __nv_ilogbf............................................................................................ 99
3.182. __nv_int2double_rn.................................................................................. 99
3.183. __nv_int2float_rd................................................................................... 100
3.184. __nv_int2float_rn................................................................................... 100
3.185. __nv_int2float_ru................................................................................... 101
3.186. __nv_int2float_rz....................................................................................101
3.187. __nv_int_as_float................................................................................... 102
3.188. __nv_isfinited........................................................................................102
3.189. __nv_isinfd...........................................................................................103
3.190. __nv_isinff............................................................................................103
3.191. __nv_isnand..........................................................................................103
3.192. __nv_isnanf...........................................................................................104
3.193. __nv_j0............................................................................................... 104
3.194. __nv_j0f.............................................................................................. 105
3.195. __nv_j1............................................................................................... 105
3.196. __nv_j1f.............................................................................................. 106
3.197. __nv_jn............................................................................................... 107
3.198. __nv_jnf.............................................................................................. 107
3.199. __nv_ldexp...........................................................................................108
3.200. __nv_ldexpf..........................................................................................108
3.201. __nv_lgamma........................................................................................ 109
3.202. __nv_lgammaf....................................................................................... 110
3.203. __nv_ll2double_rd...................................................................................110
3.204. __nv_ll2double_rn...................................................................................111
3.205. __nv_ll2double_ru...................................................................................111
3.206. __nv_ll2double_rz...................................................................................112
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | vi3.207. __nv_ll2float_rd.....................................................................................112
3.208. __nv_ll2float_rn.....................................................................................113
3.209. __nv_ll2float_ru.....................................................................................113
3.210. __nv_ll2float_rz..................................................................................... 114
3.211. __nv_llabs............................................................................................114
3.212. __nv_llmax...........................................................................................114
3.213. __nv_llmin............................................................................................115
3.214. __nv_llrint............................................................................................115
3.215. __nv_llrintf...........................................................................................116
3.216. __nv_llround......................................................................................... 116
3.217. __nv_llroundf........................................................................................ 117
3.218. __nv_log..............................................................................................117
3.219. __nv_log10........................................................................................... 118
3.220. __nv_log10f.......................................................................................... 118
3.221. __nv_log1p........................................................................................... 119
3.222. __nv_log1pf.......................................................................................... 119
3.223. __nv_log2.............................................................................................120
3.224. __nv_log2f............................................................................................121
3.225. __nv_logb.............................................................................................121
3.226. __nv_logbf............................................................................................122
3.227. __nv_logf.............................................................................................122
3.228. __nv_longlong_as_double..........................................................................123
3.229. __nv_max.............................................................................................123
3.230. __nv_min............................................................................................. 124
3.231. __nv_modf............................................................................................124
3.232. __nv_modff...........................................................................................125
3.233. __nv_mul24...........................................................................................125
3.234. __nv_mul64hi........................................................................................126
3.235. __nv_mulhi...........................................................................................126
3.236. __nv_nan..............................................................................................127
3.237. __nv_nanf.............................................................................................127
3.238. __nv_nearbyint......................................................................................128
3.239. __nv_nearbyintf.....................................................................................128
3.240. __nv_nextafter...................................................................................... 129
3.241. __nv_nextafterf..................................................................................... 129
3.242. __nv_normcdf........................................................................................130
3.243. __nv_normcdff.......................................................................................130
3.244. __nv_normcdfinv....................................................................................131
3.245. __nv_normcdfinvf...................................................................................131
3.246. __nv_popc............................................................................................132
3.247. __nv_popcll.......................................................................................... 132
3.248. __nv_pow.............................................................................................133
3.249. __nv_powf............................................................................................134
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | vii3.250. __nv_powi............................................................................................135
3.251. __nv_powif...........................................................................................136
3.252. __nv_rcbrt............................................................................................137
3.253. __nv_rcbrtf...........................................................................................137
3.254. __nv_remainder..................................................................................... 138
3.255. __nv_remainderf.................................................................................... 138
3.256. __nv_remquo.........................................................................................139
3.257. __nv_remquof........................................................................................140
3.258. __nv_rhadd...........................................................................................140
3.259. __nv_rint..............................................................................................141
3.260. __nv_rintf.............................................................................................141
3.261. __nv_round...........................................................................................142
3.262. __nv_roundf..........................................................................................142
3.263. __nv_rsqrt............................................................................................143
3.264. __nv_rsqrtf...........................................................................................143
3.265. __nv_sad..............................................................................................144
3.266. __nv_saturatef.......................................................................................144
3.267. __nv_scalbn..........................................................................................145
3.268. __nv_scalbnf.........................................................................................145
3.269. __nv_signbitd........................................................................................ 146
3.270. __nv_signbitf.........................................................................................146
3.271. __nv_sin...............................................................................................147
3.272. __nv_sincos...........................................................................................147
3.273. __nv_sincosf..........................................................................................148
3.274. __nv_sincospi........................................................................................ 148
3.275. __nv_sincospif....................................................................................... 149
3.276. __nv_sinf..............................................................................................150
3.277. __nv_sinh.............................................................................................150
3.278. __nv_sinhf............................................................................................151
3.279. __nv_sinpi............................................................................................151
3.280. __nv_sinpif...........................................................................................152
3.281. __nv_sqrt.............................................................................................152
3.282. __nv_sqrtf............................................................................................153
3.283. __nv_tan..............................................................................................153
3.284. __nv_tanf.............................................................................................154
3.285. __nv_tanh............................................................................................ 154
3.286. __nv_tanhf........................................................................................... 155
3.287. __nv_tgamma........................................................................................155
3.288. __nv_tgammaf.......................................................................................156
3.289. __nv_trunc........................................................................................... 157
3.290. __nv_truncf.......................................................................................... 157
3.291. __nv_uhadd.......................................................................................... 157
3.292. __nv_uint2double_rn............................................................................... 158
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | viii3.293. __nv_uint2float_rd..................................................................................158
3.294. __nv_uint2float_rn..................................................................................159
3.295. __nv_uint2float_ru..................................................................................159
3.296. __nv_uint2float_rz..................................................................................160
3.297. __nv_ull2double_rd.................................................................................160
3.298. __nv_ull2double_rn.................................................................................161
3.299. __nv_ull2double_ru.................................................................................161
3.300. __nv_ull2double_rz................................................................................. 162
3.301. __nv_ull2float_rd....................................................................................162
3.302. __nv_ull2float_rn....................................................................................163
3.303. __nv_ull2float_ru....................................................................................163
3.304. __nv_ull2float_rz....................................................................................164
3.305. __nv_ullmax..........................................................................................164
3.306. __nv_ullmin..........................................................................................164
3.307. __nv_umax........................................................................................... 165
3.308. __nv_umin............................................................................................165
3.309. __nv_umul24.........................................................................................166
3.310. __nv_umul64hi.......................................................................................166
3.311. __nv_umulhi..........................................................................................167
3.312. __nv_urhadd......................................................................................... 167
3.313. __nv_usad............................................................................................ 168
3.314. __nv_y0...............................................................................................168
3.315. __nv_y0f..............................................................................................169
3.316. __nv_y1...............................................................................................169
3.317. __nv_y1f..............................................................................................170
3.318. __nv_yn...............................................................................................171
3.319. __nv_ynf..............................................................................................171
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | ixLIST OF TABLES
Table 1 Supported Reflection Parameters....................................................................2
Table 2 Library version selection guidelines.................................................................3
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | xChapter 1.
INTRODUCTION
1.1. What Is libdevice?
The libdevice library is a collection of NVVM bitcode functions that implement common
functions for NVIDIA GPU devices, including math primitives and bit-manipulation
functions. These functions are optimized for particular GPU architectures, and are
intended to be linked with an NVVM IR module during compilation to PTX.
This guide documents both the functions available in libdevice and the basic usage of
the library from a compiler writer's perspective.
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 1Chapter 2.
BASIC USAGE
2.1. Linking with libdevice
The libdevice library ships as an LLVM bitcode library and is meant to be linked with
the target module early in the compilation process. The standard process for linking
with libdevice is to first link it with the target module, then run the standard LLVM
optimization and code generation passes. This allows the optimizers to inline and
perform analyses on the used library functions, and eliminate any used functions as
dead code.
Users of libnvvm can link with libdevice by adding the appropriate libdevice module
to the object being compiled. In addition, the following options for
nvvmProgram
affect the behavior of libdevice functions:
nvvmCompileProgram
Table 1 Supported Reflection Parameters
Parameter Values Description
preserve denormal values, when performing
0
(default) single-precision floating-point operations
-ftz
flush denormal values to zero, when performing
1 single-precision floating-point operations
use a faster approximation for single-
0 precision floating-point division and reciprocals
-prec-div
use IEEE round-to-nearest mode for single-
1
(default) precision floating-point division and reciprocals
use IEEE round-to-nearest mode for single-
0 precision floating-point square root
-prec-sqrt
1 use a faster approximation for single-precision floating-point square root
(default)
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 2Basic Usage
The following pseudo-code shows an example of linking an NVVM IR module with the
libdevice library using libnvvm:
nvvmProgram prog;
size_t libdeviceModSize;
const char *libdeviceMod = loadFile('/path/to/libdevice.*.bc',
&libdeviceModSize);
const char *myIr = /* NVVM IR in text or binary format */;
size_t myIrSize = /* size of myIr in bytes */;
// Create NVVM program object
nvvmCreateProgram(&prog);
// Add libdevice module to program
nvvmAddModuleToProgram(prog, libdeviceMod, libdeviceModSize);
// Add custom IR to program
nvvmAddModuleToProgram(prog, myIr, myIrSize);
// Declare compile options
const char *options[] = { "-ftz=1" };
// Compile the program
nvvmCompileProgram(prog, 1, options);
It is the responsibility of the client program to locate and read the libdevice library
binary (represented by the function in the example).
loadFile
2.2. Selecting Library Version
The libdevice library ships with several versions, each tuned for optimal performance on
a particular device architecture. The following table provides a guideline for choosing
the best libdevice version for the target architecture. All versions can be found in the
CUDA Toolkit under .
nvvm/libdevice/<library-name>
Table 2 Library version selection guidelines
Compute Capability Library
2.0 ≤ Arch < 3.0
libdevice.compute_20.XX.bc
Arch = 3.0
libdevice.compute_30.XX.bc
3.1 ≤ Arch < 3.5
libdevice.compute_20.XX.bc
3.5 ≤ Arch ≤ 3.7
libdevice.compute_35.XX.bc
3.7 < Arch < 5.0
libdevice.compute_30.XX.bc
5.0 ≤ Arch ≤ 5.3
libdevice.compute_50.XX.bc
Arch > 5.3
libdevice.compute_30.XX.bc
The in the library name corresponds to the libdevice library version number.
XX
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 3Chapter 3.
FUNCTION REFERENCE
This chapter describes all functions available in libdevice.
3.1. __nv_abs
Prototype:
i32 @__nv_abs(i32 %x)
Description:
Determine the absolute value of the 32-bit signed integer .
x
Returns:
Returns the absolute value of the 32-bit signed integer .
x
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.2. __nv_acos
Prototype:
double @__nv_acos(double %x)
Description:
Calculate the principal value of the arc cosine of the input argument .
x
Returns:
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 4Function Reference
Result will be in radians, in the interval [0, ] for inside [-1, +1].
x
‣ __nv_acos(1) returns +0.
‣ __nv_acos(x) returns NaN for x outside [-1, +1].
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.3. __nv_acosf
Prototype:
float @__nv_acosf(float %x)
Description:
Calculate the principal value of the arc cosine of the input argument .
x
Returns:
Result will be in radians, in the interval [0, ] for inside [-1, +1].
x
‣ __nv_acosf(1) returns +0.
‣ __nv_acosf(x) returns NaN for x outside [-1, +1].
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.4. __nv_acosh
Prototype:
double @__nv_acosh(double %x)
Description:
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 5Function Reference
Calculate the nonnegative arc hyperbolic cosine of the input argument .
x
Returns:
Result will be in the interval [0, ].
‣ __nv_acosh(1) returns 0.
‣ __nv_acosh(x) returns NaN for x in the interval [ , 1).
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.5. __nv_acoshf
Prototype:
float @__nv_acoshf(float %x)
Description:
Calculate the nonnegative arc hyperbolic cosine of the input argument .
x
Returns:
Result will be in the interval [0, ].
‣ __nv_acoshf(1) returns 0.
‣ __nv_acoshf(x) returns NaN for x in the interval [ , 1).
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 6Function Reference
3.6. __nv_asin
Prototype:
double @__nv_asin(double %x)
Description:
Calculate the principal value of the arc sine of the input argument .
x
Returns:
Result will be in radians, in the interval [- /2, + /2] for inside [-1, +1].
x
‣ __nv_asin(0) returns +0.
‣ __nv_asin(x) returns NaN for x outside [-1, +1].
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.7. __nv_asinf
Prototype:
float @__nv_asinf(float %x)
Description:
Calculate the principal value of the arc sine of the input argument .
x
Returns:
Result will be in radians, in the interval [- /2, + /2] for inside [-1, +1].
x
‣ __nv_asinf(0) returns +0.
‣ __nv_asinf(x) returns NaN for x outside [-1, +1].
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 7Function Reference
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.8. __nv_asinh
Prototype:
double @__nv_asinh(double %x)
Description:
Calculate the arc hyperbolic sine of the input argument .
x
Returns:
‣ __nv_asinh(0) returns 1.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.9. __nv_asinhf
Prototype:
float @__nv_asinhf(float %x)
Description:
Calculate the arc hyperbolic sine of the input argument .
x
Returns:
‣ __nv_asinh(0) returns 1.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 8Function Reference
Compute 3.0: Yes
Compute 3.5: Yes
3.10. __nv_atan
Prototype:
double @__nv_atan(double %x)
Description:
Calculate the principal value of the arc tangent of the input argument .
x
Returns:
Result will be in radians, in the interval [- /2, + /2].
‣ __nv_atan(0) returns +0.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.11. __nv_atan2
Prototype:
double @__nv_atan2(double %x, double %y)
Description:
Calculate the principal value of the arc tangent of the ratio of first and second input
arguments / . The quadrant of the result is determined by the signs of inputs and .
x y x y
Returns:
Result will be in radians, in the interval [- /, + ].
‣ __nv_atan2(0, 1) returns +0.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 9Function Reference
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.12. __nv_atan2f
Prototype:
float @__nv_atan2f(float %x, float %y)
Description:
Calculate the principal value of the arc tangent of the ratio of first and second input
arguments / . The quadrant of the result is determined by the signs of inputs and .
x y x y
Returns:
Result will be in radians, in the interval [- /, + ].
‣ __nv_atan2f(0, 1) returns +0.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.13. __nv_atanf
Prototype:
float @__nv_atanf(float %x)
Description:
Calculate the principal value of the arc tangent of the input argument .
x
Returns:
Result will be in radians, in the interval [- /2, + /2].
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 10Function Reference
‣ __nv_atan(0) returns +0.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.14. __nv_atanh
Prototype:
double @__nv_atanh(double %x)
Description:
Calculate the arc hyperbolic tangent of the input argument .
x
Returns:
‣ __nv_atanh( ) returns .
‣ __nv_atanh( ) returns .
‣ __nv_atanh(x) returns NaN for x outside interval [-1, 1].
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.15. __nv_atanhf
Prototype:
float @__nv_atanhf(float %x)
Description:
Calculate the arc hyperbolic tangent of the input argument .
x
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 11Function Reference
Returns:
‣ __nv_atanhf( ) returns .
‣ __nv_atanhf( ) returns .
‣ __nv_atanhf(x) returns NaN for x outside interval [-1, 1].
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.16. __nv_brev
Prototype:
i32 @__nv_brev(i32 %x)
Description:
Reverses the bit order of the 32 bit unsigned integer .
x
Returns:
Returns the bit-reversed value of . i.e. bit N of the return value corresponds to bit 31-N
x
of .
x
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.17. __nv_brevll
Prototype:
i64 @__nv_brevll(i64 %x)
Description:
Reverses the bit order of the 64 bit unsigned integer .
x
Returns:
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 12Function Reference
Returns the bit-reversed value of . i.e. bit N of the return value corresponds to bit 63-N
x
of .
x
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.18. __nv_byte_perm
Prototype:
i32 @__nv_byte_perm(i32 %x, i32 %y, i32 %z)
Description:
__nv_byte_perm(x,y,s) returns a 32-bit integer consisting of four bytes from eight input
bytes provided in the two input integers and , as specified by a selector, .
x y s
The input bytes are indexed as follows:
input[0] = x<7:0> input[1] = x<15:8>
input[2] = x<23:16> input[3] = x<31:24>
input[4] = y<7:0> input[5] = y<15:8>
input[6] = y<23:16> input[7] = y<31:24>
The selector indices are as follows (the upper 16-bits of the selector are not used):
selector[0] = s<2:0> selector[1] = s<6:4>
selector[2] = s<10:8> selector[3] = s<14:12>
Returns:
The returned value r is computed to be:
result[n] := input[selector[n]]
where is the nth byte of r.
result[n]
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 13Function Reference
3.19. __nv_cbrt
Prototype:
double @__nv_cbrt(double %x)
Description:
Calculate the cube root of , .
x
Returns:
Returns .
‣ __nv_cbrt( ) returns .
‣ __nv_cbrt( ) returns .
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.20. __nv_cbrtf
Prototype:
float @__nv_cbrtf(float %x)
Description:
Calculate the cube root of , .
x
Returns:
Returns .
‣ __nv_cbrtf( ) returns .
‣ __nv_cbrtf( ) returns .
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 14Function Reference
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.21. __nv_ceil
Prototype:
double @__nv_ceil(double %x)
Description:
Compute the smallest integer value not less than .
x
Returns:
Returns expressed as a floating-point number.
‣ __nv_ceil( ) returns .
‣ __nv_ceil( ) returns .
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.22. __nv_ceilf
Prototype:
float @__nv_ceilf(float %x)
Description:
Compute the smallest integer value not less than .
x
Returns:
Returns expressed as a floating-point number.
‣ __nv_ceilf( ) returns .
‣ __nv_ceilf( ) returns .
Library Availability:
Compute 2.0: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 15Function Reference
Compute 3.0: Yes
Compute 3.5: Yes
3.23. __nv_clz
Prototype:
i32 @__nv_clz(i32 %x)
Description:
Count the number of consecutive leading zero bits, starting at the most significant bit
(bit 31) of .
x
Returns:
Returns a value between 0 and 32 inclusive representing the number of zero bits.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.24. __nv_clzll
Prototype:
i32 @__nv_clzll(i64 %x)
Description:
Count the number of consecutive leading zero bits, starting at the most significant bit
(bit 63) of .
x
Returns:
Returns a value between 0 and 64 inclusive representing the number of zero bits.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 16Function Reference
3.25. __nv_copysign
Prototype:
double @__nv_copysign(double %x, double %y)
Description:
Create a floating-point value with the magnitude and the sign of .
x y
Returns:
Returns a value with the magnitude of and the sign of .
x y
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.26. __nv_copysignf
Prototype:
float @__nv_copysignf(float %x, float %y)
Description:
Create a floating-point value with the magnitude and the sign of .
x y
Returns:
Returns a value with the magnitude of and the sign of .
x y
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.27. __nv_cos
Prototype:
double @__nv_cos(double %x)
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 17Function Reference
Description:
Calculate the cosine of the input argument (measured in radians).
x
Returns:
‣ __nv_cos( ) returns 1.
‣ __nv_cos( ) returns NaN.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.28. __nv_cosf
Prototype:
float @__nv_cosf(float %x)
Description:
Calculate the cosine of the input argument (measured in radians).
x
Returns:
‣ __nv_cosf( ) returns 1.
‣ __nv_cosf( ) returns NaN.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 18Function Reference
3.29. __nv_cosh
Prototype:
double @__nv_cosh(double %x)
Description:
Calculate the hyperbolic cosine of the input argument .
x
Returns:
‣ __nv_cosh(0) returns 1.
‣ __nv_cosh( ) returns .
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.30. __nv_coshf
Prototype:
float @__nv_coshf(float %x)
Description:
Calculate the hyperbolic cosine of the input argument .
x
Returns:
‣ __nv_coshf(0) returns 1.
‣ __nv_coshf( ) returns .
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 19Function Reference
Compute 3.5: Yes
3.31. __nv_cospi
Prototype:
double @__nv_cospi(double %x)
Description:
Calculate the cosine of (measured in radians), where is the input argument.
x x
Returns:
‣ __nv_cospi( ) returns 1.
‣ __nv_cospi( ) returns NaN.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.32. __nv_cospif
Prototype:
float @__nv_cospif(float %x)
Description:
Calculate the cosine of (measured in radians), where is the input argument.
x x
Returns:
‣ __nv_cospif( ) returns 1.
‣ __nv_cospif( ) returns NaN.
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 6.
Library Availability:
Compute 2.0: Yes
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 20Function Reference
Compute 3.0: Yes
Compute 3.5: Yes
3.33. __nv_dadd_rd
Prototype:
double @__nv_dadd_rd(double %x, double %y)
Description:
Adds two floating point values and in round-down (to negative infinity) mode.
x y
Returns:
Returns + .
x y
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
This operation will never be merged into a single multiply-add instruction.
Library Availability:
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.34. __nv_dadd_rn
Prototype:
double @__nv_dadd_rn(double %x, double %y)
Description:
Adds two floating point values and in round-to-nearest-even mode.
x y
Returns:
Returns + .
x y
For accuracy information for this function see the CUDA C Programming Guide,
Appendix D.1, Table 7.
This operation will never be merged into a single multiply-add instruction.
Library Availability:
www.nvidia.com
Libdevice User's Guide Part 000 _v8.0 | 21Function Reference
Compute 2.0: Yes
Compute 3.0: Yes
Compute 3.5: Yes
3.35. __nv_dadd_ru
Prototype:
double @__nv_dadd_ru(double %x, double %y)
Description:
Adds two floating point values and in round-up (to positive infinity) mode.
x y