Skip to content

Commit fd3f052

Browse files
authored
[flang][cuda] Add interfaces for int_as_float and float_as_int (#153716)
1 parent 92cb041 commit fd3f052

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

flang/module/cudadevice.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,20 @@ attributes(device) real(8) function sinpi(x) bind(c,name='__nv_sinpi')
471471
end function
472472
end interface
473473

474+
interface int_as_float
475+
attributes(device) real function __int_as_float(i) bind(c, name='__nv_int_as_float')
476+
!dir$ ignore_tkr (d) i
477+
integer, value :: i
478+
end function
479+
end interface
480+
481+
interface float_as_int
482+
attributes(device) integer function __float_as_int(i) bind(c, name='__nv_float_as_int')
483+
!dir$ ignore_tkr (d) i
484+
real, value :: i
485+
end function
486+
end interface
487+
474488
interface __float2half_rn
475489
attributes(device) real(2) function __float2half_rn(r) bind(c, name='__nv_float2half_rn')
476490
!dir$ ignore_tkr (d) r

flang/test/Lower/CUDA/cuda-libdevice.cuf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,24 @@ end subroutine
245245
! CHECK: %{{.*}} = fir.call @__nv_float2uint_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> i32
246246
! CHECK: %{{.*}} = fir.call @__nv_float2uint_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> i32
247247

248+
attributes(global) subroutine test_int_as_float()
249+
integer :: i
250+
real :: res
251+
res = int_as_float(i)
252+
end subroutine
253+
254+
! CHECK-LABEL: _QPtest_int_as_float
255+
! CHECK: %{{.*}} = fir.call @__nv_int_as_float(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i32) -> f32
256+
257+
attributes(global) subroutine test_float_as_int()
258+
integer :: res
259+
real :: r
260+
res = float_as_int(r)
261+
end subroutine
262+
263+
! CHECK-LABEL: _QPtest_float_as_int
264+
! CHECK: %{{.*}} = fir.call @__nv_float_as_int(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> i32
265+
248266
attributes(global) subroutine test_double2loint()
249267
integer :: res
250268
double precision :: r

0 commit comments

Comments
 (0)