1// RUN: fir-opt -split-input-file -verify-diagnostics %s 2 3func.func @_QPsub1() { 4 %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a", uniq_name = "_QFsub1Ea"} 5 %1 = fir.alloca i32 6 %pinned = fir.alloca i1 7 %4:2 = hlfir.declare %0 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFsub1Ea"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) 8 %11 = fir.convert %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> !fir.ref<!fir.box<none>> 9 %s = fir.load %1 : !fir.ref<i32> 10 // expected-error@+1{{'cuf.allocate' op pinned and stream cannot appears at the same time}} 11 %13 = cuf.allocate %11 : !fir.ref<!fir.box<none>> stream(%s : i32) pinned(%pinned : !fir.ref<i1>) {data_attr = #cuf.cuda<device>} -> i32 12 return 13} 14 15// ----- 16 17func.func @_QPsub1() { 18 %1 = fir.alloca i32 19 // expected-error@+1{{'cuf.allocate' op expect box to be a reference to a class or box type value}} 20 %2 = cuf.allocate %1 : !fir.ref<i32> {data_attr = #cuf.cuda<device>} -> i32 21 return 22} 23 24// ----- 25 26func.func @_QPsub1() { 27 %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a", uniq_name = "_QFsub1Ea"} 28 %4:2 = hlfir.declare %0 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFsub1Ea"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) 29 %c100 = arith.constant 100 : index 30 %7 = fir.alloca !fir.char<1,100> {bindc_name = "msg", uniq_name = "_QFsub1Emsg"} 31 %8:2 = hlfir.declare %7 typeparams %c100 {uniq_name = "_QFsub1Emsg"} : (!fir.ref<!fir.char<1,100>>, index) -> (!fir.ref<!fir.char<1,100>>, !fir.ref<!fir.char<1,100>>) 32 %9 = fir.embox %8#1 : (!fir.ref<!fir.char<1,100>>) -> !fir.box<!fir.char<1,100>> 33 %11 = fir.convert %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> !fir.ref<!fir.box<none>> 34 %16 = fir.convert %9 : (!fir.box<!fir.char<1,100>>) -> !fir.box<none> 35 // expected-error@+1{{'cuf.allocate' op expect stat attribute when errmsg is provided}} 36 %13 = cuf.allocate %11 : !fir.ref<!fir.box<none>> errmsg(%16 : !fir.box<none>) {data_attr = #cuf.cuda<device>} -> i32 37 return 38} 39 40// ----- 41 42func.func @_QPsub1() { 43 %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a", uniq_name = "_QFsub1Ea"} 44 %4:2 = hlfir.declare %0 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFsub1Ea"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) 45 %1 = fir.alloca i32 46 %11 = fir.convert %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> !fir.ref<!fir.box<none>> 47 // expected-error@+1{{'cuf.allocate' op expect errmsg to be a reference to/or a box type value}} 48 %13 = cuf.allocate %11 : !fir.ref<!fir.box<none>> errmsg(%1 : !fir.ref<i32>) {data_attr = #cuf.cuda<device>, hasStat} -> i32 49 return 50} 51 52// ----- 53 54func.func @_QPsub1() { 55 %1 = fir.alloca i32 56 // expected-error@+1{{'cuf.deallocate' op expect box to be a reference to class or box type value}} 57 %2 = cuf.deallocate %1 : !fir.ref<i32> {data_attr = #cuf.cuda<device>} -> i32 58 return 59} 60 61// ----- 62 63func.func @_QPsub1() { 64 %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a", uniq_name = "_QFsub1Ea"} 65 %4:2 = hlfir.declare %0 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFsub1Ea"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) 66 %1 = fir.alloca i32 67 %11 = fir.convert %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> !fir.ref<!fir.box<none>> 68 // expected-error@+1{{'cuf.deallocate' op expect errmsg to be a reference to/or a box type value}} 69 %13 = cuf.deallocate %11 : !fir.ref<!fir.box<none>> errmsg(%1 : !fir.ref<i32>) {data_attr = #cuf.cuda<device>, hasStat} -> i32 70 return 71} 72 73// ----- 74 75func.func @_QPsub1() { 76 %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a", uniq_name = "_QFsub1Ea"} 77 %4:2 = hlfir.declare %0 {data_attr = #cuf.cuda<device>, fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFsub1Ea"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) 78 %c100 = arith.constant 100 : index 79 %7 = fir.alloca !fir.char<1,100> {bindc_name = "msg", uniq_name = "_QFsub1Emsg"} 80 %8:2 = hlfir.declare %7 typeparams %c100 {uniq_name = "_QFsub1Emsg"} : (!fir.ref<!fir.char<1,100>>, index) -> (!fir.ref<!fir.char<1,100>>, !fir.ref<!fir.char<1,100>>) 81 %9 = fir.embox %8#1 : (!fir.ref<!fir.char<1,100>>) -> !fir.box<!fir.char<1,100>> 82 %11 = fir.convert %4#1 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> !fir.ref<!fir.box<none>> 83 %16 = fir.convert %9 : (!fir.box<!fir.char<1,100>>) -> !fir.box<none> 84 // expected-error@+1{{'cuf.deallocate' op expect stat attribute when errmsg is provided}} 85 %13 = cuf.deallocate %11 : !fir.ref<!fir.box<none>> errmsg(%16 : !fir.box<none>) {data_attr = #cuf.cuda<device>} -> i32 86 return 87} 88 89// ----- 90 91func.func @_QPsub1() { 92 %0 = cuf.alloc f32 {bindc_name = "r", data_attr = #cuf.cuda<device>, uniq_name = "_QFsub1Er"} -> !fir.ref<f32> 93 // expected-error@+1{{'cuf.free' op expect device, managed, pinned or unified cuda attribute}} 94 cuf.free %0 : !fir.ref<f32> {data_attr = #cuf.cuda<constant>} 95 return 96} 97 98// ----- 99 100func.func @_QPsub1(%arg0: !fir.ref<!fir.array<?xf32>> {cuf.data_attr = #cuf.cuda<device>, fir.bindc_name = "adev"}, %arg1: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "ahost"}, %arg2: !fir.ref<i32> {fir.bindc_name = "n"}, %arg3: !fir.ref<i32> {fir.bindc_name = "m"}) { 101 %0 = fir.dummy_scope : !fir.dscope 102 %1:2 = hlfir.declare %arg2 dummy_scope %0 {uniq_name = "_QFsub1En"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) 103 %2:2 = hlfir.declare %arg3 dummy_scope %0 {uniq_name = "_QFsub1Em"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) 104 %3 = fir.load %1#0 : !fir.ref<i32> 105 %4 = fir.load %2#0 : !fir.ref<i32> 106 %5 = arith.muli %3, %4 : i32 107 %6 = fir.convert %5 : (i32) -> i64 108 %7 = fir.convert %6 : (i64) -> index 109 %c0 = arith.constant 0 : index 110 %8 = arith.cmpi sgt, %7, %c0 : index 111 %9 = arith.select %8, %7, %c0 : index 112 %10 = fir.shape %9 : (index) -> !fir.shape<1> 113 %11:2 = hlfir.declare %arg0(%10) dummy_scope %0 {data_attr = #cuf.cuda<device>, uniq_name = "_QFsub1Eadev"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>) 114 %12 = fir.load %1#0 : !fir.ref<i32> 115 %13 = fir.load %2#0 : !fir.ref<i32> 116 %14 = arith.muli %12, %13 : i32 117 %15 = fir.convert %14 : (i32) -> i64 118 %16 = fir.convert %15 : (i64) -> index 119 %c0_0 = arith.constant 0 : index 120 %17 = arith.cmpi sgt, %16, %c0_0 : index 121 %18 = arith.select %17, %16, %c0_0 : index 122 %19 = fir.shape %18 : (index) -> !fir.shape<1> 123 %20:2 = hlfir.declare %arg1(%19) dummy_scope %0 {uniq_name = "_QFsub1Eahost"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>) 124 // expected-error@+1{{'cuf.data_transfer' op shape can only be specified on data transfer with references}} 125 cuf.data_transfer %20#0 to %11#0, %19 : !fir.shape<1> {transfer_kind = #cuf.cuda_transfer<host_device>} : !fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>> 126 return 127} 128 129// ----- 130 131module attributes {gpu.container_module} { 132 gpu.module @cuda_device_mod { 133 gpu.func @_QPsub_device1() { 134 gpu.return 135 } 136 } 137 llvm.func internal @__cudaFortranConstructor() { 138 %0 = cuf.register_module @cuda_device_mod -> !llvm.ptr 139 // expected-error@+1{{'cuf.register_kernel' op only kernel gpu.func can be registered}} 140 cuf.register_kernel @cuda_device_mod::@_QPsub_device1(%0 : !llvm.ptr) 141 llvm.return 142 } 143} 144 145// ----- 146 147module attributes {gpu.container_module} { 148 gpu.module @cuda_device_mod { 149 gpu.func @_QPsub_device1() { 150 gpu.return 151 } 152 } 153 llvm.func internal @__cudaFortranConstructor() { 154 %0 = cuf.register_module @cuda_device_mod -> !llvm.ptr 155 // expected-error@+1{{'cuf.register_kernel' op device function not found}} 156 cuf.register_kernel @cuda_device_mod::@_QPsub_device2(%0 : !llvm.ptr) 157 llvm.return 158 } 159} 160 161// ----- 162 163module attributes {gpu.container_module} { 164 llvm.func internal @__cudaFortranConstructor() { 165 %0 = cuf.register_module @cuda_device_mod -> !llvm.ptr 166 // expected-error@+1{{'cuf.register_kernel' op gpu module not found}} 167 cuf.register_kernel @cuda_device_mod::@_QPsub_device1(%0 : !llvm.ptr) 168 llvm.return 169 } 170} 171 172// ----- 173 174module attributes {gpu.container_module} { 175 llvm.func internal @__cudaFortranConstructor() { 176 %0 = cuf.register_module @cuda_device_mod -> !llvm.ptr 177 // expected-error@+1{{'cuf.register_kernel' op expect a module and a kernel name}} 178 cuf.register_kernel @_QPsub_device1(%0 : !llvm.ptr) 179 llvm.return 180 } 181} 182 183// ----- 184 185module attributes {gpu.container_module} { 186 gpu.module @cuda_device_mod { 187 llvm.func @_QPsub_device1() { 188 llvm.return 189 } 190 } 191 llvm.func internal @__cudaFortranConstructor() { 192 %0 = cuf.register_module @cuda_device_mod -> !llvm.ptr 193 // expected-error@+1{{'cuf.register_kernel' op only gpu.kernel llvm.func can be registered}} 194 cuf.register_kernel @cuda_device_mod::@_QPsub_device1(%0 : !llvm.ptr) 195 llvm.return 196 } 197} 198