forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
compiler/src/iree/compiler/Codegen/Common/GPU/GPUGeneralizeNamedOps.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 The IREE Authors | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
//===- GPUGeneralizeNamedOps.cpp - Pass to generalize named linalg ops --===// | ||
// | ||
// The pass is to generalize named linalg ops that are better as linalg.generic | ||
// ops in IREE | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "iree/compiler/Codegen/Common/GPU/PassDetail.h" | ||
#include "iree/compiler/Codegen/Common/GPU/Passes.h" | ||
#include "mlir/Dialect/Linalg/IR/Linalg.h" | ||
#include "mlir/Dialect/Linalg/Transforms/Transforms.h" | ||
#include "mlir/Pass/Pass.h" | ||
|
||
namespace mlir { | ||
namespace iree_compiler { | ||
|
||
namespace { | ||
struct GPUGeneralizeNamedOpsPass | ||
: public GPUGeneralizeNamedOpsBase<GPUGeneralizeNamedOpsPass> { | ||
|
||
void runOnOperation() override; | ||
}; | ||
} // namespace | ||
|
||
void GPUGeneralizeNamedOpsPass::runOnOperation() { | ||
auto funcOp = getOperation(); | ||
SmallVector<linalg::LinalgOp> namedOpCandidates; | ||
funcOp.walk([&](linalg::LinalgOp linalgOp) { | ||
if (isa<linalg::BatchMatmulTransposeBOp, linalg::MatmulTransposeBOp, | ||
linalg::VecmatOp, linalg::MatvecOp>(linalgOp)) | ||
namedOpCandidates.push_back(linalgOp); | ||
}); | ||
|
||
IRRewriter rewriter(&getContext()); | ||
for (auto linalgOp : namedOpCandidates) { | ||
rewriter.setInsertionPoint(linalgOp); | ||
FailureOr<linalg::GenericOp> generalizedOp = | ||
linalg::generalizeNamedOp(rewriter, linalgOp); | ||
if (failed(generalizedOp)) { | ||
linalgOp->emitOpError("failed to generalize operation"); | ||
return signalPassFailure(); | ||
} | ||
} | ||
} | ||
|
||
std::unique_ptr<OperationPass<func::FuncOp>> createGPUGeneralizeNamedOpsPass() { | ||
return std::make_unique<GPUGeneralizeNamedOpsPass>(); | ||
} | ||
|
||
} // namespace iree_compiler | ||
} // namespace mlir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...egen/SPIRV/test/generalize_named_ops.mlir → ...on/GPU/test/gpu_generalize_named_ops.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters