Skip to content

Commit 00bd2fa

Browse files
authored
[flang][cuda] Add bind c to cudadevice procedures (#92822)
This patch adds bind c names to functions and subroutines in cudadevice so they can be lowered and not hit the intrinsic procedure TODOs.
1 parent 060b302 commit 00bd2fa

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

flang/module/cudadevice.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,34 @@ module cudadevice
1818
! Synchronization Functions
1919

2020
interface
21-
attributes(device) subroutine syncthreads()
21+
attributes(device) subroutine syncthreads() bind(c, name='__syncthreads')
2222
end subroutine
2323
end interface
2424
public :: syncthreads
2525

2626
interface
27-
attributes(device) integer function syncthreads_and(value)
27+
attributes(device) integer function syncthreads_and(value) bind(c, name='__syncthreads_and')
2828
integer :: value
2929
end function
3030
end interface
3131
public :: syncthreads_and
3232

3333
interface
34-
attributes(device) integer function syncthreads_count(value)
34+
attributes(device) integer function syncthreads_count(value) bind(c, name='__syncthreads_count')
3535
integer :: value
3636
end function
3737
end interface
3838
public :: syncthreads_count
3939

4040
interface
41-
attributes(device) integer function syncthreads_or(value)
41+
attributes(device) integer function syncthreads_or(value) bind(c, name='__syncthreads_or')
4242
integer :: value
4343
end function
4444
end interface
4545
public :: syncthreads_or
4646

4747
interface
48-
attributes(device) subroutine syncwarp(mask)
48+
attributes(device) subroutine syncwarp(mask) bind(c, name='__syncwarp')
4949
integer :: mask
5050
end subroutine
5151
end interface
@@ -54,19 +54,19 @@ attributes(device) subroutine syncwarp(mask)
5454
! Memory Fences
5555

5656
interface
57-
attributes(device) subroutine threadfence()
57+
attributes(device) subroutine threadfence() bind(c, name='__threadfence')
5858
end subroutine
5959
end interface
6060
public :: threadfence
6161

6262
interface
63-
attributes(device) subroutine threadfence_block()
63+
attributes(device) subroutine threadfence_block() bind(c, name='__threadfence_block')
6464
end subroutine
6565
end interface
6666
public :: threadfence_block
6767

6868
interface
69-
attributes(device) subroutine threadfence_system()
69+
attributes(device) subroutine threadfence_system() bind(c, name='__threadfence_system')
7070
end subroutine
7171
end interface
7272
public :: threadfence_system
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
2+
3+
! Test CUDA Fortran procedures available in cudadevice module
4+
5+
attributes(global) subroutine devsub()
6+
implicit none
7+
integer :: ret
8+
9+
call syncthreads()
10+
call syncwarp(1)
11+
call threadfence()
12+
call threadfence_block()
13+
call threadfence_system()
14+
ret = syncthreads_and(1)
15+
ret = syncthreads_count(1)
16+
ret = syncthreads_or(1)
17+
end
18+
19+
! CHECK-LABEL: func.func @_QPdevsub() attributes {cuf.proc_attr = #cuf.cuda_proc<global>}
20+
! CHECK: fir.call @__syncthreads()
21+
! CHECK: fir.call @__syncwarp(%{{.*}}) fastmath<contract> : (!fir.ref<i32>) -> ()
22+
! CHECK: fir.call @__threadfence()
23+
! CHECK: fir.call @__threadfence_block()
24+
! CHECK: fir.call @__threadfence_system()
25+
! CHECK: %{{.*}} = fir.call @__syncthreads_and(%{{.*}}) fastmath<contract> : (!fir.ref<i32>) -> i32
26+
! CHECK: %{{.*}} = fir.call @__syncthreads_count(%{{.*}}) fastmath<contract> : (!fir.ref<i32>) -> i32
27+
! CHECK: %{{.*}} = fir.call @__syncthreads_or(%{{.*}}) fastmath<contract> : (!fir.ref<i32>) -> i32
28+
29+
! CHECK: func.func private @__syncthreads() attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__syncthreads"}
30+
! CHECK: func.func private @__syncwarp(!fir.ref<i32> {cuf.data_attr = #cuf.cuda<device>}) attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__syncwarp"}
31+
! CHECK: func.func private @__threadfence() attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__threadfence"}
32+
! CHECK: func.func private @__threadfence_block() attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__threadfence_block"}
33+
! CHECK: func.func private @__threadfence_system() attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__threadfence_system"}
34+
! CHECK: func.func private @__syncthreads_and(!fir.ref<i32> {cuf.data_attr = #cuf.cuda<device>}) -> i32 attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__syncthreads_and"}
35+
! CHECK: func.func private @__syncthreads_count(!fir.ref<i32> {cuf.data_attr = #cuf.cuda<device>}) -> i32 attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__syncthreads_count"}
36+
! CHECK: func.func private @__syncthreads_or(!fir.ref<i32> {cuf.data_attr = #cuf.cuda<device>}) -> i32 attributes {cuf.proc_attr = #cuf.cuda_proc<device>, fir.bindc_name = "__syncthreads_or"}

0 commit comments

Comments
 (0)