Lines Matching full:shape
1 # Shape Inference
3 Shape inference as discussed here is considered a specific instance of type
6 dimensions. While some operations have no compile time fixed shape (e.g., output
7 shape is dictated by data) we could still have some knowledge of
11 shape.
15 `InferShapedTypeOpInterface` is used to implement the shape and element type
16 inference. The return type can often be deduced from the deduced return shape
22 ## Shape functions
24 The C++ interfaces are the base mechanism whereby shape inference is queried and
25 executed, but not the intended way to specify shape constraints in general.
27 Initially the shape inference will be declaratively specified using:
36 type (shape and elemental type) between operands and results (e.g., the
39 NOTE: The C++ shape functions are an intermediate step until the shape dialect
45 Shape inference is currently tested alongside type inference by
56 ## Shape dialect
58 This section details the shape type inference dialect (`shape`). The initial
59 focus will be on shape functions that describe shape functions could be used in
64 This will focus on the shape functions (e.g., determine the rank and dimensions
65 of the output shape). As shown in the shaped container type, shape will be one
71 * Not all shape functions need to provide all the information (e.g., one could
77 An argument could be made that these are metadata function instead of shape
78 functions, with some considering shape and elemental types different and some considering them both…
79 part of shape. But `shape function` is IMHO descriptive and metadata can span
84 The requirements for the shape inference functions are determined by the
85 requirements of shape inference, but we believe the requirements below still
86 allow freedom to consider different shape inference approaches and so we do not
87 impose a particular shape inference approach here.
89 #### Shape inference functions
91 * **Expressiveness** shape functions need to support programs where tensors
94 * **Shape error detection** Many operations will have constraints on their
98 * This also aligns with the requirement that the shape function description
100 * Shape error functions should be easy to understand, at least what
101 constraint of the operation is violated. This also requires that shape
103 shape function (e.g., the author would be able to give the semantic
108 [Inlining shape checking](#inline)) be elided.
113 * Shape functions usable by compiler and runtime.
117 * Shape function description should not be constrained by either runtime
122 shapes, then it need not consider a more generic shape lattice even
123 though the shape description supports it.
133 * Shape inference functions are expressible at runtime
135 * User can define a shape function for a new operation dynamically at runtime,
136 this allows for vendors to describe an operation and shape function
141 * Doesn't require graph-wide shape information (e.g., only require local
144 * Shape functions should be cheap to invoke on each kernel launch.
145 * Shape function can be dictated by arguments (operands, attributes and regions)
148 * Shape information that needs higher-level/graph information should use
153 * Shape functions should be pure functions.
159 determining the shape & then post to be able to actually consume the
162 * The shape function operation dialect should be interoperable with non-shape function dialect op…
179 * The shape function should be expandable such that symbolic equality and
181 shape inference.
183 * E.g., the shape functions may contain more information that is only
184 useful when used from shape inference;
186 * Shape functions are allowed to fail and report an error. The error reporting
197 1. The shape dialect is an IR representations and not a programming language;
202 1. Describe the shape inference approach that will use the shape functions;
203 * The goal is that the shape functions and the constraints one could
206 static information is used for shape output, unranked for everything
211 * While the shape functions will be able to emit errors optionally, it
214 the literature that the iteration order for shape inference affect the
215 quality of the error message produced, and the shape functions do not
217 1. Flow sensitive shape functions;
218 * To enable scalable/cheap shape inference, the shape functions do not
221 the shape functions/constraints due to the shape functions.
228 #### Inline shape inference checks {#inline}
230 Shape functions should be lowerable to runtime checks for validity. E.g. verify
232 shape dynamically and or falling back to runtime checks for attributes not
237 shape inference should not insert constructs that interfere with optimization
247 an operation. Where these are sufficient to constrain the output shape (e.g.,
248 `SameOperandAndResultType` or broadcastable) we should generate the shape
249 function from those. Where not, an explicit shape function should be specified
253 #### Why not extract the shape function from reference implementation?
255 This could be done in future! The extracted shape function would use the shape
257 structured way, one could autogenerate the shape function.
259 #### How/in what language will the shape functions be authored?
264 #### What shape inference approach is being suggested here?
266 None. There are multiple different shape inference approaches that we could
268 useful (return fixed shape for constant inputs/arguments) to the more advanced
274 1. Should shape functions that produce dynamic outputs given all statically
281 Shape functions are determined by attributes and could be arbitrarily
285 type and shape]) and so these should be easy to specify. Algebraic relationships
291 Instead of specifying an additional mechanism to specify a shape transfer
293 the shape function. The reference implementation is general and can support the