summaryrefslogtreecommitdiff
path: root/mlir/test/lib/Interfaces/TilingInterface/TestTilingInterfaceTransformOps.td
blob: 29669bd0930ed41cc0db4216960e492c05c3dde3 (plain)
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
//===- TestTilingInterfaceTransformOps.td -----------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef TEST_TILINGINTERFACE_TRANSFORM_OPS
#define TEST_TILINGINTERFACE_TRANSFORM_OPS

include "mlir/Dialect/SCF/IR/DeviceMappingInterface.td"
include "mlir/Dialect/Transform/IR/TransformDialect.td"
include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"
include "mlir/Dialect/Transform/IR/TransformTypes.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpBase.td"

// Those operations in this file are meant for testing the tiling interface
// transformations using scf operations. Over time these testing options
// might be useful transformations in their own right. Move these over
// as transform ops in the main repo (also find a proper place for them)

def TestFuseAndYieldOp : Op<Transform_Dialect, "test.fuse_and_yield",
  [FunctionalStyleTransformOpTrait, MemoryEffectsOpInterface,
   DeclareOpInterfaceMethods<TransformOpInterface>,
   ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    Tiles the operations pointed to by the target handle, fuses their
    producers greedily using the options provided as attributes.
    It also yields some of the fused producers for testing.

    On success returns the tiled operations as well as generated loops. Emits
    a definite failure if tiling fails.
  }];

  let arguments =
    (ins TransformHandleTypeInterface:$target,
        DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
        DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_interchange,
        DefaultValuedAttr<BoolAttr, "false">:$use_forall);
  let results = (outs TransformHandleTypeInterface:$transfomed,
      Variadic<TransformHandleTypeInterface>:$loops);

  let assemblyFormat = [{
    $target ($tile_sizes^)? (`interchange` $tile_interchange^)?
    (`use_forall` $use_forall^)? attr-dict 
    `:` functional-type(operands, results)
  }];
}

def TestFuseConsumerUsingSliceOp : Op<Transform_Dialect, "test.fuse_consumer_using_slice",
       [AttrSizedOperandSegments,
        DeclareOpInterfaceMethods<TransformOpInterface>,
        DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
        ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    For the `insert_slice`-like operations (that are typically generated through tiling),
    within the loop nests passed in as `loops` (that are typically generated through tiling),
    find the consumer that these slices map to (have to be the same consumer) and fuse
    the consumer into the loop.

    Returns a handle to the original consumer operation and the consumer operation after
    fusion.
  }];

  let arguments = (ins 
      Variadic<TransformHandleTypeInterface>:$targets,
      Variadic<TransformHandleTypeInterface>:$loops,
      DefaultValuedAttr<I32Attr, "1">:$num_consumer_to_fuse);
  let results = (outs TransformHandleTypeInterface:$consumer,
                      TransformHandleTypeInterface:$fused_consumer);

  let assemblyFormat = [{
    $targets `in` `(` $loops `)`
    (`num_consumer_to_fuse` `=` $num_consumer_to_fuse^)? 
    attr-dict `:` functional-type(operands, results)
  }];
}

def TestFuseConsumerOp : Op<Transform_Dialect, "test.fuse_consumer",
       [DeclareOpInterfaceMethods<TransformOpInterface>,
        DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
        ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    For the `consumer` that uses the result of the outer-most loop of a loop nest passed in 
    as `loops` (that are typically generated through tiling), fuse the consumer into the
    loop.

    Returns a handle to the consumer operation after fusion and the loops that might be
    modified.
  }];

  let arguments = (ins 
      TransformHandleTypeInterface:$consumer,
      Variadic<TransformHandleTypeInterface>:$loops);
  let results = (outs TransformHandleTypeInterface:$fused_consumer,
      Variadic<TransformHandleTypeInterface>:$result_loops);

  let assemblyFormat = [{
    $consumer `into` `(` $loops `)`
    attr-dict `:` functional-type(operands, results)
  }];
}


def TestTileUsingForallOp : Op<Transform_Dialect, "test.tile_using_forall",
       [DeclareOpInterfaceMethods<TransformOpInterface>,
        DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
        ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    Test operation use to test tiling using TilingInterface and scf.forall for
    the loop constructs. This is similar to
    `transform.structured.tile_using_for`. Use of this operation is an
    intermediate state and will be replaced in due course with either
    `transform.structured.tile_using_for` or
    `transform.structured.tile_using_forall`.

    On success returns the tiled operations as well as generated loops. Emits
    a definite failure if tiling fails.
  }];

  let arguments = (ins TransformHandleTypeInterface:$target,
                   DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
                   DefaultValuedOptionalAttr<I64ArrayAttr, "{}">:$interchange,
                   OptionalAttr<DeviceMappingArrayAttr>:$mapping);
  let results = (outs TransformHandleTypeInterface:$tiled_op,
                      Variadic<TransformHandleTypeInterface>:$loops);

  let assemblyFormat = [{
    $target ($tile_sizes^)? (`interchange` `=` $interchange^)?
    (`mapping` `=` $mapping^)?
    attr-dict `:` functional-type(operands, results)
  }];
}

def TestFuseUsingForallOp : Op<Transform_Dialect, "test.fuse_using_forall",
    [DeclareOpInterfaceMethods<TransformOpInterface>,
     DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
     ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    Test operation to tile the operation pointed to by the target handle and
    fuses their producers greedily using the options provided as attributes.
    This operation uses scf.forall for the loop construct.
  }];
  let arguments = (ins TransformHandleTypeInterface:$root_op,
                   DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
                   DefaultValuedOptionalAttr<I64ArrayAttr, "{}">:$interchange,
                   OptionalAttr<DeviceMappingArrayAttr>:$mapping);
  let results = (outs TransformHandleTypeInterface:$tiled_ops,
                      Variadic<TransformHandleTypeInterface>:$loops);

  let assemblyFormat = [{
    $root_op ($tile_sizes^)? (`interchange` $interchange^)?
    (`mapping` `=` $mapping^)?
    attr-dict `:` functional-type(operands, results)
  }];
}

def TestTileAndFuseOuterParallelPartialReductionOp : Op<
    Transform_Dialect, "test.tile_and_fuse_outer_parallel_partial_reduction",
    [FunctionalStyleTransformOpTrait, MemoryEffectsOpInterface,
     DeclareOpInterfaceMethods<TransformOpInterface>,
     ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    Test operation to tile an operation using partial reduction with
    outer parallel strategy, and to fuse its producers.
  }];

  let arguments = (ins TransformHandleTypeInterface:$root_op,
                   DefaultValuedAttr<I64ArrayAttr, "{}">:$reduction_dims,
                   DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes,
                   OptionalAttr<DeviceMappingArrayAttr>:$mapping);

  let results = (outs TransformHandleTypeInterface:$tiled_ops,
                 Variadic<TransformHandleTypeInterface>:$loops);
  let assemblyFormat = [{
    $root_op (`reduction_dims` `=` $reduction_dims^)?
    (`tile_sizes` `=` $tile_sizes^)? (`mapping` `=` $mapping^)?
    attr-dict `:` functional-type(operands, results)
  }];
}

def TestTileUsingCustomLoopOp : Op<
    Transform_Dialect, "test.tile_using_custom_loop",
    [FunctionalStyleTransformOpTrait, MemoryEffectsOpInterface,
     DeclareOpInterfaceMethods<TransformOpInterface>,
     ReportTrackingListenerFailuresOpTrait]> {
  let description = [{
    Test Transform op to tile an operation using custom loops.

    The test just folds all the loops and into a single loop and then
    delinearizes the indices.
  }];

  let arguments = (ins TransformHandleTypeInterface:$root_op,
                   DefaultValuedAttr<I64ArrayAttr, "{}">:$tile_sizes);
  let results  = (outs TransformHandleTypeInterface:$tiled_ops,
                  Variadic<TransformHandleTypeInterface>:$loops);
  
  let assemblyFormat = [{
    $root_op `tile_sizes` `=` $tile_sizes
    attr-dict `:` functional-type(operands, results)
  }];
}

#endif // TEST_TILINGINTERFACE_TRANSFORM_OPS