Skip to content

Commit

Permalink
[Stream] Do not specialize encodings that is either unrecognized or a…
Browse files Browse the repository at this point in the history
…lready serialized (#20054)

A recognized encoding indicates an attribute that implements
SerializableEncodingAttrInterface. If an encoding does not implement the
interface, it is an unknown/unrecognized encoding.

The revision makes the SpecializeEncoding pass more robust. It filters
all the ops that need the specialization. I.e., it filters out the ops
that do not have any recognized encoding. For DispatchTensorOp, it also
checks if the corresponding executables/functions match the assumptions
or not. In the pass, the specializable cases must match:

- The corresponding executable is a stream.executable op.
- The function arguments, where the types are !stream.binding_type, are
only used by stream.binding.subspan ops. Furthermore, the result type of
subspan ops have to implement IREE::Encoding::EncodingTypeInterface.

If one of the requirements does not meet, the op won't be updated. If
the encoding is unrecognized, the pass does nothing. If the encoding is
recognized and it is already serialized, the pass updates the bindings
with the serialized encodings.

To test unrecognized encoding, the revision introduces
`UnknownEncodingAttr` and uses it for testing.

---------

Signed-off-by: hanhanW <hanhan0912@gmail.com>
  • Loading branch information
hanhanW authored Feb 25, 2025
1 parent ec5b3a6 commit 2a68e1e
Show file tree
Hide file tree
Showing 4 changed files with 418 additions and 131 deletions.
11 changes: 11 additions & 0 deletions compiler/src/iree/compiler/Dialect/Encoding/IR/EncodingAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ def TestingEncodingAttr :
let genVerifyDecl = 0;
}

def UnknownEncodingAttr : IREEEncoding_Attr<"UnknownEncoding"> {
let mnemonic = "unknown_encoding";
let summary = "A pure encoding attribute for testing purpose";

let description = [{
An attribute for testing purpose. It is intended to be attached on
RankedTensorType as an encoding.
}];
let genVerifyDecl = 0;
}

def UnspecializedEncodingAttr :
IREEEncoding_Attr<"UnspecializedEncoding", [
DeclareAttrInterfaceMethods<IREEEncoding_EncodingLayoutResolverAttrInterface, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct EncodingOpAsmInterface : public OpAsmDialectInterface {
/// `.` or end with a numeric digit([0-9]+). Returns success if an alias was
/// provided, failure otherwise.
AliasResult getAlias(Attribute attr, raw_ostream &os) const override {
if (llvm::isa<EncodingAttr, TestingEncodingAttr>(attr)) {
if (llvm::isa<EncodingAttr, TestingEncodingAttr, UnknownEncodingAttr>(
attr)) {
os << "encoding";
return AliasResult::OverridableAlias;
}
Expand Down
Loading

0 comments on commit 2a68e1e

Please sign in to comment.