Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/include/byteir/Dialect/SCF/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
#ifndef BYTEIR_DIALECT_SCF_PASSES_H
#define BYTEIR_DIALECT_SCF_PASSES_H

#include "byteir/Dialect/SCF/Transforms/ForToForall.h"
#include "byteir/Dialect/SCF/Transforms/ForallCollapsing.h"
#include "byteir/Dialect/SCF/Transforms/ForallNormalize.h"
#include "byteir/Dialect/SCF/Transforms/ForallTiling.h"
#include "byteir/Dialect/SCF/Transforms/FuseNestedForall.h"
#include "byteir/Dialect/SCF/Transforms/InsertTrivialSCFLoop.h"

Expand Down
59 changes: 59 additions & 0 deletions compiler/include/byteir/Dialect/SCF/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,63 @@ def ForallCollapsing : Pass<"forall-collapsing", "mlir::func::FuncOp"> {
];
}

//===----------------------------------------------------------------------===//
// ForallTiling
//===----------------------------------------------------------------------===//

def ForallTiling : Pass<"forall-tiling"> {
let summary = "tile forall Op with given tileSize";
let constructor = "mlir::createForallTilingPass()";
let dependentDialects = [
"scf::SCFDialect",
"affine::AffineDialect"
];
let options = [
ListOption<"tileSizes", "tile-sizes", "int64_t",
"Factors to tile forall">,
Option<"noMinMaxBounds", "no-min-max-bounds", "bool",
/*default=*/"false",
"Perform tiling with fixed upper bound with inbound check "
"inside the internal loops">,
Option<"anchorTag", "anchor-tag", "std::string",
/*default=*/"",
"Optional unitAttr anchored tag to apply this pass">,
];
}

//===----------------------------------------------------------------------===//
// ForallNormalize
//===----------------------------------------------------------------------===//

def ForallNormalize : Pass<"forall-normalize"> {
let summary = "normalize forall";
let constructor = "mlir::createForallNormalizePass()";
let dependentDialects = [
"scf::SCFDialect",
"affine::AffineDialect"
];
let options = [
Option<"anchorTag", "anchor-tag", "std::string",
/*default=*/"",
"Optional unitAttr anchored tag to apply this pass">
];
}

//===----------------------------------------------------------------------===//
// ForallNormalize
//===----------------------------------------------------------------------===//

def ForToForall : Pass<"for-to-forall"> {
let summary = "convert for to forall";
let constructor = "mlir::createForToForallPass()";
let dependentDialects = [
"scf::SCFDialect",
];
let options = [
Option<"anchorTag", "anchor-tag", "std::string",
/*default=*/"",
"Optional unitAttr anchored tag to apply this pass">
];
}

#endif // BYTEIR_DIALECT_SCF_PASSES
30 changes: 30 additions & 0 deletions compiler/include/byteir/Dialect/SCF/Transforms/ForToForall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- ForToForall.h ------------------------------------- C++ --===//
//
// Copyright 2024 ByteDance Ltd. and/or its affiliates. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//

#ifndef BYTEIR_DIALECT_SCF_TRANSFORMS_FORTOFORALL_H
#define BYTEIR_DIALECT_SCF_TRANSFORMS_FORTOFORALL_H

#include "mlir/Pass/Pass.h"
#include <memory>

namespace mlir {

std::unique_ptr<Pass> createForToForallPass(llvm::StringRef anchorTag = "");

} // namespace mlir

#endif // BYTEIR_DIALECT_SCF_TRANSFORMS_FORTOFORALL_H
30 changes: 30 additions & 0 deletions compiler/include/byteir/Dialect/SCF/Transforms/ForallNormalize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- ForallNormalize.h ------------------------------------- C++ --===//
//
// Copyright 2024 ByteDance Ltd. and/or its affiliates. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//

#ifndef BYTEIR_DIALECT_SCF_TRANSFORMS_FORALLNORMALIZE_H
#define BYTEIR_DIALECT_SCF_TRANSFORMS_FORALLNORMALIZE_H

#include "mlir/Pass/Pass.h"
#include <memory>

namespace mlir {

std::unique_ptr<Pass> createForallNormalizePass(llvm::StringRef anchorTag = "");

} // namespace mlir

#endif // BYTEIR_DIALECT_SCF_TRANSFORMS_FORALLNORMALIZE_H
33 changes: 33 additions & 0 deletions compiler/include/byteir/Dialect/SCF/Transforms/ForallTiling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- ForallTiling.h ------------------------------------- C++ --===//
//
// Copyright 2024 ByteDance Ltd. and/or its affiliates. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//

#ifndef BYTEIR_DIALECT_SCF_TRANSFORMS_FORALLTILING_H
#define BYTEIR_DIALECT_SCF_TRANSFORMS_FORALLTILING_H

#include "mlir/Pass/Pass.h"
#include <memory>

namespace mlir {

std::unique_ptr<Pass>
createForallTilingPass(llvm::ArrayRef<int64_t> tileSize = {},
bool noMinMaxBounds = false,
llvm::StringRef anchorTag = "");

} // namespace mlir

#endif // BYTEIR_DIALECT_SCF_TRANSFORMS_FORALLTILING_H
14 changes: 14 additions & 0 deletions compiler/include/byteir/Dialect/SCF/Util/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@

namespace mlir {
namespace scf {
// This structure is to pass and return sets of loop parameters without
// confusing the order.
struct LoopParams {
Value lowerBound;
Value upperBound;
Value step;
};

/// Return the new lower bound, upper bound, and step in that order. Insert any
/// additional bounds calculations before the given builder and any additional
/// conversion back to the original loop induction value inside the given Block.
LoopParams normalizeLoop(OpBuilder &boundsBuilder, OpBuilder &insideLoopBuilder,
Location loc, Value lowerBound, Value upperBound,
Value step, Value inductionVar);

SmallVector<scf::ForOp> createNestedEmptyScfForOps(OpBuilder &b, Location loc,
ArrayRef<Value> lowerBounds,
Expand Down
14 changes: 14 additions & 0 deletions compiler/include/byteir/Pipelines/GPU/ElementwiseCodegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,28 @@ struct GPUTileElementwiseOptions
llvm::cl::init(256)};
};

struct GPUTileElementwiseInSCFOptions
: public PassPipelineOptions<GPUTileElementwiseInSCFOptions> {
Option<int64_t> maxBlockSize{*this, "max-block-size",
llvm::cl::desc("max block size"),
llvm::cl::init(256)};
};

void createGPUTileElementwiseTransform(
OpPassManager &pm, const GPUTileElementwiseOptions &options);

void createGPUTileElementwiseInSCF(
OpPassManager &pm, const GPUTileElementwiseInSCFOptions &options);

inline void registerGPUElementwiseCodegenPipelines() {
PassPipelineRegistration<GPUTileElementwiseOptions>(
"insert-gpu-tile-elementwise-transform",
"Insert transformation IR to tile linalg elementwise op",
createGPUTileElementwiseTransform);

PassPipelineRegistration<GPUTileElementwiseInSCFOptions>(
"tile-elementwise-in-scf", "tile elementwise op with nested forallOp",
createGPUTileElementwiseInSCF);
}

} // namespace mlir
Expand Down
2 changes: 2 additions & 0 deletions compiler/include/byteir/Pipelines/InitAllPipelines.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "byteir/Pipelines/LinalgTensorOpt.h"
#include "byteir/Pipelines/SCFOpt.h"
#include "byteir/Pipelines/ShapeOpt.h"
#include "byteir/Pipelines/VectorOpt.h"

#include "byteir/Pipelines/GPU/ElementwiseCodegen.h"
#include "byteir/Pipelines/GPU/GPUOpt.h"
Expand All @@ -58,6 +59,7 @@ inline void registerAllByteIRCommonPipelines() {
registerLinalgMemrefOptPipeline();
registerLinalgTensorOptPipeline();
registerSCFOptPipeline();
registerVectorOptPipeline();
registerShapeOptPipeline();
registerByteIRBufferizeOptPipeline();
registerByteIRAllOptPipeline();
Expand Down
47 changes: 47 additions & 0 deletions compiler/include/byteir/Pipelines/VectorOpt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===- VectorOpt.h --------------------------------------------------- C++
//---===//
//
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//

#ifndef BYTEIR_PIPELINES_VECTOROPT_H
#define BYTEIR_PIPELINES_VECTOROPT_H

#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Pass/PassRegistry.h"
#include <memory>
#include <string>

namespace mlir {
struct VectorOptPipelineOptions
: public PassPipelineOptions<VectorOptPipelineOptions> {
Option<std::string> target{
*this, "target",
llvm::cl::desc("An optional attribute to speicify target."),
llvm::cl::init("")};
};

void createVectorOptPipeline(OpPassManager &pm,
const VectorOptPipelineOptions &options);

inline void registerVectorOptPipeline() {
PassPipelineRegistration<VectorOptPipelineOptions>(
"vector-opt", "Vector Opt Pipeline", createVectorOptPipeline);
}

} // namespace mlir

#endif // BYTEIR_PIPELINES_VECTOROPT_H
31 changes: 31 additions & 0 deletions compiler/include/byteir/Transforms/HorizontalFusion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===- GraphClusteringByDevice.h ------------------------------*--- C++ -*-===//
//
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//

#ifndef BYTEIR_TRANSFORMS_HORIZONTALFUSION_H
#define BYTEIR_TRANSFORMS_HORIZONTALFUSION_H

#include "mlir/Pass/Pass.h"
#include <memory>

namespace mlir {
class ModuleOp;

std::unique_ptr<OperationPass<ModuleOp>> createHorizontalFusionPass();

} // namespace mlir

#endif // BYTEIR_TRANSFORMS_HORIZONTALFUSION_H
1 change: 1 addition & 0 deletions compiler/include/byteir/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "byteir/Transforms/FuncTag.h"
#include "byteir/Transforms/GenericDeviceConfig.h"
#include "byteir/Transforms/GraphClusteringByDevice.h"
#include "byteir/Transforms/HorizontalFusion.h"
#include "byteir/Transforms/InsertUniqueId.h"
#include "byteir/Transforms/LoopTag.h"
#include "byteir/Transforms/LoopUnroll.h"
Expand Down
12 changes: 12 additions & 0 deletions compiler/include/byteir/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ def GraphClusteringByDevice : Pass<"graph-clustering-by-device", "ModuleOp"> {
];
}

//===----------------------------------------------------------------------===//
// HorizontalFusion
//===----------------------------------------------------------------------===//
def HorizontalFusion : Pass<"horizontal-fusion-on-scf", "ModuleOp"> {
let summary = "Horizontal fusion based on scf.forall and memref.";
let constructor = "mlir::createHorizontalFusionPass()";
let dependentDialects = [
"scf::SCFDialect",
"memref::MemRefDialect"
];
}

//===----------------------------------------------------------------------===//
// LoopTag
//===----------------------------------------------------------------------===//
Expand Down
5 changes: 4 additions & 1 deletion compiler/lib/Dialect/SCF/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
add_mlir_dialect_library(ByteIRSCFPasses
ForallCollapsing.cpp
ForallNormalize.cpp
ForallTiling.cpp
ForToForall.cpp
FuseNestedForall.cpp
InsertTrivialSCFLoop.cpp
TilingInterfaceToSCFFor.cpp
Expand All @@ -21,4 +24,4 @@ add_mlir_dialect_library(ByteIRSCFPasses
MLIRSCFTransforms
MLIRSideEffectInterfaces
MLIRSupport
)
)
Loading