Skip to content

Commit

Permalink
[CPU] Enable mmt4d ukernels when iree-llvmcpu-enable-ukernels is not …
Browse files Browse the repository at this point in the history
…set (iree-org#17928)

This is a follow-up for

iree-org@3b5d269.
The previous revision enables mmt4d ukernels only when
`--iree-llvmcpu-enable-ukernels` is passed to IREE tools. If the
`ukernels` attribute is not present in hal.executable.target, it is not
enabled.

The revisions removes the constraint, so users don't need to pass
`--iree-llvmcpu-enable-ukernels=default` to enable the mmt4d ukernels.

Signed-off-by: hanhanW <[email protected]>
  • Loading branch information
hanhanW authored Jul 17, 2024
1 parent 30e2c20 commit 4de493a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ func.func @mmt4d_f32f32f32(%arg0 : tensor<?x?x16x1xf32>, %arg1 : tensor<?x?x16x1

// -----

func.func @mmt4d_no_ukernels_attr_f32f32f32(%arg0 : tensor<?x?x16x1xf32>, %arg1 : tensor<?x?x16x1xf32>,
%arg2 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32> attributes {
hal.executable.target = #hal.executable.target<"llvm-cpu", "xyz", {target_triple="x86_64-xyz-xyz", cpu_features="+avx512f"}>
} {
%0 = linalg.mmt4d ins(%arg0, %arg1 : tensor<?x?x16x1xf32>, tensor<?x?x16x1xf32>)
outs(%arg2 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32>
return %0 : tensor<?x?x16x16xf32>
}
// CHECK-LABEL: func @mmt4d_no_ukernels_attr_f32f32f32(
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]: tensor<?x?x16x1xf32>
// CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]: tensor<?x?x16x1xf32>
// CHECK-SAME: %[[ARG2:[a-zA-Z0-9]+]]: tensor<?x?x16x16xf32>
// CHECK-DAG: %[[FLAGS:.+]] = arith.constant {{[0-9]+}} : i32
// CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index
// CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index
// CHECK-DAG: %[[C1_i32:.+]] = arith.constant 1 : i32
// CHECK-DAG: %[[C16_i32:.+]] = arith.constant 16 : i32
// CHECK-DAG: %[[M:.+]] = tensor.dim %[[ARG0]], %[[C0]]
// CHECK-DAG: %[[N:.+]] = tensor.dim %[[ARG1]], %[[C0]]
// CHECK-DAG: %[[K:.+]] = tensor.dim %[[ARG1]], %[[C1]]
// CHECK: %[[MICRO_KERNEL:.+]]:2 = iree_codegen.ukernel.generic "iree_uk_mmt4d"
// CHECK-SAME: ins(%[[ARG0]], %[[ARG1]] :
// CHECK-SAME: outs(%[[ARG2]] :
// CHECK-SAME: (%[[M]], %[[N]], %[[K]], %[[C16_i32]], %[[C16_i32]], %[[C1_i32]], %[[FLAGS]] :
// CHECK: return %[[MICRO_KERNEL]]#0

// -----

func.func @mmt4d_f32f32f32_with_none_ukernel_enabled(%arg0 : tensor<?x?x16x1xf32>, %arg1 : tensor<?x?x16x1xf32>,
%arg2 : tensor<?x?x16x16xf32>) -> tensor<?x?x16x16xf32> attributes {
hal.executable.target = #hal.executable.target<"llvm-cpu", "xyz", {ukernels = "none", target_triple="x86_64-xyz-xyz", cpu_features="+avx512f"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ void LLVMCPULowerExecutableTargetPass::runOnOperation() {
pipelineOpts.enableVectorMasking =
isX86(target) || isRISCV(target) ||
(isAArch64(target) && hasAnySVEFeature(target));
pipelineOpts.enableUkernels = hasUkernel(target);
pipelineOpts.enableAArch64SSVE =
isAArch64(target) && hasAnySVEFeature(target) && hasSMEFeature(target);
pipelineOpts.enableAArch64I8mm = isAArch64(target) && hasI8mmFeature(target);
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,11 @@ void addMmt4dTilingExpertPassPipeline(OpPassManager &funcPassManager,

funcPassManager.addPass(createLLVMCPUTileAndFusePass(
static_cast<int64_t>(tilingConfig.getVectorCommonParallelLevel())));
if (pipelineOpt.enableUkernels) {
funcPassManager.addPass(createCPUPrepareUkernelsPass());
funcPassManager.addPass(
createCPULowerToUKernelsPass(clSkipIntermediateRoundings));
}
// The below two passes are nop if the "mmt4d" is explicitly excluded in the
// ukernels attribute.
funcPassManager.addPass(createCPUPrepareUkernelsPass());
funcPassManager.addPass(
createCPULowerToUKernelsPass(clSkipIntermediateRoundings));
funcPassManager.addPass(createLLVMCPUTilePass(
static_cast<int64_t>(tilingConfig.getVectorReductionLevel())));

Expand Down Expand Up @@ -545,11 +545,11 @@ void addCPUDataTilingPipeline(OpPassManager &funcPassManager,
LLVMCPUPipelineOptions &pipelineOpt) {
addTileAndDistributePasses(funcPassManager);

if (pipelineOpt.enableUkernels) {
funcPassManager.addPass(createCPUPrepareUkernelsPass());
funcPassManager.addPass(
createCPULowerToUKernelsPass(clSkipIntermediateRoundings));
}
// The below two passes are nop if pack/unpack is not specified in ukernels
// attribute. By default, they are disabled.
funcPassManager.addPass(createCPUPrepareUkernelsPass());
funcPassManager.addPass(
createCPULowerToUKernelsPass(clSkipIntermediateRoundings));

funcPassManager.addPass(
createLLVMCPUTilePass(tilingConfig.getVectorCommonParallelLevel()));
Expand Down
1 change: 0 additions & 1 deletion compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ struct LLVMCPUPipelineOptions {
bool enableVectorMasking = false;
bool enableAArch64SSVE = false;
bool enableAArch64I8mm = false;
bool enableUkernels = false;
bool lowerToAVX2 = false;
};

Expand Down
8 changes: 5 additions & 3 deletions compiler/src/iree/compiler/Codegen/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ getDefaultEnabledUkernels(IREE::HAL::ExecutableTargetAttr targetAttr) {
bool hasUkernel(IREE::HAL::ExecutableTargetAttr targetAttr,
StringRef ukernelName) {
auto enabledUkernels = getConfigStringAttr(targetAttr, "ukernels");
if (!enabledUkernels) {
return false;
StringRef enabledUkernelsStr;
if (enabledUkernels) {
enabledUkernelsStr = enabledUkernels->getValue();
} else {
enabledUkernelsStr = "default";
}
StringRef enabledUkernelsStr = enabledUkernels->getValue();
// Resolve `default`.
if (enabledUkernelsStr == "default") {
enabledUkernelsStr = getDefaultEnabledUkernels(targetAttr);
Expand Down

0 comments on commit 4de493a

Please sign in to comment.