1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
// RUN: mlir-opt -split-input-file -verify-diagnostics %s
func.func @not_enough_sizes(%sz : index) {
// expected-error@+1 {{expected 6 or more operands, but found 5}}
"gpu.launch"(%sz, %sz, %sz, %sz, %sz) ({
gpu.return
}) {operandSegmentSizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (index, index, index, index, index) -> ()
return
}
// -----
func.func @no_region_attrs(%sz : index) {
// expected-error@+1 {{unexpected number of region arguments}}
"gpu.launch"(%sz, %sz, %sz, %sz, %sz, %sz) ({
^bb1(%bx: index, %by: index, %bz: index,
%tx: index, %ty: index, %tz: index):
gpu.terminator
}) {operandSegmentSizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (index, index, index, index, index, index) -> ()
return
}
// -----
func.func @launch_requires_gpu_return(%sz : index) {
// @expected-note@+1 {{in 'gpu.launch' body region}}
gpu.launch blocks(%bx, %by, %bz) in (%sbx = %sz, %sby = %sz, %sbz = %sz)
threads(%tx, %ty, %tz) in (%stx = %sz, %sty = %sz, %stz = %sz) {
// @expected-error@+2 {{expected 'gpu.terminator' or a terminator with successors}}
%one = arith.constant 1 : i32
"gpu.yield"(%one) : (i32) -> ()
}
return
}
// -----
func.func @launch_func_too_few_operands(%sz : index) {
// expected-error@+1 {{expected 6 or more operands}}
"gpu.launch_func"(%sz, %sz, %sz, %sz, %sz)
{operandSegmentSizes = array<i32: 0, 1, 1, 1, 1, 1, 0, 0>}
: (index, index, index, index, index) -> ()
return
}
// -----
func.func @launch_func_missing_parent_module_attribute(%sz : index) {
// expected-error@+1 {{expected the closest surrounding module to have the 'gpu.container_module' attribute}}
gpu.launch_func @foo::@bar blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
return
}
// -----
module attributes {gpu.container_module} {
func.func @launch_func_missing_callee_attribute(%sz : index) {
// expected-error@+1 {{'gpu.launch_func' op requires attribute 'kernel'}}
"gpu.launch_func"(%sz, %sz, %sz, %sz, %sz, %sz)
{operandSegmentSizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0, 0>}
: (index, index, index, index, index, index) -> ()
return
}
}
// -----
module attributes {gpu.container_module} {
func.func @launch_func_no_function_attribute(%sz : index) {
// expected-error@+1 {{custom op 'gpu.launch_func' invalid kind of attribute specified}}
gpu.launch_func "foo" blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
return
}
}
// -----
module attributes {gpu.container_module} {
func.func @launch_func_undefined_module(%sz : index) {
// expected-error@+1 {{kernel module 'kernels' is undefined}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
return
}
}
// -----
module attributes {gpu.container_module} {
module @kernels {
// expected-error@+1 {{'gpu.func' op expects parent op 'gpu.module'}}
gpu.func @kernel_1(%arg1 : !llvm.ptr<f32>) {
gpu.return
}
}
}
// -----
module attributes {gpu.container_module} {
module @kernels {
}
func.func @launch_func_missing_module_attribute(%sz : index) {
// expected-error@+1 {{kernel module 'kernels' is undefined}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
return
}
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernels { }
func.func @launch_func_undefined_function(%sz : index) {
// expected-error@+1 {{kernel function '@kernels::@kernel_1' is undefined}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
return
}
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernels {
// expected-note@+1 {{see the kernel definition here}}
memref.global "private" @kernel_1 : memref<4xi32>
}
func.func @launch_func_undefined_function(%sz : index) {
// expected-error@+1 {{referenced kernel '@kernels::@kernel_1' is not a function}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz)
return
}
}
// -----
module attributes {gpu.container_module} {
module @kernels {
gpu.func @kernel_1(%arg1 : !llvm.ptr<f32>) kernel {
gpu.return
}
}
func.func @launch_func_missing_kernel_attr(%sz : index, %arg : !llvm.ptr<f32>) {
// expected-error@+1 {{kernel module 'kernels' is undefined}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz) args(%arg : !llvm.ptr<f32>)
return
}
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernels {
gpu.func @kernel_1(%arg1 : !llvm.ptr<f32>) {
gpu.return
}
}
func.func @launch_func_missing_kernel_attr(%sz : index, %arg : !llvm.ptr<f32>) {
// expected-error@+1 {{kernel function is missing the 'gpu.kernel' attribute}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz) args(%arg : !llvm.ptr<f32>)
return
}
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernels {
gpu.func @kernel_1(%arg1 : !llvm.ptr<f32>) kernel {
gpu.return
}
}
func.func @launch_func_kernel_operand_size(%sz : index, %arg : !llvm.ptr<f32>) {
// expected-error@+1 {{got 2 kernel operands but expected 1}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz) args(%arg : !llvm.ptr<f32>, %arg : !llvm.ptr<f32>)
return
}
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernels {
gpu.func @kernel_1(%arg1 : f32) kernel {
gpu.return
}
}
func.func @launch_func_kernel_operand_types(%sz : index, %arg : f32) {
// expected-err@+1 {{type of function argument 0 does not match}}
gpu.launch_func @kernels::@kernel_1 blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz) args(%arg : f32)
return
}
}
// -----
module attributes {gpu.container_module} {
func.func @launch_func_kernel_operand_attr(%sz : index) {
// expected-error@+1 {{expected ')' in argument list}}
gpu.launch_func @foo::@bar blocks in (%sz, %sz, %sz) threads in (%sz, %sz, %sz) args(%sz : index {foo})
return
}
}
// -----
func.func @reduce_no_op_no_body(%arg0 : f32) {
// expected-error@+1 {{expected either an op attribute or a non-empty body}}
%res = "gpu.all_reduce"(%arg0) ({}) : (f32) -> (f32)
return
}
// -----
func.func @reduce_op_and_body(%arg0 : f32) {
// expected-error@+1 {{expected either an op attribute or a non-empty body}}
%res = "gpu.all_reduce"(%arg0) ({
^bb(%lhs : f32, %rhs : f32):
"gpu.yield"(%lhs) : (f32) -> ()
}) {op = #gpu<all_reduce_op add>} : (f32) -> (f32)
return
}
// -----
func.func @reduce_invalid_op(%arg0 : f32) {
// expected-error@+1 {{invalid op kind}}
%res = gpu.all_reduce foo %arg0 {} : (f32) -> (f32)
return
}
// -----
func.func @reduce_invalid_op_type(%arg0 : f32) {
// expected-error@+1 {{`and` accumulator is only compatible with Integer type}}
%res = gpu.all_reduce and %arg0 {} : (f32) -> (f32)
return
}
// -----
func.func @subgroup_reduce_invalid_op_type(%arg0 : f32) {
// expected-error@+1 {{`and` accumulator is only compatible with Integer type}}
%res = gpu.subgroup_reduce and %arg0 : (f32) -> (f32)
return
}
// -----
func.func @reduce_incorrect_region_arguments(%arg0 : f32) {
// expected-error@+1 {{expected two region arguments}}
%res = gpu.all_reduce %arg0 {
^bb(%lhs : f32):
"gpu.yield"(%lhs) : (f32) -> ()
} : (f32) -> (f32)
return
}
// -----
func.func @reduce_incorrect_region_arguments(%arg0 : f32) {
// expected-error@+1 {{incorrect region argument type}}
%res = gpu.all_reduce %arg0 {
^bb(%lhs : f32, %rhs : i32):
"gpu.yield"(%lhs) : (f32) -> ()
} : (f32) -> (f32)
return
}
// -----
func.func @reduce_incorrect_yield(%arg0 : f32) {
// expected-error@+1 {{expected one gpu.yield operand}}
%res = gpu.all_reduce %arg0 {
^bb(%lhs : f32, %rhs : f32):
"gpu.yield"(%lhs, %rhs) : (f32, f32) -> ()
} : (f32) -> (f32)
return
}
// -----
func.func @reduce_incorrect_yield(%arg0 : f32) {
// expected-error@+1 {{incorrect gpu.yield type}}
%res = gpu.all_reduce %arg0 {
^bb(%lhs : f32, %rhs : f32):
%one = arith.constant 1 : i32
"gpu.yield"(%one) : (i32) -> ()
} : (f32) -> (f32)
return
}
// -----
func.func @reduce_incorrect_yield(%arg0 : f32) {
// expected-error@+1 {{expected gpu.yield op in region}}
%res = gpu.all_reduce %arg0 {
^bb(%lhs : f32, %rhs : f32):
"test.finish" () : () -> ()
} : (f32) -> (f32)
return
}
// -----
func.func @shuffle_mismatching_type(%arg0 : f32, %arg1 : i32, %arg2 : i32) {
// expected-error@+1 {{op failed to verify that all of {value, shuffleResult} have same type}}
%shfl, %pred = "gpu.shuffle"(%arg0, %arg1, %arg2) { mode = #gpu<shuffle_mode xor> } : (f32, i32, i32) -> (i32, i1)
return
}
// -----
func.func @shuffle_unsupported_type(%arg0 : index, %arg1 : i32, %arg2 : i32) {
// expected-error@+1 {{operand #0 must be i32, i64, f32 or f64}}
%shfl, %pred = gpu.shuffle xor %arg0, %arg1, %arg2 : index
return
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @+1 {{custom op 'gpu.func' gpu.func requires named arguments}}
gpu.func @kernel_1(f32, f32) {
^bb0(%arg0: f32):
gpu.return
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @+1 {{attribute 'function_type' failed to satisfy constraint: type attribute of function type}}
"gpu.func"() ({
gpu.return
}) {sym_name="kernel_1", function_type=f32} : () -> ()
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @below {{'gpu.func' op expected memref type in attribution}}
gpu.func @kernel() workgroup(%0: i32) {
gpu.return
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @below {{'gpu.func' op expected memory space workgroup in attribution}}
gpu.func @kernel() workgroup(%0: memref<4xf32, #gpu.address_space<private>>) {
gpu.return
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @below {{'gpu.func' op expected memory space private in attribution}}
gpu.func @kernel() private(%0: memref<4xf32, #gpu.address_space<workgroup>>) {
gpu.return
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-note @+1 {{return type declared here}}
gpu.func @kernel() {
%0 = arith.constant 0 : index
// expected-error @+1 {{'gpu.return' op expected 0 result operands}}
gpu.return %0 : index
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @+1 {{'gpu.func' op expected void return type for kernel function}}
gpu.func @kernel() -> index kernel {
%0 = arith.constant 0 : index
gpu.return
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @+1 {{'gpu.func' op expected at least 5 arguments to body region}}
"gpu.func"() ({
^bb0(%arg0: f32, %arg1: memref<?xf32>, %arg2: memref<5xf32, 3>, %arg3: memref<5xf32, 5>):
"gpu.return"() : () -> ()
} ) {function_type = (f32, memref<?xf32>) -> (), gpu.kernel, sym_name = "kernel_1", workgroup_attributions = 3: i64} : () -> ()
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @+1 {{expected body with at least one block}}
"gpu.func"() ({}) {function_type = () -> (), gpu.kernel, sym_name = "kernel"} : () -> ()
}
}
// -----
func.func @sync_wait_with_result() {
// expected-error @+1 {{cannot name an operation with no results}}
%t = gpu.wait
}
// -----
func.func @async_wait_without_result() {
// expected-error @+1 {{custom op 'gpu.wait' needs to be named when marked 'async'}}
gpu.wait async
}
// -----
func.func @memcpy_incompatible_type(%dst : memref<?xf32>, %src : memref<?xi32>) {
// expected-error @+1 {{'gpu.memcpy' op arguments have incompatible element type}}
gpu.memcpy %dst, %src : memref<?xf32>, memref<?xi32>
}
// -----
func.func @memcpy_incompatible_shape(%dst : memref<7xf32>, %src : memref<9xf32>) {
// expected-error @+1 {{'gpu.memcpy' op arguments have incompatible shape}}
gpu.memcpy %dst, %src : memref<7xf32>, memref<9xf32>
}
// -----
func.func @memset_incompatible_shape(%dst : memref<?xf32>, %value : i32) {
// expected-error @+1 {{'gpu.memset' op failed to verify that all of {dst, value} have same element type}}
gpu.memset %dst, %value : memref<?xf32>, i32
}
// -----
func.func @mmamatrix_invalid_shape(){
%wg = memref.alloca() {alignment = 32} : memref<32x32xf16, 3>
%i = arith.constant 16 : index
// expected-error @+1 {{MMAMatrixType must have exactly two dimensions}}
%0 = gpu.subgroup_mma_load_matrix %wg[%i, %i] {leadDimension = 32 : index} : memref<32x32xf16, 3> -> !gpu.mma_matrix<16x16x16xf16, "AOp">
return
}
// -----
func.func @mmamatrix_operand_type(){
%wg = memref.alloca() {alignment = 32} : memref<32x32xf16, 3>
%i = arith.constant 16 : index
// expected-error @+1 {{operand expected to be one of AOp, BOp or COp}}
%0 = gpu.subgroup_mma_load_matrix %wg[%i, %i] {leadDimension = 32 : index} : memref<32x32xf16, 3> -> !gpu.mma_matrix<16x16xf16, "EOp">
return
}
// -----
func.func @mmamatrix_invalid_element_type(){
%wg = memref.alloca() {alignment = 32} : memref<32x32xf16, 3>
%i = arith.constant 16 : index
// expected-error @+1 {{MMAMatrixType elements must be SI8, UI8, I32, F16, or F32}}
%0 = gpu.subgroup_mma_load_matrix %wg[%i, %i] {leadDimension = 32 : index} : memref<32x32xf16, 3> -> !gpu.mma_matrix<16x16xbf16, "AOp">
return
}
// -----
#layout_map_col_major = affine_map<(i, j) -> (j, i)>
func.func @mmaLoadOp_identity_layout(){
%wg = memref.alloca() {alignment = 32} : memref<32x32xf16, #layout_map_col_major, 3>
%i = arith.constant 16 : index
// expected-error @+1 {{expected source memref most minor dim must have unit stride}}
%0 = gpu.subgroup_mma_load_matrix %wg[%i, %i] {leadDimension = 32 : index} : memref<32x32xf16, #layout_map_col_major, 3> -> !gpu.mma_matrix<16x16xf16, "AOp">
return
}
// -----
func.func @mma_invalid_memref_type(%src: memref<32x4xvector<4x8xf32>>, %i: index) {
// expected-error @+1 {{operand #0 must be memref of 8-bit signless integer or 32-bit signless integer or 16-bit float or 32-bit float or vector of 8-bit signless integer or 32-bit signless integer or 16-bit float or 32-bit float values of ranks 1 values}}
%0 = gpu.subgroup_mma_load_matrix %src[%i, %i] {leadDimension = 4 : index} : memref<32x4xvector<4x8xf32>> -> !gpu.mma_matrix<16x16xf16, "AOp">
return
}
// -----
#layout_map_col_major = affine_map<(i, j) -> (j, i)>
func.func @wmmaStoreOp_invalid_map(%arg0 : !gpu.mma_matrix<16x16xf16, "COp">) -> () {
%sg = memref.alloca(){alignment = 32} : memref<32x32xf16, #layout_map_col_major, 3>
%i = arith.constant 16 : index
%j = arith.constant 16 : index
// expected-error @+1 {{expected destination memref most minor dim must have unit stride}}
gpu.subgroup_mma_store_matrix %arg0, %sg[%i,%j] {leadDimension= 32 : index} : !gpu.mma_matrix<16x16xf16, "COp">, memref<32x32xf16,#layout_map_col_major, 3>
return
}
// -----
func.func @wmmaStoreOp_invalid_store_operand(%arg0 : !gpu.mma_matrix<16x16xf16, "AOp">) -> () {
%sg = memref.alloca(){alignment = 32} : memref<32x32xf16, 3>
%i = arith.constant 16 : index
%j = arith.constant 16 : index
// expected-error @+1 {{expected the operand matrix being stored to have 'COp' operand type}}
gpu.subgroup_mma_store_matrix %arg0, %sg[%i,%j] {leadDimension= 32 : index} : !gpu.mma_matrix<16x16xf16, "AOp">, memref<32x32xf16, 3>
return
}
// -----
func.func @wmmaMmaOp_invalid_operand_order(%A : !gpu.mma_matrix<16x16xf16, "AOp">, %B : !gpu.mma_matrix<16x16xf16, "BOp">, %C : !gpu.mma_matrix<16x16xf16, "COp">) -> () {
// expected-error @+1 {{operands must be in the order AOp, BOp, COp}}
%D = gpu.subgroup_mma_compute %B, %A, %C : !gpu.mma_matrix<16x16xf16, "BOp">, !gpu.mma_matrix<16x16xf16, "AOp"> -> !gpu.mma_matrix<16x16xf16, "COp">
return
}
// -----
func.func @wmmaMmaOp_invalid_operand_shapes(%A : !gpu.mma_matrix<16x32xf16, "AOp">, %B : !gpu.mma_matrix<16x16xf16, "BOp">, %C : !gpu.mma_matrix<16x16xf16, "COp">) -> () {
// expected-error @+1 {{operand shapes do not satisfy matmul constraints}}
%D = gpu.subgroup_mma_compute %A, %B, %C : !gpu.mma_matrix<16x32xf16, "AOp">, !gpu.mma_matrix<16x16xf16, "BOp"> -> !gpu.mma_matrix<16x16xf16, "COp">
return
}
// -----
// Number of symbol operand count less than memref symbol count.
func.func @alloc() {
// expected-error@+1 {{symbol operand count does not equal memref symbol count}}
%1 = gpu.alloc() : memref<2x4xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1>
return
}
// -----
// Number of symbol operand count greater than memref symbol count.
func.func @alloc() {
%0 = arith.constant 7 : index
// expected-error@+1 {{symbol operand count does not equal memref symbol count}}
%1 = gpu.alloc()[%0] : memref<2x4xf32, 1>
return
}
// -----
// Number of dynamic dimension operand count greater than memref dynamic dimension count.
func.func @alloc() {
%0 = arith.constant 7 : index
// expected-error@+1 {{dimension operand count does not equal memref dynamic dimension count}}
%1 = gpu.alloc(%0, %0) : memref<2x?xf32, 1>
return
}
// -----
// Number of dynamic dimension operand count less than memref dynamic dimension count.
func.func @alloc() {
%0 = arith.constant 7 : index
// expected-error@+1 {{dimension operand count does not equal memref dynamic dimension count}}
%1 = gpu.alloc(%0) : memref<2x?x?xf32, 1>
return
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernel {
// expected-error@+1 {{'gpu.func' op gpu.known_block_size must be a dense i32 array}}
gpu.func @kernel() kernel attributes {gpu.known_block_size = 32 : i32} {
gpu.return
}
}
}
// -----
module attributes {gpu.container_module} {
gpu.module @kernel {
// expected-error@+1 {{'gpu.func' op gpu.known_block_size must contain exactly 3 elements}}
gpu.func @kernel() kernel attributes {gpu.known_block_size = array<i32: 2, 1>} {
gpu.return
}
}
}
|