xref: /llvm-project/flang/test/Lower/CUDA/cuda-data-attribute.cuf (revision 5bb379f6f0ed17873a2f500361921f98c112108a)
1abc4f74dSValentin Clement (バレンタイン クレメン)! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
2abc4f74dSValentin Clement (バレンタイン クレメン)! RUN: bbc -emit-hlfir -fcuda %s -o - | fir-opt -convert-hlfir-to-fir | FileCheck %s --check-prefix=FIR
3abc4f74dSValentin Clement (バレンタイン クレメン)
4c560ce46SValentin Clement (バレンタイン クレメン)! Test lowering of CUDA attribute on variables.
5abc4f74dSValentin Clement (バレンタイン クレメン)
6314ef961SValentin Clement (バレンタイン クレメン)module cuda_var
73a47d948SValentin Clement (バレンタイン クレメン)
83a47d948SValentin Clement (バレンタイン クレメン)  type :: t1
93a47d948SValentin Clement (バレンタイン クレメン)    integer :: a
103a47d948SValentin Clement (バレンタイン クレメン)  end type
113a47d948SValentin Clement (バレンタイン クレメン)
12314ef961SValentin Clement (バレンタイン クレメン)  real, constant :: mod_a_rc
1345daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_a_rc {data_attr = #cuf.cuda<constant>} : f32
14314ef961SValentin Clement (バレンタイン クレメン)  real, device :: mod_b_ra
1545daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_b_ra {data_attr = #cuf.cuda<device>} : f32
16314ef961SValentin Clement (バレンタイン クレメン)  real, allocatable, managed :: mod_c_rm
1745daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_c_rm {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<f32>>
183a47d948SValentin Clement (バレンタイン クレメン)
193a47d948SValentin Clement (バレンタイン クレメン)  integer, device, dimension(10) :: mod_d_i_init = (/ (i, i = 1, 10) /)
203a47d948SValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_d_i_init(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xi32>
213a47d948SValentin Clement (バレンタイン クレメン)
223a47d948SValentin Clement (バレンタイン クレメン)  real, device, dimension(10) :: mod_d_rinit = (/ (i, i = 1, 10) /)
233a47d948SValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_d_rinit(dense<[{{.*}}]> : tensor<10xf32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xf32>
243a47d948SValentin Clement (バレンタイン クレメン)
25314ef961SValentin Clement (バレンタイン クレメン)  real, allocatable, pinned :: mod_d_rp
2645daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_d_rp {data_attr = #cuf.cuda<pinned>} : !fir.box<!fir.heap<f32>>
27314ef961SValentin Clement (バレンタイン クレメン)
283a47d948SValentin Clement (バレンタイン クレメン)  type(t1), device :: mod_d_t(2)
293a47d948SValentin Clement (バレンタイン クレメン)! CHECK: fir.global @_QMcuda_varEmod_d_t {data_attr = #cuf.cuda<device>} : !fir.array<2x!fir.type<_QMcuda_varTt1{a:i32}>>
303a47d948SValentin Clement (バレンタイン クレメン)
31314ef961SValentin Clement (バレンタイン クレメン)contains
32314ef961SValentin Clement (バレンタイン クレメン)
33abc4f74dSValentin Clement (バレンタイン クレメン)subroutine local_var_attrs
34abc4f74dSValentin Clement (バレンタイン クレメン)  real, device :: rd
35abc4f74dSValentin Clement (バレンタイン クレメン)  real, allocatable, managed :: rm
36abc4f74dSValentin Clement (バレンタイン クレメン)  real, allocatable, pinned :: rp
37e953c862SValentin Clement (バレンタイン クレメン)  real, unified :: ru
38abc4f74dSValentin Clement (バレンタイン クレメン)end subroutine
39abc4f74dSValentin Clement (バレンタイン クレメン)
40314ef961SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QMcuda_varPlocal_var_attrs()
4145daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %{{.*}} {data_attr = #cuf.cuda<device>, uniq_name = "_QMcuda_varFlocal_var_attrsErd"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
4245daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %{{.*}} {data_attr = #cuf.cuda<managed>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcuda_varFlocal_var_attrsErm"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)
4345daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %{{.*}} {data_attr = #cuf.cuda<pinned>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcuda_varFlocal_var_attrsErp"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)
4445daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %{{.*}} {data_attr = #cuf.cuda<unified>, uniq_name = "_QMcuda_varFlocal_var_attrsEru"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
45e953c862SValentin Clement (バレンタイン クレメン)
46abc4f74dSValentin Clement (バレンタイン クレメン)
4745daa4fdSValentin Clement (バレンタイン クレメン)! FIR: %{{.*}} = fir.declare %{{.*}} {data_attr = #cuf.cuda<device>, uniq_name = "_QMcuda_varFlocal_var_attrsErd"} : (!fir.ref<f32>) -> !fir.ref<f32>
4845daa4fdSValentin Clement (バレンタイン クレメン)! FIR: %{{.*}} = fir.declare %{{.*}} {data_attr = #cuf.cuda<managed>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcuda_varFlocal_var_attrsErm"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<f32>>>
4945daa4fdSValentin Clement (バレンタイン クレメン)! FIR: %{{.*}} = fir.declare %{{.*}} {data_attr = #cuf.cuda<pinned>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcuda_varFlocal_var_attrsErp"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<f32>>>
5045daa4fdSValentin Clement (バレンタイン クレメン)! FIR: %{{.*}} = fir.declare %{{.*}} {data_attr = #cuf.cuda<unified>, uniq_name = "_QMcuda_varFlocal_var_attrsEru"} : (!fir.ref<f32>) -> !fir.ref<f32>
51c560ce46SValentin Clement (バレンタイン クレメン)
52c560ce46SValentin Clement (バレンタイン クレメン)subroutine dummy_arg_device(dd)
53c560ce46SValentin Clement (バレンタイン クレメン)  real, device :: dd
54c560ce46SValentin Clement (バレンタイン クレメン)end subroutine
55314ef961SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QMcuda_varPdummy_arg_device(
5645daa4fdSValentin Clement (バレンタイン クレメン)! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<f32> {cuf.data_attr = #cuf.cuda<device>, fir.bindc_name = "dd"}) {
5745daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {data_attr = #cuf.cuda<device>, uniq_name = "_QMcuda_varFdummy_arg_deviceEdd"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)
58c560ce46SValentin Clement (バレンタイン クレメン)
59c560ce46SValentin Clement (バレンタイン クレメン)subroutine dummy_arg_managed(dm)
60c560ce46SValentin Clement (バレンタイン クレメン)  real, allocatable, managed :: dm
61c560ce46SValentin Clement (バレンタイン クレメン)end subroutine
62314ef961SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QMcuda_varPdummy_arg_managed(
6345daa4fdSValentin Clement (バレンタイン クレメン)! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<f32>>> {cuf.data_attr = #cuf.cuda<managed>, fir.bindc_name = "dm"}) {
6445daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {data_attr = #cuf.cuda<managed>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcuda_varFdummy_arg_managedEdm"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)
65c560ce46SValentin Clement (バレンタイン クレメン)
66c560ce46SValentin Clement (バレンタイン クレメン)subroutine dummy_arg_pinned(dp)
67c560ce46SValentin Clement (バレンタイン クレメン)  real, allocatable, pinned :: dp
68c560ce46SValentin Clement (バレンタイン クレメン)end subroutine
69314ef961SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QMcuda_varPdummy_arg_pinned(
7045daa4fdSValentin Clement (バレンタイン クレメン)! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<f32>>> {cuf.data_attr = #cuf.cuda<pinned>, fir.bindc_name = "dp"}) {
7145daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {data_attr = #cuf.cuda<pinned>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcuda_varFdummy_arg_pinnedEdp"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)
72c560ce46SValentin Clement (バレンタイン クレメン)
73e953c862SValentin Clement (バレンタイン クレメン)subroutine dummy_arg_unified(du)
74e953c862SValentin Clement (バレンタイン クレメン)  real, unified :: du
75e953c862SValentin Clement (バレンタイン クレメン)end subroutine
76e953c862SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QMcuda_varPdummy_arg_unified(
7745daa4fdSValentin Clement (バレンタイン クレメン)! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<f32> {cuf.data_attr = #cuf.cuda<unified>, fir.bindc_name = "du"})
7845daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}}:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {data_attr = #cuf.cuda<unified>, uniq_name = "_QMcuda_varFdummy_arg_unifiedEdu"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)
79e953c862SValentin Clement (バレンタイン クレメン)
8026060de0SValentin Clement (バレンタイン クレメン)subroutine cuda_alloc_free(n)
8126060de0SValentin Clement (バレンタイン クレメン)  integer :: n
8226060de0SValentin Clement (バレンタイン クレメン)  real, device :: a(10)
8326060de0SValentin Clement (バレンタイン クレメン)  integer, unified :: u
8426060de0SValentin Clement (バレンタイン クレメン)  real, managed :: b(n)
8526060de0SValentin Clement (バレンタイン クレメン)end
8626060de0SValentin Clement (バレンタイン クレメン)
8726060de0SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QMcuda_varPcuda_alloc_free
8845daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %[[ALLOC_A:.*]] = cuf.alloc !fir.array<10xf32> {bindc_name = "a", data_attr = #cuf.cuda<device>, uniq_name = "_QMcuda_varFcuda_alloc_freeEa"} -> !fir.ref<!fir.array<10xf32>>
893a47d948SValentin Clement (バレンタイン クレメン)! CHECK: %[[SHAPE:.*]] = fir.shape %c10{{.*}} : (index) -> !fir.shape<1>
9045daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %[[DECL_A:.*]]:2 = hlfir.declare %[[ALLOC_A]](%[[SHAPE]]) {data_attr = #cuf.cuda<device>, uniq_name = "_QMcuda_varFcuda_alloc_freeEa"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>)
9126060de0SValentin Clement (バレンタイン クレメン)
9245daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %[[ALLOC_U:.*]] = cuf.alloc i32 {bindc_name = "u", data_attr = #cuf.cuda<unified>, uniq_name = "_QMcuda_varFcuda_alloc_freeEu"} -> !fir.ref<i32>
9345daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %[[DECL_U:.*]]:2 = hlfir.declare %[[ALLOC_U]] {data_attr = #cuf.cuda<unified>, uniq_name = "_QMcuda_varFcuda_alloc_freeEu"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
9426060de0SValentin Clement (バレンタイン クレメン)
9545daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %[[ALLOC_B:.*]] = cuf.alloc !fir.array<?xf32>, %{{.*}} : index {bindc_name = "b", data_attr = #cuf.cuda<managed>, uniq_name = "_QMcuda_varFcuda_alloc_freeEb"} -> !fir.ref<!fir.array<?xf32>>
9626060de0SValentin Clement (バレンタイン クレメン)! CHECK: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
9745daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: %[[DECL_B:.*]]:2 = hlfir.declare %[[ALLOC_B]](%[[SHAPE]]) {data_attr = #cuf.cuda<managed>, uniq_name = "_QMcuda_varFcuda_alloc_freeEb"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)
9826060de0SValentin Clement (バレンタイン クレメン)
9945daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: cuf.free %[[DECL_B]]#1 : !fir.ref<!fir.array<?xf32>> {data_attr = #cuf.cuda<managed>}
10045daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: cuf.free %[[DECL_U]]#1 : !fir.ref<i32> {data_attr = #cuf.cuda<unified>}
10145daa4fdSValentin Clement (バレンタイン クレメン)! CHECK: cuf.free %[[DECL_A]]#1 : !fir.ref<!fir.array<10xf32>> {data_attr = #cuf.cuda<device>}
10226060de0SValentin Clement (バレンタイン クレメン)
103ee9ca120SValentin Clement (バレンタイン クレメン)subroutine dummy(x)
104ee9ca120SValentin Clement (バレンタイン クレメン)  real, target, device :: x
105ee9ca120SValentin Clement (バレンタイン クレメン)end subroutine
106ee9ca120SValentin Clement (バレンタイン クレメン)
107ee9ca120SValentin Clement (バレンタイン クレメン)! CHECK: func.func @_QMcuda_varPdummy
10845daa4fdSValentin Clement (バレンタイン クレメン)! CHECK-NOT: cuf.free
109ee9ca120SValentin Clement (バレンタイン クレメン)
110314ef961SValentin Clement (バレンタイン クレメン)end module
11126060de0SValentin Clement (バレンタイン クレメン)
112*5bb379f6SValentin Clement (バレンタイン クレメン)subroutine craypointer()
113*5bb379f6SValentin Clement (バレンタイン クレメン)  real, device :: x(*); pointer(px, x)
114*5bb379f6SValentin Clement (バレンタイン クレメン)end
11526060de0SValentin Clement (バレンタイン クレメン)
116*5bb379f6SValentin Clement (バレンタイン クレメン)! CHECK-LABEL: func.func @_QPcraypointer()
117*5bb379f6SValentin Clement (バレンタイン クレメン)! CHECK: %{{.*}} = cuf.alloc !fir.box<!fir.ptr<!fir.array<?xf32>>> {data_attr = #cuf.cuda<device>} -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
118