iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.

Home Page:http://iree.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Codegen] Move `LoweringConfigAttr` to an attribute interface

qedawkins opened this issue · comments

The #iree_codegen.lowering_config attribute is designed such that different backends will interpret its contents differently. This is at odds with the the current implementation of the attribute which has a fixed set of fields and a number of backend specific member functions.

def IREECodegen_LoweringConfigAttr :
AttrDef<IREECodegen_Dialect, "LoweringConfig", []> {
let mnemonic = "lowering_config";
let summary = [{drive lowering of an operation within dispatch region}];
let description = [{
Specifies the information that is used by backend compiler to
translate an operation to scalar code. The way the information is
used is specific to each backend (indeed specific to the pass
pipeline used) to compile that operation.
TODO: Currently there is no verification that the configuration
specifies everything needed for a pass-pipeline. The values to set
for these parameters is dependent on the pass-pipeline
implementation. In future, each pass pipeline could verify that
the lowering configuration has all the necessary attributes for
the pipeline.
}];
let assemblyFormat = [{
`<` `tile_sizes` `=` $tilingLevels
(`,` `native_vector_size` `=` `[` $nativeVectorSize^ `]`)? `>`
}];

The addition of fields to this attribute means that all backends and any shared passes need to reason about it (likely just emitting errors). A recent example of the GPU side was the introduction of a special attribute on the TranslationInfo to track the intended target intrinsic for an operation, however translation info applies globally.

def IREEGPU_MmaScheduleAttr : AttrDef<IREEGPU_Dialect, "MMASchedule"> {

The solution is to create an interface for LoweringConfig attributes that interfaces with common passes and has separate concrete implementations for backends that need it. Today the two primary shared passes are TileAndDistributeToWorkgroups and GenericVectorization

IREE::Codegen::LoweringConfigAttr rootOpConfig = getLoweringConfig(rootOp);

IREE::Codegen::LoweringConfigAttr loweringConfig = getLoweringConfig(op);

So the interface methods to start will be

SmallVector<int64_t> getTileSizeVals(unsigned level);
SmallVector<int64_t> getNativeVectorSizeVals();

cc @MaheshRavishankar @hanhanW