Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d734a32
This commit is for adapting FLIR to Ascend and adds two passes Triton…
CHAIYD-2025 Nov 8, 2025
8e7a478
This patch is add the entry of th pass.
CHAIYD-2025 Nov 11, 2025
c671b9e
Migrating and adapting passes for ascend, including ToHFusion, Triton…
ikushare Nov 11, 2025
1e6b4db
TritonLinearize
ph0375 Nov 19, 2025
032cc38
Delete include/triton-shared/Analysis/.MaskAnalysis.h.swp
ph0375 Nov 19, 2025
9e46192
TritonToLinalgIncubated
ph0375 Nov 19, 2025
1322a41
Merge branch 'ascend_with_flir' of github.com:FlagTree/flir into asce…
ph0375 Nov 19, 2025
bbc6e4f
Delete lib/TritonToLinalgIncubated/.LoadStoreConverter.cpp.swp
ph0375 Nov 20, 2025
f5bbec7
Delete include/triton-shared/TritonToLinalgIncubated/,
ph0375 Nov 20, 2025
b69f0a6
name_fix
ph0375 Nov 21, 2025
0ae4152
Merge branch 'ascend_with_flir' of github.com:FlagTree/flir into asce…
ph0375 Nov 21, 2025
944f043
mlir_fix
ph0375 Nov 21, 2025
7c0e64b
mlir_fix
ph0375 Nov 21, 2025
7659c77
mlir
ph0375 Nov 21, 2025
fe9248c
Update LoadStoreConverter.cpp
ph0375 Nov 24, 2025
0a25002
Add includes for GPU and Math conversions
ph0375 Nov 24, 2025
b7e3bfd
Clean up CMakeLists.txt by removing unused settings
ph0375 Nov 24, 2025
8f60126
Delete include/triton-shared/mlir_compat.h
ph0375 Nov 24, 2025
21d7e65
Update LoadStoreConverter.cpp
ph0375 Nov 24, 2025
c1f710f
Update TritonToLinalgIncubatedPass.cpp
ph0375 Nov 24, 2025
4354632
TritonToUnstructureIncubated
ikushare Nov 25, 2025
fa54436
DiscreteMaskAccessConversion
ph0375 Nov 26, 2025
2fd30b6
TritonToAnnotation
ikushare Nov 27, 2025
a4b00f7
[BACKEND]Enhance hardware backend support
CHAIYD-2025 Dec 3, 2025
d554322
[FIX]Change name in UnifiedHardware.
CHAIYD-2025 Dec 5, 2025
6984c70
BubbleUpOperationPass
ikushare Dec 8, 2025
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ add_subdirectory(lib)
add_subdirectory(test)
add_subdirectory(tools)

set(ASCENDNPU_IR_SRC_DIR ${PROJECT_SOURCE_DIR}/third_party/ascendnpu-ir)
set(ASCENDNPU_IR_BINARY_DIR ${PROJECT_BINARY_DIR}/third_party/ascendnpu-ir)
set(BISHENGIR_BUILD_STANDALONE_IR_ONLY ON)
add_subdirectory(${ASCENDNPU_IR_SRC_DIR} ${ASCENDNPU_IR_BINARY_DIR})

if (TRITON_SHARED_BUILD_CPU_BACKEND)
add_triton_plugin(TritonShared ${CMAKE_CURRENT_SOURCE_DIR}/triton_shared.cc LINK_LIBS TritonSharedAnalysis TritonToLinalg TritonTilingExtIR)
endif()


60 changes: 59 additions & 1 deletion include/triton-shared/Analysis/MaskAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,59 @@
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "triton-shared/Analysis/OpFoldResultUtils.h"


#include "mlir/Support/LogicalResult.h"
#include "mlir/IR/OpDefinition.h"
#include "triton/Dialect/Triton/IR/Dialect.h"
#include "llvm/Support/LogicalResult.h"

#include "llvm/ADT/SmallVector.h"
#include "triton/Dialect/Triton/IR/Dialect.h"


#include <utility>

namespace mlir {

class OpBuilder;

namespace triton {

struct dimInfo {
OpFoldResult div;
OpFoldResult shape;
bool isSlt;
Value rhs; // rhs value of CmpIOp
bool isRealDim;
int64_t dim;
dimInfo() : isSlt(false), isRealDim(false), dim(0) {}
dimInfo(OpFoldResult div, OpFoldResult shape, int64_t dim = 0) : div(div), shape(shape), isSlt(false), isRealDim(true), dim(dim) {}
bool operator==(const dimInfo &other) const {
auto staticDiv = getIntAttr(div);
auto staticShape = getIntAttr(shape);
auto otherShape = getIntAttr(other.shape);
auto otherDiv = getIntAttr(other.div);
assert(staticDiv.has_value() && staticDiv.has_value() && otherDiv.has_value() && otherShape.has_value() && "MaskAnalysis: do not support dynamic shape/div");
return staticDiv.value() == otherDiv.value() && staticShape.value() == otherShape.value() && dim == other.dim;
}
void dump() const ;
bool hasModulo() const {
auto intAttr = getIntAttr(shape);
if (!intAttr.has_value()) {
return false;
}
return intAttr.value() != 0;
};
bool hasDivision() const {
auto intAttr = getIntAttr(div);
if (!intAttr.has_value()) {
return false;
}
return intAttr.value() != 0;
};
};
// Data structure used to decode the pattern in a mask used for load and store.
// start and end field represent the start and end index of a range (produced
// by make_range, addi, etc.). While multi-dimensional data is possible, we
Expand Down Expand Up @@ -50,7 +91,9 @@ struct MaskState {
SmallVector<OpFoldResult> dims;
OpFoldResult scalar;
const bool useUnsafeMask;

///ASCEND
SmallVector<dimInfo> stateInfo;

void dump() const;

MaskState(bool useUnsafeMask = false) : useUnsafeMask(useUnsafeMask) {}
Expand Down Expand Up @@ -80,6 +123,13 @@ struct MaskState {
std::pair<memref::SubViewOp, memref::SubViewOp>
getStackedSubviews(Value block1, Value block2, const Location loc,
OpBuilder &builder) const;
////ASCEND
tensor::InsertSliceOp getInsertSlice(Value source, Value dest,
const Location &loc,
OpBuilder &builder) const;


void eraseInsertedOps(Operation *rawOp, PatternRewriter &rewriter);

private:
// -------
Expand Down Expand Up @@ -156,6 +206,14 @@ struct MaskState {
// dimension that contains the range.
LogicalResult parseExpandDims(triton::ExpandDimsOp expandDimsOp,
const Location loc, OpBuilder &builder);
///////////////////ASCEND
LogicalResult parseRemsi(arith::RemSIOp remsiOp,
const Location loc,
OpBuilder &builder);

LogicalResult parseDivsi(arith::DivSIOp divsiOp,
const Location loc,
OpBuilder &builder) ;

LogicalResult parseLoopIterArg(Value v, const Location loc,
OpBuilder &builder);
Expand Down
10 changes: 10 additions & 0 deletions include/triton-shared/Analysis/OpFoldResultUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace mlir {

class OpBuilder;
Value materializeValue(OpBuilder &builder, Location loc, OpFoldResult ofr);

// Return integer if ofr is an IntegerAttr. Note that this function differs
// from getConstantIntValue, which returns an integer if ofr is the constant
Expand Down Expand Up @@ -52,7 +53,16 @@ OpFoldResult subOFRs(const OpFoldResult lhs, const OpFoldResult rhs,
// instruction if needed and use its result Value.
OpFoldResult mulOFRValue(const OpFoldResult lhs, const Value rhs,
const Location loc, OpBuilder &b);
////////////ASCEND
OpFoldResult divOFRs(const OpFoldResult lhs, const OpFoldResult rhs,
const Location loc, OpBuilder &b);

OpFoldResult remOFRs(const OpFoldResult lhs, const OpFoldResult rhs,
const Location loc, OpBuilder &b);
OpFoldResult mulOFRs(const OpFoldResult lhs, const OpFoldResult rhs,
const Location loc, OpBuilder &b);

/////////////ASCEND
OpFoldResult minOFRs(const OpFoldResult lhs, const OpFoldResult rhs,
const Location loc, OpBuilder &b);

Expand Down
110 changes: 110 additions & 0 deletions include/triton-shared/BubbleUpOperation/BubbleUpOperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

#include "mlir/Pass/Pass.h"
#include "triton/Dialect/Triton/IR/Dialect.h"

#include "mlir/IR/PatternMatch.h"

#define GEN_PASS_DECL_BUBBLEUPOPERATION
#include "triton-shared/BubbleUpOperation/Passes.h.inc"

#define GEN_PASS_DEF_BUBBLEUPOPERATION
#include "triton-shared/BubbleUpOperation/Passes.h.inc"

namespace mlir {
namespace triton {

std::unique_ptr<OperationPass<ModuleOp>>
createBubbleUpOperationPass(const BubbleUpOperationOptions &options = {});

} // namespace triton
} // namespace mlir

using namespace mlir;
using namespace triton;

template <typename ExtractOpTy>
class BubbleUpExtract : public OpRewritePattern<ExtractOpTy> {
static_assert(std::is_same_v<ExtractOpTy, tensor::ExtractOp> ||
std::is_same_v<ExtractOpTy, tensor::ExtractSliceOp>);

public:
using OpRewritePattern<ExtractOpTy>::OpRewritePattern;

explicit BubbleUpExtract(MLIRContext *context, bool enableAggressiveMode);

LogicalResult matchAndRewrite(ExtractOpTy op,
PatternRewriter &rewriter) const override;

private:
Value createExtractOp(ExtractOpTy op, Value value, Location loc,
PatternRewriter &rewriter) const;
template <typename BinOpTy>
void bubbleUpIntBinaryOp(ExtractOpTy op, BinOpTy binOp, Location loc,
PatternRewriter &rewriter) const;
template <typename BinOpTy>
void bubbleUpFloatBinaryOp(ExtractOpTy op, BinOpTy binOp, Location loc,
PatternRewriter &rewriter) const;

void bubbleUpOperation(ExtractOpTy op, arith::ExtSIOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, arith::CmpIOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, arith::TruncFOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, arith::ExtFOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, arith::FPToSIOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, arith::SIToFPOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, triton::ClampFOp parentOp,
Location loc, PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, arith::CmpFOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, triton::BroadcastOp parentOp,
Location loc, PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, triton::ExpandDimsOp parentOp,
Location loc, PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, triton::SplatOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, triton::MakeRangeOp parentOp,
Location loc, PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, math::FloorOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, math::CeilOp parentOp, Location loc,
PatternRewriter &rewriter) const;
void bubbleUpOperation(ExtractOpTy op, tensor::ExtractSliceOp parentOp, Location loc,
PatternRewriter &rewriter) const;

bool enableAggressiveMode;
};

class BubbleUpOperationPass
: public ::impl::BubbleUpOperationBase<BubbleUpOperationPass> {
public:
explicit BubbleUpOperationPass(const BubbleUpOperationOptions &options);
void runOnOperation() override;
};
3 changes: 3 additions & 0 deletions include/triton-shared/BubbleUpOperation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls --name BubbleUpOperation)
add_public_tablegen_target(BubbleUpOperationConversionPassIncGen)
37 changes: 37 additions & 0 deletions include/triton-shared/BubbleUpOperation/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef TRITON_ADAPTER_TRITON_TO_UNSTRUCTURE_CONVERSION_PASSES_H
#define TRITON_ADAPTER_TRITON_TO_UNSTRUCTURE_CONVERSION_PASSES_H

#include "BubbleUpOperation.h"

namespace mlir {
namespace triton {

#define GEN_PASS_REGISTRATION
#include "triton-shared/TritonToUnstructureIncubated/Passes.h.inc"

} // namespace triton
} // namespace mlir

#endif // TRITON_ADAPTER_TRITON_TO_UNSTRUCTURE_CONVERSION_PASSES_H
15 changes: 15 additions & 0 deletions include/triton-shared/BubbleUpOperation/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef TRITON_TO_UNSTRUCTURE_CONVERSION_PASSES
#define TRITON_TO_UNSTRUCTURE_CONVERSION_PASSES

include "mlir/Pass/PassBase.td"

def BubbleUpOperation : Pass<"bubble-up-operation", "mlir::ModuleOp"> {
let summary = "Apply bubble up operation optimization";
let constructor = "triton::createBubbleUpOperationPass()";
let options = [
Option<"enableAggressiveMode", "enable-aggressive-mode", "bool", "true",
"Enable aggressive bubble up operation.">,
];
}

#endif // TRITON_TO_UNSTRUCTURE_CONVERSION_PASSES
10 changes: 10 additions & 0 deletions include/triton-shared/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
add_subdirectory(Conversion)
add_subdirectory(Dialect)
add_subdirectory(TritonToAnnotation)
add_subdirectory(TritonToHIVM)
add_subdirectory(TritonToHFusion)
add_subdirectory(TritonToLinalgIncubated)
add_subdirectory(TritonToLLVM)
add_subdirectory(DiscreteMaskAccessConversion)
add_subdirectory(TritonToUnstructureIncubated)
#add_subdirectory(Dialect)
add_subdirectory(TritonLinearize)
add_subdirectory(BubbleUpOperation)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls --name DiscreteMaskAccessConversion)
add_public_tablegen_target(DiscreteMaskAccessConversionPassIncGen)
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef TRITON_ADAPTER_DISCRETEMASKACCESSCONVERSION_H
#define TRITON_ADAPTER_DISCRETEMASKACCESSCONVERSION_H

#include "mlir/Pass/Pass.h"
#include "triton/Dialect/Triton/IR/Dialect.h"

#include "mlir/IR/PatternMatch.h"

#define GEN_PASS_CLASSES
#if 0
#include "ascend/triton-adapter/include/DiscreteMaskAccessConversion/Passes.h.inc"
#else
#include "triton-shared/DiscreteMaskAccessConversion/Passes.h.inc"
#endif
//#include "../../include/DiscreteMaskAccessConversion/Passes.h.inc"

namespace mlir {
namespace triton {

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

} // namespace triton
} // namespace mlir

namespace {

using namespace mlir;
using namespace triton;

class DiscreteMaskAccessConversionPass
: public DiscreteMaskAccessConversionBase<DiscreteMaskAccessConversionPass> {
public:

void runOnOperation() override;
};

} // namespace

#endif // DISCRETE_MASK_ACCESS_CONVERSION_H
Loading