Skip to content

Commit

Permalink
[Codegen][Tuner] verifier for the default tuning spec
Browse files Browse the repository at this point in the history
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
  • Loading branch information
bangtianliu committed Dec 19, 2024
1 parent e553425 commit b35931b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// TODO(https://github.com/iree-org/iree/issues/19214): Add missing
// configurations to this spec.

module @iree_default_tuning_spec_gfx942 attributes { transform.with_named_sequence } {
module @iree_default_tuning_spec_gfx942 attributes { transform.with_named_sequence, iree_codegen.default_tuning_spec } {

transform.named_sequence @apply_op_config(%op: !transform.any_op {transform.readonly},
%config: !transform.any_param {transform.readonly}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ module @foo_module attributes { transform.with_named_sequence } {
transform.named_sequence @foo(%arg0: !transform.any_op {transform.readonly})
attributes { iree_codegen.tuning_spec_entrypoint } {}
}

// -----

// expected-error @+1{{The default tuning specification must include an operation with the symbol name '__kernel_config'}}
module @iree_default_tuning_spec attributes { iree_codegen.default_tuning_spec } {
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace mlir::iree_compiler {
// Constant names.
//===----------------------------------------------------------------------===//
constexpr StringLiteral kConfigAttrName = "lowering_config";
constexpr StringLiteral kTuningDefaultSpecAttrName =
"iree_codegen.default_tuning_spec";
constexpr StringLiteral kTuningSpecEntrypointAttrName =
"iree_codegen.tuning_spec_entrypoint";
constexpr StringLiteral kSerializedTuningSpecAttrName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ IREECodegenDialect::verifyOperationAttribute(Operation *op,
NamedAttribute attribute) {
StringRef symbol = attribute.getName().strref();
Attribute attr = attribute.getValue();

// This function verifies the validity of a specific operation attribute.
// - If the attribute's name matches `kTuningDefaultSpecAttrName` :
// - For the `ModuleOp` operation ( representing the default spec):
// - Ensure the module contains one operation with the symbol
// name `__kernel_config`. If not, emit an error.
// - If the attribute's name matches `kTuningSpecEntrypointAttrName`
// ("iree_codegen.tuning_spec_entrypoint"):
// 1. The attribute value must be a UnitAttr.
Expand All @@ -63,6 +66,19 @@ IREECodegenDialect::verifyOperationAttribute(Operation *op,
// b. It must have exactly one argument type, and the argument must be
// of type `transform::AnyOpType`.

if (symbol == kTuningDefaultSpecAttrName) {
if (auto moduleOp = dyn_cast<ModuleOp>(op)) {
if (!llvm::any_of(moduleOp.getOps(), [](auto &op) {
return SymbolTable::getSymbolName(&op).getValue() ==
kKernelConfigSpecName;
})) {
return moduleOp.emitError()
<< "The default tuning specification must include an "
"operation with the symbol name '__kernel_config'.";
}
}
}

if (symbol != kTuningSpecEntrypointAttrName)
return success();

Expand Down

0 comments on commit b35931b

Please sign in to comment.