|
1 |
| -// RUN: mlir-opt %s --transform-interpreter -canonicalize -cse -split-input-file | FileCheck %s |
| 1 | +// RUN: mlir-opt %s --transform-interpreter -canonicalize -cse -split-input-file -verify-diagnostics | FileCheck %s |
2 | 2 |
|
3 | 3 | // Offset per thread:
|
4 | 4 | // CHECK-DAG: affine_map<(d0)[s0] -> (d0 * (s0 ceildiv 10))>
|
@@ -451,3 +451,138 @@ module attributes {transform.with_named_sequence} {
|
451 | 451 | }
|
452 | 452 | }
|
453 | 453 |
|
| 454 | +// ----- |
| 455 | + |
| 456 | +// CHECK-DAG: #[[$map0:.+]] = affine_map<()[s0] -> (s0 ceildiv 10)> |
| 457 | +// CHECK-DAG: #[[$map1:.+]] = affine_map<()[s0] -> (s0 ceildiv 20)> |
| 458 | +// CHECK-DAG: #[[$map2:.+]] = affine_map<(d0)[s0] -> (d0 * -10 + s0, 10)> |
| 459 | +// CHECK-DAG: #[[$map3:.+]] = affine_map<(d0)[s0] -> (d0 * -20 + s0, 20)> |
| 460 | +// CHECK-DAG: #[[$map4:.+]] = affine_map<(d0) -> (d0 * 10)> |
| 461 | +// CHECK-DAG: #[[$map5:.+]] = affine_map<(d0) -> (d0 * 20)> |
| 462 | + |
| 463 | +// CHECK-LABEL: matmul_tile_size_dynamic( |
| 464 | +// CHECK-SAME: %[[A:[0-9a-z]+]]: tensor<?x?xf32> |
| 465 | +// CHECK-SAME: %[[B:[0-9a-z]+]]: tensor<?x?xf32> |
| 466 | +// CHECK-SAME: %[[C:[0-9a-z]+]]: tensor<?x?xf32> |
| 467 | +func.func @matmul_tile_size_dynamic(%A: tensor<?x?xf32>, %B: tensor<?x?xf32>, %C: tensor<?x?xf32>) -> tensor<?x?xf32> { |
| 468 | + // CHECK: %[[c1:.*]] = arith.constant 1 : index |
| 469 | + // CHECK: %[[c0:.*]] = arith.constant 0 : index |
| 470 | + // CHECK: %[[M:.+]] = tensor.dim %[[A]], %[[c0]] : |
| 471 | + // CHECK: %[[N:.+]] = tensor.dim %[[B]], %[[c1]] : |
| 472 | + // CHECK: %[[NT0:.+]] = affine.apply #map()[%[[M]]] |
| 473 | + // CHECK: %[[NT1:.+]] = affine.apply #map1()[%[[N]]] |
| 474 | + // CHECK: %[[K:.+]] = tensor.dim %[[A]], %[[c1]] : |
| 475 | + // CHECK: scf.forall (%[[IV0:.+]], %[[IV1:.+]]) in (%[[NT0]], %[[NT1]]) shared_outs(%[[C_BLK:.*]] = %[[C]]) |
| 476 | + // CHECK: %[[TS0:.+]] = affine.min #[[$map2]](%[[IV0]])[%[[M]]] |
| 477 | + // CHECK: %[[TS1:.+]] = affine.min #[[$map3]](%[[IV1]])[%[[N]]] |
| 478 | + // CHECK: %[[LB0:.+]] = affine.apply #[[$map4]](%[[IV0]]) |
| 479 | + // CHECK: %[[LB1:.+]] = affine.apply #[[$map5]](%[[IV1]]) |
| 480 | + // CHECK: tensor.extract_slice %[[A]][%[[LB0]], 0] [%[[TS0]], %[[K]]] [1, 1] : |
| 481 | + // CHECK: tensor.extract_slice %[[B]][0, %[[LB1]]] [%[[K]], %[[TS1]]] [1, 1] : |
| 482 | + // CHECK: tensor.extract_slice %[[C_BLK]][%[[LB0]], %[[LB1]]] [%[[TS0]], %[[TS1]]] [1, 1] : |
| 483 | + // CHECK: linalg.matmul |
| 484 | + // CHECK: scf.forall.in_parallel |
| 485 | + // CHECK-NEXT: tensor.parallel_insert_slice |
| 486 | + %0 = linalg.matmul ins(%A, %B : tensor<?x?xf32>, tensor<?x?xf32>) |
| 487 | + outs(%C : tensor<?x?xf32>) -> (tensor<?x?xf32>) |
| 488 | + return %0 : tensor<?x?xf32> |
| 489 | +} |
| 490 | + |
| 491 | +module attributes {transform.with_named_sequence} { |
| 492 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 493 | + %0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 494 | + %sz = transform.param.constant 10 : i64 -> !transform.param<i64> |
| 495 | + %1:2 = transform.structured.tile_using_forall %0 tile_sizes [%sz : !transform.param<i64>, 20] |
| 496 | + : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 497 | + transform.yield |
| 498 | + } |
| 499 | +} |
| 500 | + |
| 501 | +// ----- |
| 502 | + |
| 503 | +func.func @matmul_tile_size_dynamic(%A: tensor<?x?xf32>, %B: tensor<?x?xf32>, %C: tensor<?x?xf32>) -> tensor<?x?xf32> { |
| 504 | + %0 = linalg.matmul ins(%A, %B : tensor<?x?xf32>, tensor<?x?xf32>) |
| 505 | + outs(%C : tensor<?x?xf32>) -> (tensor<?x?xf32>) |
| 506 | + return %0 : tensor<?x?xf32> |
| 507 | +} |
| 508 | + |
| 509 | +module attributes {transform.with_named_sequence} { |
| 510 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 511 | + %0 = transform.structured.match ops{["linalg.matmul_transpose_b"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 512 | + %c10 = transform.param.constant 10 : i64 -> !transform.param<i64> |
| 513 | + %c20 = transform.param.constant 20 : i64 -> !transform.param<i64> |
| 514 | + %sz = transform.merge_handles %c10, %c20 : !transform.param<i64> |
| 515 | + // expected-error @below {{requires exactly one parameter associated}} |
| 516 | + %1:2 = transform.structured.tile_using_forall %0 tile_sizes [%sz : !transform.param<i64>, 20] |
| 517 | + : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 518 | + transform.yield |
| 519 | + } |
| 520 | +} |
| 521 | + |
| 522 | +// ----- |
| 523 | + |
| 524 | +// CHECK-DAG: #[[$map0:.+]] = affine_map<()[s0] -> (s0 ceildiv 10)> |
| 525 | +// CHECK-DAG: #[[$map1:.+]] = affine_map<()[s0] -> (s0 ceildiv 20)> |
| 526 | +// CHECK-DAG: #[[$map2:.+]] = affine_map<(d0)[s0] -> (d0 * -10 + s0, 10)> |
| 527 | +// CHECK-DAG: #[[$map3:.+]] = affine_map<(d0)[s0] -> (d0 * -20 + s0, 20)> |
| 528 | +// CHECK-DAG: #[[$map4:.+]] = affine_map<(d0) -> (d0 * 10)> |
| 529 | +// CHECK-DAG: #[[$map5:.+]] = affine_map<(d0) -> (d0 * 20)> |
| 530 | + |
| 531 | +// CHECK-LABEL: matmul_tile_size_dynamic( |
| 532 | +// CHECK-SAME: %[[A:[0-9a-z]+]]: tensor<?x?xf32> |
| 533 | +// CHECK-SAME: %[[B:[0-9a-z]+]]: tensor<?x?xf32> |
| 534 | +// CHECK-SAME: %[[C:[0-9a-z]+]]: tensor<?x?xf32> |
| 535 | +func.func @matmul_tile_size_dynamic(%A: tensor<?x?xf32>, %B: tensor<?x?xf32>, %C: tensor<?x?xf32>) -> tensor<?x?xf32> { |
| 536 | + // CHECK: %[[c1:.*]] = arith.constant 1 : index |
| 537 | + // CHECK: %[[c0:.*]] = arith.constant 0 : index |
| 538 | + // CHECK: %[[M:.+]] = tensor.dim %[[A]], %[[c0]] : |
| 539 | + // CHECK: %[[N:.+]] = tensor.dim %[[B]], %[[c1]] : |
| 540 | + // CHECK: %[[NT0:.+]] = affine.apply #map()[%[[M]]] |
| 541 | + // CHECK: %[[NT1:.+]] = affine.apply #map1()[%[[N]]] |
| 542 | + // CHECK: %[[K:.+]] = tensor.dim %[[A]], %[[c1]] : |
| 543 | + // CHECK: scf.forall (%[[IV0:.+]], %[[IV1:.+]]) in (%[[NT0]], %[[NT1]]) shared_outs(%[[C_BLK:.*]] = %[[C]]) |
| 544 | + // CHECK: %[[TS0:.+]] = affine.min #[[$map2]](%[[IV0]])[%[[M]]] |
| 545 | + // CHECK: %[[TS1:.+]] = affine.min #[[$map3]](%[[IV1]])[%[[N]]] |
| 546 | + // CHECK: %[[LB0:.+]] = affine.apply #[[$map4]](%[[IV0]]) |
| 547 | + // CHECK: %[[LB1:.+]] = affine.apply #[[$map5]](%[[IV1]]) |
| 548 | + // CHECK: tensor.extract_slice %[[A]][%[[LB0]], 0] [%[[TS0]], %[[K]]] [1, 1] : |
| 549 | + // CHECK: tensor.extract_slice %[[B]][0, %[[LB1]]] [%[[K]], %[[TS1]]] [1, 1] : |
| 550 | + // CHECK: tensor.extract_slice %[[C_BLK]][%[[LB0]], %[[LB1]]] [%[[TS0]], %[[TS1]]] [1, 1] : |
| 551 | + // CHECK: linalg.matmul |
| 552 | + // CHECK: scf.forall.in_parallel |
| 553 | + // CHECK-NEXT: tensor.parallel_insert_slice |
| 554 | + %0 = linalg.matmul ins(%A, %B : tensor<?x?xf32>, tensor<?x?xf32>) |
| 555 | + outs(%C : tensor<?x?xf32>) -> (tensor<?x?xf32>) |
| 556 | + return %0 : tensor<?x?xf32> |
| 557 | +} |
| 558 | + |
| 559 | +module attributes {transform.with_named_sequence} { |
| 560 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 561 | + %0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 562 | + %c10 = transform.param.constant 10 : i64 -> !transform.any_param |
| 563 | + %c20 = transform.param.constant 20 : i64 -> !transform.any_param |
| 564 | + %sz = transform.merge_handles %c10, %c20 : !transform.any_param |
| 565 | + %1:2 = transform.structured.tile_using_forall %0 tile_sizes *(%sz : !transform.any_param) |
| 566 | + : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 567 | + transform.yield |
| 568 | + } |
| 569 | +} |
| 570 | + |
| 571 | +// ----- |
| 572 | + |
| 573 | +func.func @matmul_tile_size_dynamic(%A: tensor<?x?xf32>, %B: tensor<?x?xf32>, %C: tensor<?x?xf32>) -> tensor<?x?xf32> { |
| 574 | + %0 = linalg.matmul ins(%A, %B : tensor<?x?xf32>, tensor<?x?xf32>) |
| 575 | + outs(%C : tensor<?x?xf32>) -> (tensor<?x?xf32>) |
| 576 | + return %0 : tensor<?x?xf32> |
| 577 | +} |
| 578 | + |
| 579 | +module attributes {transform.with_named_sequence} { |
| 580 | + transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { |
| 581 | + %0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 582 | + %sz = transform.param.constant "[10 : i64, 20 : i64]" -> !transform.any_param |
| 583 | + // expected-error @below {{expected the parameter to be associated with an integer attribute}} |
| 584 | + %1:2 = transform.structured.tile_using_forall %0 tile_sizes *(%sz : !transform.any_param) |
| 585 | + : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 586 | + transform.yield |
| 587 | + } |
| 588 | +} |
0 commit comments