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