1// RUN: mlir-opt %s -split-input-file -verify-diagnostics 2 3// ----- 4func.func @test_create_nd_tdesc_vc_1(%src: memref<24xf32>) { 5 // expected-error@+1 {{Expecting the TensorDesc rank is up to 2 and not greater than the ranks of shape, strides, offsets or the memref source}} 6 %1 = xegpu.create_nd_tdesc %src[0] : memref<24xf32> -> !xegpu.tensor_desc<8x16xf32> 7 return 8} 9 10// ----- 11 12func.func @test_create_nd_tdesc_vc_2(%src: memref<24x32xf32>) { 13 // expected-error@+1 {{TensorDesc should have the same element type with the source if it is a memref}} 14 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> !xegpu.tensor_desc<8x16xf16> 15 return 16} 17 18// ----- 19func.func @test_create_nd_tdesc_vc_3(%src: memref<2x24x32xf32, 3>) { 20 // expected-error@+1 {{SLM is not supported for 2D Block TensorDesc}} 21 %1 = xegpu.create_nd_tdesc %src[0, 0, 0] : memref<2x24x32xf32, 3> -> !xegpu.tensor_desc<8x16xf32, #xegpu.block_tdesc_attr<memory_space = slm>> 22 return 23} 24 25// ----- 26func.func @test_create_nd_tdesc_vc_4(%src: memref<2x24x32xf32, 3>) { 27 // expected-error@+1 {{Memory space mismatch}} 28 %1 = xegpu.create_nd_tdesc %src[0, 0, 0] : memref<2x24x32xf32, 3> -> !xegpu.tensor_desc<16xf32> 29 return 30} 31 32// ----- 33func.func @test_prefetch_nd_vc_1(%src: memref<24x32xf16>) { 34 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf16> -> !xegpu.tensor_desc<8x16xf16> 35 // expected-error@+1 {{invalid l1_hint: #xegpu.cache_hint<write_back>}} 36 xegpu.prefetch_nd %1 <{l1_hint = #xegpu.cache_hint<write_back>}>: !xegpu.tensor_desc<8x16xf16> 37 return 38} 39 40// ----- 41func.func @test_prefetch_nd_vc_2(%src: memref<24xf16>) { 42 %0 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7]> : vector<8xindex> 43 %1 = xegpu.create_tdesc %src, %0 : memref<24xf16>, vector<8xindex> 44 -> !xegpu.tensor_desc<8xf16, #xegpu.scatter_tdesc_attr<>> 45 // expected-error@+1 {{Expects a non-scattered TensorDesc}} 46 xegpu.prefetch_nd %1 <{l1_hint = #xegpu.cache_hint<cached>}> 47 : !xegpu.tensor_desc<8xf16, #xegpu.scatter_tdesc_attr<>> 48 return 49} 50 51// ----- 52func.func @test_load_nd_vc_1(%src: memref<8x16xf16>) { 53 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<8x16xf16> -> !xegpu.tensor_desc<8x16xf16> 54 // expected-error@+1 {{invalid l1_hint: #xegpu.cache_hint<write_back>}} 55 %2 = xegpu.load_nd %1 <{l1_hint = #xegpu.cache_hint<write_back>}> 56 : !xegpu.tensor_desc<8x16xf16> -> vector<4x16x2xf16> 57 return 58} 59 60// ----- 61func.func @test_load_nd_vc_2(%src: memref<16xf16>) { 62 %0 = arith.constant dense<[0, 2, 4, 6, 8, 10, 12, 14]> : vector<8xindex> 63 %1 = xegpu.create_tdesc %src, %0 : memref<16xf16>, vector<8xindex> 64 -> !xegpu.tensor_desc<8x2xf16, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 65 // expected-error@+1 {{Expects a non-scattered TensorDesc.}} 66 %2 = xegpu.load_nd %1 <{l1_hint = #xegpu.cache_hint<cached>}> 67 : !xegpu.tensor_desc<8x2xf16, #xegpu.scatter_tdesc_attr<chunk_size = 2>> -> vector<8x2xf16> 68 return 69} 70 71// ----- 72func.func @test_load_nd_vc_3(%src: memref<8x16xf16>) { 73 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<8x16xf16> -> !xegpu.tensor_desc<16xf16> 74 // expected-warning@+1 {{Invalid Packed Attr.}} 75 %2 = xegpu.load_nd %1 <{packed, l1_hint = #xegpu.cache_hint<cached>, l2_hint = #xegpu.cache_hint<uncached>}> 76 : !xegpu.tensor_desc<16xf16> -> vector<16xf16> 77 return 78} 79 80// ----- 81func.func @test_load_nd_vc_4(%src: memref<24x32xf32>) { 82 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> 83 !xegpu.tensor_desc<8x16xf32, #xegpu.sg_map<wi_layout = [1, 16], wi_data = [1, 1]>> 84 // expected-error@+1 {{Result shape doesn't match TensorDesc shape.}} 85 %2 = xegpu.load_nd %1 <{l1_hint = #xegpu.cache_hint<cached>, l2_hint = #xegpu.cache_hint<uncached>}> : !xegpu.tensor_desc<8x16xf32, #xegpu.sg_map<wi_layout = [1, 16], wi_data = [1, 1]>> -> vector<8x2xf32> 86 return 87} 88 89// ----- 90func.func @test_load_nd_vc_5(%src: memref<24x32xf32>) { 91 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> 92 !xegpu.tensor_desc<16xf32, #xegpu.sg_map<wi_layout = [1, 16], wi_data = [1, 1]>> 93 // expected-error@+1 {{Result shape doesn't match TensorDesc shape.}} 94 %2 = xegpu.load_nd %1: !xegpu.tensor_desc<16xf32, #xegpu.sg_map<wi_layout = [1, 16], wi_data = [1, 1]>> -> vector<16xf32> 95 return 96} 97 98// ----- 99func.func @test_store_nd_vc_1(%dst: memref<24x32xf16>) { 100 %1 = arith.constant dense<1.0>: vector<24x32xf16> 101 %2 = xegpu.create_nd_tdesc %dst[0, 0] : memref<24x32xf16> -> !xegpu.tensor_desc<24x32xf16> 102 // expected-error@+1 {{invalid l1_hint: #xegpu.cache_hint<streaming>}} 103 xegpu.store_nd %1, %2 <{l1_hint = #xegpu.cache_hint<streaming>}>: vector<24x32xf16>, !xegpu.tensor_desc<24x32xf16> 104 return 105} 106 107// ----- 108func.func @test_store_nd_vc_2(%dst: memref<16xf16>) { 109 %0 = arith.constant dense<[0, 2, 4, 6, 8, 10, 12, 14]> : vector<8xindex> 110 %1 = arith.constant dense<1.0>: vector<8x2xf16> 111 %2 = xegpu.create_tdesc %dst, %0 : memref<16xf16>, vector<8xindex> 112 -> !xegpu.tensor_desc<8x2xf16, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 113 // expected-error@+1 {{Expects a non-scattered TensorDesc}} 114 xegpu.store_nd %1, %2 <{l1_hint = #xegpu.cache_hint<streaming>}> 115 : vector<8x2xf16>, !xegpu.tensor_desc<8x2xf16, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 116 return 117} 118 119// ----- 120func.func @test_update_nd_offset_1(%dst: memref<16xf16>) { 121 %0 = arith.constant dense<[0, 2, 4, 6, 8, 10, 12, 14]> : vector<8xindex> 122 %1 = xegpu.create_tdesc %dst, %0 : memref<16xf16>, vector<8xindex> 123 -> !xegpu.tensor_desc<8x2xf16, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 124 // expected-error@+1 {{Expects a non-scattered TensorDesc}} 125 xegpu.update_nd_offset %1, [0, 2] : !xegpu.tensor_desc<8x2xf16, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 126 return 127} 128 129// ----- 130func.func @test_create_tdesc_vc_1(%src: ui64) { 131 %0 = arith.constant dense<[0, 2, 4, 6, 8, 10, 12, 14]> : vector<8xindex> 132 // expected-error@+1 {{Expects a scattered TensorDesc}} 133 %1 = xegpu.create_tdesc %src, %0 : ui64, vector<8xindex> -> !xegpu.tensor_desc<8xf16> 134 return 135} 136 137// ----- 138func.func @test_create_tdesc_vc_2(%src: ui64) { 139 %0 = arith.constant dense<[0, 2, 4, 6, 8, 10, 12, 14]> : vector<8xindex> 140 // expected-error@+1 {{Incorrect TensorDesc shape}} 141 %1 = xegpu.create_tdesc %src, %0 : ui64, vector<8xindex> 142 -> !xegpu.tensor_desc<8x4xf16, #xegpu.scatter_tdesc_attr<>> 143 return 144} 145 146// ----- 147func.func @test_create_tdesc_vc_1(%src: memref<?xf32>) { 148 %0 = arith.constant dense<[0, 8, 16, 24]> : vector<4xindex> 149 // expected-error@+1 {{Memory space mismatch}} 150 %1 = xegpu.create_tdesc %src, %0 : memref<?xf32>, vector<4xindex> 151 -> !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<memory_space = slm, chunk_size = 2>> 152 return 153} 154 155// ----- 156func.func @test_prefetch_vc_1(%src: memref<24x32xf16>) { 157 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf16> -> !xegpu.tensor_desc<24x32xf16> 158 // expected-error@+1 {{Expects a scattered TensorDesc}} 159 xegpu.prefetch %1 <{l1_hint = #xegpu.cache_hint<write_back>}>: !xegpu.tensor_desc<24x32xf16> 160 return 161} 162 163// ----- 164func.func @test_prefetch_vc_2(%src: ui64) { 165 %0 = arith.constant dense<[0, 8, 16, 24]> : vector<4xindex> 166 %1 = xegpu.create_tdesc %src, %0 : ui64, vector<4xindex> 167 -> !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 168 // expected-error@+1 {{invalid l1_hint: #xegpu.cache_hint<write_back>}} 169 xegpu.prefetch %1 <{l1_hint = #xegpu.cache_hint<write_back>}>: !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 170 return 171} 172 173// ----- 174func.func @test_load_gather_vc_1(%src: memref<24x32xf16>) { 175 %0 = arith.constant dense<1>: vector<4xi1> 176 %1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf16> -> !xegpu.tensor_desc<4x2xf16> 177 // expected-error@+1 {{Expects a scattered TensorDesc}} 178 %2 = xegpu.load %1, %0 <{l1_hint = #xegpu.cache_hint<cached>}> 179 : !xegpu.tensor_desc<4x2xf16>, vector<4xi1> -> vector<4x2xf16> 180 return 181} 182 183// ----- 184func.func @test_load_gather_vc_2(%src: ui64) { 185 %cst = arith.constant dense<[0, 8, 16, 24]> : vector<4xindex> 186 %0 = arith.constant dense<1>: vector<4xi1> 187 %1 = xegpu.create_tdesc %src, %cst : ui64, vector<4xindex> 188 -> !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 189 // expected-error@+1 {{invalid l1_hint: #xegpu.cache_hint<write_back>}} 190 %2 = xegpu.load %1, %0 <{l1_hint = #xegpu.cache_hint<write_back>}> 191 : !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<chunk_size = 2>>, vector<4xi1> 192 -> vector<4x2xf32> 193 return 194} 195 196// ----- 197func.func @test_store_scatter_vc_1(%src: memref<24x32xf32>) { 198 %0 = arith.constant dense<1>: vector<4xi1> 199 %1 = arith.constant dense<2.9>: vector<4x2xf32> 200 %2 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> -> !xegpu.tensor_desc<4x2xf32> 201 // expected-error@+1 {{Expects a scattered TensorDesc}} 202 xegpu.store %1, %2, %0 <{l1_hint = #xegpu.cache_hint<cached>}> 203 : vector<4x2xf32>, !xegpu.tensor_desc<4x2xf32>, vector<4xi1> 204 return 205} 206 207// ----- 208func.func @test_store_scatter_vc_2(%src: ui64) { 209 %cst = arith.constant dense<[0, 8, 16, 24]>: vector<4xindex> 210 %0 = arith.constant dense<1>: vector<4xi1> 211 %1 = arith.constant dense<2.9>: vector<4x2xf32> 212 %2 = xegpu.create_tdesc %src, %cst : ui64, vector<4xindex> 213 -> !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<chunk_size = 2>> 214 // expected-error@+1 {{invalid l1_hint: #xegpu.cache_hint<streaming>}} 215 xegpu.store %1, %2, %0 <{l1_hint = #xegpu.cache_hint<streaming>}> : vector<4x2xf32>, 216 !xegpu.tensor_desc<4x2xf32, #xegpu.scatter_tdesc_attr<chunk_size = 2>>, vector<4xi1> 217 return 218} 219 220// ----- 221func.func @test_dpas_vc_1(%a : vector<8x8xf16>, %b: vector<8x16x2xf16>) { 222 // expected-error@+1 {{K-dimension mismatch}} 223 %1 = xegpu.dpas %a, %b : vector<8x8xf16>, vector<8x16x2xf16> -> vector<8x16xf32> 224 return 225} 226 227// ----- 228func.func @test_dpas_vc_2(%a : vector<8x8x2xf16>, %b: vector<8x16x2xf16>) { 229 // expected-error@+1 {{expecting lhs to be a 2D vector, and rhs to be either 2D or 3D (packed) vector}} 230 %1 = xegpu.dpas %a, %b : vector<8x8x2xf16>, vector<8x16x2xf16> -> vector<8x16xf32> 231 return 232} 233 234// ----- 235func.func @test_atomic_rmw(%src: ui64, %value : vector<16x4xf32>, %mask : vector<16xi1>) { 236 %0 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]> : vector<16xindex> 237 %1 = xegpu.create_tdesc %src, %0 : ui64, vector<16xindex> -> !xegpu.tensor_desc<16x8xf32, #xegpu.scatter_tdesc_attr<chunk_size = 8>> 238 // expected-error@+1 {{failed to verify that all of {tensorDesc, value, result} have same shape}} 239 xegpu.atomic_rmw addf %1, %mask, %value: !xegpu.tensor_desc<16x8xf32, #xegpu.scatter_tdesc_attr<chunk_size = 8>>, vector<16xi1>, vector<16x4xf32> -> vector<16x8xf32> 240 return 241}