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 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
|
// RUN: mlir-opt %s --pass-pipeline="builtin.module(test-transform-dialect-interpreter{debug-payload-root-tag=start_here})" --split-input-file --verify-diagnostics
module attributes { transform.with_named_sequence } {
transform.named_sequence @print_structured(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "structured" : !transform.any_op
transform.yield
}
transform.named_sequence @match_structured_empty(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
%0 = transform.match.structured %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
// Entry point. Match any structured operation and emit at remark.
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0
@match_structured_empty -> @print_structured
: (!transform.any_op) -> !transform.any_op
}
func.func @payload() attributes { transform.target_tag = "start_here" } {
%preA = tensor.empty() : tensor<2x3xf32>
%cA = arith.constant 1.0 : f32
// expected-remark @below {{structured}}
%A = linalg.fill ins(%cA : f32) outs(%preA : tensor<2x3xf32>) -> tensor<2x3xf32>
%B = arith.constant dense<1.0> : tensor<3x4xf32>
%C = arith.constant dense<1000.0> : tensor<2x4xf32>
// expected-remark @below {{structured}}
%D = linalg.matmul ins(%A, %B: tensor<2x3xf32>, tensor<3x4xf32>)
outs(%C: tensor<2x4xf32>) -> tensor<2x4xf32>
%E = arith.constant dense<2.0> : tensor<2x4xf32>
// expected-remark @below {{structured}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%D : tensor<2x4xf32>) outs(%E : tensor<2x4xf32>) {
^bb0(%arg0: f32, %arg1: f32):
linalg.yield %arg0 : f32
} -> tensor<2x4xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @do_nothing(%arg0: !transform.any_op {transform.readonly}) {
transform.yield
}
transform.named_sequence @print_in_matcher(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
transform.print %arg0 : !transform.any_op
transform.yield %arg0 : !transform.any_op
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0
@print_in_matcher -> @do_nothing
: (!transform.any_op) -> !transform.any_op
}
func.func @payload() attributes { transform.target_tag = "start_here" } {
// CHECK: [[ IR Printer ]]
// CHECK: test.print_me
%0 = "test.print_me"() : () -> (i1)
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @do_nothing(%arg0: !transform.any_op {transform.readonly}) {
transform.yield
}
// Entry point. Match any structured operation and emit a remark. Also emit
// a different remark at all considered operations. When it fails, the
// failure is suppressed and the resulting handle is assocaited with an empty
// list, hence nothing is printed. Both remark printing operations happen
// after the check in the sequence, so they only apply if the check operation
// produced success (due to failure suppression or not).
transform.named_sequence @match_structured_suppress(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
%0 = transform.match.structured failures(suppress) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.test_print_remark_at_operand %0, "structured" : !transform.any_op
transform.test_print_remark_at_operand %arg0, "other" : !transform.any_op
transform.yield %0 : !transform.any_op
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0
@match_structured_suppress -> @do_nothing
: (!transform.any_op) -> !transform.any_op
}
func.func @payload() attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{other}}
%D = arith.constant dense<1.0> : tensor<2x4xf32>
// expected-remark @below {{other}}
%E = arith.constant dense<2.0> : tensor<2x4xf32>
// expected-remark @below {{structured}}
// expected-remark @below {{other}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%D : tensor<2x4xf32>) outs(%E : tensor<2x4xf32>) {
^bb0(%arg0: f32, %arg1: f32):
// expected-remark @below {{other}}
linalg.yield %arg0 : f32
} -> tensor<2x4xf32>
// expected-remark @below {{other}}
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @print_passthrough(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "passthrough" : !transform.any_op
transform.yield
}
transform.named_sequence @match_structured_body_passthrough(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
%0 = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.body %arg1 { passthrough } : !transform.any_op
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0
@match_structured_body_passthrough -> @print_passthrough
: (!transform.any_op) -> !transform.any_op
}
func.func @payload(%in: tensor<2xf32>, %out: tensor<2xf32>) attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{passthrough}}
linalg.generic {
indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>],
iterator_types = ["parallel"]
} ins(%in : tensor<2xf32>) outs(%out : tensor<2xf32>) {
^bb0(%arg0: f32, %arg1: f32):
linalg.yield %arg0 : f32
} -> tensor<2xf32>
linalg.generic {
indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>],
iterator_types = ["parallel"]
} ins(%in : tensor<2xf32>) outs(%out : tensor<2xf32>) {
^bb0(%arg0: f32, %arg1: f32):
%0 = arith.mulf %arg0, %arg1 : f32
linalg.yield %0 : f32
} -> tensor<2xf32>
// expected-remark @below {{passthrough}}
linalg.copy ins(%in : tensor<2xf32>) outs(%out : tensor<2xf32>) -> tensor<2xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @print_reduction(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "reduction" : !transform.any_op
transform.yield
}
transform.named_sequence @match_structured_body_reduction(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
%0 = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.body %arg1 { reduction_position = 0 } : !transform.any_op
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0
@match_structured_body_reduction -> @print_reduction
: (!transform.any_op) -> !transform.any_op
}
func.func @payload(%lhs: tensor<2x4xf32>, %rhs: tensor<4x3xf32>, %out: tensor<2x3xf32>) attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{reduction}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%lhs, %rhs: tensor<2x4xf32>, tensor<4x3xf32>) outs(%out: tensor<2x3xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32):
%0 = arith.mulf %arg0, %arg1 : f32
%1 = arith.addf %0, %arg2 : f32
linalg.yield %1 : f32
} -> tensor<2x3xf32>
%r = tensor.empty() : tensor<2x3xf32>
linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>,
affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%lhs, %rhs: tensor<2x4xf32>, tensor<4x3xf32>) outs(%out, %r: tensor<2x3xf32>, tensor<2x3xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
%0 = arith.mulf %arg0, %arg1 : f32
%1 = arith.cmpf olt, %0, %arg2 : f32
%2 = arith.select %1, %0, %arg2 : f32
%3 = arith.select %1, %arg3, %0 : f32
linalg.yield %2, %3 : f32, f32
} -> (tensor<2x3xf32>, tensor<2x3xf32>)
// expected-remark @below {{reduction}}
linalg.matmul ins(%lhs, %rhs: tensor<2x4xf32>, tensor<4x3xf32>) outs(%out: tensor<2x3xf32>) -> tensor<2x3xf32>
%e = tensor.empty() : tensor<2x4xf32>
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%lhs: tensor<2x4xf32>) outs(%e: tensor<2x4xf32>) {
^bb0(%arg0: f32, %arg1: f32):
linalg.yield %arg0 : f32
} -> tensor<2x4xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @do_nothing(%arg0: !transform.any_op {transform.readonly}) {
transform.yield
}
transform.named_sequence @print_dimension_size_match(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "matched sizes" : !transform.any_op
transform.yield
}
transform.named_sequence @match_dimension_capture(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
// Capture multiple dimension values. Suppress failures so we can print them anyway after the capture.
%0:9 = transform.match.structured failures(suppress) %arg0
: (!transform.any_op) -> (!transform.any_op, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>,
!transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>) {
^bb0(%arg1: !transform.any_op):
// This also tests the positional specification used by other ops, which may not test it again.
%1 = transform.match.structured.dim %arg1[all] : (!transform.any_op) -> !transform.param<i64>
%2 = transform.match.structured.dim %arg1[0] : (!transform.any_op) -> !transform.param<i64>
%3 = transform.match.structured.dim %arg1[-1] : (!transform.any_op) -> !transform.param<i64>
%4 = transform.match.structured.dim %arg1[0, 2] : (!transform.any_op) -> !transform.param<i64>
%5 = transform.match.structured.dim %arg1[0, -1] : (!transform.any_op) -> !transform.param<i64>
%6 = transform.match.structured.dim %arg1[except(-1)] : (!transform.any_op) -> !transform.param<i64>
%7 = transform.match.structured.dim %arg1[except(0, -2)] : (!transform.any_op) -> !transform.param<i64>
%8 = transform.match.structured.dim %arg1[0, -3] : (!transform.any_op) -> !transform.param<i64>
transform.match.structured.yield %arg1, %1, %2, %3, %4, %5, %6, %7, %8
: !transform.any_op, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>,
!transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>
}
transform.test_print_param %0#1, "dimensions all:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#2, "dimension 0:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#3, "dimension -1:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#4, "dimensions 0, 2:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#5, "dimensions 0, -1:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#6, "dimensions except -1:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#7, "dimensions except 0, -2:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.test_print_param %0#8, "dimensions 0, -3:" at %0#0 : !transform.param<i64>, !transform.any_op
transform.yield %0#0 : !transform.any_op
}
transform.named_sequence @match_dimension_sizes(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op) {
%0 = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.dim %arg1[all] : (!transform.any_op) -> !transform.param<i64>
%c2 = transform.param.constant 2 : i64 -> !transform.param<i64>
%c3 = transform.param.constant 3 : i64 -> !transform.param<i64>
%c4 = transform.param.constant 4 : i64 -> !transform.param<i64>
%2 = transform.merge_handles %c2, %c3, %c4 : !transform.param<i64>
transform.match.param.cmpi eq %1, %2 : !transform.param<i64>
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%0 = transform.foreach_match in %arg0 @match_dimension_capture -> @do_nothing : (!transform.any_op) -> !transform.any_op
%1 = transform.foreach_match in %0 @match_dimension_sizes -> @print_dimension_size_match : (!transform.any_op) -> !transform.any_op
}
func.func @payload(%lhs: tensor<2x4xf32>, %rhs: tensor<4x3xf32>, %out: tensor<2x3xf32>) attributes { transform.target_tag = "start_here" } {
// The last does not emit anything because it fails to match
// due to 0 and -3 being the same dimension in the 3D case.
// expected-remark @below {{dimensions all: 2 : i64, 3 : i64, 4 : i64}}
// expected-remark @below {{dimension 0: 2 : i64}}
// expected-remark @below {{dimension -1: 4 : i64}}
// expected-remark @below {{dimensions 0, 2: 2 : i64, 4 : i64}}
// expected-remark @below {{dimensions 0, -1: 2 : i64, 4 : i64}}
// expected-remark @below {{dimensions except -1: 2 : i64, 3 : i64}}
// expected-remark @below {{dimensions except 0, -2: 4 : i64}}
// expected-remark @below {{dimensions 0, -3:}}
// expected-remark @below {{matched sizes}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%lhs, %rhs: tensor<2x4xf32>, tensor<4x3xf32>) outs(%out: tensor<2x3xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32):
%0 = arith.mulf %arg0, %arg1 : f32
%1 = arith.addf %0, %arg2 : f32
linalg.yield %1 : f32
} -> tensor<2x3xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @print_all_reduction(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "all reduction" : !transform.any_op
transform.yield
}
transform.named_sequence @print_all_parallel(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "all parallel" : !transform.any_op
transform.yield
}
transform.named_sequence @print_last_reduction(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "last reduction" : !transform.any_op
transform.yield
}
transform.named_sequence @print_parallel_except_last(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "parallel except last" : !transform.any_op
transform.yield
}
transform.named_sequence @match_all_reduction(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
transform.match.structured failures(propagate) %arg0 : !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.dim %arg1[all] { reduction } : !transform.any_op
transform.match.structured.yield
}
transform.yield %arg0 : !transform.any_op
}
transform.named_sequence @match_all_parallel(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
transform.match.structured failures(propagate) %arg0 : !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.dim %arg1[all] { parallel } : !transform.any_op
transform.match.structured.yield
}
transform.yield %arg0 : !transform.any_op
}
transform.named_sequence @match_last_reduction(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
transform.match.structured failures(propagate) %arg0 : !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.dim %arg1[-1] { reduction } : !transform.any_op
transform.match.structured.yield
}
transform.yield %arg0 : !transform.any_op
}
transform.named_sequence @match_parallel_except_last(%arg0: !transform.any_op {transform.readonly}) -> !transform.any_op {
transform.match.structured failures(propagate) %arg0 : !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.dim %arg1[except(-1)] { parallel } : !transform.any_op
transform.match.structured.yield
}
transform.yield %arg0 : !transform.any_op
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%0 = transform.foreach_match in %arg0 @match_all_reduction -> @print_all_reduction : (!transform.any_op) -> !transform.any_op
%1 = transform.foreach_match in %0 @match_all_parallel -> @print_all_parallel : (!transform.any_op) -> !transform.any_op
%2 = transform.foreach_match in %1 @match_last_reduction -> @print_last_reduction : (!transform.any_op) -> !transform.any_op
%3 = transform.foreach_match in %2 @match_parallel_except_last -> @print_parallel_except_last : (!transform.any_op) -> !transform.any_op
}
func.func @payload(%lhs: tensor<2x4xf32>, %rhs: tensor<4x3xf32>, %out: tensor<2x3xf32>) attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{last reduction}}
// expected-remark @below {{parallel except last}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%lhs, %rhs: tensor<2x4xf32>, tensor<4x3xf32>) outs(%out: tensor<2x3xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32):
%0 = arith.mulf %arg0, %arg1 : f32
%1 = arith.addf %0, %arg2 : f32
linalg.yield %1 : f32
} -> tensor<2x3xf32>
// expected-remark @below {{last reduction}}
// expected-remark @below {{parallel except last}}
linalg.matmul ins(%lhs, %rhs : tensor<2x4xf32>, tensor<4x3xf32>) outs(%out : tensor<2x3xf32>) -> tensor<2x3xf32>
%cst = arith.constant 1.0 : f32
// expected-remark @below {{all parallel}}
// expected-remark @below {{parallel except last}}
linalg.fill ins(%cst : f32) outs(%out: tensor<2x3xf32>) -> tensor<2x3xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_bitwidth(%arg0: !transform.any_op {transform.readonly}) -> (!transform.any_op, !transform.param<i64>) {
%bw = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.param<i64> {
^bb0(%arg1: !transform.any_op):
%0 = transform.match.structured.init %arg1 [0] : (!transform.any_op) -> !transform.any_value
%1 = transform.match.structured.elemental_bitwidth %0 : (!transform.any_value) -> !transform.param<i64>
transform.match.structured.yield %1 : !transform.param<i64>
}
transform.yield %arg0, %bw : !transform.any_op, !transform.param<i64>
}
transform.named_sequence @print_bitwidth(%arg0: !transform.any_op {transform.readonly}, %arg1: !transform.param<i64> {transform.readonly}) {
transform.test_print_param %arg1, "bitwidth:" at %arg0 : !transform.param<i64>, !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0 @match_bitwidth -> @print_bitwidth : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%f32: f32, %tf32: tensor<?xf32>,
%index: index, %tindex: tensor<?xindex>)
attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{bitwidth: 32}}
linalg.fill ins(%f32: f32) outs(%tf32: tensor<?xf32>) -> tensor<?xf32>
linalg.fill ins(%index: index) outs(%tindex: tensor<?xindex>) -> tensor<?xindex>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_init(%arg0: !transform.any_op {transform.readonly})
-> (!transform.any_op, !transform.any_value, !transform.any_value, !transform.any_op) {
%outs:3 = transform.match.structured failures(suppress) %arg0
: (!transform.any_op) -> (!transform.any_value, !transform.any_value, !transform.any_op) {
^bb0(%arg1: !transform.any_op):
%0 = transform.match.structured.init %arg1 [0] : (!transform.any_op) -> !transform.any_value
%1 = transform.match.structured.init %arg1 [all] : (!transform.any_op) -> !transform.any_value
%2 = transform.match.structured.init %arg1 [0] : (!transform.any_op) -> !transform.any_op
transform.match.structured.yield %0, %1, %2 : !transform.any_value, !transform.any_value, !transform.any_op
}
transform.yield %arg0, %outs#0, %outs#1, %outs#2 : !transform.any_op, !transform.any_value, !transform.any_value, !transform.any_op
}
transform.named_sequence @print_init(%arg0: !transform.any_op {transform.readonly},
%arg1: !transform.any_value {transform.readonly},
%arg2: !transform.any_value {transform.readonly},
%arg3: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand_value %arg1, "output 0" : !transform.any_value
transform.test_print_remark_at_operand %arg3, "output producer" : !transform.any_op
transform.test_print_remark_at_operand_value %arg2, "all output" : !transform.any_value
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
transform.foreach_match in %arg0 @match_init -> @print_init : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%f32: f32,
// expected-remark @below {{output 0}}
// expected-remark @below {{all output}}
// expected-note @below {{value handle points to a block argument #1 in block #0 in region #0}}
%tf32: tensor<?xf32>,
// expected-remark @below {{all output}}
// expected-note @below {{value handle points to a block argument #2 in block #0 in region #0}}
%tf32_2: tensor<?xf32>)
attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{output 0}}
// expected-remark @below {{output producer}}
// expected-remark @below {{all output}}
// expected-note @below {{value handle points to an op result #0}}
%0 = linalg.fill ins(%f32: f32) outs(%tf32: tensor<?xf32>) -> tensor<?xf32>
linalg.generic {
indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>],
iterator_types = ["parallel"]
} ins(%tf32: tensor<?xf32>) outs(%0, %tf32_2: tensor<?xf32>, tensor<?xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32):
linalg.yield %arg0, %arg0 : f32, f32
} -> (tensor<?xf32>, tensor<?xf32>)
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_init_0_permutation(%arg0: !transform.any_op {transform.readonly})
-> !transform.any_op {
%0 = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.init %arg1[0] { permutation }: !transform.any_op
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.named_sequence @match_init_1_permutation(%arg0: !transform.any_op {transform.readonly})
-> !transform.any_op {
%0 = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.init %arg1[1] { permutation }: !transform.any_op
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.named_sequence @match_init_2_projected_permutation(%arg0: !transform.any_op {transform.readonly})
-> !transform.any_op {
%0 = transform.match.structured failures(propagate) %arg0 : (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
transform.match.structured.init %arg1[2] { projected_permutation }: !transform.any_op
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.named_sequence @print_init_0_permutation(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "matched output 0 permutation" : !transform.any_op
transform.yield
}
transform.named_sequence @print_init_1_permutation(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "matched output 1 permutation" : !transform.any_op
transform.yield
}
transform.named_sequence @print_init_2_projected_permutation(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "matched output 2 projected permutation" : !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%0 = transform.foreach_match in %arg0 @match_init_0_permutation -> @print_init_0_permutation : (!transform.any_op) -> !transform.any_op
%1 = transform.foreach_match in %0 @match_init_1_permutation -> @print_init_1_permutation : (!transform.any_op) -> !transform.any_op
%2 = transform.foreach_match in %1 @match_init_2_projected_permutation -> @print_init_2_projected_permutation : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%f32: f32,
%oned: tensor<?xf32>,
%oned2: tensor<?xf32>,
%twod: tensor<?x?xf32>)
attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{matched output 2 projected permutation}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0)>,
affine_map<(d0, d1) -> (d0 + d1)>,
affine_map<(d0, d1) -> (d1)>,
affine_map<(d0, d1) -> (d1, d0)>],
iterator_types = ["parallel", "parallel"]
} ins(%oned: tensor<?xf32>) outs(%oned, %oned2, %twod: tensor<?xf32>, tensor<?xf32>, tensor<?x?xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
linalg.yield %arg0, %arg0, %arg0 : f32, f32, f32
} -> (tensor<?xf32>, tensor<?xf32>, tensor<?x?xf32>)
// expected-remark @below {{matched output 2 projected permutation}}
// expected-remark @below {{matched output 1 permutation}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0)>,
affine_map<(d0, d1) -> (d0 + d1)>,
affine_map<(d0, d1) -> (d1, d0)>,
affine_map<(d0, d1) -> (d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%oned: tensor<?xf32>) outs(%oned, %twod, %oned2: tensor<?xf32>, tensor<?x?xf32>, tensor<?xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
linalg.yield %arg0, %arg0, %arg0 : f32, f32, f32
} -> (tensor<?xf32>, tensor<?x?xf32>, tensor<?xf32>)
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_num_io(%arg0: !transform.any_op {transform.readonly})
-> (!transform.param<i64>, !transform.param<i64>, !transform.any_op) {
%0:3 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> (!transform.param<i64>, !transform.param<i64>, !transform.any_op) {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.num_inputs %arg1 : (!transform.any_op) -> !transform.param<i64>
%2 = transform.match.structured.num_inits %arg1 : (!transform.any_op) -> !transform.param<i64>
transform.match.structured.yield %1, %2, %arg1 : !transform.param<i64>, !transform.param<i64>, !transform.any_op
}
transform.yield %0#0, %0#1, %0#2 : !transform.param<i64>, !transform.param<i64>, !transform.any_op
}
transform.named_sequence @print_num_io(
%arg0: !transform.param<i64> {transform.readonly},
%arg1: !transform.param<i64> {transform.readonly},
%arg2: !transform.any_op {transform.readonly}) {
transform.test_print_param %arg0, "inputs" at %arg2 : !transform.param<i64>, !transform.any_op
transform.test_print_param %arg1, "outputs" at %arg2 : !transform.param<i64>, !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%0 = transform.foreach_match in %arg0 @match_num_io -> @print_num_io : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%f32: f32,
%oned: tensor<?xf32>,
%oned2: tensor<?xf32>,
%twod: tensor<?x?xf32>)
attributes { transform.target_tag = "start_here" } {
// expected-remark @below {{inputs 1}}
// expected-remark @below {{outputs 3}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0)>,
affine_map<(d0, d1) -> (d0 + d1)>,
affine_map<(d0, d1) -> (d1)>,
affine_map<(d0, d1) -> (d1, d0)>],
iterator_types = ["parallel", "parallel"]
} ins(%oned: tensor<?xf32>) outs(%oned, %oned2, %twod: tensor<?xf32>, tensor<?xf32>, tensor<?x?xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
linalg.yield %arg0, %arg0, %arg0 : f32, f32, f32
} -> (tensor<?xf32>, tensor<?xf32>, tensor<?x?xf32>)
// expected-remark @below {{inputs 2}}
// expected-remark @below {{outputs 2}}
linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0)>,
affine_map<(d0, d1) -> (d1, d0)>,
affine_map<(d0, d1) -> (d0 + d1)>,
affine_map<(d0, d1) -> (d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%oned, %twod: tensor<?xf32>, tensor<?x?xf32>) outs(%oned, %oned2: tensor<?xf32>, tensor<?xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32, %arg3: f32):
linalg.yield %arg0, %arg0 : f32, f32
} -> (tensor<?xf32>, tensor<?xf32>)
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_rank(%arg0: !transform.any_op {transform.readonly})
-> (!transform.param<i64>, !transform.any_op) {
%0:2 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> (!transform.param<i64>, !transform.any_op) {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.rank %arg1 : (!transform.any_op) -> !transform.param<i64>
transform.match.structured.yield %1, %arg1 : !transform.param<i64>, !transform.any_op
}
transform.yield %0#0, %0#1 : !transform.param<i64>, !transform.any_op
}
transform.named_sequence @print_rank(%arg0: !transform.param<i64> {transform.readonly},
%arg2: !transform.any_op {transform.readonly}) {
transform.test_print_param %arg0, "rank" at %arg2 : !transform.param<i64>, !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%0 = transform.foreach_match in %arg0 @match_rank -> @print_rank : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%f32: f32,
%twod: tensor<42x42xf32>)
attributes { transform.target_tag = "start_here" } {
%0 = tensor.empty() : tensor<42x42xf32>
// expected-remark @below {{rank 2}}
%1 = linalg.fill ins(%f32 : f32) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
// expected-remark @below {{rank 3}}
linalg.matmul ins(%twod, %twod : tensor<42x42xf32>, tensor<42x42xf32>)
outs(%1 : tensor<42x42xf32>) -> tensor<42x42xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_single_result(%arg0: !transform.any_op {transform.readonly})
-> (!transform.any_op, !transform.any_op) {
%0:2 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> (!transform.any_op, !transform.any_op) {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.result %arg1[0] { single } : (!transform.any_op) -> !transform.any_op
transform.match.structured.yield %1, %arg1 : !transform.any_op, !transform.any_op
}
transform.yield %0#0, %0#1 : !transform.any_op, !transform.any_op
}
transform.named_sequence @match_result_value(%arg0: !transform.any_op {transform.readonly})
-> (!transform.any_value, !transform.any_op) {
%0:2 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> (!transform.any_value, !transform.any_op) {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.result %arg1[0] : (!transform.any_op) -> !transform.any_value
transform.match.structured.yield %1, %arg1 : !transform.any_value, !transform.any_op
}
transform.yield %0#0, %0#1 : !transform.any_value, !transform.any_op
}
transform.named_sequence @match_any_result(%arg0: !transform.any_op {transform.readonly})
-> (!transform.any_op) {
%0 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> !transform.any_op {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.result %arg1[-1] { any } : (!transform.any_op) -> !transform.any_op
transform.match.structured.yield %arg1 : !transform.any_op
}
transform.yield %0 : !transform.any_op
}
transform.named_sequence @print_single_result(%arg0: !transform.any_op {transform.readonly},
%arg2: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg2, "matched single result" : !transform.any_op
transform.test_print_remark_at_operand %arg0, "single user" : !transform.any_op
transform.yield
}
transform.named_sequence @print_result_value(%arg0: !transform.any_value {transform.readonly},
%arg1: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg1, "matched result value" : !transform.any_op
transform.test_print_remark_at_operand_value %arg0, "op result" : !transform.any_value
transform.yield
}
transform.named_sequence @print_any_result(%arg0: !transform.any_op {transform.readonly}) {
transform.test_print_remark_at_operand %arg0, "matched any result" : !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%0 = transform.foreach_match in %arg0 @match_single_result -> @print_single_result : (!transform.any_op) -> !transform.any_op
%1 = transform.foreach_match in %0 @match_result_value -> @print_result_value : (!transform.any_op) -> !transform.any_op
%2 = transform.foreach_match in %1 @match_any_result -> @print_any_result : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%f32: f32, %f322: f32, %f323: f32,
%twod: tensor<42x42xf32>)
attributes { transform.target_tag = "start_here" } {
%0 = tensor.empty() : tensor<42x42xf32>
// expected-remark @below {{matched result value}}
// expected-remark @below {{op result}}
// expected-note @below {{value handle points to an op result #0}}
%1 = linalg.fill ins(%f32 : f32) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
// expected-remark @below {{matched result value}}
// expected-remark @below {{op result}}
// expected-note @below {{value handle points to an op result #0}}
// expected-remark @below {{matched single result}}
// expected-remark @below {{matched any result}}
%2 = linalg.fill ins(%f322 : f32) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
// expected-remark @below {{matched result value}}
// expected-remark @below {{op result}}
// expected-note @below {{value handle points to an op result #0}}
// expected-remark @below {{matched any result}}
%3 = linalg.fill ins(%f323 : f32) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
// expected-remark @below {{matched result value}}
// expected-remark @below {{op result}}
// expected-note @below {{value handle points to an op result #0}}
// expected-remark @below {{single user}}
linalg.elemwise_unary {fun = #linalg.unary_fn<negf>} ins(%2 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
// expected-remark @below {{matched result value}}
// expected-remark @below {{op result}}
// expected-note @below {{value handle points to an op result #0}}
linalg.elemwise_unary {fun = #linalg.unary_fn<exp>} ins(%3 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
// expected-remark @below {{matched result value}}
// expected-remark @below {{op result}}
// expected-note @below {{value handle points to an op result #0}}
linalg.elemwise_unary {fun = #linalg.unary_fn<exp>} ins(%3 : tensor<42x42xf32>) outs(%0 : tensor<42x42xf32>) -> tensor<42x42xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_input_indexing_map(%arg0: !transform.any_op {transform.readonly})
-> (!transform.affine_map, !transform.any_op) {
%0 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> !transform.affine_map {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.input %arg1[0] : (!transform.any_op) -> !transform.affine_map
transform.match.structured.yield %1 : !transform.affine_map
}
transform.yield %0, %arg0 : !transform.affine_map, !transform.any_op
}
transform.named_sequence @match_init_indexing_map(%arg0: !transform.any_op {transform.readonly})
-> (!transform.affine_map, !transform.any_op) {
%0 = transform.match.structured failures(propagate) %arg0
: (!transform.any_op) -> !transform.affine_map {
^bb0(%arg1: !transform.any_op):
%1 = transform.match.structured.init %arg1[0] : (!transform.any_op) -> !transform.affine_map
transform.match.structured.yield %1 : !transform.affine_map
}
transform.yield %0, %arg0 : !transform.affine_map, !transform.any_op
}
transform.named_sequence @print_indexing_map_1(%arg0: !transform.affine_map {transform.readonly},
%arg1: !transform.any_op {transform.readonly}) {
transform.test_print_param %arg0, "indexing map 1" at %arg1 : !transform.affine_map, !transform.any_op
transform.yield
}
transform.named_sequence @print_indexing_map_2(%arg0: !transform.affine_map {transform.readonly},
%arg1: !transform.any_op {transform.readonly}) {
transform.test_print_param %arg0, "indexing map 2" at %arg1 : !transform.affine_map, !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%3 = transform.foreach_match in %arg0 @match_input_indexing_map -> @print_indexing_map_1 : (!transform.any_op) -> !transform.any_op
%4 = transform.foreach_match in %3 @match_init_indexing_map -> @print_indexing_map_2 : (!transform.any_op) -> !transform.any_op
transform.yield
}
func.func @payload(%lhs: tensor<32x32xf32>, %rhs: tensor<32x32xf32>)
attributes { transform.target_tag = "start_here" } {
%out = tensor.empty() : tensor<32x32xf32>
%cst = arith.constant 1.0 : f32
// expected-remark @below {{indexing map 1 affine_map<(d0, d1) -> ()>}}
// expected-remark @below {{indexing map 2 affine_map<(d0, d1) -> (d0, d1)>}}
%res = linalg.fill ins(%cst : f32) outs(%out : tensor<32x32xf32>) -> tensor<32x32xf32>
// expected-remark @below {{indexing map 1 affine_map<(d0, d1, d2) -> (d0, d2)>}}
// expected-remark @below {{indexing map 2 affine_map<(d0, d1, d2) -> (d0, d1)>}}
linalg.matmul ins(%lhs, %rhs : tensor<32x32xf32>, tensor<32x32xf32>) outs(%res : tensor<32x32xf32>) -> tensor<32x32xf32>
return
}
}
// -----
module attributes { transform.with_named_sequence } {
transform.named_sequence @match_contraction(%arg0: !transform.any_op {transform.readonly})
-> (!transform.any_op, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>) {
%1:4 = transform.match.structured %arg0 : (!transform.any_op) -> (!transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>) {
^bb0(%struct: !transform.any_op):
transform.match.structured.body %struct { contraction = ["arith.mulf", "arith.addf"] } : !transform.any_op
%0:4 = transform.match.structured.classify_contraction_dims %struct
: (!transform.any_op) -> (!transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>)
transform.match.structured.yield %0#0, %0#1, %0#2, %0#3
: !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>
}
transform.yield %arg0, %1#0, %1#1, %1#2, %1#3 : !transform.any_op, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>, !transform.param<i64>
}
transform.named_sequence @print_contraction(
%op: !transform.any_op {transform.readonly},
%batch: !transform.param<i64> {transform.readonly},
%m: !transform.param<i64> {transform.readonly},
%n: !transform.param<i64> {transform.readonly},
%k: !transform.param<i64> {transform.readonly}) {
transform.test_print_remark_at_operand %op, "contraction" : !transform.any_op
transform.test_print_param %batch, "batch dims" at %op : !transform.param<i64>, !transform.any_op
transform.test_print_param %m, "m dims" at %op : !transform.param<i64>, !transform.any_op
transform.test_print_param %n, "n dims" at %op : !transform.param<i64>, !transform.any_op
transform.test_print_param %k, "k dims" at %op : !transform.param<i64>, !transform.any_op
transform.yield
}
transform.sequence failures(propagate) attributes { transform.target_tag = "transform" } {
^bb0(%arg0: !transform.any_op):
%3 = transform.foreach_match in %arg0 @match_contraction -> @print_contraction : (!transform.any_op) -> !transform.any_op
transform.yield
}
}
module attributes { transform.target_tag = "start_here" } {
func.func @matmul_simple(%lhs: tensor<10x20xf32>, %rhs: tensor<20x15xf32>) -> tensor<10x15xf64> {
%cst = arith.constant 0.0 : f64
%empty = tensor.empty() : tensor<10x15xf64>
%fill = linalg.fill ins(%cst : f64) outs(%empty : tensor<10x15xf64>) -> tensor<10x15xf64>
// expected-remark @below {{contraction}}
// expected-remark @below {{batch dims}}
// expected-remark @below {{m dims 0}}
// expected-remark @below {{n dims 1}}
// expected-remark @below {{k dims 2}}
%result = linalg.matmul ins(%lhs, %rhs: tensor<10x20xf32>, tensor<20x15xf32>) outs(%fill: tensor<10x15xf64>) -> tensor<10x15xf64>
return %result : tensor<10x15xf64>
}
func.func @double_batch(%lhs: tensor<40x10x50x20xf32>, %rhs: tensor<40x20x50x15xf32>) -> tensor<40x10x50x15xf32> {
%cst = arith.constant 0.0 : f32
%empty = tensor.empty() : tensor<40x10x50x15xf32>
%fill = linalg.fill ins(%cst : f32) outs(%empty : tensor<40x10x50x15xf32>) -> tensor<40x10x50x15xf32>
// expected-remark @below {{contraction}}
// expected-remark @below {{batch dims 0 : i64, 2 : i64}}
// expected-remark @below {{m dims 1}}
// expected-remark @below {{n dims 3}}
// expected-remark @below {{k dims 4}}
%result = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d4)>,
affine_map<(d0, d1, d2, d3, d4) -> (d0, d4, d2, d3)>,
affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel", "reduction"]
} ins(%lhs, %rhs : tensor<40x10x50x20xf32>, tensor<40x20x50x15xf32>)
outs(%fill : tensor<40x10x50x15xf32>) {
^bb(%arg0: f32, %arg1: f32, %arg2: f32):
%0 = arith.mulf %arg0, %arg1 : f32
%1 = arith.addf %arg2, %0 : f32
linalg.yield %1 : f32
} -> tensor<40x10x50x15xf32>
return %result : tensor<40x10x50x15xf32>
}
}
|