已合并
修改文件格式 #111
li-yuanjie-da创建于 4月21日
修改文件格式 #111
已合并
共 145 个文件变更+2141-2282
| @@ -11,7 +11,7 @@ | |||
| 11 | # Using clang-format to reformat a file: | 11 | # Using clang-format to reformat a file: |
| 12 | # clang-format -i -style=Google <file> | 12 | # clang-format -i -style=Google <file> |
| 13 | 13 | ||
| 14 | -BasedOnStyle: Google | 14 | +BasedOnStyle: LLVM |
| 15 | ColumnLimit: 120 | 15 | ColumnLimit: 120 |
| 16 | AccessModifierOffset: -4 | 16 | AccessModifierOffset: -4 |
| 17 | SortIncludes: false | 17 | SortIncludes: false |
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | using namespace mlir; | 16 | using namespace mlir; |
| 17 | 17 | ||
| 18 | -int main(int argc, char **argv) | 18 | +int main(int argc, char** argv) |
| 19 | { | 19 | { |
| 20 | DialectRegistry registry; | 20 | DialectRegistry registry; |
| 21 | ascir::registerDialects(registry); | 21 | ascir::registerDialects(registry); |
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | using namespace mlir; | 16 | using namespace mlir; |
| 17 | 17 | ||
| 18 | -int main(int argc, char **argv) | 18 | +int main(int argc, char** argv) |
| 19 | { | 19 | { |
| 20 | DialectRegistry registry; | 20 | DialectRegistry registry; |
| 21 | ascir::registerDialects(registry); | 21 | ascir::registerDialects(registry); |
| @@ -28,14 +28,14 @@ | |||
| 28 | 28 | ||
| 29 | using namespace mlir; | 29 | using namespace mlir; |
| 30 | 30 | ||
| 31 | -int main(int argc, char **argv) | 31 | +int main(int argc, char** argv) |
| 32 | { | 32 | { |
| 33 | registerAllTranslations(); | 33 | registerAllTranslations(); |
| 34 | 34 | ||
| 35 | TranslateFromMLIRRegistration reg( | 35 | TranslateFromMLIRRegistration reg( |
| 36 | "mlir-to-ascendc", "translate from mlir to Ascend C", | 36 | "mlir-to-ascendc", "translate from mlir to Ascend C", |
| 37 | - [](Operation *op, raw_ostream &output) { return translateToAscendC(op, output); }, | 37 | + [](Operation* op, raw_ostream& output) { return translateToAscendC(op, output); }, |
| 38 | - [](DialectRegistry ®istry) { | 38 | + [](DialectRegistry& registry) { |
| 39 | registry.insert< | 39 | registry.insert< |
| 40 | // | 40 | // |
| 41 | arith::ArithDialect, ascendc::AscendCDialect, cf::ControlFlowDialect, DLTIDialect, | 41 | arith::ArithDialect, ascendc::AscendCDialect, cf::ControlFlowDialect, DLTIDialect, |
| @@ -41,19 +41,19 @@ | |||
| 41 | namespace mlir { | 41 | namespace mlir { |
| 42 | namespace ascendc { | 42 | namespace ascendc { |
| 43 | 43 | ||
| 44 | -ParseResult parsePrettyTPosition(AsmParser &odsParser, TPositionAttr &attr); | 44 | +ParseResult parsePrettyTPosition(AsmParser& odsParser, TPositionAttr& attr); |
| 45 | -void printPrettyTPosition(AsmPrinter &odsPrinter, const TPositionAttr &attr); | 45 | +void printPrettyTPosition(AsmPrinter& odsPrinter, const TPositionAttr& attr); |
| 46 | 46 | ||
| 47 | -ParseResult parsePrettyCubeFormat(AsmParser &odsParser, CubeFormatAttr &attr); | 47 | +ParseResult parsePrettyCubeFormat(AsmParser& odsParser, CubeFormatAttr& attr); |
| 48 | -void printPrettyCubeFormat(AsmPrinter &odsPrinter, const CubeFormatAttr &attr); | 48 | +void printPrettyCubeFormat(AsmPrinter& odsPrinter, const CubeFormatAttr& attr); |
| 49 | 49 | ||
| 50 | -ParseResult parsePrettyLayoutMode(AsmParser &odsParser, LayoutModeAttr &attr); | 50 | +ParseResult parsePrettyLayoutMode(AsmParser& odsParser, LayoutModeAttr& attr); |
| 51 | -void printPrettyLayoutMode(AsmPrinter &odsPrinter, const LayoutModeAttr &attr); | 51 | +void printPrettyLayoutMode(AsmPrinter& odsPrinter, const LayoutModeAttr& attr); |
| 52 | 52 | ||
| 53 | -ParseResult parsePrettyCO2Layout(AsmParser &odsParser, CO2LayoutAttr &attr); | 53 | +ParseResult parsePrettyCO2Layout(AsmParser& odsParser, CO2LayoutAttr& attr); |
| 54 | -void printPrettyCO2Layout(AsmPrinter &odsPrinter, const CO2LayoutAttr &attr); | 54 | +void printPrettyCO2Layout(AsmPrinter& odsPrinter, const CO2LayoutAttr& attr); |
| 55 | 55 | ||
| 56 | -void registerExternalModels(DialectRegistry ®istry); | 56 | +void registerExternalModels(DialectRegistry& registry); |
| 57 | 57 | ||
| 58 | } // namespace ascendc | 58 | } // namespace ascendc |
| 59 | } // namespace mlir | 59 | } // namespace mlir |
| @@ -15,7 +15,7 @@ namespace mlir { | |||
| 15 | namespace OpTrait { | 15 | namespace OpTrait { |
| 16 | template <typename ConcreteOp> | 16 | template <typename ConcreteOp> |
| 17 | struct AscConstructorTrait : public TraitBase<ConcreteOp, AscConstructorTrait> { | 17 | struct AscConstructorTrait : public TraitBase<ConcreteOp, AscConstructorTrait> { |
| 18 | - static mlir::LogicalResult verifyTrait(Operation *op) | 18 | + static mlir::LogicalResult verifyTrait(Operation* op) |
| 19 | { | 19 | { |
| 20 | if (op->getNumResults() != 1) { | 20 | if (op->getNumResults() != 1) { |
| 21 | return op->emitError("AscConstructorTrait must have a result"); | 21 | return op->emitError("AscConstructorTrait must have a result"); |
| @@ -26,7 +26,7 @@ struct AscConstructorTrait : public TraitBase<ConcreteOp, AscConstructorTrait> { | |||
| 26 | 26 | ||
| 27 | template <typename ConcreteOp> | 27 | template <typename ConcreteOp> |
| 28 | struct AscMemberFuncTrait : public TraitBase<ConcreteOp, AscMemberFuncTrait> { | 28 | struct AscMemberFuncTrait : public TraitBase<ConcreteOp, AscMemberFuncTrait> { |
| 29 | - static mlir::LogicalResult verifyTrait(Operation *op) | 29 | + static mlir::LogicalResult verifyTrait(Operation* op) |
| 30 | { | 30 | { |
| 31 | if (op->getNumOperands() < 1 || op->getNumResults() > 1) { | 31 | if (op->getNumOperands() < 1 || op->getNumResults() > 1) { |
| 32 | return op->emitError("AscMemberFuncTrait must have more than one inputs and less than one return value"); | 32 | return op->emitError("AscMemberFuncTrait must have more than one inputs and less than one return value"); |
| @@ -37,7 +37,7 @@ struct AscMemberFuncTrait : public TraitBase<ConcreteOp, AscMemberFuncTrait> { | |||
| 37 | 37 | ||
| 38 | template <typename ConcreteOp> | 38 | template <typename ConcreteOp> |
| 39 | struct AscFuncTrait : public TraitBase<ConcreteOp, AscFuncTrait> { | 39 | struct AscFuncTrait : public TraitBase<ConcreteOp, AscFuncTrait> { |
| 40 | - static mlir::LogicalResult verifyTrait(Operation *op) | 40 | + static mlir::LogicalResult verifyTrait(Operation* op) |
| 41 | { | 41 | { |
| 42 | if (op->getNumResults() > 1) { | 42 | if (op->getNumResults() > 1) { |
| 43 | return op->emitError("AscFunc trait only support less than one return value"); | 43 | return op->emitError("AscFunc trait only support less than one return value"); |
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | -#define LITERAL constexpr const char * | 13 | +#define LITERAL constexpr const char* |
| 14 | 14 | ||
| 15 | namespace mlir { | 15 | namespace mlir { |
| 16 | namespace ascendc { | 16 | namespace ascendc { |
| @@ -24,14 +24,11 @@ template <typename OpT> | |||
| 24 | struct HoistOpPattern : public OpRewritePattern<OpT> { | 24 | struct HoistOpPattern : public OpRewritePattern<OpT> { |
| 25 | using OpRewritePattern<OpT>::OpRewritePattern; | 25 | using OpRewritePattern<OpT>::OpRewritePattern; |
| 26 | 26 | ||
| 27 | - virtual bool hoistable(OpT) const | 27 | + virtual bool hoistable(OpT) const { return true; } |
| 28 | - { | ||
| 29 | - return true; | ||
| 30 | - } | ||
| 31 | 28 | ||
| 32 | - LogicalResult matchAndRewrite(OpT op, PatternRewriter &rewriter) const override | 29 | + LogicalResult matchAndRewrite(OpT op, PatternRewriter& rewriter) const override |
| 33 | { | 30 | { |
| 34 | - Operation *parent = op->getParentOp(); | 31 | + Operation* parent = op->getParentOp(); |
| 35 | if (isa<func::FuncOp>(parent)) | 32 | if (isa<func::FuncOp>(parent)) |
| 36 | return failure(); | 33 | return failure(); |
| 37 | if (!hoistable(op)) | 34 | if (!hoistable(op)) |
| @@ -47,11 +44,11 @@ struct HoistOpPattern : public OpRewritePattern<OpT> { | |||
| 47 | } | 44 | } |
| 48 | }; | 45 | }; |
| 49 | 46 | ||
| 50 | -bool opPrecedes(Operation *lhs, Operation *rhs); | 47 | +bool opPrecedes(Operation* lhs, Operation* rhs); |
| 51 | 48 | ||
| 52 | -bool opPrecedes(Operation *lhs, Operation *rhs, DominanceInfo &di); | 49 | +bool opPrecedes(Operation* lhs, Operation* rhs, DominanceInfo& di); |
| 53 | 50 | ||
| 54 | -void registerInlinerInterfaces(DialectRegistry ®istry); | 51 | +void registerInlinerInterfaces(DialectRegistry& registry); |
| 55 | 52 | ||
| 56 | } // namespace ascendc | 53 | } // namespace ascendc |
| 57 | } // namespace mlir | 54 | } // namespace mlir |
| @@ -34,7 +34,7 @@ | |||
| 34 | namespace mlir { | 34 | namespace mlir { |
| 35 | namespace emitasc { | 35 | namespace emitasc { |
| 36 | 36 | ||
| 37 | -void registerExternalModels(DialectRegistry ®istry); | 37 | +void registerExternalModels(DialectRegistry& registry); |
| 38 | 38 | ||
| 39 | } // namespace emitasc | 39 | } // namespace emitasc |
| 40 | } // namespace mlir | 40 | } // namespace mlir |
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | -#define LITERAL constexpr const char * | 13 | +#define LITERAL constexpr const char* |
| 14 | 14 | ||
| 15 | namespace mlir { | 15 | namespace mlir { |
| 16 | namespace emitasc { | 16 | namespace emitasc { |
| @@ -20,7 +20,7 @@ namespace ascir { | |||
| 20 | struct ConstantOpBuilder { | 20 | struct ConstantOpBuilder { |
| 21 | using ConstantOp = ::mlir::arith::ConstantOp; | 21 | using ConstantOp = ::mlir::arith::ConstantOp; |
| 22 | 22 | ||
| 23 | - ConstantOpBuilder(OpBuilder &builder) : builder(builder) {} | 23 | + ConstantOpBuilder(OpBuilder& builder) : builder(builder) {} |
| 24 | ~ConstantOpBuilder() = default; | 24 | ~ConstantOpBuilder() = default; |
| 25 | 25 | ||
| 26 | ConstantOp create(TypedAttr attr) | 26 | ConstantOp create(TypedAttr attr) |
| @@ -29,60 +29,27 @@ struct ConstantOpBuilder { | |||
| 29 | return op; | 29 | return op; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | - ConstantOp create(IndexType type, int64_t value) | 32 | + ConstantOp create(IndexType type, int64_t value) { return create(builder.getIndexAttr(value)); } |
| 33 | - { | ||
| 34 | - return create(builder.getIndexAttr(value)); | ||
| 35 | - } | ||
| 36 | 33 | ||
| 37 | - ConstantOp create(IntegerType type, int64_t value) | 34 | + ConstantOp create(IntegerType type, int64_t value) { return create(builder.getIntegerAttr(type, value)); } |
| 38 | - { | ||
| 39 | - return create(builder.getIntegerAttr(type, value)); | ||
| 40 | - } | ||
| 41 | 35 | ||
| 42 | - ConstantOp create(FloatType type, double value) | 36 | + ConstantOp create(FloatType type, double value) { return create(builder.getFloatAttr(type, value)); } |
| 43 | - { | ||
| 44 | - return create(builder.getFloatAttr(type, value)); | ||
| 45 | - } | ||
| 46 | 37 | ||
| 47 | - Value index(int64_t value) | 38 | + Value index(int64_t value) { return create(builder.getIndexType(), value); } |
| 48 | - { | ||
| 49 | - return create(builder.getIndexType(), value); | ||
| 50 | - } | ||
| 51 | 39 | ||
| 52 | - Value i64(int64_t value) | 40 | + Value i64(int64_t value) { return create(builder.getI64Type(), value); } |
| 53 | - { | ||
| 54 | - return create(builder.getI64Type(), value); | ||
| 55 | - } | ||
| 56 | 41 | ||
| 57 | - Value i32(int32_t value) | 42 | + Value i32(int32_t value) { return create(builder.getI32Type(), value); } |
| 58 | - { | ||
| 59 | - return create(builder.getI32Type(), value); | ||
| 60 | - } | ||
| 61 | 43 | ||
| 62 | - Value i16(int16_t value) | 44 | + Value i16(int16_t value) { return create(builder.getI16Type(), value); } |
| 63 | - { | ||
| 64 | - return create(builder.getI16Type(), value); | ||
| 65 | - } | ||
| 66 | 45 | ||
| 67 | - Value i8(int8_t value) | 46 | + Value i8(int8_t value) { return create(builder.getI8Type(), value); } |
| 68 | - { | ||
| 69 | - return create(builder.getI8Type(), value); | ||
| 70 | - } | ||
| 71 | 47 | ||
| 72 | - Value f64(double value) | 48 | + Value f64(double value) { return create(builder.getF64Type(), value); } |
| 73 | - { | ||
| 74 | - return create(builder.getF64Type(), value); | ||
| 75 | - } | ||
| 76 | 49 | ||
| 77 | - Value f32(float value) | 50 | + Value f32(float value) { return create(builder.getF32Type(), value); } |
| 78 | - { | ||
| 79 | - return create(builder.getF32Type(), value); | ||
| 80 | - } | ||
| 81 | 51 | ||
| 82 | - Value f16(float value) | 52 | + Value f16(float value) { return create(builder.getF16Type(), value); } |
| 83 | - { | ||
| 84 | - return create(builder.getF16Type(), value); | ||
| 85 | - } | ||
| 86 | 53 | ||
| 87 | template <typename IntType> | 54 | template <typename IntType> |
| 88 | Value integer(IntType value) | 55 | Value integer(IntType value) |
| @@ -90,8 +57,8 @@ struct ConstantOpBuilder { | |||
| 90 | return create(builder.getIntegerType(sizeof(IntType) * CHAR_BIT), value); | 57 | return create(builder.getIntegerType(sizeof(IntType) * CHAR_BIT), value); |
| 91 | } | 58 | } |
| 92 | 59 | ||
| 93 | - private: | 60 | +private: |
| 94 | - OpBuilder &builder; | 61 | + OpBuilder& builder; |
| 95 | }; | 62 | }; |
| 96 | 63 | ||
| 97 | } // namespace ascir | 64 | } // namespace ascir |
| @@ -20,33 +20,21 @@ template <typename... AllowedOpT> | |||
| 20 | struct AllowlistInlinerInterface : public DialectInlinerInterface { | 20 | struct AllowlistInlinerInterface : public DialectInlinerInterface { |
| 21 | using DialectInlinerInterface::DialectInlinerInterface; | 21 | using DialectInlinerInterface::DialectInlinerInterface; |
| 22 | 22 | ||
| 23 | - bool isLegalToInline(Operation *op, Region *, bool, IRMapping &) const override | 23 | + bool isLegalToInline(Operation* op, Region*, bool, IRMapping&) const override { return isa<AllowedOpT...>(op); } |
| 24 | - { | ||
| 25 | - return isa<AllowedOpT...>(op); | ||
| 26 | - } | ||
| 27 | }; | 24 | }; |
| 28 | 25 | ||
| 29 | struct PermissiveInlinerInterface : public DialectInlinerInterface { | 26 | struct PermissiveInlinerInterface : public DialectInlinerInterface { |
| 30 | using DialectInlinerInterface::DialectInlinerInterface; | 27 | using DialectInlinerInterface::DialectInlinerInterface; |
| 31 | 28 | ||
| 32 | - bool isLegalToInline(Operation *, Operation *, bool) const override | 29 | + bool isLegalToInline(Operation*, Operation*, bool) const override { return true; } |
| 33 | - { | ||
| 34 | - return true; | ||
| 35 | - } | ||
| 36 | 30 | ||
| 37 | - bool isLegalToInline(Region *, Region *, bool, IRMapping &) const override | 31 | + bool isLegalToInline(Region*, Region*, bool, IRMapping&) const override { return true; } |
| 38 | - { | ||
| 39 | - return true; | ||
| 40 | - } | ||
| 41 | 32 | ||
| 42 | - bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const override | 33 | + bool isLegalToInline(Operation*, Region*, bool, IRMapping&) const override { return true; } |
| 43 | - { | ||
| 44 | - return true; | ||
| 45 | - } | ||
| 46 | 34 | ||
| 47 | - void handleTerminator(Operation *, Block *) const override {} | 35 | + void handleTerminator(Operation*, Block*) const override {} |
| 48 | 36 | ||
| 49 | - void handleTerminator(Operation *, ValueRange) const override {} | 37 | + void handleTerminator(Operation*, ValueRange) const override {} |
| 50 | }; | 38 | }; |
| 51 | 39 | ||
| 52 | } // namespace ascir | 40 | } // namespace ascir |
| @@ -22,7 +22,7 @@ | |||
| 22 | namespace mlir { | 22 | namespace mlir { |
| 23 | namespace ascir { | 23 | namespace ascir { |
| 24 | 24 | ||
| 25 | -inline void registerDialects(DialectRegistry ®istry) | 25 | +inline void registerDialects(DialectRegistry& registry) |
| 26 | { | 26 | { |
| 27 | registerAllDialects(registry); | 27 | registerAllDialects(registry); |
| 28 | registry.insert<ascendc::AscendCDialect, emitasc::EmitAscDialect>(); | 28 | registry.insert<ascendc::AscendCDialect, emitasc::EmitAscDialect>(); |
| @@ -30,10 +30,7 @@ inline void registerDialects(DialectRegistry ®istry) | |||
| 30 | emitasc::registerExternalModels(registry); | 30 | emitasc::registerExternalModels(registry); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | -inline void registerExtensions(DialectRegistry ®istry) | 33 | +inline void registerExtensions(DialectRegistry& registry) { registerAllExtensions(registry); } |
| 34 | -{ | ||
| 35 | - registerAllExtensions(registry); | ||
| 36 | -} | ||
| 37 | 34 | ||
| 38 | inline void registerPasses() | 35 | inline void registerPasses() |
| 39 | { | 36 | { |
| @@ -21,11 +21,8 @@ namespace mlir { | |||
| 21 | 21 | ||
| 22 | template <typename T> | 22 | template <typename T> |
| 23 | struct PointerLikeTypeHash { | 23 | struct PointerLikeTypeHash { |
| 24 | - std::hash<const void *> h; | 24 | + std::hash<const void*> h; |
| 25 | - size_t operator()(const T &op) const | 25 | + size_t operator()(const T& op) const { return h(op.getAsOpaquePointer()); } |
| 26 | - { | ||
| 27 | - return h(op.getAsOpaquePointer()); | ||
| 28 | - } | ||
| 29 | }; | 26 | }; |
| 30 | 27 | ||
| 31 | template <typename T> | 28 | template <typename T> |
| @@ -16,9 +16,9 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | namespace ascendc { | 17 | namespace ascendc { |
| 18 | 18 | ||
| 19 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SimpleSoftMaxOp op); | 19 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SimpleSoftMaxOp op); |
| 20 | 20 | ||
| 21 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SoftMaxOp op); | 21 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SoftMaxOp op); |
| 22 | 22 | ||
| 23 | } // namespace ascendc | 23 | } // namespace ascendc |
| 24 | } // namespace mlir | 24 | } // namespace mlir |
| @@ -18,15 +18,15 @@ namespace ascendc { | |||
| 18 | 18 | ||
| 19 | // Resource Management | 19 | // Resource Management |
| 20 | 20 | ||
| 21 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::KfcInitOp op); | 21 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::KfcInitOp op); |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::KfcInitObjOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::KfcInitObjOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::KfcIsRunOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::KfcIsRunOp op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::KfcRunOp op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::KfcRunOp op); |
| 28 | 28 | ||
| 29 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::KfcQuitOp op); | 29 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::KfcQuitOp op); |
| 30 | 30 | ||
| 31 | } // namespace ascendc | 31 | } // namespace ascendc |
| 32 | } // namespace mlir | 32 | } // namespace mlir |
| @@ -21,14 +21,13 @@ namespace ascendc { | |||
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename UnaryMathOp> | 23 | template <typename UnaryMathOp> |
| 24 | -auto printOperation(CodeEmitter &emitter, UnaryMathOp op) | 24 | +auto printOperation(CodeEmitter& emitter, UnaryMathOp op) -> LogicalResultForT< |
| 25 | - -> LogicalResultForT<UnaryMathOp, ascendc::AcoshOp, ascendc::AcosOp, ascendc::AsinhOp, ascendc::AsinOp, | 25 | + UnaryMathOp, ascendc::AcoshOp, ascendc::AcosOp, ascendc::AsinhOp, ascendc::AsinOp, ascendc::AtanhOp, |
| 26 | - ascendc::AtanhOp, ascendc::AtanOp, ascendc::CeilOp, ascendc::CoshOp, ascendc::CosOp, | 26 | + ascendc::AtanOp, ascendc::CeilOp, ascendc::CoshOp, ascendc::CosOp, ascendc::DigammaOp, ascendc::ErfcOp, |
| 27 | - ascendc::DigammaOp, ascendc::ErfcOp, ascendc::ErfOp, ascendc::FloorOp, ascendc::FracOp, | 27 | + ascendc::ErfOp, ascendc::FloorOp, ascendc::FracOp, ascendc::LgammaOp, ascendc::LogOp, ascendc::RoundOp, |
| 28 | - ascendc::LgammaOp, ascendc::LogOp, ascendc::RoundOp, ascendc::SignOp, ascendc::SinhOp, | 28 | + ascendc::SignOp, ascendc::SinhOp, ascendc::SinOp, ascendc::TanhOp, ascendc::TanOp, ascendc::TruncOp> |
| 29 | - ascendc::SinOp, ascendc::TanhOp, ascendc::TanOp, ascendc::TruncOp> | ||
| 30 | { | 29 | { |
| 31 | - auto &os = emitter.ostream(); | 30 | + auto& os = emitter.ostream(); |
| 32 | os << ascNamespace << "::" << op.getAPIName(); | 31 | os << ascNamespace << "::" << op.getAPIName(); |
| 33 | os << "<"; | 32 | os << "<"; |
| 34 | auto dstType = op.getDst().getType().getElementType(); | 33 | auto dstType = op.getDst().getType().getElementType(); |
| @@ -50,9 +49,9 @@ auto printOperation(CodeEmitter &emitter, UnaryMathOp op) | |||
| 50 | //===----------------------------------------------------------------------===// | 49 | //===----------------------------------------------------------------------===// |
| 51 | 50 | ||
| 52 | template <typename BinaryMathOp> | 51 | template <typename BinaryMathOp> |
| 53 | -LogicalResultForT<BinaryMathOp, ascendc::PowerOp, ascendc::XorOp> printOperation(CodeEmitter &emitter, BinaryMathOp op) | 52 | +LogicalResultForT<BinaryMathOp, ascendc::PowerOp, ascendc::XorOp> printOperation(CodeEmitter& emitter, BinaryMathOp op) |
| 54 | { | 53 | { |
| 55 | - auto &os = emitter.ostream(); | 54 | + auto& os = emitter.ostream(); |
| 56 | os << ascNamespace << "::" << op.getAPIName(); | 55 | os << ascNamespace << "::" << op.getAPIName(); |
| 57 | os << "<"; | 56 | os << "<"; |
| 58 | auto dstType = op.getDst().getType().getElementType(); | 57 | auto dstType = op.getDst().getType().getElementType(); |
| @@ -75,9 +74,9 @@ LogicalResultForT<BinaryMathOp, ascendc::PowerOp, ascendc::XorOp> printOperation | |||
| 75 | //===----------------------------------------------------------------------===// | 74 | //===----------------------------------------------------------------------===// |
| 76 | 75 | ||
| 77 | template <typename Clamp> | 76 | template <typename Clamp> |
| 78 | -LogicalResultForT<Clamp, ascendc::ClampMaxOp, ascendc::ClampMinOp> printOperation(CodeEmitter &emitter, Clamp op) | 77 | +LogicalResultForT<Clamp, ascendc::ClampMaxOp, ascendc::ClampMinOp> printOperation(CodeEmitter& emitter, Clamp op) |
| 79 | { | 78 | { |
| 80 | - auto &os = emitter.ostream(); | 79 | + auto& os = emitter.ostream(); |
| 81 | os << ascNamespace << "::" << op.getAPIName(); | 80 | os << ascNamespace << "::" << op.getAPIName(); |
| 82 | os << "<"; | 81 | os << "<"; |
| 83 | auto dstType = op.getDst().getType().getElementType(); | 82 | auto dstType = op.getDst().getType().getElementType(); |
| @@ -92,11 +91,11 @@ LogicalResultForT<Clamp, ascendc::ClampMaxOp, ascendc::ClampMinOp> printOperatio | |||
| 92 | return success(); | 91 | return success(); |
| 93 | } | 92 | } |
| 94 | 93 | ||
| 95 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ExpOp op); | 94 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ExpOp op); |
| 96 | 95 | ||
| 97 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::AxpyOp op); | 96 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::AxpyOp op); |
| 98 | 97 | ||
| 99 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CumSumOp op); | 98 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CumSumOp op); |
| 100 | 99 | ||
| 101 | } // namespace ascendc | 100 | } // namespace ascendc |
| 102 | } // namespace mlir | 101 | } // namespace mlir |
| @@ -15,13 +15,13 @@ | |||
| 15 | 15 | ||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | namespace ascendc { | 17 | namespace ascendc { |
| 18 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::MatmulInitOp op); | 18 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::MatmulInitOp op); |
| 19 | 19 | ||
| 20 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::MatmulGetMatmulApiTilingOp op); | 20 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::MatmulGetMatmulApiTilingOp op); |
| 21 | 21 | ||
| 22 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::MatmulEndOp op); | 22 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::MatmulEndOp op); |
| 23 | 23 | ||
| 24 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::RegistMatmulObjOp op); | 24 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::RegistMatmulObjOp op); |
| 25 | 25 | ||
| 26 | } // namespace ascendc | 26 | } // namespace ascendc |
| 27 | } // namespace mlir | 27 | } // namespace mlir |
| @@ -16,7 +16,7 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | namespace ascendc { | 17 | namespace ascendc { |
| 18 | 18 | ||
| 19 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::RmsNormOp op); | 19 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::RmsNormOp op); |
| 20 | 20 | ||
| 21 | } // namespace ascendc | 21 | } // namespace ascendc |
| 22 | } // namespace mlir | 22 | } // namespace mlir |
| @@ -16,7 +16,7 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | namespace ascendc { | 17 | namespace ascendc { |
| 18 | 18 | ||
| 19 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::QuantOp op); | 19 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::QuantOp op); |
| 20 | 20 | ||
| 21 | } // namespace ascendc | 21 | } // namespace ascendc |
| 22 | } // namespace mlir | 22 | } // namespace mlir |
| @@ -20,7 +20,7 @@ namespace ascendc { | |||
| 20 | // AIPP operations | 20 | // AIPP operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, SetAippFunctionsOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, SetAippFunctionsOp op); |
| 24 | 24 | ||
| 25 | } // namespace ascendc | 25 | } // namespace ascendc |
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| @@ -20,13 +20,13 @@ namespace ascendc { | |||
| 20 | // Synchronization operations | 20 | // Synchronization operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::PipeBarrierOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::PipeBarrierOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::WaitFlagOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::WaitFlagOp op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CrossCoreSetFlagOp op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CrossCoreSetFlagOp op); |
| 28 | 28 | ||
| 29 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CrossCoreWaitFlagOp op); | 29 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CrossCoreWaitFlagOp op); |
| 30 | 30 | ||
| 31 | } // namespace ascendc | 31 | } // namespace ascendc |
| 32 | } // namespace mlir | 32 | } // namespace mlir |
| @@ -20,11 +20,11 @@ namespace ascendc { | |||
| 20 | // Data Conversion operations | 20 | // Data Conversion operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TransDataTo5HDTensorListOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TransDataTo5HDTensorListOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TransDataTo5HDUintListOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TransDataTo5HDUintListOp op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TransDataTo5HDOp op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TransDataTo5HDOp op); |
| 28 | 28 | ||
| 29 | } // namespace ascendc | 29 | } // namespace ascendc |
| 30 | } // namespace mlir | 30 | } // namespace mlir |
| @@ -20,11 +20,11 @@ namespace ascendc { | |||
| 20 | // Data copy operations | 20 | // Data copy operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::DataCopySliceOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::DataCopySliceOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CopyL0Op op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CopyL0Op op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CopyL1Op op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CopyL1Op op); |
| 28 | 28 | ||
| 29 | } // namespace ascendc | 29 | } // namespace ascendc |
| 30 | } // namespace mlir | 30 | } // namespace mlir |
| @@ -20,7 +20,7 @@ namespace ascendc { | |||
| 20 | // Debug operations | 20 | // Debug operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::PrintfOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::PrintfOp op); |
| 24 | 24 | ||
| 25 | } // namespace ascendc | 25 | } // namespace ascendc |
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| @@ -16,7 +16,7 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | namespace ascendc { | 17 | namespace ascendc { |
| 18 | 18 | ||
| 19 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TensorDescOp op); | 19 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TensorDescOp op); |
| 20 | 20 | ||
| 21 | LogicalResult printOperation(CodeEmitter& emitter, ascendc::TensorDescSetShapeAddrOp op); | 21 | LogicalResult printOperation(CodeEmitter& emitter, ascendc::TensorDescSetShapeAddrOp op); |
| 22 | 22 | ||
| @@ -21,10 +21,10 @@ namespace ascendc { | |||
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename CVOp> | 23 | template <typename CVOp> |
| 24 | -LogicalResultForT<CVOp, ascendc::AscendIsAICOp, ascendc::AscendIsAIVOp> printOperation(CodeEmitter &emitter, CVOp op) | 24 | +LogicalResultForT<CVOp, ascendc::AscendIsAICOp, ascendc::AscendIsAIVOp> printOperation(CodeEmitter& emitter, CVOp op) |
| 25 | { | 25 | { |
| 26 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 26 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 27 | - auto &os = emitter.ostream(); | 27 | + auto& os = emitter.ostream(); |
| 28 | os << " = g_coreType == AscendC::"; | 28 | os << " = g_coreType == AscendC::"; |
| 29 | if (isa<ascendc::AscendIsAICOp>(op)) { | 29 | if (isa<ascendc::AscendIsAICOp>(op)) { |
| 30 | os << "AIC"; | 30 | os << "AIC"; |
| @@ -34,32 +34,32 @@ LogicalResultForT<CVOp, ascendc::AscendIsAICOp, ascendc::AscendIsAIVOp> printOpe | |||
| 34 | return success(); | 34 | return success(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ConstructOp op); | 37 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ConstructOp op); |
| 38 | 38 | ||
| 39 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::FftsCrossCoreSyncOp op); | 39 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::FftsCrossCoreSyncOp op); |
| 40 | 40 | ||
| 41 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GetMrgSortResultOp op); | 41 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GetMrgSortResultOp op); |
| 42 | 42 | ||
| 43 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::MrgSortOp op); | 43 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::MrgSortOp op); |
| 44 | 44 | ||
| 45 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SortOp op); | 45 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SortOp op); |
| 46 | 46 | ||
| 47 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::PopStackBufferOp op); | 47 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::PopStackBufferOp op); |
| 48 | 48 | ||
| 49 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SetFftsBaseAddrOp op); | 49 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetFftsBaseAddrOp op); |
| 50 | 50 | ||
| 51 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ResetMaskOp op); | 51 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ResetMaskOp op); |
| 52 | 52 | ||
| 53 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::FixpipeOp op); | 53 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::FixpipeOp op); |
| 54 | 54 | ||
| 55 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::FixpipeWithWorkspaceOp op); | 55 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::FixpipeWithWorkspaceOp op); |
| 56 | 56 | ||
| 57 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GetStoreAtomicConfigOp op); | 57 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GetStoreAtomicConfigOp op); |
| 58 | 58 | ||
| 59 | template <typename FixpipeOp> | 59 | template <typename FixpipeOp> |
| 60 | -auto printFixpipeTemplate(CodeEmitter &emitter, FixpipeOp op) | 60 | +auto printFixpipeTemplate(CodeEmitter& emitter, FixpipeOp op) |
| 61 | { | 61 | { |
| 62 | - auto &os = emitter.ostream(); | 62 | + auto& os = emitter.ostream(); |
| 63 | auto dstType = cast<ascendc::GlobalTensorType>(op.getDst().getType()).getElementType(); | 63 | auto dstType = cast<ascendc::GlobalTensorType>(op.getDst().getType()).getElementType(); |
| 64 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 64 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| 65 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 65 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -77,7 +77,7 @@ auto printFixpipeTemplate(CodeEmitter &emitter, FixpipeOp op) | |||
| 77 | 77 | ||
| 78 | } // namespace ascendc | 78 | } // namespace ascendc |
| 79 | 79 | ||
| 80 | -LogicalResult printOperation(CodeEmitter &emitter, LLVM::UndefOp op); | 80 | +LogicalResult printOperation(CodeEmitter& emitter, LLVM::UndefOp op); |
| 81 | 81 | ||
| 82 | } // namespace mlir | 82 | } // namespace mlir |
| 83 | 83 | ||
| @@ -20,7 +20,7 @@ namespace ascendc { | |||
| 20 | // Scalar operations | 20 | // Scalar operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ScalarCastOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ScalarCastOp op); |
| 24 | 24 | ||
| 25 | } // namespace ascendc | 25 | } // namespace ascendc |
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| @@ -20,9 +20,9 @@ namespace ascendc { | |||
| 20 | // Memory swap and workspace operations | 20 | // Memory swap and workspace operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GetSysWorkspacePtrOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GetSysWorkspacePtrOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SetSysWorkspaceOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetSysWorkspaceOp op); |
| 26 | 26 | ||
| 27 | } // namespace ascendc | 27 | } // namespace ascendc |
| 28 | } // namespace mlir | 28 | } // namespace mlir |
| @@ -20,9 +20,9 @@ namespace ascendc { | |||
| 20 | // System Variable operations | 20 | // System Variable operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GetBlockIdxOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GetBlockIdxOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GetBlockNumOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GetBlockNumOp op); |
| 26 | 26 | ||
| 27 | } // namespace ascendc | 27 | } // namespace ascendc |
| 28 | } // namespace mlir | 28 | } // namespace mlir |
| @@ -16,9 +16,9 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | namespace ascendc { | 17 | namespace ascendc { |
| 18 | 18 | ||
| 19 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BilinearInterpolationL0Op op); | 19 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BilinearInterpolationL0Op op); |
| 20 | 20 | ||
| 21 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BilinearInterpolationL1Op op); | 21 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BilinearInterpolationL1Op op); |
| 22 | 22 | ||
| 23 | } // namespace ascendc | 23 | } // namespace ascendc |
| 24 | } // namespace mlir | 24 | } // namespace mlir |
| @@ -21,44 +21,44 @@ namespace ascendc { | |||
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename BinaryOp> | 23 | template <typename BinaryOp> |
| 24 | -auto printBinaryL0Params(CodeEmitter &emitter, BinaryOp op) | 24 | +auto printBinaryL0Params(CodeEmitter& emitter, BinaryOp op) |
| 25 | { | 25 | { |
| 26 | - auto &os = emitter.ostream(); | 26 | + auto& os = emitter.ostream(); |
| 27 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " | 27 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " |
| 28 | << emitter.getOrCreateName(op.getSrc1()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " | 28 | << emitter.getOrCreateName(op.getSrc1()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " |
| 29 | << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | 29 | << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | template <typename BinaryOp> | 32 | template <typename BinaryOp> |
| 33 | -auto printBinaryL1Params(CodeEmitter &emitter, BinaryOp op, StringRef maskName) | 33 | +auto printBinaryL1Params(CodeEmitter& emitter, BinaryOp op, StringRef maskName) |
| 34 | { | 34 | { |
| 35 | - auto &os = emitter.ostream(); | 35 | + auto& os = emitter.ostream(); |
| 36 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " | 36 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " |
| 37 | << emitter.getOrCreateName(op.getSrc1()) << ", " << maskName << ", " | 37 | << emitter.getOrCreateName(op.getSrc1()) << ", " << maskName << ", " |
| 38 | << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | 38 | << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | template <typename BinaryOp> | 41 | template <typename BinaryOp> |
| 42 | -auto printBinaryL2Params(CodeEmitter &emitter, BinaryOp op) | 42 | +auto printBinaryL2Params(CodeEmitter& emitter, BinaryOp op) |
| 43 | { | 43 | { |
| 44 | - auto &os = emitter.ostream(); | 44 | + auto& os = emitter.ostream(); |
| 45 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " | 45 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " |
| 46 | << emitter.getOrCreateName(op.getSrc1()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; | 46 | << emitter.getOrCreateName(op.getSrc1()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | template <typename BinaryL0Op> | 49 | template <typename BinaryL0Op> |
| 50 | -auto printOperation(CodeEmitter &emitter, BinaryL0Op op) -> LogicalResultForT<BinaryL0Op, ascendc::MulCastL0Op> | 50 | +auto printOperation(CodeEmitter& emitter, BinaryL0Op op) -> LogicalResultForT<BinaryL0Op, ascendc::MulCastL0Op> |
| 51 | { | 51 | { |
| 52 | - auto &os = emitter.ostream(); | 52 | + auto& os = emitter.ostream(); |
| 53 | os << ascNamespace << "::" << op.getAPIName(); | 53 | os << ascNamespace << "::" << op.getAPIName(); |
| 54 | printBinaryL0Params(emitter, op); | 54 | printBinaryL0Params(emitter, op); |
| 55 | return success(); | 55 | return success(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | template <typename BinaryL1Op> | 58 | template <typename BinaryL1Op> |
| 59 | -auto printOperation(CodeEmitter &emitter, BinaryL1Op op) -> LogicalResultForT<BinaryL1Op, ascendc::MulCastL1Op> | 59 | +auto printOperation(CodeEmitter& emitter, BinaryL1Op op) -> LogicalResultForT<BinaryL1Op, ascendc::MulCastL1Op> |
| 60 | { | 60 | { |
| 61 | - auto &os = emitter.ostream(); | 61 | + auto& os = emitter.ostream(); |
| 62 | auto maskName = printMask(emitter, op); | 62 | auto maskName = printMask(emitter, op); |
| 63 | os << ascNamespace << "::" << op.getAPIName(); | 63 | os << ascNamespace << "::" << op.getAPIName(); |
| 64 | printBinaryL1Params(emitter, op, maskName); | 64 | printBinaryL1Params(emitter, op, maskName); |
| @@ -66,39 +66,38 @@ auto printOperation(CodeEmitter &emitter, BinaryL1Op op) -> LogicalResultForT<Bi | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | template <typename BinaryL2Op> | 68 | template <typename BinaryL2Op> |
| 69 | -auto printOperation(CodeEmitter &emitter, BinaryL2Op op) | 69 | +auto printOperation(CodeEmitter& emitter, BinaryL2Op op) -> LogicalResultForT< |
| 70 | - -> LogicalResultForT<BinaryL2Op, ascendc::AddL2Op, ascendc::AddDeqReluL2Op, ascendc::AddReluL2Op, | 70 | + BinaryL2Op, ascendc::AddL2Op, ascendc::AddDeqReluL2Op, ascendc::AddReluL2Op, ascendc::AddReluCastL2Op, |
| 71 | - ascendc::AddReluCastL2Op, ascendc::AndL2Op, ascendc::DivL2Op, ascendc::FusedAbsSubL2Op, | 71 | + ascendc::AndL2Op, ascendc::DivL2Op, ascendc::FusedAbsSubL2Op, ascendc::FusedExpSubL2Op, ascendc::FusedMulAddL2Op, |
| 72 | - ascendc::FusedExpSubL2Op, ascendc::FusedMulAddL2Op, ascendc::FusedMulAddReluL2Op, | 72 | + ascendc::FusedMulAddReluL2Op, ascendc::MaxL2Op, ascendc::MinL2Op, ascendc::MulL2Op, ascendc::MulAddDstL2Op, |
| 73 | - ascendc::MaxL2Op, ascendc::MinL2Op, ascendc::MulL2Op, ascendc::MulAddDstL2Op, | 73 | + ascendc::MulCastL2Op, ascendc::OrL2Op, ascendc::PreluL2Op, ascendc::SubL2Op, ascendc::SubReluL2Op, |
| 74 | - ascendc::MulCastL2Op, ascendc::OrL2Op, ascendc::PreluL2Op, ascendc::SubL2Op, | 74 | + ascendc::SubReluCastL2Op> |
| 75 | - ascendc::SubReluL2Op, ascendc::SubReluCastL2Op> | ||
| 76 | { | 75 | { |
| 77 | - auto &os = emitter.ostream(); | 76 | + auto& os = emitter.ostream(); |
| 78 | os << ascNamespace << "::" << op.getAPIName(); | 77 | os << ascNamespace << "::" << op.getAPIName(); |
| 79 | printBinaryL2Params(emitter, op); | 78 | printBinaryL2Params(emitter, op); |
| 80 | return success(); | 79 | return success(); |
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | template <typename BinaryTemplateL0Op> | 82 | template <typename BinaryTemplateL0Op> |
| 84 | -auto printOperation(CodeEmitter &emitter, BinaryTemplateL0Op op) | 83 | +auto printOperation(CodeEmitter& emitter, BinaryTemplateL0Op op) -> LogicalResultForT< |
| 85 | - -> LogicalResultForT<BinaryTemplateL0Op, ascendc::AddL0Op, ascendc::AddReluL0Op, ascendc::AndL0Op, ascendc::DivL0Op, | 84 | + BinaryTemplateL0Op, ascendc::AddL0Op, ascendc::AddReluL0Op, ascendc::AndL0Op, ascendc::DivL0Op, |
| 86 | - ascendc::FusedMulAddL0Op, ascendc::FusedMulAddReluL0Op, ascendc::MaxL0Op, ascendc::MinL0Op, | 85 | + ascendc::FusedMulAddL0Op, ascendc::FusedMulAddReluL0Op, ascendc::MaxL0Op, ascendc::MinL0Op, ascendc::MulL0Op, |
| 87 | - ascendc::MulL0Op, ascendc::OrL0Op, ascendc::SubL0Op, ascendc::SubReluL0Op> | 86 | + ascendc::OrL0Op, ascendc::SubL0Op, ascendc::SubReluL0Op> |
| 88 | { | 87 | { |
| 89 | - auto &os = emitter.ostream(); | 88 | + auto& os = emitter.ostream(); |
| 90 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 89 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 91 | printBinaryL0Params(emitter, op); | 90 | printBinaryL0Params(emitter, op); |
| 92 | return success(); | 91 | return success(); |
| 93 | } | 92 | } |
| 94 | 93 | ||
| 95 | template <typename BinaryTemplateL1Op> | 94 | template <typename BinaryTemplateL1Op> |
| 96 | -auto printOperation(CodeEmitter &emitter, BinaryTemplateL1Op op) | 95 | +auto printOperation(CodeEmitter& emitter, BinaryTemplateL1Op op) -> LogicalResultForT< |
| 97 | - -> LogicalResultForT<BinaryTemplateL1Op, ascendc::AddL1Op, ascendc::AddReluL1Op, ascendc::AndL1Op, ascendc::DivL1Op, | 96 | + BinaryTemplateL1Op, ascendc::AddL1Op, ascendc::AddReluL1Op, ascendc::AndL1Op, ascendc::DivL1Op, |
| 98 | - ascendc::FusedMulAddL1Op, ascendc::FusedMulAddReluL1Op, ascendc::MaxL1Op, ascendc::MinL1Op, | 97 | + ascendc::FusedMulAddL1Op, ascendc::FusedMulAddReluL1Op, ascendc::MaxL1Op, ascendc::MinL1Op, ascendc::MulL1Op, |
| 99 | - ascendc::MulL1Op, ascendc::OrL1Op, ascendc::SubL1Op, ascendc::SubReluL1Op> | 98 | + ascendc::OrL1Op, ascendc::SubL1Op, ascendc::SubReluL1Op> |
| 100 | { | 99 | { |
| 101 | - auto &os = emitter.ostream(); | 100 | + auto& os = emitter.ostream(); |
| 102 | auto maskName = printMask(emitter, op); | 101 | auto maskName = printMask(emitter, op); |
| 103 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 102 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 104 | printBinaryL1Params(emitter, op, maskName); | 103 | printBinaryL1Params(emitter, op, maskName); |
| @@ -106,22 +105,20 @@ auto printOperation(CodeEmitter &emitter, BinaryTemplateL1Op op) | |||
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | template <typename BinaryCastL0Op> | 107 | template <typename BinaryCastL0Op> |
| 109 | -auto printOperation(CodeEmitter &emitter, BinaryCastL0Op op) | 108 | +auto printOperation(CodeEmitter& emitter, BinaryCastL0Op op) -> LogicalResultForT< |
| 110 | - -> LogicalResultForT<BinaryCastL0Op, ascendc::AddDeqReluL0Op, ascendc::AddReluCastL0Op, ascendc::SubReluCastL0Op, | 109 | + BinaryCastL0Op, ascendc::AddDeqReluL0Op, ascendc::AddReluCastL0Op, ascendc::SubReluCastL0Op, ascendc::MulAddDstL0Op> |
| 111 | - ascendc::MulAddDstL0Op> | ||
| 112 | { | 110 | { |
| 113 | - auto &os = emitter.ostream(); | 111 | + auto& os = emitter.ostream(); |
| 114 | FAIL_OR(printIsSetMaskCastTemplate(emitter, op)); | 112 | FAIL_OR(printIsSetMaskCastTemplate(emitter, op)); |
| 115 | printBinaryL0Params(emitter, op); | 113 | printBinaryL0Params(emitter, op); |
| 116 | return success(); | 114 | return success(); |
| 117 | } | 115 | } |
| 118 | 116 | ||
| 119 | template <typename BinaryCastL1Op> | 117 | template <typename BinaryCastL1Op> |
| 120 | -auto printOperation(CodeEmitter &emitter, BinaryCastL1Op op) | 118 | +auto printOperation(CodeEmitter& emitter, BinaryCastL1Op op) -> LogicalResultForT< |
| 121 | - -> LogicalResultForT<BinaryCastL1Op, ascendc::AddDeqReluL1Op, ascendc::AddReluCastL1Op, ascendc::SubReluCastL1Op, | 119 | + BinaryCastL1Op, ascendc::AddDeqReluL1Op, ascendc::AddReluCastL1Op, ascendc::SubReluCastL1Op, ascendc::MulAddDstL1Op> |
| 122 | - ascendc::MulAddDstL1Op> | ||
| 123 | { | 120 | { |
| 124 | - auto &os = emitter.ostream(); | 121 | + auto& os = emitter.ostream(); |
| 125 | auto maskName = printMask(emitter, op); | 122 | auto maskName = printMask(emitter, op); |
| 126 | FAIL_OR(printIsSetMaskCastTemplate(emitter, op)); | 123 | FAIL_OR(printIsSetMaskCastTemplate(emitter, op)); |
| 127 | printBinaryL1Params(emitter, op, maskName); | 124 | printBinaryL1Params(emitter, op, maskName); |
| @@ -129,18 +126,18 @@ auto printOperation(CodeEmitter &emitter, BinaryCastL1Op op) | |||
| 129 | } | 126 | } |
| 130 | 127 | ||
| 131 | template <typename BinaryL3Op> | 128 | template <typename BinaryL3Op> |
| 132 | -auto printOperation(CodeEmitter &emitter, BinaryL3Op op) | 129 | +auto printOperation(CodeEmitter& emitter, BinaryL3Op op) |
| 133 | -> LogicalResultForT<BinaryL3Op, ascendc::AddL3Op, ascendc::DivL3Op, ascendc::MulL3Op, ascendc::SubL3Op> | 130 | -> LogicalResultForT<BinaryL3Op, ascendc::AddL3Op, ascendc::DivL3Op, ascendc::MulL3Op, ascendc::SubL3Op> |
| 134 | { | 131 | { |
| 135 | - auto &os = emitter.ostream(); | 132 | + auto& os = emitter.ostream(); |
| 136 | os << emitter.getOrCreateName(op.getDst()) << " = " << emitter.getOrCreateName(op.getSrc0()) << "." | 133 | os << emitter.getOrCreateName(op.getDst()) << " = " << emitter.getOrCreateName(op.getSrc0()) << "." |
| 137 | << op.getAPIName() << "(" << emitter.getOrCreateName(op.getSrc1()) << ")"; | 134 | << op.getAPIName() << "(" << emitter.getOrCreateName(op.getSrc1()) << ")"; |
| 138 | return success(); | 135 | return success(); |
| 139 | } | 136 | } |
| 140 | 137 | ||
| 141 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BilinearInterpolationL0Op op); | 138 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BilinearInterpolationL0Op op); |
| 142 | 139 | ||
| 143 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BilinearInterpolationL1Op op); | 140 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BilinearInterpolationL1Op op); |
| 144 | 141 | ||
| 145 | } // namespace ascendc | 142 | } // namespace ascendc |
| 146 | } // namespace mlir | 143 | } // namespace mlir |
| @@ -21,11 +21,11 @@ namespace ascendc { | |||
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename VecScalarL0Op> | 23 | template <typename VecScalarL0Op> |
| 24 | -auto printOperation(CodeEmitter &emitter, VecScalarL0Op op) | 24 | +auto printOperation(CodeEmitter& emitter, VecScalarL0Op op) -> LogicalResultForT< |
| 25 | - -> LogicalResultForT<VecScalarL0Op, ascendc::AddsL0Op, ascendc::LeakyReluL0Op, ascendc::MaxsL0Op, ascendc::MinsL0Op, | 25 | + VecScalarL0Op, ascendc::AddsL0Op, ascendc::LeakyReluL0Op, ascendc::MaxsL0Op, ascendc::MinsL0Op, ascendc::MulsL0Op, |
| 26 | - ascendc::MulsL0Op, ascendc::ShiftLeftL0Op, ascendc::ShiftRightL0Op> | 26 | + ascendc::ShiftLeftL0Op, ascendc::ShiftRightL0Op> |
| 27 | { | 27 | { |
| 28 | - auto &os = emitter.ostream(); | 28 | + auto& os = emitter.ostream(); |
| 29 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 29 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 30 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 30 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 31 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " | 31 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " |
| @@ -34,11 +34,11 @@ auto printOperation(CodeEmitter &emitter, VecScalarL0Op op) | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | template <typename VecScalarL1Op> | 36 | template <typename VecScalarL1Op> |
| 37 | -auto printOperation(CodeEmitter &emitter, VecScalarL1Op op) | 37 | +auto printOperation(CodeEmitter& emitter, VecScalarL1Op op) -> LogicalResultForT< |
| 38 | - -> LogicalResultForT<VecScalarL1Op, ascendc::AddsL1Op, ascendc::LeakyReluL1Op, ascendc::MaxsL1Op, ascendc::MinsL1Op, | 38 | + VecScalarL1Op, ascendc::AddsL1Op, ascendc::LeakyReluL1Op, ascendc::MaxsL1Op, ascendc::MinsL1Op, ascendc::MulsL1Op, |
| 39 | - ascendc::MulsL1Op, ascendc::ShiftLeftL1Op, ascendc::ShiftRightL1Op> | 39 | + ascendc::ShiftLeftL1Op, ascendc::ShiftRightL1Op> |
| 40 | { | 40 | { |
| 41 | - auto &os = emitter.ostream(); | 41 | + auto& os = emitter.ostream(); |
| 42 | auto maskName = printMask(emitter, op); | 42 | auto maskName = printMask(emitter, op); |
| 43 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 43 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 44 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 44 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| @@ -48,11 +48,11 @@ auto printOperation(CodeEmitter &emitter, VecScalarL1Op op) | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | template <typename VecScalarL2Op> | 50 | template <typename VecScalarL2Op> |
| 51 | -auto printOperation(CodeEmitter &emitter, VecScalarL2Op op) | 51 | +auto printOperation(CodeEmitter& emitter, VecScalarL2Op op) -> LogicalResultForT< |
| 52 | - -> LogicalResultForT<VecScalarL2Op, ascendc::AddsL2Op, ascendc::LeakyReluL2Op, ascendc::MaxsL2Op, ascendc::MinsL2Op, | 52 | + VecScalarL2Op, ascendc::AddsL2Op, ascendc::LeakyReluL2Op, ascendc::MaxsL2Op, ascendc::MinsL2Op, ascendc::MulsL2Op, |
| 53 | - ascendc::MulsL2Op, ascendc::ShiftLeftL2Op, ascendc::ShiftRightL2Op> | 53 | + ascendc::ShiftLeftL2Op, ascendc::ShiftRightL2Op> |
| 54 | { | 54 | { |
| 55 | - auto &os = emitter.ostream(); | 55 | + auto& os = emitter.ostream(); |
| 56 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 56 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 57 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 57 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 58 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; | 58 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; |
| @@ -30,9 +30,9 @@ LogicalResult printOperation(CodeEmitter& emitter, ascendc::CompareScalarL1Op op | |||
| 30 | // Select operations | 30 | // Select operations |
| 31 | //===----------------------------------------------------------------------===// | 31 | //===----------------------------------------------------------------------===// |
| 32 | 32 | ||
| 33 | -LogicalResult printOperation(CodeEmitter &emitter, SelectScalarL1Op op); | 33 | +LogicalResult printOperation(CodeEmitter& emitter, SelectScalarL1Op op); |
| 34 | 34 | ||
| 35 | -LogicalResult printOperation(CodeEmitter &emitter, SelectL1Op op); | 35 | +LogicalResult printOperation(CodeEmitter& emitter, SelectL1Op op); |
| 36 | 36 | ||
| 37 | } // namespace ascendc | 37 | } // namespace ascendc |
| 38 | } // namespace mlir | 38 | } // namespace mlir |
| @@ -20,11 +20,11 @@ namespace ascendc { | |||
| 20 | // Duplicate operations | 20 | // Duplicate operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::DuplicateL0Op op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::DuplicateL0Op op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::DuplicateL1Op op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::DuplicateL1Op op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::DuplicateL2Op op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::DuplicateL2Op op); |
| 28 | 28 | ||
| 29 | } // namespace ascendc | 29 | } // namespace ascendc |
| 30 | } // namespace mlir | 30 | } // namespace mlir |
| @@ -20,17 +20,17 @@ namespace ascendc { | |||
| 20 | // Gatherb operations | 20 | // Gatherb operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GatherbL0Op op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GatherbL0Op op); |
| 24 | 24 | ||
| 25 | //===----------------------------------------------------------------------===// | 25 | //===----------------------------------------------------------------------===// |
| 26 | // Gather operations | 26 | // Gather operations |
| 27 | //===----------------------------------------------------------------------===// | 27 | //===----------------------------------------------------------------------===// |
| 28 | 28 | ||
| 29 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GatherL0Op op); | 29 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GatherL0Op op); |
| 30 | 30 | ||
| 31 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GatherL1Op op); | 31 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GatherL1Op op); |
| 32 | 32 | ||
| 33 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GatherL2Op op); | 33 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GatherL2Op op); |
| 34 | 34 | ||
| 35 | } // namespace ascendc | 35 | } // namespace ascendc |
| 36 | } // namespace mlir | 36 | } // namespace mlir |
| @@ -20,7 +20,7 @@ namespace ascendc { | |||
| 20 | // GatherMask operations | 20 | // GatherMask operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GatherMaskOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GatherMaskOp op); |
| 24 | 24 | ||
| 25 | } // namespace ascendc | 25 | } // namespace ascendc |
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| @@ -20,45 +20,45 @@ namespace ascendc { | |||
| 20 | // BlockReduceMax operations | 20 | // BlockReduceMax operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BlockReduceMaxL1Op op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BlockReduceMaxL1Op op); |
| 24 | 24 | ||
| 25 | //===----------------------------------------------------------------------===// | 25 | //===----------------------------------------------------------------------===// |
| 26 | // BlockReduceMin operations | 26 | // BlockReduceMin operations |
| 27 | //===----------------------------------------------------------------------===// | 27 | //===----------------------------------------------------------------------===// |
| 28 | 28 | ||
| 29 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BlockReduceMinL1Op op); | 29 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BlockReduceMinL1Op op); |
| 30 | 30 | ||
| 31 | //===----------------------------------------------------------------------===// | 31 | //===----------------------------------------------------------------------===// |
| 32 | // BlockReduceSum operations | 32 | // BlockReduceSum operations |
| 33 | //===----------------------------------------------------------------------===// | 33 | //===----------------------------------------------------------------------===// |
| 34 | 34 | ||
| 35 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::BlockReduceSumL1Op op); | 35 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::BlockReduceSumL1Op op); |
| 36 | 36 | ||
| 37 | //===----------------------------------------------------------------------===// | 37 | //===----------------------------------------------------------------------===// |
| 38 | // Vector reduce operations | 38 | // Vector reduce operations |
| 39 | //===----------------------------------------------------------------------===// | 39 | //===----------------------------------------------------------------------===// |
| 40 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::PairReduceSumL1Op op); | 40 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::PairReduceSumL1Op op); |
| 41 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::WholeReduceMaxL1Op op); | 41 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::WholeReduceMaxL1Op op); |
| 42 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::WholeReduceMinL1Op op); | 42 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::WholeReduceMinL1Op op); |
| 43 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::WholeReduceSumL1Op op); | 43 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::WholeReduceSumL1Op op); |
| 44 | 44 | ||
| 45 | //===----------------------------------------------------------------------===// | 45 | //===----------------------------------------------------------------------===// |
| 46 | // ReduceMax operations | 46 | // ReduceMax operations |
| 47 | //===----------------------------------------------------------------------===// | 47 | //===----------------------------------------------------------------------===// |
| 48 | 48 | ||
| 49 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ReduceMaxL1Op op); | 49 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ReduceMaxL1Op op); |
| 50 | 50 | ||
| 51 | //===----------------------------------------------------------------------===// | 51 | //===----------------------------------------------------------------------===// |
| 52 | // ReduceMin operations | 52 | // ReduceMin operations |
| 53 | //===----------------------------------------------------------------------===// | 53 | //===----------------------------------------------------------------------===// |
| 54 | 54 | ||
| 55 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ReduceMinL1Op op); | 55 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ReduceMinL1Op op); |
| 56 | 56 | ||
| 57 | //===----------------------------------------------------------------------===// | 57 | //===----------------------------------------------------------------------===// |
| 58 | // ReduceSum operations | 58 | // ReduceSum operations |
| 59 | //===----------------------------------------------------------------------===// | 59 | //===----------------------------------------------------------------------===// |
| 60 | 60 | ||
| 61 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ReduceSumL1Op op); | 61 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ReduceSumL1Op op); |
| 62 | 62 | ||
| 63 | } // namespace ascendc | 63 | } // namespace ascendc |
| 64 | } // namespace mlir | 64 | } // namespace mlir |
| @@ -20,7 +20,7 @@ namespace ascendc { | |||
| 20 | // Scatter operations | 20 | // Scatter operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ScatterL1Op op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ScatterL1Op op); |
| 24 | 24 | ||
| 25 | } // namespace ascendc | 25 | } // namespace ascendc |
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| @@ -21,9 +21,9 @@ namespace ascendc { | |||
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename VecScalarL0Op> | 23 | template <typename VecScalarL0Op> |
| 24 | -auto printOperation(CodeEmitter &emitter, VecScalarL0Op op) -> LogicalResultForT<VecScalarL0Op, ascendc::AxpyL0Op> | 24 | +auto printOperation(CodeEmitter& emitter, VecScalarL0Op op) -> LogicalResultForT<VecScalarL0Op, ascendc::AxpyL0Op> |
| 25 | { | 25 | { |
| 26 | - auto &os = emitter.ostream(); | 26 | + auto& os = emitter.ostream(); |
| 27 | auto dstTensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 27 | auto dstTensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 28 | auto srcTensorType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 28 | auto srcTensorType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| 29 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 29 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -38,9 +38,9 @@ auto printOperation(CodeEmitter &emitter, VecScalarL0Op op) -> LogicalResultForT | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | template <typename VecScalarL1Op> | 40 | template <typename VecScalarL1Op> |
| 41 | -auto printOperation(CodeEmitter &emitter, VecScalarL1Op op) -> LogicalResultForT<VecScalarL1Op, ascendc::AxpyL1Op> | 41 | +auto printOperation(CodeEmitter& emitter, VecScalarL1Op op) -> LogicalResultForT<VecScalarL1Op, ascendc::AxpyL1Op> |
| 42 | { | 42 | { |
| 43 | - auto &os = emitter.ostream(); | 43 | + auto& os = emitter.ostream(); |
| 44 | auto maskName = printMask(emitter, op); | 44 | auto maskName = printMask(emitter, op); |
| 45 | auto dstTensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 45 | auto dstTensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 46 | auto srcTensorType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 46 | auto srcTensorType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| @@ -56,9 +56,9 @@ auto printOperation(CodeEmitter &emitter, VecScalarL1Op op) -> LogicalResultForT | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | template <typename VecScalarL2Op> | 58 | template <typename VecScalarL2Op> |
| 59 | -auto printOperation(CodeEmitter &emitter, VecScalarL2Op op) -> LogicalResultForT<VecScalarL2Op, ascendc::AxpyL2Op> | 59 | +auto printOperation(CodeEmitter& emitter, VecScalarL2Op op) -> LogicalResultForT<VecScalarL2Op, ascendc::AxpyL2Op> |
| 60 | { | 60 | { |
| 61 | - auto &os = emitter.ostream(); | 61 | + auto& os = emitter.ostream(); |
| 62 | os << ascNamespace << "::" << op.getAPIName(); | 62 | os << ascNamespace << "::" << op.getAPIName(); |
| 63 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 63 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 64 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; | 64 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; |
| @@ -21,48 +21,48 @@ namespace ascendc { | |||
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename UnaryOp> | 23 | template <typename UnaryOp> |
| 24 | -auto printUnaryL0Params(CodeEmitter &emitter, UnaryOp op) | 24 | +auto printUnaryL0Params(CodeEmitter& emitter, UnaryOp op) |
| 25 | { | 25 | { |
| 26 | - auto &os = emitter.ostream(); | 26 | + auto& os = emitter.ostream(); |
| 27 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 27 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 28 | << emitter.getOrCreateName(op.getMask()) << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 28 | << emitter.getOrCreateName(op.getMask()) << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " |
| 29 | << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | 29 | << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | template <typename UnaryOp> | 32 | template <typename UnaryOp> |
| 33 | -auto printUnaryL1Params(CodeEmitter &emitter, UnaryOp op, StringRef maskName) | 33 | +auto printUnaryL1Params(CodeEmitter& emitter, UnaryOp op, StringRef maskName) |
| 34 | { | 34 | { |
| 35 | - auto &os = emitter.ostream(); | 35 | + auto& os = emitter.ostream(); |
| 36 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 36 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 37 | << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 37 | << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " |
| 38 | << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | 38 | << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | template <typename UnaryOp> | 41 | template <typename UnaryOp> |
| 42 | -auto printUnaryL2Params(CodeEmitter &emitter, UnaryOp op) | 42 | +auto printUnaryL2Params(CodeEmitter& emitter, UnaryOp op) |
| 43 | { | 43 | { |
| 44 | - auto &os = emitter.ostream(); | 44 | + auto& os = emitter.ostream(); |
| 45 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " | 45 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 46 | << emitter.getOrCreateName(op.getCalCount()) << ")"; | 46 | << emitter.getOrCreateName(op.getCalCount()) << ")"; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | template <typename UnaryL0Op> | 49 | template <typename UnaryL0Op> |
| 50 | -auto printOperation(CodeEmitter &emitter, UnaryL0Op op) | 50 | +auto printOperation(CodeEmitter& emitter, UnaryL0Op op) -> LogicalResultForT< |
| 51 | - -> LogicalResultForT<UnaryL0Op, ascendc::AbsL0Op, ascendc::ExpL0Op, ascendc::LnL0Op, ascendc::NotL0Op, | 51 | + UnaryL0Op, ascendc::AbsL0Op, ascendc::ExpL0Op, ascendc::LnL0Op, ascendc::NotL0Op, ascendc::ReciprocalL0Op, |
| 52 | - ascendc::ReciprocalL0Op, ascendc::ReluL0Op, ascendc::RsqrtL0Op, ascendc::SqrtL0Op> | 52 | + ascendc::ReluL0Op, ascendc::RsqrtL0Op, ascendc::SqrtL0Op> |
| 53 | { | 53 | { |
| 54 | - auto &os = emitter.ostream(); | 54 | + auto& os = emitter.ostream(); |
| 55 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 55 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 56 | printUnaryL0Params(emitter, op); | 56 | printUnaryL0Params(emitter, op); |
| 57 | return success(); | 57 | return success(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename UnaryL1Op> | 60 | template <typename UnaryL1Op> |
| 61 | -auto printOperation(CodeEmitter &emitter, UnaryL1Op op) | 61 | +auto printOperation(CodeEmitter& emitter, UnaryL1Op op) -> LogicalResultForT< |
| 62 | - -> LogicalResultForT<UnaryL1Op, ascendc::AbsL1Op, ascendc::ExpL1Op, ascendc::LnL1Op, ascendc::NotL1Op, | 62 | + UnaryL1Op, ascendc::AbsL1Op, ascendc::ExpL1Op, ascendc::LnL1Op, ascendc::NotL1Op, ascendc::ReciprocalL1Op, |
| 63 | - ascendc::ReciprocalL1Op, ascendc::ReluL1Op, ascendc::RsqrtL1Op, ascendc::SqrtL1Op> | 63 | + ascendc::ReluL1Op, ascendc::RsqrtL1Op, ascendc::SqrtL1Op> |
| 64 | { | 64 | { |
| 65 | - auto &os = emitter.ostream(); | 65 | + auto& os = emitter.ostream(); |
| 66 | auto maskName = printMask(emitter, op); | 66 | auto maskName = printMask(emitter, op); |
| 67 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 67 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 68 | printUnaryL1Params(emitter, op, maskName); | 68 | printUnaryL1Params(emitter, op, maskName); |
| @@ -70,12 +70,11 @@ auto printOperation(CodeEmitter &emitter, UnaryL1Op op) | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | template <typename UnaryL2Op> | 72 | template <typename UnaryL2Op> |
| 73 | -auto printOperation(CodeEmitter &emitter, UnaryL2Op op) | 73 | +auto printOperation(CodeEmitter& emitter, UnaryL2Op op) -> LogicalResultForT< |
| 74 | - -> LogicalResultForT<UnaryL2Op, ascendc::AbsL2Op, ascendc::ExpL2Op, ascendc::LnL2Op, ascendc::NotL2Op, | 74 | + UnaryL2Op, ascendc::AbsL2Op, ascendc::ExpL2Op, ascendc::LnL2Op, ascendc::NotL2Op, ascendc::ReciprocalL2Op, |
| 75 | - ascendc::ReciprocalL2Op, ascendc::ReluL2Op, ascendc::RsqrtL2Op, ascendc::SqrtL2Op, | 75 | + ascendc::ReluL2Op, ascendc::RsqrtL2Op, ascendc::SqrtL2Op, ascendc::NegL2Op> |
| 76 | - ascendc::NegL2Op> | ||
| 77 | { | 76 | { |
| 78 | - auto &os = emitter.ostream(); | 77 | + auto& os = emitter.ostream(); |
| 79 | os << ascNamespace << "::" << op.getAPIName(); | 78 | os << ascNamespace << "::" << op.getAPIName(); |
| 80 | printUnaryL2Params(emitter, op); | 79 | printUnaryL2Params(emitter, op); |
| 81 | return success(); | 80 | return success(); |
| @@ -21,9 +21,9 @@ namespace ascendc { | |||
| 21 | // ===----------------------------------------------------------------------===// | 21 | // ===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | template <typename OpType> | 23 | template <typename OpType> |
| 24 | -LogicalResult printCastL01Template(CodeEmitter &emitter, OpType op) | 24 | +LogicalResult printCastL01Template(CodeEmitter& emitter, OpType op) |
| 25 | { | 25 | { |
| 26 | - auto &os = emitter.ostream(); | 26 | + auto& os = emitter.ostream(); |
| 27 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 27 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 28 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 28 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| 29 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 29 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -35,9 +35,9 @@ LogicalResult printCastL01Template(CodeEmitter &emitter, OpType op) | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | template <typename OpType> | 37 | template <typename OpType> |
| 38 | -LogicalResult printCastDeqL01Template(CodeEmitter &emitter, OpType op) | 38 | +LogicalResult printCastDeqL01Template(CodeEmitter& emitter, OpType op) |
| 39 | { | 39 | { |
| 40 | - auto &os = emitter.ostream(); | 40 | + auto& os = emitter.ostream(); |
| 41 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 41 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 42 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 42 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| 43 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 43 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -49,9 +49,9 @@ LogicalResult printCastDeqL01Template(CodeEmitter &emitter, OpType op) | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | template <typename OpType> | 51 | template <typename OpType> |
| 52 | -LogicalResult printCastDeqL2Template(CodeEmitter &emitter, OpType op) | 52 | +LogicalResult printCastDeqL2Template(CodeEmitter& emitter, OpType op) |
| 53 | { | 53 | { |
| 54 | - auto &os = emitter.ostream(); | 54 | + auto& os = emitter.ostream(); |
| 55 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 55 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 56 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 56 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| 57 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 57 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -62,19 +62,19 @@ LogicalResult printCastDeqL2Template(CodeEmitter &emitter, OpType op) | |||
| 62 | return success(); | 62 | return success(); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CastL0Op op); | 65 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CastL0Op op); |
| 66 | 66 | ||
| 67 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CastL1Op op); | 67 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CastL1Op op); |
| 68 | 68 | ||
| 69 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CastL2Op op); | 69 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CastL2Op op); |
| 70 | 70 | ||
| 71 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CastDeqL0Op op); | 71 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CastDeqL0Op op); |
| 72 | 72 | ||
| 73 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CastDeqL1Op op); | 73 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CastDeqL1Op op); |
| 74 | 74 | ||
| 75 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::CastDeqL2Op op); | 75 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::CastDeqL2Op op); |
| 76 | 76 | ||
| 77 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SetDeqScaleOp op); | 77 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetDeqScaleOp op); |
| 78 | 78 | ||
| 79 | LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetDeqScaleL4Op op); | 79 | LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetDeqScaleL4Op op); |
| 80 | } // namespace ascendc | 80 | } // namespace ascendc |
| @@ -23,19 +23,19 @@ | |||
| 23 | 23 | ||
| 24 | namespace mlir { | 24 | namespace mlir { |
| 25 | 25 | ||
| 26 | -static constexpr const char *ascNamespace = "AscendC"; | 26 | +static constexpr const char* ascNamespace = "AscendC"; |
| 27 | struct CodeEmitter { | 27 | struct CodeEmitter { |
| 28 | const std::string structFieldNamePrefix = "var"; | 28 | const std::string structFieldNamePrefix = "var"; |
| 29 | 29 | ||
| 30 | - static void emitCubeFormat(raw_ostream &os, ascendc::CubeFormat format); | 30 | + static void emitCubeFormat(raw_ostream& os, ascendc::CubeFormat format); |
| 31 | 31 | ||
| 32 | - static void emitTPosition(raw_ostream &os, ascendc::TPosition pos); | 32 | + static void emitTPosition(raw_ostream& os, ascendc::TPosition pos); |
| 33 | 33 | ||
| 34 | - static void emitLayoutMode(raw_ostream &os, ascendc::LayoutMode layout); | 34 | + static void emitLayoutMode(raw_ostream& os, ascendc::LayoutMode layout); |
| 35 | 35 | ||
| 36 | - explicit CodeEmitter(raw_ostream &os); | 36 | + explicit CodeEmitter(raw_ostream& os); |
| 37 | 37 | ||
| 38 | - static void emitMatmulConfig(raw_ostream &os, ascendc::MatmulConfigAttr config); | 38 | + static void emitMatmulConfig(raw_ostream& os, ascendc::MatmulConfigAttr config); |
| 39 | 39 | ||
| 40 | LogicalResult emitAscMatmulSimplifiedTemplate(Location loc, Type type, bool emitAsUnsigned); | 40 | LogicalResult emitAscMatmulSimplifiedTemplate(Location loc, Type type, bool emitAsUnsigned); |
| 41 | 41 | ||
| @@ -55,7 +55,7 @@ struct CodeEmitter { | |||
| 55 | LogicalResult emitVariableDeclaration(OpResult opResult, bool trailingSemicolon); | 55 | LogicalResult emitVariableDeclaration(OpResult opResult, bool trailingSemicolon); |
| 56 | 56 | ||
| 57 | /// Emits a label for the block. | 57 | /// Emits a label for the block. |
| 58 | - LogicalResult emitLabel(Block &block); | 58 | + LogicalResult emitLabel(Block& block); |
| 59 | 59 | ||
| 60 | /// Emits the variable declaration and assignment prefix for 'op'. | 60 | /// Emits the variable declaration and assignment prefix for 'op'. |
| 61 | /// - emits separate variable followed by std::tie for multi-valued operation; | 61 | /// - emits separate variable followed by std::tie for multi-valued operation; |
| @@ -63,16 +63,16 @@ struct CodeEmitter { | |||
| 63 | /// - emits nothing if no value produced by op; | 63 | /// - emits nothing if no value produced by op; |
| 64 | /// Emits final '=' operator where a type is produced. Returns failure if | 64 | /// Emits final '=' operator where a type is produced. Returns failure if |
| 65 | /// any result type could not be converted. | 65 | /// any result type could not be converted. |
| 66 | - LogicalResult emitAssignPrefix(Operation &op); | 66 | + LogicalResult emitAssignPrefix(Operation& op); |
| 67 | 67 | ||
| 68 | /// Return the existing or a new label of a Block. | 68 | /// Return the existing or a new label of a Block. |
| 69 | - StringRef getOrCreateName(Block &block); | 69 | + StringRef getOrCreateName(Block& block); |
| 70 | 70 | ||
| 71 | /// Whether to map an mlir integer to a unsigned integer in C++. | 71 | /// Whether to map an mlir integer to a unsigned integer in C++. |
| 72 | bool shouldMapToUnsigned(IntegerType::SignednessSemantics val); | 72 | bool shouldMapToUnsigned(IntegerType::SignednessSemantics val); |
| 73 | 73 | ||
| 74 | /// Emits the operands of the operation. All operands are emitted in order. | 74 | /// Emits the operands of the operation. All operands are emitted in order. |
| 75 | - LogicalResult emitOperands(Operation &op); | 75 | + LogicalResult emitOperands(Operation& op); |
| 76 | 76 | ||
| 77 | /// Return the existing or a new name for a Value. | 77 | /// Return the existing or a new name for a Value. |
| 78 | StringRef getOrCreateName(Value val); | 78 | StringRef getOrCreateName(Value val); |
| @@ -85,37 +85,31 @@ struct CodeEmitter { | |||
| 85 | 85 | ||
| 86 | /// RAII helper function to manage entering/exiting C++ scopes. | 86 | /// RAII helper function to manage entering/exiting C++ scopes. |
| 87 | struct Scope { | 87 | struct Scope { |
| 88 | - Scope(CodeEmitter &emitter) | 88 | + Scope(CodeEmitter& emitter) |
| 89 | : valueMapperScope(emitter.valueMapper), blockMapperScope(emitter.blockMapper), emitter(emitter) | 89 | : valueMapperScope(emitter.valueMapper), blockMapperScope(emitter.blockMapper), emitter(emitter) |
| 90 | { | 90 | { |
| 91 | emitter.nameStack.pushScope(); | 91 | emitter.nameStack.pushScope(); |
| 92 | } | 92 | } |
| 93 | - ~Scope() | 93 | + ~Scope() { emitter.nameStack.popScope(); } |
| 94 | - { | ||
| 95 | - emitter.nameStack.popScope(); | ||
| 96 | - } | ||
| 97 | 94 | ||
| 98 | - private: | 95 | + private: |
| 99 | llvm::ScopedHashTableScope<Value, std::string> valueMapperScope; | 96 | llvm::ScopedHashTableScope<Value, std::string> valueMapperScope; |
| 100 | - llvm::ScopedHashTableScope<Block *, std::string> blockMapperScope; | 97 | + llvm::ScopedHashTableScope<Block*, std::string> blockMapperScope; |
| 101 | - CodeEmitter &emitter; | 98 | + CodeEmitter& emitter; |
| 102 | }; | 99 | }; |
| 103 | 100 | ||
| 104 | /// Returns wether the Value is assigned to a C++ variable in the scope. | 101 | /// Returns wether the Value is assigned to a C++ variable in the scope. |
| 105 | bool hasValueInScope(Value val); | 102 | bool hasValueInScope(Value val); |
| 106 | 103 | ||
| 107 | // Returns whether a label is assigned to the block. | 104 | // Returns whether a label is assigned to the block. |
| 108 | - bool hasBlockLabel(Block &block); | 105 | + bool hasBlockLabel(Block& block); |
| 109 | 106 | ||
| 110 | /// Returns the output stream. | 107 | /// Returns the output stream. |
| 111 | - raw_indented_ostream &ostream() | 108 | + raw_indented_ostream& ostream() { return os; }; |
| 112 | - { | ||
| 113 | - return os; | ||
| 114 | - }; | ||
| 115 | 109 | ||
| 116 | - private: | 110 | +private: |
| 117 | using ValueMapper = llvm::ScopedHashTable<Value, std::string>; | 111 | using ValueMapper = llvm::ScopedHashTable<Value, std::string>; |
| 118 | - using BlockMapper = llvm::ScopedHashTable<Block *, std::string>; | 112 | + using BlockMapper = llvm::ScopedHashTable<Block*, std::string>; |
| 119 | using StructGlobalMapper = std::unordered_map<std::string, std::string>; | 113 | using StructGlobalMapper = std::unordered_map<std::string, std::string>; |
| 120 | using TypeEmitFn = std::function<LogicalResult(Location, Type, bool)>; | 114 | using TypeEmitFn = std::function<LogicalResult(Location, Type, bool)>; |
| 121 | using AttributeEmitFn = std::function<LogicalResult(Location, Attribute)>; | 115 | using AttributeEmitFn = std::function<LogicalResult(Location, Attribute)>; |
| @@ -183,11 +177,11 @@ struct CodeEmitter { | |||
| 183 | 177 | ||
| 184 | LogicalResult emitAscMrgSortSrcListType(Location loc, Type type, bool emitAsUnsigned); | 178 | LogicalResult emitAscMrgSortSrcListType(Location loc, Type type, bool emitAsUnsigned); |
| 185 | 179 | ||
| 186 | - LogicalResult emitIntegerType(IntegerType &iType, Location loc, Type type, bool emitAsUnsigned); | 180 | + LogicalResult emitIntegerType(IntegerType& iType, Location loc, Type type, bool emitAsUnsigned); |
| 187 | 181 | ||
| 188 | - LogicalResult emitFloatType(FloatType &fType, Location loc, Type type, bool emitAsUnsigned); | 182 | + LogicalResult emitFloatType(FloatType& fType, Location loc, Type type, bool emitAsUnsigned); |
| 189 | 183 | ||
| 190 | - LogicalResult emitBaseMemRefType(BaseMemRefType &pType, Location loc, Type type, bool emitAsUnsigned); | 184 | + LogicalResult emitBaseMemRefType(BaseMemRefType& pType, Location loc, Type type, bool emitAsUnsigned); |
| 191 | 185 | ||
| 192 | LogicalResult emitFloatAttr(Location loc, Attribute attr); | 186 | LogicalResult emitFloatAttr(Location loc, Attribute attr); |
| 193 | 187 | ||
| @@ -205,9 +199,9 @@ struct CodeEmitter { | |||
| 205 | 199 | ||
| 206 | LogicalResult emitStringAttr(Location loc, Attribute attr); | 200 | LogicalResult emitStringAttr(Location loc, Attribute attr); |
| 207 | 201 | ||
| 208 | - void printInt(const APInt &value, bool isUnsigned); | 202 | + void printInt(const APInt& value, bool isUnsigned); |
| 209 | 203 | ||
| 210 | - void printFloat(const APFloat &value); | 204 | + void printFloat(const APFloat& value); |
| 211 | }; | 205 | }; |
| 212 | } // namespace mlir | 206 | } // namespace mlir |
| 213 | 207 | ||
| @@ -41,13 +41,13 @@ | |||
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | -#define FAIL_OR(expr) \ | 44 | +#define FAIL_OR(expr) \ |
| 45 | - if (failed(expr)) \ | 45 | + if (failed(expr)) \ |
| 46 | return failure() | 46 | return failure() |
| 47 | 47 | ||
| 48 | -#define EXEC_IF_TRUE(condition, expr) \ | 48 | +#define EXEC_IF_TRUE(condition, expr) \ |
| 49 | - if (condition) { \ | 49 | + if (condition) { \ |
| 50 | - expr \ | 50 | + expr \ |
| 51 | } | 51 | } |
| 52 | namespace mlir { | 52 | namespace mlir { |
| 53 | 53 | ||
| @@ -62,7 +62,7 @@ using LogicalResultForT = LogicalResultIf<llvm::is_one_of<T, AllowedTypes...>::v | |||
| 62 | // When generating code for an `scf.for op`, printing a trailing semicolon is | 62 | // When generating code for an `scf.for op`, printing a trailing semicolon is |
| 63 | // handled within the `printOperation` function. | 63 | // handled within the `printOperation` function. |
| 64 | template <typename OpType> | 64 | template <typename OpType> |
| 65 | -bool needsSemicolon(const OpType &op) | 65 | +bool needsSemicolon(const OpType& op) |
| 66 | { | 66 | { |
| 67 | return !isa<scf::IfOp, scf::ForOp, scf::IndexSwitchOp, scf::YieldOp>(op); | 67 | return !isa<scf::IfOp, scf::ForOp, scf::IndexSwitchOp, scf::YieldOp>(op); |
| 68 | } | 68 | } |
| @@ -79,12 +79,12 @@ LogicalResult isScalarOperation(OpType op) | |||
| 79 | return success(); | 79 | return success(); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | -LogicalResult printConstantOp(CodeEmitter &emitter, Operation *operation, Attribute value); | 82 | +LogicalResult printConstantOp(CodeEmitter& emitter, Operation* operation, Attribute value); |
| 83 | 83 | ||
| 84 | template <typename OpType> | 84 | template <typename OpType> |
| 85 | -LogicalResult printIsSetMaskCastTemplate(CodeEmitter &emitter, OpType op) | 85 | +LogicalResult printIsSetMaskCastTemplate(CodeEmitter& emitter, OpType op) |
| 86 | { | 86 | { |
| 87 | - auto &os = emitter.ostream(); | 87 | + auto& os = emitter.ostream(); |
| 88 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 88 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 89 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc1().getType()).getElementType(); | 89 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc1().getType()).getElementType(); |
| 90 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 90 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -96,9 +96,9 @@ LogicalResult printIsSetMaskCastTemplate(CodeEmitter &emitter, OpType op) | |||
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | template <typename OpType> | 98 | template <typename OpType> |
| 99 | -LogicalResult printIsSetMaskTemplate(CodeEmitter &emitter, OpType op) | 99 | +LogicalResult printIsSetMaskTemplate(CodeEmitter& emitter, OpType op) |
| 100 | { | 100 | { |
| 101 | - auto &os = emitter.ostream(); | 101 | + auto& os = emitter.ostream(); |
| 102 | auto tensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 102 | auto tensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 103 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 103 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 104 | FAIL_OR(emitter.emitType(op.getLoc(), tensorType)); | 104 | FAIL_OR(emitter.emitType(op.getLoc(), tensorType)); |
| @@ -107,11 +107,11 @@ LogicalResult printIsSetMaskTemplate(CodeEmitter &emitter, OpType op) | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | template <typename OpType> | 109 | template <typename OpType> |
| 110 | -auto printMask(CodeEmitter &emitter, OpType op) | 110 | +auto printMask(CodeEmitter& emitter, OpType op) |
| 111 | { | 111 | { |
| 112 | static int maskCounter = 0; | 112 | static int maskCounter = 0; |
| 113 | auto uniqueId = std::to_string(maskCounter++); | 113 | auto uniqueId = std::to_string(maskCounter++); |
| 114 | - auto &os = emitter.ostream(); | 114 | + auto& os = emitter.ostream(); |
| 115 | auto maskName = (emitter.getOrCreateName(op.getDst()) + "_mask_list" + uniqueId).str(); | 115 | auto maskName = (emitter.getOrCreateName(op.getDst()) + "_mask_list" + uniqueId).str(); |
| 116 | os << "uint64_t " << maskName << "[] = {"; | 116 | os << "uint64_t " << maskName << "[] = {"; |
| 117 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 117 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| @@ -126,13 +126,13 @@ namespace ascendc { | |||
| 126 | // Mask operations | 126 | // Mask operations |
| 127 | //===----------------------------------------------------------------------===// | 127 | //===----------------------------------------------------------------------===// |
| 128 | 128 | ||
| 129 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SetVectorMaskL0Op op); | 129 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetVectorMaskL0Op op); |
| 130 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::SetVectorMaskL1Op op); | 130 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::SetVectorMaskL1Op op); |
| 131 | 131 | ||
| 132 | } // namespace ascendc | 132 | } // namespace ascendc |
| 133 | 133 | ||
| 134 | } // namespace mlir | 134 | } // namespace mlir |
| 135 | 135 | ||
| 136 | -mlir::LogicalResult emitOperation(mlir::CodeEmitter &emitter, mlir::Operation &op, bool trailingSemicolon); | 136 | +mlir::LogicalResult emitOperation(mlir::CodeEmitter& emitter, mlir::Operation& op, bool trailingSemicolon); |
| 137 | 137 | ||
| 138 | 138 | ||
| @@ -20,9 +20,9 @@ namespace ascendc { | |||
| 20 | // GlobalTensor operations | 20 | // GlobalTensor operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GlobalTensorSubIndexOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GlobalTensorSubIndexOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::GlobalTensorBracketOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::GlobalTensorBracketOp op); |
| 26 | 26 | ||
| 27 | } // namespace ascendc | 27 | } // namespace ascendc |
| 28 | } // namespace mlir | 28 | } // namespace mlir |
| @@ -20,13 +20,13 @@ namespace ascendc { | |||
| 20 | // LocalTensor operations | 20 | // LocalTensor operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::LocalTensorV2Op op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::LocalTensorV2Op op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::LocalTensorReinterpretCastOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::LocalTensorReinterpretCastOp op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::LocalTensorSubIndexOp op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::LocalTensorSubIndexOp op); |
| 28 | 28 | ||
| 29 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::LocalTensorBracketOp op); | 29 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::LocalTensorBracketOp op); |
| 30 | 30 | ||
| 31 | } // namespace ascendc | 31 | } // namespace ascendc |
| 32 | } // namespace mlir | 32 | } // namespace mlir |
| @@ -20,9 +20,9 @@ namespace ascendc { | |||
| 20 | // ShapeInfo operations | 20 | // ShapeInfo operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ShapeInfoShapeOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ShapeInfoShapeOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ShapeInfoOriginalShapeOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ShapeInfoOriginalShapeOp op); |
| 26 | 26 | ||
| 27 | } // namespace ascendc | 27 | } // namespace ascendc |
| 28 | } // namespace mlir | 28 | } // namespace mlir |
| @@ -21,29 +21,29 @@ namespace emitasc { | |||
| 21 | // EmitAsc operations | 21 | // EmitAsc operations |
| 22 | //===----------------------------------------------------------------------===// | 22 | //===----------------------------------------------------------------------===// |
| 23 | 23 | ||
| 24 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::CallOpaqueOp op); | 24 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::CallOpaqueOp op); |
| 25 | 25 | ||
| 26 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::CopyStructOp op); | 26 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::CopyStructOp op); |
| 27 | 27 | ||
| 28 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::DeclarePyStructOp op); | 28 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::DeclarePyStructOp op); |
| 29 | 29 | ||
| 30 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::DereferenceOp op); | 30 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::DereferenceOp op); |
| 31 | 31 | ||
| 32 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::MemberOp op); | 32 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::MemberOp op); |
| 33 | 33 | ||
| 34 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::MemberPtrOp op); | 34 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::MemberPtrOp op); |
| 35 | 35 | ||
| 36 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::MemberRefOp op); | 36 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::MemberRefOp op); |
| 37 | 37 | ||
| 38 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::PtrOffsetOp op); | 38 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::PtrOffsetOp op); |
| 39 | 39 | ||
| 40 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::ReinterpretCastOp op); | 40 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::ReinterpretCastOp op); |
| 41 | 41 | ||
| 42 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::SetMemberOp op); | 42 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::SetMemberOp op); |
| 43 | 43 | ||
| 44 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::VariableOp op); | 44 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::VariableOp op); |
| 45 | 45 | ||
| 46 | -LogicalResult printOperation(CodeEmitter &emitter, emitasc::VerbatimOp op); | 46 | +LogicalResult printOperation(CodeEmitter& emitter, emitasc::VerbatimOp op); |
| 47 | 47 | ||
| 48 | } // namespace emitasc | 48 | } // namespace emitasc |
| 49 | } // namespace mlir | 49 | } // namespace mlir |
| @@ -29,7 +29,7 @@ struct EmitNameStack { | |||
| 29 | void pushScope(); | 29 | void pushScope(); |
| 30 | void popScope(); | 30 | void popScope(); |
| 31 | 31 | ||
| 32 | - CountStack &getCountStack(const std::string &prefix); | 32 | + CountStack& getCountStack(const std::string& prefix); |
| 33 | std::string getNameForEmission(Value val); | 33 | std::string getNameForEmission(Value val); |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| @@ -16,25 +16,24 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | 17 | ||
| 18 | template <typename BinaryOpType> | 18 | template <typename BinaryOpType> |
| 19 | -auto printOperation(CodeEmitter &emitter, BinaryOpType op) | 19 | +auto printOperation(CodeEmitter& emitter, BinaryOpType op) -> LogicalResultForT< |
| 20 | - -> LogicalResultForT<BinaryOpType, arith::AddIOp, arith::MulIOp, arith::DivSIOp, arith::RemSIOp, arith::SubIOp, | 20 | + BinaryOpType, arith::AddIOp, arith::MulIOp, arith::DivSIOp, arith::RemSIOp, arith::SubIOp, arith::CeilDivSIOp, |
| 21 | - arith::CeilDivSIOp, arith::AndIOp, arith::OrIOp, arith::ShLIOp, arith::MaximumFOp, | 21 | + arith::AndIOp, arith::OrIOp, arith::ShLIOp, arith::MaximumFOp, arith::MaxNumFOp, arith::MinimumFOp, |
| 22 | - arith::MaxNumFOp, arith::MinimumFOp, arith::MinNumFOp, arith::AddFOp, arith::DivFOp, | 22 | + arith::MinNumFOp, arith::AddFOp, arith::DivFOp, arith::ShRSIOp, arith::ShRUIOp, arith::SubFOp, arith::MaxSIOp, |
| 23 | - arith::ShRSIOp, arith::ShRUIOp, arith::SubFOp, arith::MaxSIOp, arith::MulFOp, arith::MinSIOp, | 23 | + arith::MulFOp, arith::MinSIOp, arith::XOrIOp, arith::DivUIOp> |
| 24 | - arith::XOrIOp, arith::DivUIOp> | ||
| 25 | { | 24 | { |
| 26 | if (failed(isScalarOperation(op)) || failed(emitter.emitAssignPrefix(*op.getOperation()))) { | 25 | if (failed(isScalarOperation(op)) || failed(emitter.emitAssignPrefix(*op.getOperation()))) { |
| 27 | return failure(); | 26 | return failure(); |
| 28 | } | 27 | } |
| 29 | - auto &os = emitter.ostream(); | 28 | + auto& os = emitter.ostream(); |
| 30 | if constexpr (std::is_same_v<BinaryOpType, arith::CeilDivSIOp>) { | 29 | if constexpr (std::is_same_v<BinaryOpType, arith::CeilDivSIOp>) { |
| 31 | os << "(" << emitter.getOrCreateName(op.getLhs()) << " + " << emitter.getOrCreateName(op.getRhs()) << " - 1) / " | 30 | os << "(" << emitter.getOrCreateName(op.getLhs()) << " + " << emitter.getOrCreateName(op.getRhs()) << " - 1) / " |
| 32 | << emitter.getOrCreateName(op.getRhs()); | 31 | << emitter.getOrCreateName(op.getRhs()); |
| 33 | return success(); | 32 | return success(); |
| 34 | } | 33 | } |
| 35 | - if constexpr (llvm::is_one_of<BinaryOpType, arith::MaximumFOp, arith::MaxNumFOp, arith::MinimumFOp, | 34 | + if constexpr (llvm::is_one_of< |
| 36 | - arith::MinNumFOp, arith::MinSIOp, arith::MaxSIOp>::value) | 35 | + BinaryOpType, arith::MaximumFOp, arith::MaxNumFOp, arith::MinimumFOp, arith::MinNumFOp, |
| 37 | - { | 36 | + arith::MinSIOp, arith::MaxSIOp>::value) { |
| 38 | auto lhs = emitter.getOrCreateName(op.getLhs()); | 37 | auto lhs = emitter.getOrCreateName(op.getLhs()); |
| 39 | auto rhs = emitter.getOrCreateName(op.getRhs()); | 38 | auto rhs = emitter.getOrCreateName(op.getRhs()); |
| 40 | os << "((" << lhs; | 39 | os << "((" << lhs; |
| @@ -75,31 +74,31 @@ auto printOperation(CodeEmitter &emitter, BinaryOpType op) | |||
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | template <typename CastOpType> | 76 | template <typename CastOpType> |
| 78 | -auto printOperation(CodeEmitter &emitter, CastOpType op) | 77 | +auto printOperation(CodeEmitter& emitter, CastOpType op) -> LogicalResultForT< |
| 79 | - -> LogicalResultForT<CastOpType, arith::ExtUIOp, arith::ExtSIOp, arith::ExtFOp, arith::TruncIOp, arith::TruncFOp, | 78 | + CastOpType, arith::ExtUIOp, arith::ExtSIOp, arith::ExtFOp, arith::TruncIOp, arith::TruncFOp, arith::FPToSIOp, |
| 80 | - arith::FPToSIOp, arith::FPToUIOp, arith::SIToFPOp, arith::UIToFPOp> | 79 | + arith::FPToUIOp, arith::SIToFPOp, arith::UIToFPOp> |
| 81 | { | 80 | { |
| 82 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 81 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 83 | - auto &os = emitter.ostream(); | 82 | + auto& os = emitter.ostream(); |
| 84 | os << "static_cast<"; | 83 | os << "static_cast<"; |
| 85 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 84 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 86 | os << ">(" << emitter.getOrCreateName(op.getIn()) << ")"; | 85 | os << ">(" << emitter.getOrCreateName(op.getIn()) << ")"; |
| 87 | return success(); | 86 | return success(); |
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | -LogicalResult printOperation(CodeEmitter &emitter, arith::ConstantOp constantOp); | 89 | +LogicalResult printOperation(CodeEmitter& emitter, arith::ConstantOp constantOp); |
| 91 | 90 | ||
| 92 | -LogicalResult printOperation(CodeEmitter &emitter, arith::MulUIExtendedOp op); | 91 | +LogicalResult printOperation(CodeEmitter& emitter, arith::MulUIExtendedOp op); |
| 93 | 92 | ||
| 94 | -LogicalResult printOperation(CodeEmitter &emitter, arith::CmpIOp op); | 93 | +LogicalResult printOperation(CodeEmitter& emitter, arith::CmpIOp op); |
| 95 | 94 | ||
| 96 | -LogicalResult printOperation(CodeEmitter &emitter, arith::CmpFOp op); | 95 | +LogicalResult printOperation(CodeEmitter& emitter, arith::CmpFOp op); |
| 97 | 96 | ||
| 98 | -LogicalResult printOperation(CodeEmitter &emitter, arith::BitcastOp op); | 97 | +LogicalResult printOperation(CodeEmitter& emitter, arith::BitcastOp op); |
| 99 | 98 | ||
| 100 | -LogicalResult printOperation(CodeEmitter &emitter, arith::SelectOp op); | 99 | +LogicalResult printOperation(CodeEmitter& emitter, arith::SelectOp op); |
| 101 | 100 | ||
| 102 | -LogicalResult printOperation(CodeEmitter &emitter, arith::IndexCastOp op); | 101 | +LogicalResult printOperation(CodeEmitter& emitter, arith::IndexCastOp op); |
| 103 | 102 | ||
| 104 | } // namespace mlir | 103 | } // namespace mlir |
| 105 | 104 | ||
| @@ -15,15 +15,15 @@ | |||
| 15 | 15 | ||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | 17 | ||
| 18 | -LogicalResult printOperation(CodeEmitter &emitter, emitc::ConstantOp constantOp); | 18 | +LogicalResult printOperation(CodeEmitter& emitter, emitc::ConstantOp constantOp); |
| 19 | 19 | ||
| 20 | -LogicalResult printOperation(CodeEmitter &emitter, emitc::VariableOp variableOp); | 20 | +LogicalResult printOperation(CodeEmitter& emitter, emitc::VariableOp variableOp); |
| 21 | 21 | ||
| 22 | -LogicalResult printOperation(CodeEmitter &emitter, emitc::CastOp castOp); | 22 | +LogicalResult printOperation(CodeEmitter& emitter, emitc::CastOp castOp); |
| 23 | 23 | ||
| 24 | -LogicalResult printOperation(CodeEmitter &emitter, emitc::IncludeOp includeOp); | 24 | +LogicalResult printOperation(CodeEmitter& emitter, emitc::IncludeOp includeOp); |
| 25 | 25 | ||
| 26 | -LogicalResult printOperation(CodeEmitter &emitter, emitc::VerbatimOp verbatimOp); | 26 | +LogicalResult printOperation(CodeEmitter& emitter, emitc::VerbatimOp verbatimOp); |
| 27 | 27 | ||
| 28 | } // namespace mlir | 28 | } // namespace mlir |
| 29 | 29 | ||
| @@ -15,13 +15,13 @@ | |||
| 15 | 15 | ||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | 17 | ||
| 18 | -LogicalResult printOperation(CodeEmitter &codeEmitter, func::ConstantOp constantOp); | 18 | +LogicalResult printOperation(CodeEmitter& codeEmitter, func::ConstantOp constantOp); |
| 19 | 19 | ||
| 20 | -LogicalResult printOperation(CodeEmitter &codeEmitter, func::CallOp callOp); | 20 | +LogicalResult printOperation(CodeEmitter& codeEmitter, func::CallOp callOp); |
| 21 | 21 | ||
| 22 | -LogicalResult printOperation(CodeEmitter &codeEmitter, func::ReturnOp returnOp); | 22 | +LogicalResult printOperation(CodeEmitter& codeEmitter, func::ReturnOp returnOp); |
| 23 | 23 | ||
| 24 | -LogicalResult printOperation(CodeEmitter &codeEmitter, func::FuncOp functionOp); | 24 | +LogicalResult printOperation(CodeEmitter& codeEmitter, func::FuncOp functionOp); |
| 25 | 25 | ||
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| 27 | 27 | ||
| @@ -16,15 +16,14 @@ | |||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | 17 | ||
| 18 | template <typename UnaryOpType> | 18 | template <typename UnaryOpType> |
| 19 | -auto printOperation(CodeEmitter &emitter, UnaryOpType op) | 19 | +auto printOperation(CodeEmitter& emitter, UnaryOpType op) -> LogicalResultForT< |
| 20 | - -> LogicalResultForT<UnaryOpType, math::AbsFOp, math::SqrtOp, math::ExpOp, math::LogOp, math::CosOp, math::SinOp, | 20 | + UnaryOpType, math::AbsFOp, math::SqrtOp, math::ExpOp, math::LogOp, math::CosOp, math::SinOp, math::Log2Op, |
| 21 | - math::Log2Op, math::ErfOp, math::CeilOp, math::FloorOp, math::RsqrtOp, math::Exp2Op, | 21 | + math::ErfOp, math::CeilOp, math::FloorOp, math::RsqrtOp, math::Exp2Op, math::RoundOp> |
| 22 | - math::RoundOp> | ||
| 23 | { | 22 | { |
| 24 | if (failed(isScalarOperation(op)) || failed(emitter.emitAssignPrefix(*op.getOperation()))) { | 23 | if (failed(isScalarOperation(op)) || failed(emitter.emitAssignPrefix(*op.getOperation()))) { |
| 25 | return failure(); | 24 | return failure(); |
| 26 | } | 25 | } |
| 27 | - auto &os = emitter.ostream(); | 26 | + auto& os = emitter.ostream(); |
| 28 | if constexpr (std::is_same_v<UnaryOpType, math::AbsFOp>) { | 27 | if constexpr (std::is_same_v<UnaryOpType, math::AbsFOp>) { |
| 29 | auto lhs = emitter.getOrCreateName(op.getOperand()); | 28 | auto lhs = emitter.getOrCreateName(op.getOperand()); |
| 30 | os << "(" << lhs << " > static_cast<"; | 29 | os << "(" << lhs << " > static_cast<"; |
| @@ -61,11 +60,11 @@ auto printOperation(CodeEmitter &emitter, UnaryOpType op) | |||
| 61 | } | 60 | } |
| 62 | 61 | ||
| 63 | template <typename BinaryOpType> | 62 | template <typename BinaryOpType> |
| 64 | -LogicalResultForT<BinaryOpType, math::Atan2Op> printOperation(CodeEmitter &emitter, BinaryOpType op) | 63 | +LogicalResultForT<BinaryOpType, math::Atan2Op> printOperation(CodeEmitter& emitter, BinaryOpType op) |
| 65 | { | 64 | { |
| 66 | FAIL_OR(isScalarOperation(op)); | 65 | FAIL_OR(isScalarOperation(op)); |
| 67 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 66 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 68 | - auto &os = emitter.ostream(); | 67 | + auto& os = emitter.ostream(); |
| 69 | if constexpr (std::is_same_v<BinaryOpType, math::Atan2Op>) { | 68 | if constexpr (std::is_same_v<BinaryOpType, math::Atan2Op>) { |
| 70 | auto lhs = emitter.getOrCreateName(op.getLhs()); | 69 | auto lhs = emitter.getOrCreateName(op.getLhs()); |
| 71 | auto rhs = emitter.getOrCreateName(op.getRhs()); | 70 | auto rhs = emitter.getOrCreateName(op.getRhs()); |
| @@ -77,9 +76,9 @@ LogicalResultForT<BinaryOpType, math::Atan2Op> printOperation(CodeEmitter &emitt | |||
| 77 | return failure(); | 76 | return failure(); |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 80 | -LogicalResult printOperation(CodeEmitter &emitter, math::FmaOp op); | 79 | +LogicalResult printOperation(CodeEmitter& emitter, math::FmaOp op); |
| 81 | 80 | ||
| 82 | -LogicalResult printOperation(CodeEmitter &emitter, math::CopySignOp op); | 81 | +LogicalResult printOperation(CodeEmitter& emitter, math::CopySignOp op); |
| 83 | 82 | ||
| 84 | } // namespace mlir | 83 | } // namespace mlir |
| 85 | 84 | ||
| @@ -15,13 +15,13 @@ | |||
| 15 | 15 | ||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | 17 | ||
| 18 | -LogicalResult printOperation(CodeEmitter &emitter, memref::AllocaOp op); | 18 | +LogicalResult printOperation(CodeEmitter& emitter, memref::AllocaOp op); |
| 19 | 19 | ||
| 20 | -LogicalResult printOperation(CodeEmitter &emitter, memref::LoadOp op); | 20 | +LogicalResult printOperation(CodeEmitter& emitter, memref::LoadOp op); |
| 21 | 21 | ||
| 22 | -LogicalResult printOperation(CodeEmitter &emitter, memref::StoreOp op); | 22 | +LogicalResult printOperation(CodeEmitter& emitter, memref::StoreOp op); |
| 23 | 23 | ||
| 24 | -LogicalResult printOperation(CodeEmitter &emitter, memref::CastOp op); | 24 | +LogicalResult printOperation(CodeEmitter& emitter, memref::CastOp op); |
| 25 | 25 | ||
| 26 | } // namespace mlir | 26 | } // namespace mlir |
| 27 | 27 | ||
| @@ -15,19 +15,19 @@ | |||
| 15 | 15 | ||
| 16 | namespace mlir { | 16 | namespace mlir { |
| 17 | 17 | ||
| 18 | -LogicalResult emitBlock(CodeEmitter &codeEmitter, Block &block); | 18 | +LogicalResult emitBlock(CodeEmitter& codeEmitter, Block& block); |
| 19 | 19 | ||
| 20 | -LogicalResult printOperation(CodeEmitter &codeEmitter, scf::ForOp forOp); | 20 | +LogicalResult printOperation(CodeEmitter& codeEmitter, scf::ForOp forOp); |
| 21 | 21 | ||
| 22 | -LogicalResult printOperation(CodeEmitter &codeEmitter, scf::IfOp ifOp); | 22 | +LogicalResult printOperation(CodeEmitter& codeEmitter, scf::IfOp ifOp); |
| 23 | 23 | ||
| 24 | -LogicalResult printOperation(CodeEmitter &codeEmitter, scf::IndexSwitchOp op); | 24 | +LogicalResult printOperation(CodeEmitter& codeEmitter, scf::IndexSwitchOp op); |
| 25 | 25 | ||
| 26 | -LogicalResult printOperation(CodeEmitter &codeEmitter, scf::YieldOp yieldOp); | 26 | +LogicalResult printOperation(CodeEmitter& codeEmitter, scf::YieldOp yieldOp); |
| 27 | 27 | ||
| 28 | -LogicalResult printOperation(CodeEmitter &codeEmitter, scf::ConditionOp conditionOp); | 28 | +LogicalResult printOperation(CodeEmitter& codeEmitter, scf::ConditionOp conditionOp); |
| 29 | 29 | ||
| 30 | -LogicalResult printOperation(CodeEmitter &codeEmitter, scf::WhileOp whileOp); | 30 | +LogicalResult printOperation(CodeEmitter& codeEmitter, scf::WhileOp whileOp); |
| 31 | 31 | ||
| 32 | } // namespace mlir | 32 | } // namespace mlir |
| 33 | 33 | ||
| @@ -20,9 +20,9 @@ namespace ascendc { | |||
| 20 | // Buffer operations (TBuf) | 20 | // Buffer operations (TBuf) |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TBufGetTensorOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TBufGetTensorOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TBufGetWithOffsetOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TBufGetWithOffsetOp op); |
| 26 | 26 | ||
| 27 | } // namespace ascendc | 27 | } // namespace ascendc |
| 28 | } // namespace mlir | 28 | } // namespace mlir |
| @@ -20,19 +20,19 @@ namespace ascendc { | |||
| 20 | // TQueQind operations | 20 | // TQueQind operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TQueBindAllocTensorOp op); | 23 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TQueBindAllocTensorOp op); |
| 24 | 24 | ||
| 25 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TQueBindAllocTensorInPlaceOp op); | 25 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TQueBindAllocTensorInPlaceOp op); |
| 26 | 26 | ||
| 27 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TQueBindDequeTensorOp op); | 27 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TQueBindDequeTensorOp op); |
| 28 | 28 | ||
| 29 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TQueBindDequeTensorInPlaceOp op); | 29 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TQueBindDequeTensorInPlaceOp op); |
| 30 | 30 | ||
| 31 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TQueBindDequeTensorPosOp op); | 31 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TQueBindDequeTensorPosOp op); |
| 32 | 32 | ||
| 33 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::TQueBindEnqueTensorPosOp op); | 33 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::TQueBindEnqueTensorPosOp op); |
| 34 | 34 | ||
| 35 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::ToQueBindOp op); | 35 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::ToQueBindOp op); |
| 36 | 36 | ||
| 37 | } // namespace ascendc | 37 | } // namespace ascendc |
| 38 | } // namespace mlir | 38 | } // namespace mlir |
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | namespace mlir { | 17 | namespace mlir { |
| 18 | 18 | ||
| 19 | -LogicalResult translateToAscendC(Operation *op, raw_ostream &os); | 19 | +LogicalResult translateToAscendC(Operation* op, raw_ostream& os); |
| 20 | 20 | ||
| 21 | } // namespace mlir | 21 | } // namespace mlir |
| 22 | 22 | ||
| @@ -18,9 +18,9 @@ | |||
| 18 | namespace mlir { | 18 | namespace mlir { |
| 19 | namespace ascendc { | 19 | namespace ascendc { |
| 20 | template <typename ConcreteOp> | 20 | template <typename ConcreteOp> |
| 21 | -LogicalResult emitFunctionParams(CodeEmitter &emitter, ConcreteOp op, size_t startPos = 0) | 21 | +LogicalResult emitFunctionParams(CodeEmitter& emitter, ConcreteOp op, size_t startPos = 0) |
| 22 | { | 22 | { |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | bool first = true; | 24 | bool first = true; |
| 25 | for (size_t i = startPos; i < op.getOperation()->getNumOperands(); ++i) { | 25 | for (size_t i = startPos; i < op.getOperation()->getNumOperands(); ++i) { |
| 26 | if (!first) { | 26 | if (!first) { |
| @@ -34,16 +34,16 @@ LogicalResult emitFunctionParams(CodeEmitter &emitter, ConcreteOp op, size_t sta | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | template <typename ConcreteOp> | 36 | template <typename ConcreteOp> |
| 37 | -LogicalResult autoPrintConstructorOp(CodeEmitter &emitter, ConcreteOp op) | 37 | +LogicalResult autoPrintConstructorOp(CodeEmitter& emitter, ConcreteOp op) |
| 38 | { | 38 | { |
| 39 | return emitter.emitVariableDeclaration(op->getResult(0), false); | 39 | return emitter.emitVariableDeclaration(op->getResult(0), false); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | template <typename ConcreteOp> | 42 | template <typename ConcreteOp> |
| 43 | -LogicalResult autoPrintMemberFuncOp(CodeEmitter &emitter, ConcreteOp op) | 43 | +LogicalResult autoPrintMemberFuncOp(CodeEmitter& emitter, ConcreteOp op) |
| 44 | { | 44 | { |
| 45 | auto resNum = op.getOperation()->getNumResults(); | 45 | auto resNum = op.getOperation()->getNumResults(); |
| 46 | - auto &os = emitter.ostream(); | 46 | + auto& os = emitter.ostream(); |
| 47 | if (resNum == 1) { | 47 | if (resNum == 1) { |
| 48 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 48 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 49 | os << " = "; | 49 | os << " = "; |
| @@ -56,10 +56,10 @@ LogicalResult autoPrintMemberFuncOp(CodeEmitter &emitter, ConcreteOp op) | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | template <typename ConcreteOp> | 58 | template <typename ConcreteOp> |
| 59 | -LogicalResult autoPrintAscFuncOp(CodeEmitter &emitter, ConcreteOp op) | 59 | +LogicalResult autoPrintAscFuncOp(CodeEmitter& emitter, ConcreteOp op) |
| 60 | { | 60 | { |
| 61 | auto resNum = op.getOperation()->getNumResults(); | 61 | auto resNum = op.getOperation()->getNumResults(); |
| 62 | - auto &os = emitter.ostream(); | 62 | + auto& os = emitter.ostream(); |
| 63 | if (resNum == 1) { | 63 | if (resNum == 1) { |
| 64 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 64 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 65 | os << " = "; | 65 | os << " = "; |
| @@ -71,7 +71,7 @@ LogicalResult autoPrintAscFuncOp(CodeEmitter &emitter, ConcreteOp op) | |||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | template <typename ConcreteOp> | 73 | template <typename ConcreteOp> |
| 74 | -LogicalResult autoPrintOp(CodeEmitter &emitter, ConcreteOp op) | 74 | +LogicalResult autoPrintOp(CodeEmitter& emitter, ConcreteOp op) |
| 75 | { | 75 | { |
| 76 | if constexpr (ConcreteOp::template hasTrait<mlir::OpTrait::AscConstructorTrait>()) { | 76 | if constexpr (ConcreteOp::template hasTrait<mlir::OpTrait::AscConstructorTrait>()) { |
| 77 | return autoPrintConstructorOp<ConcreteOp>(emitter, op); | 77 | return autoPrintConstructorOp<ConcreteOp>(emitter, op); |
| @@ -19,8 +19,8 @@ namespace mlir { | |||
| 19 | /// Convenience functions to produce interleaved output with functions returning a LogicalResult. | 19 | /// Convenience functions to produce interleaved output with functions returning a LogicalResult. |
| 20 | /// This is different than those in STLExtras as functions used on each element doesn't return a string. | 20 | /// This is different than those in STLExtras as functions used on each element doesn't return a string. |
| 21 | template <typename ForwardIterator, typename UnaryFunctor, typename NullaryFunctor> | 21 | template <typename ForwardIterator, typename UnaryFunctor, typename NullaryFunctor> |
| 22 | -inline LogicalResult interleaveWithError(ForwardIterator beginIter, ForwardIterator endIter, UnaryFunctor eachFn, | 22 | +inline LogicalResult |
| 23 | - NullaryFunctor betweenFn) | 23 | +interleaveWithError(ForwardIterator beginIter, ForwardIterator endIter, UnaryFunctor eachFn, NullaryFunctor betweenFn) |
| 24 | { | 24 | { |
| 25 | if (beginIter == endIter) | 25 | if (beginIter == endIter) |
| 26 | return success(); | 26 | return success(); |
| @@ -36,13 +36,13 @@ inline LogicalResult interleaveWithError(ForwardIterator beginIter, ForwardItera | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | template <typename Container, typename UnaryFunctor, typename NullaryFunctor> | 38 | template <typename Container, typename UnaryFunctor, typename NullaryFunctor> |
| 39 | -inline LogicalResult interleaveWithError(const Container &container, UnaryFunctor eachFn, NullaryFunctor betweenFn) | 39 | +inline LogicalResult interleaveWithError(const Container& container, UnaryFunctor eachFn, NullaryFunctor betweenFn) |
| 40 | { | 40 | { |
| 41 | return interleaveWithError(std::cbegin(container), std::cend(container), eachFn, betweenFn); | 41 | return interleaveWithError(std::cbegin(container), std::cend(container), eachFn, betweenFn); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | template <typename Container, typename UnaryFunctor> | 44 | template <typename Container, typename UnaryFunctor> |
| 45 | -inline LogicalResult interleaveCommaWithError(const Container &c, raw_ostream &os, UnaryFunctor eachFn) | 45 | +inline LogicalResult interleaveCommaWithError(const Container& c, raw_ostream& os, UnaryFunctor eachFn) |
| 46 | { | 46 | { |
| 47 | return interleaveWithError(std::cbegin(c), std::cend(c), eachFn, [&]() { os << ", "; }); | 47 | return interleaveWithError(std::cbegin(c), std::cend(c), eachFn, [&]() { os << ", "; }); |
| 48 | } | 48 | } |
| @@ -27,7 +27,7 @@ using namespace mlir::ascendc; | |||
| 27 | // TPositionAttr | 27 | // TPositionAttr |
| 28 | //===----------------------------------------------------------------------===// | 28 | //===----------------------------------------------------------------------===// |
| 29 | 29 | ||
| 30 | -ParseResult mlir::ascendc::parsePrettyTPosition(AsmParser &odsParser, TPositionAttr &attr) | 30 | +ParseResult mlir::ascendc::parsePrettyTPosition(AsmParser& odsParser, TPositionAttr& attr) |
| 31 | { | 31 | { |
| 32 | StringRef pos; | 32 | StringRef pos; |
| 33 | if (odsParser.parseKeyword(&pos)) | 33 | if (odsParser.parseKeyword(&pos)) |
| @@ -39,7 +39,7 @@ ParseResult mlir::ascendc::parsePrettyTPosition(AsmParser &odsParser, TPositionA | |||
| 39 | return odsParser.emitError(odsParser.getNameLoc()) << "position is not recognized: " << pos; | 39 | return odsParser.emitError(odsParser.getNameLoc()) << "position is not recognized: " << pos; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | -void mlir::ascendc::printPrettyTPosition(AsmPrinter &odsPrinter, const TPositionAttr &attr) | 42 | +void mlir::ascendc::printPrettyTPosition(AsmPrinter& odsPrinter, const TPositionAttr& attr) |
| 43 | { | 43 | { |
| 44 | odsPrinter << stringifyTPosition(attr.getValue()); | 44 | odsPrinter << stringifyTPosition(attr.getValue()); |
| 45 | } | 45 | } |
| @@ -48,7 +48,7 @@ void mlir::ascendc::printPrettyTPosition(AsmPrinter &odsPrinter, const TPosition | |||
| 48 | // CubeFormatAttr | 48 | // CubeFormatAttr |
| 49 | //===----------------------------------------------------------------------===// | 49 | //===----------------------------------------------------------------------===// |
| 50 | 50 | ||
| 51 | -ParseResult ascendc::parsePrettyCubeFormat(AsmParser &odsParser, CubeFormatAttr &attr) | 51 | +ParseResult ascendc::parsePrettyCubeFormat(AsmParser& odsParser, CubeFormatAttr& attr) |
| 52 | { | 52 | { |
| 53 | StringRef pos; | 53 | StringRef pos; |
| 54 | if (odsParser.parseKeyword(&pos)) | 54 | if (odsParser.parseKeyword(&pos)) |
| @@ -60,7 +60,7 @@ ParseResult ascendc::parsePrettyCubeFormat(AsmParser &odsParser, CubeFormatAttr | |||
| 60 | return odsParser.emitError(odsParser.getNameLoc()) << "cube format is not recognized: " << pos; | 60 | return odsParser.emitError(odsParser.getNameLoc()) << "cube format is not recognized: " << pos; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | -void ascendc::printPrettyCubeFormat(AsmPrinter &odsPrinter, const CubeFormatAttr &attr) | 63 | +void ascendc::printPrettyCubeFormat(AsmPrinter& odsPrinter, const CubeFormatAttr& attr) |
| 64 | { | 64 | { |
| 65 | odsPrinter << stringifyCubeFormat(attr.getValue()); | 65 | odsPrinter << stringifyCubeFormat(attr.getValue()); |
| 66 | } | 66 | } |
| @@ -69,7 +69,7 @@ void ascendc::printPrettyCubeFormat(AsmPrinter &odsPrinter, const CubeFormatAttr | |||
| 69 | // LayoutModeAttr | 69 | // LayoutModeAttr |
| 70 | //===----------------------------------------------------------------------===// | 70 | //===----------------------------------------------------------------------===// |
| 71 | 71 | ||
| 72 | -ParseResult ascendc::parsePrettyLayoutMode(AsmParser &odsParser, LayoutModeAttr &attr) | 72 | +ParseResult ascendc::parsePrettyLayoutMode(AsmParser& odsParser, LayoutModeAttr& attr) |
| 73 | { | 73 | { |
| 74 | StringRef pos; | 74 | StringRef pos; |
| 75 | if (odsParser.parseKeyword(&pos)) | 75 | if (odsParser.parseKeyword(&pos)) |
| @@ -81,7 +81,7 @@ ParseResult ascendc::parsePrettyLayoutMode(AsmParser &odsParser, LayoutModeAttr | |||
| 81 | return odsParser.emitError(odsParser.getNameLoc()) << "layout mode is not recognized: " << pos; | 81 | return odsParser.emitError(odsParser.getNameLoc()) << "layout mode is not recognized: " << pos; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | -void ascendc::printPrettyLayoutMode(AsmPrinter &odsPrinter, const LayoutModeAttr &attr) | 84 | +void ascendc::printPrettyLayoutMode(AsmPrinter& odsPrinter, const LayoutModeAttr& attr) |
| 85 | { | 85 | { |
| 86 | odsPrinter << stringifyLayoutMode(attr.getValue()); | 86 | odsPrinter << stringifyLayoutMode(attr.getValue()); |
| 87 | } | 87 | } |
| @@ -90,7 +90,7 @@ void ascendc::printPrettyLayoutMode(AsmPrinter &odsPrinter, const LayoutModeAttr | |||
| 90 | // CO2LayoutAttr | 90 | // CO2LayoutAttr |
| 91 | //===----------------------------------------------------------------------===// | 91 | //===----------------------------------------------------------------------===// |
| 92 | 92 | ||
| 93 | -ParseResult mlir::ascendc::parsePrettyCO2Layout(AsmParser &odsParser, CO2LayoutAttr &attr) | 93 | +ParseResult mlir::ascendc::parsePrettyCO2Layout(AsmParser& odsParser, CO2LayoutAttr& attr) |
| 94 | { | 94 | { |
| 95 | StringRef pos; | 95 | StringRef pos; |
| 96 | if (odsParser.parseKeyword(&pos)) | 96 | if (odsParser.parseKeyword(&pos)) |
| @@ -102,7 +102,7 @@ ParseResult mlir::ascendc::parsePrettyCO2Layout(AsmParser &odsParser, CO2LayoutA | |||
| 102 | return odsParser.emitError(odsParser.getNameLoc()) << "CO2Layout is not recognized: " << pos; | 102 | return odsParser.emitError(odsParser.getNameLoc()) << "CO2Layout is not recognized: " << pos; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | -void mlir::ascendc::printPrettyCO2Layout(AsmPrinter &odsPrinter, const CO2LayoutAttr &attr) | 105 | +void mlir::ascendc::printPrettyCO2Layout(AsmPrinter& odsPrinter, const CO2LayoutAttr& attr) |
| 106 | { | 106 | { |
| 107 | odsPrinter << stringifyCO2Layout(attr.getValue()); | 107 | odsPrinter << stringifyCO2Layout(attr.getValue()); |
| 108 | } | 108 | } |
| @@ -35,9 +35,9 @@ void AscendCDialect::initialize() | |||
| 35 | // External models | 35 | // External models |
| 36 | //===----------------------------------------------------------------------===// | 36 | //===----------------------------------------------------------------------===// |
| 37 | 37 | ||
| 38 | -void ascendc::registerExternalModels(DialectRegistry ®istry) | 38 | +void ascendc::registerExternalModels(DialectRegistry& registry) |
| 39 | { | 39 | { |
| 40 | using namespace ascir; | 40 | using namespace ascir; |
| 41 | registry.addExtension( | 41 | registry.addExtension( |
| 42 | - +[](MLIRContext *ctx, AscendCDialect *dialect) { dialect->addInterface<PermissiveInlinerInterface>(); }); | 42 | + +[](MLIRContext* ctx, AscendCDialect* dialect) { dialect->addInterface<PermissiveInlinerInterface>(); }); |
| 43 | } | 43 | } |
| @@ -22,7 +22,7 @@ using namespace mlir::ascendc; | |||
| 22 | 22 | ||
| 23 | namespace { | 23 | namespace { |
| 24 | 24 | ||
| 25 | -LogicalResult eraseUnusedOp(Operation *op, PatternRewriter &rewriter) | 25 | +LogicalResult eraseUnusedOp(Operation* op, PatternRewriter& rewriter) |
| 26 | { | 26 | { |
| 27 | if (!op->getUses().empty()) { | 27 | if (!op->getUses().empty()) { |
| 28 | return failure(); | 28 | return failure(); |
| @@ -37,7 +37,7 @@ LogicalResult eraseUnusedOp(Operation *op, PatternRewriter &rewriter) | |||
| 37 | // GlobalTensorOp | 37 | // GlobalTensorOp |
| 38 | //===----------------------------------------------------------------------===// | 38 | //===----------------------------------------------------------------------===// |
| 39 | 39 | ||
| 40 | -LogicalResult GlobalTensorOp::canonicalize(GlobalTensorOp op, PatternRewriter &rewriter) | 40 | +LogicalResult GlobalTensorOp::canonicalize(GlobalTensorOp op, PatternRewriter& rewriter) |
| 41 | { | 41 | { |
| 42 | return eraseUnusedOp(op, rewriter); | 42 | return eraseUnusedOp(op, rewriter); |
| 43 | } | 43 | } |
| @@ -46,7 +46,7 @@ LogicalResult GlobalTensorOp::canonicalize(GlobalTensorOp op, PatternRewriter &r | |||
| 46 | // LocalTensorOp | 46 | // LocalTensorOp |
| 47 | //===----------------------------------------------------------------------===// | 47 | //===----------------------------------------------------------------------===// |
| 48 | 48 | ||
| 49 | -LogicalResult LocalTensorOp::canonicalize(LocalTensorOp op, PatternRewriter &rewriter) | 49 | +LogicalResult LocalTensorOp::canonicalize(LocalTensorOp op, PatternRewriter& rewriter) |
| 50 | { | 50 | { |
| 51 | return eraseUnusedOp(op, rewriter); | 51 | return eraseUnusedOp(op, rewriter); |
| 52 | } | 52 | } |
| @@ -55,9 +55,9 @@ LogicalResult LocalTensorOp::canonicalize(LocalTensorOp op, PatternRewriter &rew | |||
| 55 | // PipeBarrierOp | 55 | // PipeBarrierOp |
| 56 | //===----------------------------------------------------------------------===// | 56 | //===----------------------------------------------------------------------===// |
| 57 | 57 | ||
| 58 | -LogicalResult PipeBarrierOp::canonicalize(PipeBarrierOp op, PatternRewriter &rewriter) | 58 | +LogicalResult PipeBarrierOp::canonicalize(PipeBarrierOp op, PatternRewriter& rewriter) |
| 59 | { | 59 | { |
| 60 | - Block *block = op->getBlock(); | 60 | + Block* block = op->getBlock(); |
| 61 | auto nextIt = std::next(Block::iterator(op)); | 61 | auto nextIt = std::next(Block::iterator(op)); |
| 62 | if (nextIt == block->end()) | 62 | if (nextIt == block->end()) |
| 63 | return failure(); | 63 | return failure(); |
| @@ -29,23 +29,20 @@ template <typename ConcreteT> | |||
| 29 | class BaseTensorImpl { | 29 | class BaseTensorImpl { |
| 30 | using BaseT = typename ConcreteT::Base; | 30 | using BaseT = typename ConcreteT::Base; |
| 31 | 31 | ||
| 32 | - public: | 32 | +public: |
| 33 | static ConcreteT get(ArrayRef<int64_t> shape, Type elementType) | 33 | static ConcreteT get(ArrayRef<int64_t> shape, Type elementType) |
| 34 | { | 34 | { |
| 35 | return BaseT::get(elementType.getContext(), shape, elementType); | 35 | return BaseT::get(elementType.getContext(), shape, elementType); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | - static ConcreteT get(Type elementType) | 38 | + static ConcreteT get(Type elementType) { return ConcreteT::get({}, elementType); } |
| 39 | - { | ||
| 40 | - return ConcreteT::get({}, elementType); | ||
| 41 | - } | ||
| 42 | 39 | ||
| 43 | static ConcreteT get(BaseTensorType baseType) | 40 | static ConcreteT get(BaseTensorType baseType) |
| 44 | { | 41 | { |
| 45 | return BaseT::get(baseType.getContext(), baseType.getShape(), baseType.getElementType()); | 42 | return BaseT::get(baseType.getContext(), baseType.getShape(), baseType.getElementType()); |
| 46 | } | 43 | } |
| 47 | 44 | ||
| 48 | - static Type parse(AsmParser &odsParser) | 45 | + static Type parse(AsmParser& odsParser) |
| 49 | { | 46 | { |
| 50 | Type elementType; | 47 | Type elementType; |
| 51 | if (odsParser.parseLess()) | 48 | if (odsParser.parseLess()) |
| @@ -54,9 +51,9 @@ class BaseTensorImpl { | |||
| 54 | if (odsParser.parseOptionalStar()) { | 51 | if (odsParser.parseOptionalStar()) { |
| 55 | // No '*' consumed => tensor is ranked (i.e. has shape) | 52 | // No '*' consumed => tensor is ranked (i.e. has shape) |
| 56 | if (odsParser.parseDimensionList(shape)) { | 53 | if (odsParser.parseDimensionList(shape)) { |
| 57 | - odsParser.emitError(odsParser.getNameLoc(), | 54 | + odsParser.emitError( |
| 58 | - "either dimension list (for ranked tensor) or '*' symbol (for " | 55 | + odsParser.getNameLoc(), "either dimension list (for ranked tensor) or '*' symbol (for " |
| 59 | - "unranked tensor) must be declared"); | 56 | + "unranked tensor) must be declared"); |
| 60 | return Type(); | 57 | return Type(); |
| 61 | } | 58 | } |
| 62 | } else if (odsParser.parseXInDimensionList()) { | 59 | } else if (odsParser.parseXInDimensionList()) { |
| @@ -68,7 +65,7 @@ class BaseTensorImpl { | |||
| 68 | return ConcreteT::get(shape, elementType); | 65 | return ConcreteT::get(shape, elementType); |
| 69 | } | 66 | } |
| 70 | 67 | ||
| 71 | - static void print(const ConcreteT &tensor, AsmPrinter &odsPrinter) | 68 | + static void print(const ConcreteT& tensor, AsmPrinter& odsPrinter) |
| 72 | { | 69 | { |
| 73 | odsPrinter << "<"; | 70 | odsPrinter << "<"; |
| 74 | ArrayRef<int64_t> shape = tensor.getShape(); | 71 | ArrayRef<int64_t> shape = tensor.getShape(); |
| @@ -86,17 +83,14 @@ class BaseTensorImpl { | |||
| 86 | odsPrinter << tensor.getElementType() << ">"; | 83 | odsPrinter << tensor.getElementType() << ">"; |
| 87 | } | 84 | } |
| 88 | 85 | ||
| 89 | - static ShapedType cloneWith(const ConcreteT &tensor, std::optional<ArrayRef<int64_t>> shape, Type elementType) | 86 | + static ShapedType cloneWith(const ConcreteT& tensor, std::optional<ArrayRef<int64_t>> shape, Type elementType) |
| 90 | { | 87 | { |
| 91 | if (shape) | 88 | if (shape) |
| 92 | return ConcreteT::get(*shape, elementType); | 89 | return ConcreteT::get(*shape, elementType); |
| 93 | return ConcreteT::get(tensor.getShape(), elementType); | 90 | return ConcreteT::get(tensor.getShape(), elementType); |
| 94 | } | 91 | } |
| 95 | 92 | ||
| 96 | - static bool hasRank(const ConcreteT &tensor) | 93 | + static bool hasRank(const ConcreteT& tensor) { return !tensor.getShape().empty(); } |
| 97 | - { | ||
| 98 | - return !tensor.getShape().empty(); | ||
| 99 | - } | ||
| 100 | }; | 94 | }; |
| 101 | 95 | ||
| 102 | //===----------------------------------------------------------------------===// | 96 | //===----------------------------------------------------------------------===// |
| @@ -118,12 +112,12 @@ BaseGlobalTensorType BaseGlobalTensorType::get(BaseTensorType baseType) | |||
| 118 | return BaseTensorImpl<BaseGlobalTensorType>::get(baseType); | 112 | return BaseTensorImpl<BaseGlobalTensorType>::get(baseType); |
| 119 | } | 113 | } |
| 120 | 114 | ||
| 121 | -Type BaseGlobalTensorType::parse(AsmParser &odsParser) | 115 | +Type BaseGlobalTensorType::parse(AsmParser& odsParser) |
| 122 | { | 116 | { |
| 123 | return BaseTensorImpl<BaseGlobalTensorType>::parse(odsParser); | 117 | return BaseTensorImpl<BaseGlobalTensorType>::parse(odsParser); |
| 124 | } | 118 | } |
| 125 | 119 | ||
| 126 | -void BaseGlobalTensorType::print(AsmPrinter &odsPrinter) const | 120 | +void BaseGlobalTensorType::print(AsmPrinter& odsPrinter) const |
| 127 | { | 121 | { |
| 128 | BaseTensorImpl<BaseGlobalTensorType>::print(*this, odsPrinter); | 122 | BaseTensorImpl<BaseGlobalTensorType>::print(*this, odsPrinter); |
| 129 | } | 123 | } |
| @@ -133,10 +127,7 @@ ShapedType BaseGlobalTensorType::cloneWith(std::optional<ArrayRef<int64_t>> shap | |||
| 133 | return BaseTensorImpl<BaseGlobalTensorType>::cloneWith(*this, shape, elementType); | 127 | return BaseTensorImpl<BaseGlobalTensorType>::cloneWith(*this, shape, elementType); |
| 134 | } | 128 | } |
| 135 | 129 | ||
| 136 | -bool BaseGlobalTensorType::hasRank() const | 130 | +bool BaseGlobalTensorType::hasRank() const { return BaseTensorImpl<BaseGlobalTensorType>::hasRank(*this); } |
| 137 | -{ | ||
| 138 | - return BaseTensorImpl<BaseGlobalTensorType>::hasRank(*this); | ||
| 139 | -} | ||
| 140 | 131 | ||
| 141 | //===----------------------------------------------------------------------===// | 132 | //===----------------------------------------------------------------------===// |
| 142 | // BaseLocalTensorType | 133 | // BaseLocalTensorType |
| @@ -157,12 +148,9 @@ BaseLocalTensorType BaseLocalTensorType::get(BaseTensorType baseType) | |||
| 157 | return BaseTensorImpl<BaseLocalTensorType>::get(baseType); | 148 | return BaseTensorImpl<BaseLocalTensorType>::get(baseType); |
| 158 | } | 149 | } |
| 159 | 150 | ||
| 160 | -Type BaseLocalTensorType::parse(AsmParser &odsParser) | 151 | +Type BaseLocalTensorType::parse(AsmParser& odsParser) { return BaseTensorImpl<BaseLocalTensorType>::parse(odsParser); } |
| 161 | -{ | ||
| 162 | - return BaseTensorImpl<BaseLocalTensorType>::parse(odsParser); | ||
| 163 | -} | ||
| 164 | 152 | ||
| 165 | -void BaseLocalTensorType::print(AsmPrinter &odsPrinter) const | 153 | +void BaseLocalTensorType::print(AsmPrinter& odsPrinter) const |
| 166 | { | 154 | { |
| 167 | BaseTensorImpl<BaseLocalTensorType>::print(*this, odsPrinter); | 155 | BaseTensorImpl<BaseLocalTensorType>::print(*this, odsPrinter); |
| 168 | } | 156 | } |
| @@ -172,10 +160,7 @@ ShapedType BaseLocalTensorType::cloneWith(std::optional<ArrayRef<int64_t>> shape | |||
| 172 | return BaseTensorImpl<BaseLocalTensorType>::cloneWith(*this, shape, elementType); | 160 | return BaseTensorImpl<BaseLocalTensorType>::cloneWith(*this, shape, elementType); |
| 173 | } | 161 | } |
| 174 | 162 | ||
| 175 | -bool BaseLocalTensorType::hasRank() const | 163 | +bool BaseLocalTensorType::hasRank() const { return BaseTensorImpl<BaseLocalTensorType>::hasRank(*this); } |
| 176 | -{ | ||
| 177 | - return BaseTensorImpl<BaseLocalTensorType>::hasRank(*this); | ||
| 178 | -} | ||
| 179 | 164 | ||
| 180 | //===----------------------------------------------------------------------===// | 165 | //===----------------------------------------------------------------------===// |
| 181 | // GlobalTensorType | 166 | // GlobalTensorType |
| @@ -186,22 +171,16 @@ GlobalTensorType GlobalTensorType::get(ArrayRef<int64_t> shape, Type elementType | |||
| 186 | return BaseTensorImpl<GlobalTensorType>::get(shape, elementType); | 171 | return BaseTensorImpl<GlobalTensorType>::get(shape, elementType); |
| 187 | } | 172 | } |
| 188 | 173 | ||
| 189 | -GlobalTensorType GlobalTensorType::get(Type elementType) | 174 | +GlobalTensorType GlobalTensorType::get(Type elementType) { return BaseTensorImpl<GlobalTensorType>::get(elementType); } |
| 190 | -{ | ||
| 191 | - return BaseTensorImpl<GlobalTensorType>::get(elementType); | ||
| 192 | -} | ||
| 193 | 175 | ||
| 194 | GlobalTensorType GlobalTensorType::get(BaseTensorType baseType) | 176 | GlobalTensorType GlobalTensorType::get(BaseTensorType baseType) |
| 195 | { | 177 | { |
| 196 | return BaseTensorImpl<GlobalTensorType>::get(baseType); | 178 | return BaseTensorImpl<GlobalTensorType>::get(baseType); |
| 197 | } | 179 | } |
| 198 | 180 | ||
| 199 | -Type GlobalTensorType::parse(AsmParser &odsParser) | 181 | +Type GlobalTensorType::parse(AsmParser& odsParser) { return BaseTensorImpl<GlobalTensorType>::parse(odsParser); } |
| 200 | -{ | ||
| 201 | - return BaseTensorImpl<GlobalTensorType>::parse(odsParser); | ||
| 202 | -} | ||
| 203 | 182 | ||
| 204 | -void GlobalTensorType::print(AsmPrinter &odsPrinter) const | 183 | +void GlobalTensorType::print(AsmPrinter& odsPrinter) const |
| 205 | { | 184 | { |
| 206 | BaseTensorImpl<GlobalTensorType>::print(*this, odsPrinter); | 185 | BaseTensorImpl<GlobalTensorType>::print(*this, odsPrinter); |
| 207 | } | 186 | } |
| @@ -211,10 +190,7 @@ ShapedType GlobalTensorType::cloneWith(std::optional<ArrayRef<int64_t>> shape, T | |||
| 211 | return BaseTensorImpl<GlobalTensorType>::cloneWith(*this, shape, elementType); | 190 | return BaseTensorImpl<GlobalTensorType>::cloneWith(*this, shape, elementType); |
| 212 | } | 191 | } |
| 213 | 192 | ||
| 214 | -bool GlobalTensorType::hasRank() const | 193 | +bool GlobalTensorType::hasRank() const { return BaseTensorImpl<GlobalTensorType>::hasRank(*this); } |
| 215 | -{ | ||
| 216 | - return BaseTensorImpl<GlobalTensorType>::hasRank(*this); | ||
| 217 | -} | ||
| 218 | 194 | ||
| 219 | //===----------------------------------------------------------------------===// | 195 | //===----------------------------------------------------------------------===// |
| 220 | // LocalTensorType | 196 | // LocalTensorType |
| @@ -225,35 +201,20 @@ LocalTensorType LocalTensorType::get(ArrayRef<int64_t> shape, Type elementType) | |||
| 225 | return BaseTensorImpl<LocalTensorType>::get(shape, elementType); | 201 | return BaseTensorImpl<LocalTensorType>::get(shape, elementType); |
| 226 | } | 202 | } |
| 227 | 203 | ||
| 228 | -LocalTensorType LocalTensorType::get(Type elementType) | 204 | +LocalTensorType LocalTensorType::get(Type elementType) { return BaseTensorImpl<LocalTensorType>::get(elementType); } |
| 229 | -{ | ||
| 230 | - return BaseTensorImpl<LocalTensorType>::get(elementType); | ||
| 231 | -} | ||
| 232 | 205 | ||
| 233 | -LocalTensorType LocalTensorType::get(BaseTensorType baseType) | 206 | +LocalTensorType LocalTensorType::get(BaseTensorType baseType) { return BaseTensorImpl<LocalTensorType>::get(baseType); } |
| 234 | -{ | ||
| 235 | - return BaseTensorImpl<LocalTensorType>::get(baseType); | ||
| 236 | -} | ||
| 237 | 207 | ||
| 238 | -Type LocalTensorType::parse(AsmParser &odsParser) | 208 | +Type LocalTensorType::parse(AsmParser& odsParser) { return BaseTensorImpl<LocalTensorType>::parse(odsParser); } |
| 239 | -{ | ||
| 240 | - return BaseTensorImpl<LocalTensorType>::parse(odsParser); | ||
| 241 | -} | ||
| 242 | 209 | ||
| 243 | -void LocalTensorType::print(AsmPrinter &odsPrinter) const | 210 | +void LocalTensorType::print(AsmPrinter& odsPrinter) const { BaseTensorImpl<LocalTensorType>::print(*this, odsPrinter); } |
| 244 | -{ | ||
| 245 | - BaseTensorImpl<LocalTensorType>::print(*this, odsPrinter); | ||
| 246 | -} | ||
| 247 | 211 | ||
| 248 | ShapedType LocalTensorType::cloneWith(std::optional<ArrayRef<int64_t>> shape, Type elementType) const | 212 | ShapedType LocalTensorType::cloneWith(std::optional<ArrayRef<int64_t>> shape, Type elementType) const |
| 249 | { | 213 | { |
| 250 | return BaseTensorImpl<LocalTensorType>::cloneWith(*this, shape, elementType); | 214 | return BaseTensorImpl<LocalTensorType>::cloneWith(*this, shape, elementType); |
| 251 | } | 215 | } |
| 252 | 216 | ||
| 253 | -bool LocalTensorType::hasRank() const | 217 | +bool LocalTensorType::hasRank() const { return BaseTensorImpl<LocalTensorType>::hasRank(*this); } |
| 254 | -{ | ||
| 255 | - return BaseTensorImpl<LocalTensorType>::hasRank(*this); | ||
| 256 | -} | ||
| 257 | 218 | ||
| 258 | //===----------------------------------------------------------------------===// | 219 | //===----------------------------------------------------------------------===// |
| 259 | // AscendCDialect | 220 | // AscendCDialect |
| @@ -35,11 +35,8 @@ namespace { | |||
| 35 | using PyStructVector = SmallVector<emitasc::PyStructType>; | 35 | using PyStructVector = SmallVector<emitasc::PyStructType>; |
| 36 | 36 | ||
| 37 | struct PyStructTypeHash { | 37 | struct PyStructTypeHash { |
| 38 | - std::hash<const void *> h; | 38 | + std::hash<const void*> h; |
| 39 | - size_t operator()(emitasc::PyStructType type) const | 39 | + size_t operator()(emitasc::PyStructType type) const { return h(type.getAsOpaquePointer()); } |
| 40 | - { | ||
| 41 | - return h(type.getAsOpaquePointer()); | ||
| 42 | - } | ||
| 43 | }; | 40 | }; |
| 44 | 41 | ||
| 45 | PyStructVector deduplicate(ArrayRef<emitasc::PyStructType> pyStructs) | 42 | PyStructVector deduplicate(ArrayRef<emitasc::PyStructType> pyStructs) |
| @@ -56,7 +53,7 @@ PyStructVector deduplicate(ArrayRef<emitasc::PyStructType> pyStructs) | |||
| 56 | return result; | 53 | return result; |
| 57 | } | 54 | } |
| 58 | 55 | ||
| 59 | -void CollectPyStructTypes(PyStructVector &structs, Value &arg) | 56 | +void CollectPyStructTypes(PyStructVector& structs, Value& arg) |
| 60 | { | 57 | { |
| 61 | arg.getType().walk([&](Type type) { | 58 | arg.getType().walk([&](Type type) { |
| 62 | if (auto pyStructType = dyn_cast<emitasc::PyStructType>(type)) { | 59 | if (auto pyStructType = dyn_cast<emitasc::PyStructType>(type)) { |
| @@ -66,15 +63,15 @@ void CollectPyStructTypes(PyStructVector &structs, Value &arg) | |||
| 66 | } | 63 | } |
| 67 | 64 | ||
| 68 | class DeclarePyStructPass : public ascendc::impl::DeclarePyStructBase<DeclarePyStructPass> { | 65 | class DeclarePyStructPass : public ascendc::impl::DeclarePyStructBase<DeclarePyStructPass> { |
| 69 | - public: | 66 | +public: |
| 70 | void runOnOperation() override | 67 | void runOnOperation() override |
| 71 | { | 68 | { |
| 72 | auto mod = getOperation(); | 69 | auto mod = getOperation(); |
| 73 | PyStructVector structs; | 70 | PyStructVector structs; |
| 74 | - mod.walk([&](Operation *op) { | 71 | + mod.walk([&](Operation* op) { |
| 75 | - for (auto ®ion : op->getRegions()) { | 72 | + for (auto& region : op->getRegions()) { |
| 76 | - for (auto &block : region) { | 73 | + for (auto& block : region) { |
| 77 | - for (auto &arg : block.getArguments()) { | 74 | + for (auto& arg : block.getArguments()) { |
| 78 | CollectPyStructTypes(structs, arg); | 75 | CollectPyStructTypes(structs, arg); |
| 79 | } | 76 | } |
| 80 | } | 77 | } |
| @@ -97,9 +94,6 @@ class DeclarePyStructPass : public ascendc::impl::DeclarePyStructBase<DeclarePyS | |||
| 97 | 94 | ||
| 98 | namespace mlir { | 95 | namespace mlir { |
| 99 | namespace ascendc { | 96 | namespace ascendc { |
| 100 | -std::unique_ptr<Pass> createDeclarePyStructPass() | 97 | +std::unique_ptr<Pass> createDeclarePyStructPass() { return std::make_unique<DeclarePyStructPass>(); } |
| 101 | -{ | ||
| 102 | - return std::make_unique<DeclarePyStructPass>(); | ||
| 103 | -} | ||
| 104 | } // namespace ascendc | 98 | } // namespace ascendc |
| 105 | } // namespace mlir | 99 | } // namespace mlir |
| @@ -30,7 +30,7 @@ using namespace mlir::ascendc; | |||
| 30 | namespace { | 30 | namespace { |
| 31 | 31 | ||
| 32 | class DefineCubeOnlyPass : public ascendc::impl::DefineCubeOnlyBase<DefineCubeOnlyPass> { | 32 | class DefineCubeOnlyPass : public ascendc::impl::DefineCubeOnlyBase<DefineCubeOnlyPass> { |
| 33 | - public: | 33 | +public: |
| 34 | void runOnOperation() override | 34 | void runOnOperation() override |
| 35 | { | 35 | { |
| 36 | auto mod = getOperation(); | 36 | auto mod = getOperation(); |
| @@ -44,9 +44,6 @@ class DefineCubeOnlyPass : public ascendc::impl::DefineCubeOnlyBase<DefineCubeOn | |||
| 44 | 44 | ||
| 45 | namespace mlir { | 45 | namespace mlir { |
| 46 | namespace ascendc { | 46 | namespace ascendc { |
| 47 | -std::unique_ptr<Pass> createDefineCubeOnlyPass() | 47 | +std::unique_ptr<Pass> createDefineCubeOnlyPass() { return std::make_unique<DefineCubeOnlyPass>(); } |
| 48 | -{ | ||
| 49 | - return std::make_unique<DefineCubeOnlyPass>(); | ||
| 50 | -} | ||
| 51 | } // namespace ascendc | 48 | } // namespace ascendc |
| 52 | } // namespace mlir | 49 | } // namespace mlir |
| @@ -29,7 +29,7 @@ using namespace mlir::ascendc; | |||
| 29 | namespace { | 29 | namespace { |
| 30 | 30 | ||
| 31 | class DetectEnableDebugPass : public ascendc::impl::DetectEnableDebugBase<DetectEnableDebugPass> { | 31 | class DetectEnableDebugPass : public ascendc::impl::DetectEnableDebugBase<DetectEnableDebugPass> { |
| 32 | - public: | 32 | +public: |
| 33 | void runOnOperation() override | 33 | void runOnOperation() override |
| 34 | { | 34 | { |
| 35 | ModuleOp op = getOperation(); | 35 | ModuleOp op = getOperation(); |
| @@ -44,7 +44,4 @@ class DetectEnableDebugPass : public ascendc::impl::DetectEnableDebugBase<Detect | |||
| 44 | 44 | ||
| 45 | } // namespace | 45 | } // namespace |
| 46 | 46 | ||
| 47 | -std::unique_ptr<Pass> mlir::ascendc::createDetectEnableDebugPass() | 47 | +std::unique_ptr<Pass> mlir::ascendc::createDetectEnableDebugPass() { return std::make_unique<DetectEnableDebugPass>(); } |
| 48 | -{ | ||
| 49 | - return std::make_unique<DetectEnableDebugPass>(); | ||
| 50 | -} | ||
| @@ -29,7 +29,7 @@ using namespace mlir::ascendc; | |||
| 29 | namespace { | 29 | namespace { |
| 30 | 30 | ||
| 31 | class DetectKernelTypePass : public ascendc::impl::DetectKernelTypeBase<DetectKernelTypePass> { | 31 | class DetectKernelTypePass : public ascendc::impl::DetectKernelTypeBase<DetectKernelTypePass> { |
| 32 | - public: | 32 | +public: |
| 33 | void runOnOperation() override | 33 | void runOnOperation() override |
| 34 | { | 34 | { |
| 35 | ModuleOp op = getOperation(); | 35 | ModuleOp op = getOperation(); |
| @@ -42,9 +42,6 @@ class DetectKernelTypePass : public ascendc::impl::DetectKernelTypeBase<DetectKe | |||
| 42 | 42 | ||
| 43 | namespace mlir { | 43 | namespace mlir { |
| 44 | namespace ascendc { | 44 | namespace ascendc { |
| 45 | -std::unique_ptr<Pass> createDetectKernelTypePass() | 45 | +std::unique_ptr<Pass> createDetectKernelTypePass() { return std::make_unique<DetectKernelTypePass>(); } |
| 46 | -{ | ||
| 47 | - return std::make_unique<DetectKernelTypePass>(); | ||
| 48 | -} | ||
| 49 | } // namespace ascendc | 46 | } // namespace ascendc |
| 50 | } // namespace mlir | 47 | } // namespace mlir |
| @@ -26,7 +26,7 @@ using namespace mlir; | |||
| 26 | namespace { | 26 | namespace { |
| 27 | 27 | ||
| 28 | template <typename OpT> | 28 | template <typename OpT> |
| 29 | -void eraseOps(Operation *root) | 29 | +void eraseOps(Operation* root) |
| 30 | { | 30 | { |
| 31 | root->walk([](OpT op) { op.erase(); }); | 31 | root->walk([](OpT op) { op.erase(); }); |
| 32 | } | 32 | } |
| @@ -62,9 +62,6 @@ struct EraseSyncPass : public ascendc::impl::EraseSyncBase<EraseSyncPass> { | |||
| 62 | 62 | ||
| 63 | namespace mlir { | 63 | namespace mlir { |
| 64 | namespace ascendc { | 64 | namespace ascendc { |
| 65 | -std::unique_ptr<Pass> createEraseSyncPass() | 65 | +std::unique_ptr<Pass> createEraseSyncPass() { return std::make_unique<EraseSyncPass>(); } |
| 66 | -{ | ||
| 67 | - return std::make_unique<EraseSyncPass>(); | ||
| 68 | -} | ||
| 69 | } // namespace ascendc | 66 | } // namespace ascendc |
| 70 | } // namespace mlir | 67 | } // namespace mlir |
| @@ -29,18 +29,16 @@ using namespace mlir::ascendc; | |||
| 29 | namespace { | 29 | namespace { |
| 30 | 30 | ||
| 31 | class GenerateBoilerplatePass : public ascendc::impl::GenerateBoilerplateBase<GenerateBoilerplatePass> { | 31 | class GenerateBoilerplatePass : public ascendc::impl::GenerateBoilerplateBase<GenerateBoilerplatePass> { |
| 32 | - public: | 32 | +public: |
| 33 | void runOnOperation() override | 33 | void runOnOperation() override |
| 34 | { | 34 | { |
| 35 | auto mod = getOperation(); | 35 | auto mod = getOperation(); |
| 36 | auto builder = ImplicitLocOpBuilder::atBlockBegin(mod->getLoc(), mod.getBody()); | 36 | auto builder = ImplicitLocOpBuilder::atBlockBegin(mod->getLoc(), mod.getBody()); |
| 37 | builder.create<emitc::IncludeOp>("kernel_operator.h"); | 37 | builder.create<emitc::IncludeOp>("kernel_operator.h"); |
| 38 | - bool hasListTensorDesc = mod.walk([](ascendc::ListTensorDescOp) { | 38 | + bool hasListTensorDesc = |
| 39 | - return WalkResult::interrupt(); | 39 | + mod.walk([](ascendc::ListTensorDescOp) { return WalkResult::interrupt(); }).wasInterrupted(); |
| 40 | - }).wasInterrupted(); | 40 | + bool hasListTensorDescV2 = |
| 41 | - bool hasListTensorDescV2 = mod.walk([](ascendc::ListTensorDescV2Op) { | 41 | + mod.walk([](ascendc::ListTensorDescV2Op) { return WalkResult::interrupt(); }).wasInterrupted(); |
| 42 | - return WalkResult::interrupt(); | ||
| 43 | - }).wasInterrupted(); | ||
| 44 | if (hasListTensorDesc || hasListTensorDescV2) { | 42 | if (hasListTensorDesc || hasListTensorDescV2) { |
| 45 | builder.create<emitc::IncludeOp>("kernel_operator_list_tensor_intf.h"); | 43 | builder.create<emitc::IncludeOp>("kernel_operator_list_tensor_intf.h"); |
| 46 | } | 44 | } |
| @@ -59,9 +57,6 @@ class GenerateBoilerplatePass : public ascendc::impl::GenerateBoilerplateBase<Ge | |||
| 59 | 57 | ||
| 60 | namespace mlir { | 58 | namespace mlir { |
| 61 | namespace ascendc { | 59 | namespace ascendc { |
| 62 | -std::unique_ptr<Pass> createGenerateBoilerplatePass() | 60 | +std::unique_ptr<Pass> createGenerateBoilerplatePass() { return std::make_unique<GenerateBoilerplatePass>(); } |
| 63 | -{ | ||
| 64 | - return std::make_unique<GenerateBoilerplatePass>(); | ||
| 65 | -} | ||
| 66 | } // namespace ascendc | 61 | } // namespace ascendc |
| 67 | } // namespace mlir | 62 | } // namespace mlir |
| @@ -27,10 +27,10 @@ using namespace mlir; | |||
| 27 | namespace { | 27 | namespace { |
| 28 | 28 | ||
| 29 | struct HoistQueBindPass : public ascendc::impl::HoistQueBindBase<HoistQueBindPass> { | 29 | struct HoistQueBindPass : public ascendc::impl::HoistQueBindBase<HoistQueBindPass> { |
| 30 | - public: | 30 | +public: |
| 31 | void runOnOperation() override | 31 | void runOnOperation() override |
| 32 | { | 32 | { |
| 33 | - MLIRContext *context = &getContext(); | 33 | + MLIRContext* context = &getContext(); |
| 34 | RewritePatternSet patterns(context); | 34 | RewritePatternSet patterns(context); |
| 35 | patterns.add< | 35 | patterns.add< |
| 36 | // | 36 | // |
| @@ -49,9 +49,6 @@ struct HoistQueBindPass : public ascendc::impl::HoistQueBindBase<HoistQueBindPas | |||
| 49 | 49 | ||
| 50 | namespace mlir { | 50 | namespace mlir { |
| 51 | namespace ascendc { | 51 | namespace ascendc { |
| 52 | -std::unique_ptr<Pass> createHoistQueBindPass() | 52 | +std::unique_ptr<Pass> createHoistQueBindPass() { return std::make_unique<HoistQueBindPass>(); } |
| 53 | -{ | ||
| 54 | - return std::make_unique<HoistQueBindPass>(); | ||
| 55 | -} | ||
| 56 | } // namespace ascendc | 53 | } // namespace ascendc |
| 57 | } // namespace mlir | 54 | } // namespace mlir |
| @@ -29,16 +29,13 @@ namespace { | |||
| 29 | struct HoistTensor : ascendc::HoistOpPattern<ascendc::LocalTensorAutoOp> { | 29 | struct HoistTensor : ascendc::HoistOpPattern<ascendc::LocalTensorAutoOp> { |
| 30 | using HoistOpPattern::HoistOpPattern; | 30 | using HoistOpPattern::HoistOpPattern; |
| 31 | 31 | ||
| 32 | - bool hoistable(ascendc::LocalTensorAutoOp op) const override | 32 | + bool hoistable(ascendc::LocalTensorAutoOp op) const override { return !op.getInput() && !op.getOutput(); } |
| 33 | - { | ||
| 34 | - return !op.getInput() && !op.getOutput(); | ||
| 35 | - } | ||
| 36 | }; | 33 | }; |
| 37 | 34 | ||
| 38 | struct HoistUBAllocationPass : public ascendc::impl::HoistUBAllocationBase<HoistUBAllocationPass> { | 35 | struct HoistUBAllocationPass : public ascendc::impl::HoistUBAllocationBase<HoistUBAllocationPass> { |
| 39 | void runOnOperation() override | 36 | void runOnOperation() override |
| 40 | { | 37 | { |
| 41 | - MLIRContext *context = &getContext(); | 38 | + MLIRContext* context = &getContext(); |
| 42 | RewritePatternSet patterns(context); | 39 | RewritePatternSet patterns(context); |
| 43 | patterns.add<HoistTensor>(context); | 40 | patterns.add<HoistTensor>(context); |
| 44 | if (applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)).failed()) { | 41 | if (applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)).failed()) { |
| @@ -51,9 +48,6 @@ struct HoistUBAllocationPass : public ascendc::impl::HoistUBAllocationBase<Hoist | |||
| 51 | 48 | ||
| 52 | namespace mlir { | 49 | namespace mlir { |
| 53 | namespace ascendc { | 50 | namespace ascendc { |
| 54 | -std::unique_ptr<Pass> createHoistUBAllocationPass() | 51 | +std::unique_ptr<Pass> createHoistUBAllocationPass() { return std::make_unique<HoistUBAllocationPass>(); } |
| 55 | -{ | ||
| 56 | - return std::make_unique<HoistUBAllocationPass>(); | ||
| 57 | -} | ||
| 58 | } // namespace ascendc | 52 | } // namespace ascendc |
| 59 | } // namespace mlir | 53 | } // namespace mlir |
| @@ -29,17 +29,18 @@ using namespace mlir::ascendc; | |||
| 29 | 29 | ||
| 30 | namespace { | 30 | namespace { |
| 31 | 31 | ||
| 32 | -void createDataCopyIfNeeded(Operation *op) | 32 | +void createDataCopyIfNeeded(Operation* op) |
| 33 | { | 33 | { |
| 34 | - for (auto &use : op->getUses()) { | 34 | + for (auto& use : op->getUses()) { |
| 35 | auto copyOp = dyn_cast<ascendc::DataCopyOp>(use.getOwner()); | 35 | auto copyOp = dyn_cast<ascendc::DataCopyOp>(use.getOwner()); |
| 36 | if (!copyOp || copyOp.getDirection() != ascendc::CopyDirection::ubuf_gm) | 36 | if (!copyOp || copyOp.getDirection() != ascendc::CopyDirection::ubuf_gm) |
| 37 | return; | 37 | return; |
| 38 | OpBuilder builder(op); | 38 | OpBuilder builder(op); |
| 39 | ascir::ConstantOpBuilder consts(builder); | 39 | ascir::ConstantOpBuilder consts(builder); |
| 40 | auto type = cast<ascendc::BaseTensorType>(use.get().getType()); | 40 | auto type = cast<ascendc::BaseTensorType>(use.get().getType()); |
| 41 | - auto dst = builder.create<ascendc::LocalTensorAutoOp>(op->getLoc(), type, /*input*/ false, | 41 | + auto dst = builder.create<ascendc::LocalTensorAutoOp>( |
| 42 | - /*output*/ true, ValueRange {}); | 42 | + op->getLoc(), type, /*input*/ false, |
| 43 | + /*output*/ true, ValueRange{}); | ||
| 43 | builder.setInsertionPointAfter(op); | 44 | builder.setInsertionPointAfter(op); |
| 44 | Value calCount = consts.i64(type.getNumElements()); | 45 | Value calCount = consts.i64(type.getNumElements()); |
| 45 | builder.create<ascendc::DataCopyL2Op>(op->getLoc(), dst, use.get(), calCount); | 46 | builder.create<ascendc::DataCopyL2Op>(op->getLoc(), dst, use.get(), calCount); |
| @@ -52,7 +53,7 @@ void setInOutTensors(func::FuncOp funcOp) | |||
| 52 | funcOp.walk([](ascendc::LocalTensorAutoOp op) { | 53 | funcOp.walk([](ascendc::LocalTensorAutoOp op) { |
| 53 | bool input = false; | 54 | bool input = false; |
| 54 | bool output = false; | 55 | bool output = false; |
| 55 | - for (Operation *user : op->getUsers()) { | 56 | + for (Operation* user : op->getUsers()) { |
| 56 | if (auto copyOp = dyn_cast<ascendc::DataCopyOp>(user)) { | 57 | if (auto copyOp = dyn_cast<ascendc::DataCopyOp>(user)) { |
| 57 | auto dir = copyOp.getDirection(); | 58 | auto dir = copyOp.getDirection(); |
| 58 | if (dir == ascendc::CopyDirection::gm_ubuf) { | 59 | if (dir == ascendc::CopyDirection::gm_ubuf) { |
| @@ -72,7 +73,7 @@ void setInOutTensors(func::FuncOp funcOp) | |||
| 72 | funcOp.walk([](scf::IfOp op) { createDataCopyIfNeeded(op); }); | 73 | funcOp.walk([](scf::IfOp op) { createDataCopyIfNeeded(op); }); |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | -void fixInOutTensor(func::FuncOp &funcOp) | 76 | +void fixInOutTensor(func::FuncOp& funcOp) |
| 76 | { | 77 | { |
| 77 | funcOp.walk([](ascendc::LocalTensorAutoOp inTensor) { | 78 | funcOp.walk([](ascendc::LocalTensorAutoOp inTensor) { |
| 78 | if (!inTensor.getInput() || inTensor.getOutput()) | 79 | if (!inTensor.getInput() || inTensor.getOutput()) |
| @@ -81,15 +82,16 @@ void fixInOutTensor(func::FuncOp &funcOp) | |||
| 81 | OpBuilder builder(inTensor); | 82 | OpBuilder builder(inTensor); |
| 82 | auto tensorType = inTensor.getResult().getType(); | 83 | auto tensorType = inTensor.getResult().getType(); |
| 83 | inTensor.setOutput(false); | 84 | inTensor.setOutput(false); |
| 84 | - for (auto &use : inTensor->getUses()) { | 85 | + for (auto& use : inTensor->getUses()) { |
| 85 | - auto *owner = use.getOwner(); | 86 | + auto* owner = use.getOwner(); |
| 86 | auto copyOp = dyn_cast<ascendc::DataCopyOp>(owner); | 87 | auto copyOp = dyn_cast<ascendc::DataCopyOp>(owner); |
| 87 | if (!copyOp || copyOp.getDirection() != ascendc::CopyDirection::ubuf_gm) | 88 | if (!copyOp || copyOp.getDirection() != ascendc::CopyDirection::ubuf_gm) |
| 88 | return builder.setInsertionPoint(owner); | 89 | return builder.setInsertionPoint(owner); |
| 89 | ascir::ConstantOpBuilder consts(builder); | 90 | ascir::ConstantOpBuilder consts(builder); |
| 90 | Value calCount = consts.i64(tensorType.getNumElements()); | 91 | Value calCount = consts.i64(tensorType.getNumElements()); |
| 91 | - auto outTensor = builder.create<ascendc::LocalTensorAutoOp>(loc, tensorType, /*input*/ false, | 92 | + auto outTensor = builder.create<ascendc::LocalTensorAutoOp>( |
| 92 | - /*output*/ true, ValueRange {}); | 93 | + loc, tensorType, /*input*/ false, |
| 94 | + /*output*/ true, ValueRange{}); | ||
| 93 | builder.create<ascendc::DataCopyL2Op>(loc, outTensor, inTensor, calCount); | 95 | builder.create<ascendc::DataCopyL2Op>(loc, outTensor, inTensor, calCount); |
| 94 | owner->setOperand(use.getOperandNumber(), outTensor); | 96 | owner->setOperand(use.getOperandNumber(), outTensor); |
| 95 | } | 97 | } |
| @@ -105,7 +107,7 @@ struct InputOutputTensorPass : public ascendc::impl::InputOutputTensorBase<Input | |||
| 105 | } | 107 | } |
| 106 | setInOutTensors(funcOp); | 108 | setInOutTensors(funcOp); |
| 107 | fixInOutTensor(funcOp); | 109 | fixInOutTensor(funcOp); |
| 108 | - MLIRContext *context = &getContext(); | 110 | + MLIRContext* context = &getContext(); |
| 109 | RewritePatternSet patterns(context); | 111 | RewritePatternSet patterns(context); |
| 110 | ascendc::LocalTensorAutoOp::getCanonicalizationPatterns(patterns, context); | 112 | ascendc::LocalTensorAutoOp::getCanonicalizationPatterns(patterns, context); |
| 111 | if (applyPatternsAndFoldGreedily(funcOp, std::move(patterns)).failed()) { | 113 | if (applyPatternsAndFoldGreedily(funcOp, std::move(patterns)).failed()) { |
| @@ -119,9 +121,6 @@ struct InputOutputTensorPass : public ascendc::impl::InputOutputTensorBase<Input | |||
| 119 | 121 | ||
| 120 | namespace mlir { | 122 | namespace mlir { |
| 121 | namespace ascendc { | 123 | namespace ascendc { |
| 122 | -std::unique_ptr<Pass> createInputOutputTensorPass() | 124 | +std::unique_ptr<Pass> createInputOutputTensorPass() { return std::make_unique<InputOutputTensorPass>(); } |
| 123 | -{ | ||
| 124 | - return std::make_unique<InputOutputTensorPass>(); | ||
| 125 | -} | ||
| 126 | } // namespace ascendc | 125 | } // namespace ascendc |
| 127 | } // namespace mlir | 126 | } // namespace mlir |
| @@ -58,7 +58,7 @@ void enqueueTensors(func::FuncOp funcOp) | |||
| 58 | }); | 58 | }); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | -void createSetGetValueSync(bool isBefore, OpBuilder &builder, Location loc) | 61 | +void createSetGetValueSync(bool isBefore, OpBuilder& builder, Location loc) |
| 62 | { | 62 | { |
| 63 | ascendc::HardEvent currentEvent = isBefore ? ascendc::HardEvent::V_S : ascendc::HardEvent::S_V; | 63 | ascendc::HardEvent currentEvent = isBefore ? ascendc::HardEvent::V_S : ascendc::HardEvent::S_V; |
| 64 | Value pipe = builder.create<ascendc::PipeOp>(loc); | 64 | Value pipe = builder.create<ascendc::PipeOp>(loc); |
| @@ -68,7 +68,7 @@ void createSetGetValueSync(bool isBefore, OpBuilder &builder, Location loc) | |||
| 68 | builder.create<ascendc::WaitFlagOp>(loc, currentEvent, eventId); | 68 | builder.create<ascendc::WaitFlagOp>(loc, currentEvent, eventId); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | -void syncGetValueOp(func::FuncOp &funcOp) | 71 | +void syncGetValueOp(func::FuncOp& funcOp) |
| 72 | { | 72 | { |
| 73 | funcOp.walk([](ascendc::APIOp op) { | 73 | funcOp.walk([](ascendc::APIOp op) { |
| 74 | if (isa<ascendc::LocalTensorGetValueOp, ascendc::GlobalTensorGetValueOp>(op)) { | 74 | if (isa<ascendc::LocalTensorGetValueOp, ascendc::GlobalTensorGetValueOp>(op)) { |
| @@ -81,7 +81,7 @@ void syncGetValueOp(func::FuncOp &funcOp) | |||
| 81 | }); | 81 | }); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | -void syncSetValueOp(func::FuncOp &funcOp) | 84 | +void syncSetValueOp(func::FuncOp& funcOp) |
| 85 | { | 85 | { |
| 86 | funcOp.walk([](ascendc::APIOp op) { | 86 | funcOp.walk([](ascendc::APIOp op) { |
| 87 | if (isa<ascendc::LocalTensorSetValueOp, ascendc::GlobalTensorSetValueOp>(op)) { | 87 | if (isa<ascendc::LocalTensorSetValueOp, ascendc::GlobalTensorSetValueOp>(op)) { |
| @@ -104,11 +104,11 @@ void syncSetValueOp(func::FuncOp &funcOp) | |||
| 104 | }); | 104 | }); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | -bool reEnque(OpBuilder &b, Location loc, ascendc::TQueBindEnqueTensorOp enq, ascendc::TQueBindDequeTensorOp deq) | 107 | +bool reEnque(OpBuilder& b, Location loc, ascendc::TQueBindEnqueTensorOp enq, ascendc::TQueBindDequeTensorOp deq) |
| 108 | { | 108 | { |
| 109 | DominanceInfo di; | 109 | DominanceInfo di; |
| 110 | if (!di.dominates(enq, deq)) { | 110 | if (!di.dominates(enq, deq)) { |
| 111 | - auto *enqParent = deq->getParentRegion()->findAncestorOpInRegion(*enq); | 111 | + auto* enqParent = deq->getParentRegion()->findAncestorOpInRegion(*enq); |
| 112 | if (!enqParent) { | 112 | if (!enqParent) { |
| 113 | enq.emitOpError("failed to be hoisted to tensor deque op scope"); | 113 | enq.emitOpError("failed to be hoisted to tensor deque op scope"); |
| 114 | return false; | 114 | return false; |
| @@ -120,31 +120,31 @@ bool reEnque(OpBuilder &b, Location loc, ascendc::TQueBindEnqueTensorOp enq, asc | |||
| 120 | return true; | 120 | return true; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | -bool dequeueTensors(Region ®ion) | 123 | +bool dequeueTensors(Region& region) |
| 124 | { | 124 | { |
| 125 | DominanceInfo di; | 125 | DominanceInfo di; |
| 126 | bool res = true; | 126 | bool res = true; |
| 127 | - for (Block &block : region) { | 127 | + for (Block& block : region) { |
| 128 | - for (Operation &op : llvm::make_early_inc_range(block)) { | 128 | + for (Operation& op : llvm::make_early_inc_range(block)) { |
| 129 | auto enq = dyn_cast<ascendc::TQueBindEnqueTensorOp>(op); | 129 | auto enq = dyn_cast<ascendc::TQueBindEnqueTensorOp>(op); |
| 130 | if (!enq) { | 130 | if (!enq) { |
| 131 | - for (Region &inner : op.getRegions()) { | 131 | + for (Region& inner : op.getRegions()) { |
| 132 | res &= dequeueTensors(inner); | 132 | res &= dequeueTensors(inner); |
| 133 | } | 133 | } |
| 134 | continue; | 134 | continue; |
| 135 | } | 135 | } |
| 136 | auto tensor = enq.getTensor(); | 136 | auto tensor = enq.getTensor(); |
| 137 | - std::vector<Operation *> users; | 137 | + std::vector<Operation*> users; |
| 138 | - llvm::copy_if(tensor.getUsers(), std::back_inserter(users), [&](Operation *user) { | 138 | + llvm::copy_if(tensor.getUsers(), std::back_inserter(users), [&](Operation* user) { |
| 139 | return !isa<ascendc::TQueBindFreeTensorOp>(user) && ascendc::opPrecedes(enq, user, di); | 139 | return !isa<ascendc::TQueBindFreeTensorOp>(user) && ascendc::opPrecedes(enq, user, di); |
| 140 | }); | 140 | }); |
| 141 | if (users.empty()) { | 141 | if (users.empty()) { |
| 142 | continue; | 142 | continue; |
| 143 | } | 143 | } |
| 144 | - Operation *firstUser = *std::min_element(users.begin(), users.end(), [&](Operation *lhs, Operation *rhs) { | 144 | + Operation* firstUser = *std::min_element(users.begin(), users.end(), [&](Operation* lhs, Operation* rhs) { |
| 145 | return ascendc::opPrecedes(lhs, rhs, di); | 145 | return ascendc::opPrecedes(lhs, rhs, di); |
| 146 | }); | 146 | }); |
| 147 | - auto *userInSameRegion = enq->getParentRegion()->findAncestorOpInRegion(*firstUser); | 147 | + auto* userInSameRegion = enq->getParentRegion()->findAncestorOpInRegion(*firstUser); |
| 148 | if (userInSameRegion) { | 148 | if (userInSameRegion) { |
| 149 | firstUser = userInSameRegion; | 149 | firstUser = userInSameRegion; |
| 150 | } | 150 | } |
| @@ -153,8 +153,8 @@ bool dequeueTensors(Region ®ion) | |||
| 153 | if (!reEnque(builder, op.getLoc(), enq, deq)) { | 153 | if (!reEnque(builder, op.getLoc(), enq, deq)) { |
| 154 | return false; | 154 | return false; |
| 155 | } | 155 | } |
| 156 | - tensor.replaceUsesWithIf(deq.getTensor(), [&](OpOperand &opnd) { | 156 | + tensor.replaceUsesWithIf(deq.getTensor(), [&](OpOperand& opnd) { |
| 157 | - auto *owner = opnd.getOwner(); | 157 | + auto* owner = opnd.getOwner(); |
| 158 | return llvm::is_contained(users, owner); | 158 | return llvm::is_contained(users, owner); |
| 159 | }); | 159 | }); |
| 160 | } | 160 | } |
| @@ -172,7 +172,7 @@ void canonicalizeBarriers(func::FuncOp funcOp) | |||
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | struct InsertSyncPass : public ascendc::impl::InsertSyncBase<InsertSyncPass> { | 174 | struct InsertSyncPass : public ascendc::impl::InsertSyncBase<InsertSyncPass> { |
| 175 | - public: | 175 | +public: |
| 176 | void runOnOperation() override | 176 | void runOnOperation() override |
| 177 | { | 177 | { |
| 178 | func::FuncOp funcOp = getOperation(); | 178 | func::FuncOp funcOp = getOperation(); |
| @@ -194,9 +194,6 @@ struct InsertSyncPass : public ascendc::impl::InsertSyncBase<InsertSyncPass> { | |||
| 194 | 194 | ||
| 195 | namespace mlir { | 195 | namespace mlir { |
| 196 | namespace ascendc { | 196 | namespace ascendc { |
| 197 | -std::unique_ptr<Pass> createInsertSyncPass() | 197 | +std::unique_ptr<Pass> createInsertSyncPass() { return std::make_unique<InsertSyncPass>(); } |
| 198 | -{ | ||
| 199 | - return std::make_unique<InsertSyncPass>(); | ||
| 200 | -} | ||
| 201 | } // namespace ascendc | 198 | } // namespace ascendc |
| 202 | } // namespace mlir | 199 | } // namespace mlir |
| @@ -35,8 +35,8 @@ namespace { | |||
| 35 | BlockArgument appendKernelArgument(func::FuncOp op, emitasc::KernelArgument kind, StringRef name, Type type) | 35 | BlockArgument appendKernelArgument(func::FuncOp op, emitasc::KernelArgument kind, StringRef name, Type type) |
| 36 | { | 36 | { |
| 37 | OpBuilder builder(op.getContext()); | 37 | OpBuilder builder(op.getContext()); |
| 38 | - NamedAttribute kernelArg(builder.getStringAttr(emitasc::attr::kernelArg), | 38 | + NamedAttribute kernelArg( |
| 39 | - builder.getAttr<emitasc::KernelArgumentAttr>(kind)); | 39 | + builder.getStringAttr(emitasc::attr::kernelArg), builder.getAttr<emitasc::KernelArgumentAttr>(kind)); |
| 40 | unsigned idx = op.getNumArguments(); | 40 | unsigned idx = op.getNumArguments(); |
| 41 | op.insertArgument(idx, type, builder.getDictionaryAttr(kernelArg), NameLoc::get(builder.getStringAttr(name))); | 41 | op.insertArgument(idx, type, builder.getDictionaryAttr(kernelArg), NameLoc::get(builder.getStringAttr(name))); |
| 42 | return op.getArgument(idx); | 42 | return op.getArgument(idx); |
| @@ -46,14 +46,15 @@ void processKernel(func::FuncOp op) | |||
| 46 | { | 46 | { |
| 47 | auto builder = OpBuilder::atBlockBegin(&op.getFunctionBody().front()); | 47 | auto builder = OpBuilder::atBlockBegin(&op.getFunctionBody().front()); |
| 48 | for (unsigned i = 0; i < op.getNumArguments(); i++) { | 48 | for (unsigned i = 0; i < op.getNumArguments(); i++) { |
| 49 | - op.setArgAttr(i, emitasc::attr::kernelArg, | 49 | + op.setArgAttr( |
| 50 | - builder.getAttr<emitasc::KernelArgumentAttr>(emitasc::KernelArgument::Explicit)); | 50 | + i, emitasc::attr::kernelArg, |
| 51 | + builder.getAttr<emitasc::KernelArgumentAttr>(emitasc::KernelArgument::Explicit)); | ||
| 51 | } | 52 | } |
| 52 | auto as = builder.getI64IntegerAttr(static_cast<int64_t>(ascendc::AddressSpace::gm)); | 53 | auto as = builder.getI64IntegerAttr(static_cast<int64_t>(ascendc::AddressSpace::gm)); |
| 53 | auto loc = builder.getUnknownLoc(); | 54 | auto loc = builder.getUnknownLoc(); |
| 54 | - auto fftsAddr = | 55 | + auto fftsAddr = appendKernelArgument( |
| 55 | - appendKernelArgument(op, emitasc::KernelArgument::FftsAddr, "ffts_addr", | 56 | + op, emitasc::KernelArgument::FftsAddr, "ffts_addr", |
| 56 | - MemRefType::get(ShapedType::kDynamic, builder.getIntegerType(64, false), AffineMap(), as)); | 57 | + MemRefType::get(ShapedType::kDynamic, builder.getIntegerType(64, false), AffineMap(), as)); |
| 57 | builder.create<ascendc::SetFftsBaseAddrOp>(loc, fftsAddr); | 58 | builder.create<ascendc::SetFftsBaseAddrOp>(loc, fftsAddr); |
| 58 | bool hasMatmul = op.walk([](ascendc::RegistMatmulObjOp) { return WalkResult::interrupt(); }).wasInterrupted(); | 59 | bool hasMatmul = op.walk([](ascendc::RegistMatmulObjOp) { return WalkResult::interrupt(); }).wasInterrupted(); |
| 59 | bool matmulCubeOnly = op->getParentOfType<ModuleOp>()->hasAttrOfType<UnitAttr>(ascendc::attr::matmulCubeOnly); | 60 | bool matmulCubeOnly = op->getParentOfType<ModuleOp>()->hasAttrOfType<UnitAttr>(ascendc::attr::matmulCubeOnly); |
| @@ -83,9 +84,6 @@ struct LegalizeKernelArgsPass : public ascendc::impl::LegalizeKernelArgsBase<Leg | |||
| 83 | 84 | ||
| 84 | namespace mlir { | 85 | namespace mlir { |
| 85 | namespace ascendc { | 86 | namespace ascendc { |
| 86 | -std::unique_ptr<Pass> createLegalizeKernelArgsPass() | 87 | +std::unique_ptr<Pass> createLegalizeKernelArgsPass() { return std::make_unique<LegalizeKernelArgsPass>(); } |
| 87 | -{ | ||
| 88 | - return std::make_unique<LegalizeKernelArgsPass>(); | ||
| 89 | -} | ||
| 90 | } // namespace ascendc | 88 | } // namespace ascendc |
| 91 | } // namespace mlir | 89 | } // namespace mlir |
| @@ -43,7 +43,7 @@ struct MaterializeLocalTensor : OpRewritePattern<ascendc::LocalTensorAutoOp> { | |||
| 43 | llvm_unreachable("position is undefined because tensor cannot be enqueued"); | 43 | llvm_unreachable("position is undefined because tensor cannot be enqueued"); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | - LogicalResult matchAndRewrite(ascendc::LocalTensorAutoOp op, PatternRewriter &rewriter) const override | 46 | + LogicalResult matchAndRewrite(ascendc::LocalTensorAutoOp op, PatternRewriter& rewriter) const override |
| 47 | { | 47 | { |
| 48 | auto type = op.getType(); | 48 | auto type = op.getType(); |
| 49 | auto loc = op.getLoc(); | 49 | auto loc = op.getLoc(); |
| @@ -84,7 +84,7 @@ class MaterializeTensorPass : public ascendc::impl::MaterializeTensorBase<Materi | |||
| 84 | if (funcOp.isDeclaration()) { | 84 | if (funcOp.isDeclaration()) { |
| 85 | return; | 85 | return; |
| 86 | } | 86 | } |
| 87 | - MLIRContext *context = &getContext(); | 87 | + MLIRContext* context = &getContext(); |
| 88 | RewritePatternSet patterns(context); | 88 | RewritePatternSet patterns(context); |
| 89 | patterns.add<MaterializeLocalTensor>(context); | 89 | patterns.add<MaterializeLocalTensor>(context); |
| 90 | if (applyPatternsAndFoldGreedily(funcOp, std::move(patterns)).failed()) { | 90 | if (applyPatternsAndFoldGreedily(funcOp, std::move(patterns)).failed()) { |
| @@ -96,9 +96,6 @@ class MaterializeTensorPass : public ascendc::impl::MaterializeTensorBase<Materi | |||
| 96 | 96 | ||
| 97 | namespace mlir { | 97 | namespace mlir { |
| 98 | namespace ascendc { | 98 | namespace ascendc { |
| 99 | -std::unique_ptr<Pass> createMaterializeTensorPass() | 99 | +std::unique_ptr<Pass> createMaterializeTensorPass() { return std::make_unique<MaterializeTensorPass>(); } |
| 100 | -{ | ||
| 101 | - return std::make_unique<MaterializeTensorPass>(); | ||
| 102 | -} | ||
| 103 | } // namespace ascendc | 100 | } // namespace ascendc |
| 104 | } // namespace mlir | 101 | } // namespace mlir |
| @@ -34,9 +34,6 @@ struct NoopPass : public ascendc::impl::NoopBase<NoopPass> { | |||
| 34 | 34 | ||
| 35 | namespace mlir { | 35 | namespace mlir { |
| 36 | namespace ascendc { | 36 | namespace ascendc { |
| 37 | -std::unique_ptr<Pass> createNoopPass() | 37 | +std::unique_ptr<Pass> createNoopPass() { return std::make_unique<NoopPass>(); } |
| 38 | -{ | ||
| 39 | - return std::make_unique<NoopPass>(); | ||
| 40 | -} | ||
| 41 | } // namespace ascendc | 38 | } // namespace ascendc |
| 42 | } // namespace mlir | 39 | } // namespace mlir |
| @@ -42,9 +42,6 @@ struct PrivatizeFuncPass : public ascendc::impl::PrivatizeFuncBase<PrivatizeFunc | |||
| 42 | 42 | ||
| 43 | namespace mlir { | 43 | namespace mlir { |
| 44 | namespace ascendc { | 44 | namespace ascendc { |
| 45 | -std::unique_ptr<Pass> createPrivatizeFuncPass() | 45 | +std::unique_ptr<Pass> createPrivatizeFuncPass() { return std::make_unique<PrivatizeFuncPass>(); } |
| 46 | -{ | ||
| 47 | - return std::make_unique<PrivatizeFuncPass>(); | ||
| 48 | -} | ||
| 49 | } // namespace ascendc | 46 | } // namespace ascendc |
| 50 | } // namespace mlir | 47 | } // namespace mlir |
| @@ -42,19 +42,13 @@ void unifyPipe(func::FuncOp root) | |||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | class UnifyPipePass : public ascendc::impl::UnifyPipeBase<UnifyPipePass> { | 44 | class UnifyPipePass : public ascendc::impl::UnifyPipeBase<UnifyPipePass> { |
| 45 | - void runOnOperation() override | 45 | + void runOnOperation() override { unifyPipe(getOperation()); } |
| 46 | - { | ||
| 47 | - unifyPipe(getOperation()); | ||
| 48 | - } | ||
| 49 | }; | 46 | }; |
| 50 | 47 | ||
| 51 | } // namespace | 48 | } // namespace |
| 52 | 49 | ||
| 53 | namespace mlir { | 50 | namespace mlir { |
| 54 | namespace ascendc { | 51 | namespace ascendc { |
| 55 | -std::unique_ptr<Pass> createUnifyPipePass() | 52 | +std::unique_ptr<Pass> createUnifyPipePass() { return std::make_unique<UnifyPipePass>(); } |
| 56 | -{ | ||
| 57 | - return std::make_unique<UnifyPipePass>(); | ||
| 58 | -} | ||
| 59 | } // namespace ascendc | 53 | } // namespace ascendc |
| 60 | } // namespace mlir | 54 | } // namespace mlir |
| @@ -28,7 +28,7 @@ using namespace mlir; | |||
| 28 | namespace { | 28 | namespace { |
| 29 | 29 | ||
| 30 | template <typename Transfer> | 30 | template <typename Transfer> |
| 31 | -ascendc::TQueBindAllocTensorOp findDef(TypedValue<ascendc::LocalTensorType> tensor, Transfer &deqToEnq) | 31 | +ascendc::TQueBindAllocTensorOp findDef(TypedValue<ascendc::LocalTensorType> tensor, Transfer& deqToEnq) |
| 32 | { | 32 | { |
| 33 | if (auto op = tensor.getDefiningOp<ascendc::TQueBindDequeTensorOp>()) { | 33 | if (auto op = tensor.getDefiningOp<ascendc::TQueBindDequeTensorOp>()) { |
| 34 | return findDef(deqToEnq[op].getTensor(), deqToEnq); | 34 | return findDef(deqToEnq[op].getTensor(), deqToEnq); |
| @@ -40,15 +40,16 @@ ascendc::TQueBindAllocTensorOp findDef(TypedValue<ascendc::LocalTensorType> tens | |||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | struct VerifySyncPass : public ascendc::impl::VerifySyncBase<VerifySyncPass> { | 42 | struct VerifySyncPass : public ascendc::impl::VerifySyncBase<VerifySyncPass> { |
| 43 | - void dealTQueBindFreeTensorOp(ascendc::TQueBindFreeTensorOp &TQueBindFreeTensorOp, | 43 | + void dealTQueBindFreeTensorOp( |
| 44 | - ValueMap<SmallVector<Operation *>> &queBinds, | 44 | + ascendc::TQueBindFreeTensorOp& TQueBindFreeTensorOp, ValueMap<SmallVector<Operation*>>& queBinds, |
| 45 | - std::unordered_map<ascendc::TQueBindDequeTensorOp, ascendc::TQueBindEnqueTensorOp, | 45 | + std::unordered_map< |
| 46 | - PointerLikeTypeHash<ascendc::TQueBindDequeTensorOp>> &deqToEnq) | 46 | + ascendc::TQueBindDequeTensorOp, ascendc::TQueBindEnqueTensorOp, |
| 47 | + PointerLikeTypeHash<ascendc::TQueBindDequeTensorOp>>& deqToEnq) | ||
| 47 | { | 48 | { |
| 48 | - auto &operations = queBinds[TQueBindFreeTensorOp.getQueue()]; | 49 | + auto& operations = queBinds[TQueBindFreeTensorOp.getQueue()]; |
| 49 | auto allocTensorOp = findDef(TQueBindFreeTensorOp.getTensor(), deqToEnq); | 50 | auto allocTensorOp = findDef(TQueBindFreeTensorOp.getTensor(), deqToEnq); |
| 50 | if (allocTensorOp) { | 51 | if (allocTensorOp) { |
| 51 | - auto *it = llvm::find_if(operations, [&](Operation *op) { | 52 | + auto* it = llvm::find_if(operations, [&](Operation* op) { |
| 52 | auto exAllocOp = dyn_cast<ascendc::TQueBindAllocTensorOp>(op); | 53 | auto exAllocOp = dyn_cast<ascendc::TQueBindAllocTensorOp>(op); |
| 53 | return exAllocOp.getTensor() == allocTensorOp.getTensor(); | 54 | return exAllocOp.getTensor() == allocTensorOp.getTensor(); |
| 54 | }); | 55 | }); |
| @@ -62,42 +63,46 @@ struct VerifySyncPass : public ascendc::impl::VerifySyncBase<VerifySyncPass> { | |||
| 62 | } | 63 | } |
| 63 | } else { | 64 | } else { |
| 64 | TQueBindFreeTensorOp.emitWarning() | 65 | TQueBindFreeTensorOp.emitWarning() |
| 65 | - .append(TQueBindFreeTensorOp.getAPIName(), ": there is no corresponding call to ", | 66 | + .append( |
| 66 | - ascendc::TQueBindAllocTensorOp::getAPIName()) | 67 | + TQueBindFreeTensorOp.getAPIName(), ": there is no corresponding call to ", |
| 68 | + ascendc::TQueBindAllocTensorOp::getAPIName()) | ||
| 67 | .attachNote(TQueBindFreeTensorOp.getTensor().getLoc()) | 69 | .attachNote(TQueBindFreeTensorOp.getTensor().getLoc()) |
| 68 | .append("tensor declared here"); | 70 | .append("tensor declared here"); |
| 69 | } | 71 | } |
| 70 | } | 72 | } |
| 71 | 73 | ||
| 72 | - void dealTQueBindDequeTensorOp(Operation *oriOp, ascendc::TQueBindDequeTensorOp &deque, | 74 | + void dealTQueBindDequeTensorOp( |
| 73 | - ValueMap<SmallVector<Operation *>> &queBinds, | 75 | + Operation* oriOp, ascendc::TQueBindDequeTensorOp& deque, ValueMap<SmallVector<Operation*>>& queBinds, |
| 74 | - std::unordered_map<ascendc::TQueBindDequeTensorOp, ascendc::TQueBindEnqueTensorOp, | 76 | + std::unordered_map< |
| 75 | - PointerLikeTypeHash<ascendc::TQueBindDequeTensorOp>> &deqToEnq, | 77 | + ascendc::TQueBindDequeTensorOp, ascendc::TQueBindEnqueTensorOp, |
| 76 | - DominanceInfo &di) | 78 | + PointerLikeTypeHash<ascendc::TQueBindDequeTensorOp>>& deqToEnq, |
| 79 | + DominanceInfo& di) | ||
| 77 | { | 80 | { |
| 78 | - auto &operations = queBinds[deque.getQueue()]; | 81 | + auto& operations = queBinds[deque.getQueue()]; |
| 79 | - auto *it = llvm::find_if(operations, [](Operation *op) { return isa<ascendc::TQueBindEnqueTensorOp>(op); }); | 82 | + auto* it = llvm::find_if(operations, [](Operation* op) { return isa<ascendc::TQueBindEnqueTensorOp>(op); }); |
| 80 | if (it != operations.end()) { | 83 | if (it != operations.end()) { |
| 81 | auto firstEnque = dyn_cast<ascendc::TQueBindEnqueTensorOp>(*it); | 84 | auto firstEnque = dyn_cast<ascendc::TQueBindEnqueTensorOp>(*it); |
| 82 | deqToEnq[deque] = firstEnque; | 85 | deqToEnq[deque] = firstEnque; |
| 83 | operations.erase(it); | 86 | operations.erase(it); |
| 84 | auto tensor = firstEnque.getTensor(); | 87 | auto tensor = firstEnque.getTensor(); |
| 85 | // check that tensor is not used between enque and deque | 88 | // check that tensor is not used between enque and deque |
| 86 | - std::vector<Operation *> users; | 89 | + std::vector<Operation*> users; |
| 87 | - llvm::copy_if(tensor.getUsers(), std::back_inserter(users), [&](Operation *user) { | 90 | + llvm::copy_if(tensor.getUsers(), std::back_inserter(users), [&](Operation* user) { |
| 88 | return ascendc::opPrecedes(firstEnque, user, di) && ascendc::opPrecedes(user, deque, di); | 91 | return ascendc::opPrecedes(firstEnque, user, di) && ascendc::opPrecedes(user, deque, di); |
| 89 | }); | 92 | }); |
| 90 | - for (auto *op : users) { | 93 | + for (auto* op : users) { |
| 91 | op->emitWarning() | 94 | op->emitWarning() |
| 92 | - .append("unexpected use of tensor between ", ascendc::TQueBindEnqueTensorOp::getAPIName(), " and ", | 95 | + .append( |
| 93 | - ascendc::TQueBindDequeTensorOp::getAPIName()) | 96 | + "unexpected use of tensor between ", ascendc::TQueBindEnqueTensorOp::getAPIName(), " and ", |
| 97 | + ascendc::TQueBindDequeTensorOp::getAPIName()) | ||
| 94 | .attachNote(tensor.getLoc()) | 98 | .attachNote(tensor.getLoc()) |
| 95 | .append("tensor declared here"); | 99 | .append("tensor declared here"); |
| 96 | } | 100 | } |
| 97 | } else { | 101 | } else { |
| 98 | oriOp->emitWarning() | 102 | oriOp->emitWarning() |
| 99 | - .append(deque.getAPIName(), ": there is no corresponding call to ", | 103 | + .append( |
| 100 | - ascendc::TQueBindEnqueTensorOp::getAPIName()) | 104 | + deque.getAPIName(), ": there is no corresponding call to ", |
| 105 | + ascendc::TQueBindEnqueTensorOp::getAPIName()) | ||
| 101 | .attachNote(deque.getQueue().getLoc()) | 106 | .attachNote(deque.getQueue().getLoc()) |
| 102 | .append("queue declared here"); | 107 | .append("queue declared here"); |
| 103 | } | 108 | } |
| @@ -109,12 +114,13 @@ struct VerifySyncPass : public ascendc::impl::VerifySyncBase<VerifySyncPass> { | |||
| 109 | if (funcOp.isDeclaration()) { | 114 | if (funcOp.isDeclaration()) { |
| 110 | return; | 115 | return; |
| 111 | } | 116 | } |
| 112 | - ValueMap<SmallVector<Operation *>> queBinds; | 117 | + ValueMap<SmallVector<Operation*>> queBinds; |
| 113 | - std::unordered_map<ascendc::TQueBindDequeTensorOp, ascendc::TQueBindEnqueTensorOp, | 118 | + std::unordered_map< |
| 114 | - PointerLikeTypeHash<ascendc::TQueBindDequeTensorOp>> | 119 | + ascendc::TQueBindDequeTensorOp, ascendc::TQueBindEnqueTensorOp, |
| 120 | + PointerLikeTypeHash<ascendc::TQueBindDequeTensorOp>> | ||
| 115 | deqToEnq; | 121 | deqToEnq; |
| 116 | DominanceInfo di; | 122 | DominanceInfo di; |
| 117 | - funcOp.walk([&](Operation *op) { | 123 | + funcOp.walk([&](Operation* op) { |
| 118 | if (auto alloc = dyn_cast<ascendc::TQueBindAllocTensorOp>(op)) { | 124 | if (auto alloc = dyn_cast<ascendc::TQueBindAllocTensorOp>(op)) { |
| 119 | queBinds[alloc.getQueue()].push_back(op); | 125 | queBinds[alloc.getQueue()].push_back(op); |
| 120 | } else if (auto TQueBindFreeTensorOp = dyn_cast<ascendc::TQueBindFreeTensorOp>(op)) { | 126 | } else if (auto TQueBindFreeTensorOp = dyn_cast<ascendc::TQueBindFreeTensorOp>(op)) { |
| @@ -125,17 +131,19 @@ struct VerifySyncPass : public ascendc::impl::VerifySyncBase<VerifySyncPass> { | |||
| 125 | dealTQueBindDequeTensorOp(op, deque, queBinds, deqToEnq, di); | 131 | dealTQueBindDequeTensorOp(op, deque, queBinds, deqToEnq, di); |
| 126 | } | 132 | } |
| 127 | }); | 133 | }); |
| 128 | - for (auto &[queBind, operations] : queBinds) { | 134 | + for (auto& [queBind, operations] : queBinds) { |
| 129 | if (operations.empty()) | 135 | if (operations.empty()) |
| 130 | continue; | 136 | continue; |
| 131 | - for (auto &op : operations) { | 137 | + for (auto& op : operations) { |
| 132 | if (auto alloc = dyn_cast<ascendc::TQueBindAllocTensorOp>(op)) { | 138 | if (auto alloc = dyn_cast<ascendc::TQueBindAllocTensorOp>(op)) { |
| 133 | - alloc.emitWarning().append(alloc.getAPIName(), ": there is no corresponding call to ", | 139 | + alloc.emitWarning().append( |
| 134 | - ascendc::TQueBindFreeTensorOp::getAPIName(), " for this tensor"); | 140 | + alloc.getAPIName(), ": there is no corresponding call to ", |
| 141 | + ascendc::TQueBindFreeTensorOp::getAPIName(), " for this tensor"); | ||
| 135 | } else if (auto enque = dyn_cast<ascendc::TQueBindEnqueTensorOp>(op)) { | 142 | } else if (auto enque = dyn_cast<ascendc::TQueBindEnqueTensorOp>(op)) { |
| 136 | enque.emitWarning() | 143 | enque.emitWarning() |
| 137 | - .append(enque.getAPIName(), ": there is no corresponding call to ", | 144 | + .append( |
| 138 | - ascendc::TQueBindDequeTensorOp::getAPIName(), " for this tensor") | 145 | + enque.getAPIName(), ": there is no corresponding call to ", |
| 146 | + ascendc::TQueBindDequeTensorOp::getAPIName(), " for this tensor") | ||
| 139 | .attachNote(enque.getQueue().getLoc()) | 147 | .attachNote(enque.getQueue().getLoc()) |
| 140 | .append("queue declared here"); | 148 | .append("queue declared here"); |
| 141 | } | 149 | } |
| @@ -148,9 +156,6 @@ struct VerifySyncPass : public ascendc::impl::VerifySyncBase<VerifySyncPass> { | |||
| 148 | 156 | ||
| 149 | namespace mlir { | 157 | namespace mlir { |
| 150 | namespace ascendc { | 158 | namespace ascendc { |
| 151 | -std::unique_ptr<Pass> createVerifySyncPass() | 159 | +std::unique_ptr<Pass> createVerifySyncPass() { return std::make_unique<VerifySyncPass>(); } |
| 152 | -{ | ||
| 153 | - return std::make_unique<VerifySyncPass>(); | ||
| 154 | -} | ||
| 155 | } // namespace ascendc | 160 | } // namespace ascendc |
| 156 | } // namespace mlir | 161 | } // namespace mlir |
| @@ -24,33 +24,30 @@ using AllowInline = ascir::AllowlistInlinerInterface<T...>; | |||
| 24 | 24 | ||
| 25 | namespace ascendc { | 25 | namespace ascendc { |
| 26 | 26 | ||
| 27 | -bool opPrecedes(Operation *lhs, Operation *rhs) | 27 | +bool opPrecedes(Operation* lhs, Operation* rhs) { return lhs != rhs && lhs->isBeforeInBlock(rhs); } |
| 28 | -{ | ||
| 29 | - return lhs != rhs && lhs->isBeforeInBlock(rhs); | ||
| 30 | -} | ||
| 31 | 28 | ||
| 32 | -bool opPrecedes(Operation *lhs, Operation *rhs, DominanceInfo &di) | 29 | +bool opPrecedes(Operation* lhs, Operation* rhs, DominanceInfo& di) |
| 33 | { | 30 | { |
| 34 | if (lhs == rhs) { | 31 | if (lhs == rhs) { |
| 35 | return false; | 32 | return false; |
| 36 | } | 33 | } |
| 37 | - Block *lhsBlk = lhs->getBlock(); | 34 | + Block* lhsBlk = lhs->getBlock(); |
| 38 | - Block *rhsBlk = rhs->getBlock(); | 35 | + Block* rhsBlk = rhs->getBlock(); |
| 39 | if (lhsBlk == rhsBlk) { | 36 | if (lhsBlk == rhsBlk) { |
| 40 | return lhs->isBeforeInBlock(rhs); | 37 | return lhs->isBeforeInBlock(rhs); |
| 41 | } | 38 | } |
| 42 | - Block *dtr = di.findNearestCommonDominator(lhsBlk, rhsBlk); | 39 | + Block* dtr = di.findNearestCommonDominator(lhsBlk, rhsBlk); |
| 43 | - Operation *lhsAnc = dtr->findAncestorOpInBlock(*lhs); | 40 | + Operation* lhsAnc = dtr->findAncestorOpInBlock(*lhs); |
| 44 | - Operation *rhsAnc = dtr->findAncestorOpInBlock(*rhs); | 41 | + Operation* rhsAnc = dtr->findAncestorOpInBlock(*rhs); |
| 45 | return lhsAnc->isBeforeInBlock(rhsAnc); | 42 | return lhsAnc->isBeforeInBlock(rhsAnc); |
| 46 | } | 43 | } |
| 47 | 44 | ||
| 48 | -void registerInlinerInterfaces(DialectRegistry ®istry) | 45 | +void registerInlinerInterfaces(DialectRegistry& registry) |
| 49 | { | 46 | { |
| 50 | - registry.addExtension(+[](MLIRContext *ctx, BuiltinDialect *dialect) { | 47 | + registry.addExtension(+[](MLIRContext* ctx, BuiltinDialect* dialect) { |
| 51 | dialect->addInterface<AllowInline<UnrealizedConversionCastOp>>(); | 48 | dialect->addInterface<AllowInline<UnrealizedConversionCastOp>>(); |
| 52 | }); | 49 | }); |
| 53 | - registry.addExtension(+[](MLIRContext *ctx, emitc::EmitCDialect *dialect) { | 50 | + registry.addExtension(+[](MLIRContext* ctx, emitc::EmitCDialect* dialect) { |
| 54 | dialect->addInterface<AllowInline<emitc::CastOp, emitc::ConstantOp>>(); | 51 | dialect->addInterface<AllowInline<emitc::CastOp, emitc::ConstantOp>>(); |
| 55 | }); | 52 | }); |
| 56 | } | 53 | } |
| @@ -33,8 +33,8 @@ void EmitAscDialect::initialize() | |||
| 33 | // External models | 33 | // External models |
| 34 | //===----------------------------------------------------------------------===// | 34 | //===----------------------------------------------------------------------===// |
| 35 | 35 | ||
| 36 | -void emitasc::registerExternalModels(DialectRegistry ®istry) | 36 | +void emitasc::registerExternalModels(DialectRegistry& registry) |
| 37 | { | 37 | { |
| 38 | registry.addExtension( | 38 | registry.addExtension( |
| 39 | - +[](MLIRContext *ctx, EmitAscDialect *dialect) { dialect->addInterface<ascir::PermissiveInlinerInterface>(); }); | 39 | + +[](MLIRContext* ctx, EmitAscDialect* dialect) { dialect->addInterface<ascir::PermissiveInlinerInterface>(); }); |
| 40 | } | 40 | } |
| @@ -24,10 +24,7 @@ using namespace mlir::emitasc; | |||
| 24 | // PtrOffsetOp | 24 | // PtrOffsetOp |
| 25 | //===----------------------------------------------------------------------===// | 25 | //===----------------------------------------------------------------------===// |
| 26 | 26 | ||
| 27 | -Value PtrOffsetOp::getViewSource() | 27 | +Value PtrOffsetOp::getViewSource() { return getBase(); } |
| 28 | -{ | ||
| 29 | - return getBase(); | ||
| 30 | -} | ||
| 31 | 28 | ||
| 32 | OpFoldResult PtrOffsetOp::fold(FoldAdaptor adaptor) | 29 | OpFoldResult PtrOffsetOp::fold(FoldAdaptor adaptor) |
| 33 | { | 30 | { |
| @@ -51,10 +48,7 @@ bool ReinterpretCastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) | |||
| 51 | // VariableOp | 48 | // VariableOp |
| 52 | //===----------------------------------------------------------------------===// | 49 | //===----------------------------------------------------------------------===// |
| 53 | 50 | ||
| 54 | -bool VariableOp::isStatic() | 51 | +bool VariableOp::isStatic() { return getStaticInit().has_value(); } |
| 55 | -{ | ||
| 56 | - return getStaticInit().has_value(); | ||
| 57 | -} | ||
| 58 | 52 | ||
| 59 | OpFoldResult VariableOp::getInit(bool fold) | 53 | OpFoldResult VariableOp::getInit(bool fold) |
| 60 | { | 54 | { |
| @@ -18,18 +18,18 @@ using mlir::raw_indented_ostream; | |||
| 18 | namespace { | 18 | namespace { |
| 19 | 19 | ||
| 20 | class GenAPITypedefs { | 20 | class GenAPITypedefs { |
| 21 | - const RecordKeeper &records; | 21 | + const RecordKeeper& records; |
| 22 | 22 | ||
| 23 | - public: | 23 | +public: |
| 24 | - explicit GenAPITypedefs(const RecordKeeper &records) : records(records) {} | 24 | + explicit GenAPITypedefs(const RecordKeeper& records) : records(records) {} |
| 25 | 25 | ||
| 26 | - void run(raw_ostream &os); | 26 | + void run(raw_ostream& os); |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | -void GenAPITypedefs::run(raw_ostream &os) | 29 | +void GenAPITypedefs::run(raw_ostream& os) |
| 30 | { | 30 | { |
| 31 | raw_indented_ostream ios(os); | 31 | raw_indented_ostream ios(os); |
| 32 | - for (const auto *def : records.getAllDerivedDefinitions("APIType")) { | 32 | + for (const auto* def : records.getAllDerivedDefinitions("APIType")) { |
| 33 | if (!def->getValueAsBit("genTypedef")) { | 33 | if (!def->getValueAsBit("genTypedef")) { |
| 34 | continue; | 34 | continue; |
| 35 | } | 35 | } |
| @@ -41,7 +41,7 @@ void GenAPITypedefs::run(raw_ostream &os) | |||
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | -TableGen::Emitter::OptClass<GenAPITypedefs> registration("gen-api-typedefs", | 44 | +TableGen::Emitter::OptClass<GenAPITypedefs> |
| 45 | - "Generate MLIR typedefs from API type declarations"); | 45 | + registration("gen-api-typedefs", "Generate MLIR typedefs from API type declarations"); |
| 46 | 46 | ||
| 47 | } // namespace | 47 | } // namespace |
| @@ -30,7 +30,7 @@ std::string snakeToCamel(StringRef str) | |||
| 30 | std::string result; | 30 | std::string result; |
| 31 | result.reserve(size); | 31 | result.reserve(size); |
| 32 | result += std::string_view(tokens.front()); | 32 | result += std::string_view(tokens.front()); |
| 33 | - for (auto *it = tokens.begin() + 1; it != tokens.end(); ++it) { | 33 | + for (auto* it = tokens.begin() + 1; it != tokens.end(); ++it) { |
| 34 | result += it->take_front(1).upper(); | 34 | result += it->take_front(1).upper(); |
| 35 | result += std::string_view(it->drop_front(1)); | 35 | result += std::string_view(it->drop_front(1)); |
| 36 | } | 36 | } |
| @@ -38,20 +38,20 @@ std::string snakeToCamel(StringRef str) | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | class GenAPITypes { | 40 | class GenAPITypes { |
| 41 | - const RecordKeeper &records; | 41 | + const RecordKeeper& records; |
| 42 | 42 | ||
| 43 | - public: | 43 | +public: |
| 44 | - explicit GenAPITypes(const RecordKeeper &records) : records(records) {} | 44 | + explicit GenAPITypes(const RecordKeeper& records) : records(records) {} |
| 45 | 45 | ||
| 46 | - void run(raw_ostream &os); | 46 | + void run(raw_ostream& os); |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | -void GenAPITypes::run(raw_ostream &os) | 49 | +void GenAPITypes::run(raw_ostream& os) |
| 50 | { | 50 | { |
| 51 | raw_indented_ostream ios(os); | 51 | raw_indented_ostream ios(os); |
| 52 | auto typeDefs = records.getAllDerivedDefinitions("APIType"); | 52 | auto typeDefs = records.getAllDerivedDefinitions("APIType"); |
| 53 | ios << "#ifdef GEN_EMITTER\n"; | 53 | ios << "#ifdef GEN_EMITTER\n"; |
| 54 | - for (const auto *def : typeDefs) { | 54 | + for (const auto* def : typeDefs) { |
| 55 | if (!def->getValueAsBit("genEmitter")) { | 55 | if (!def->getValueAsBit("genEmitter")) { |
| 56 | continue; | 56 | continue; |
| 57 | } | 57 | } |
| @@ -28,25 +28,25 @@ using mlir::raw_indented_ostream; | |||
| 28 | 28 | ||
| 29 | namespace { | 29 | namespace { |
| 30 | class GenOpEmitsDecls { | 30 | class GenOpEmitsDecls { |
| 31 | - public: | 31 | +public: |
| 32 | - explicit GenOpEmitsDecls(const RecordKeeper &records) : records(records) {} | 32 | + explicit GenOpEmitsDecls(const RecordKeeper& records) : records(records) {} |
| 33 | - void run(raw_ostream &os); | 33 | + void run(raw_ostream& os); |
| 34 | 34 | ||
| 35 | - private: | 35 | +private: |
| 36 | - const RecordKeeper &records; | 36 | + const RecordKeeper& records; |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | -void printOpType(raw_indented_ostream &os, const Record *def) | 39 | +void printOpType(raw_indented_ostream& os, const Record* def) |
| 40 | { | 40 | { |
| 41 | const auto opTypeFullName = def->getName(); | 41 | const auto opTypeFullName = def->getName(); |
| 42 | const auto opType = mlir::asc::removeDialectPrefix(opTypeFullName, mlir::asc::kAscDialectName); | 42 | const auto opType = mlir::asc::removeDialectPrefix(opTypeFullName, mlir::asc::kAscDialectName); |
| 43 | os << mlir::asc::kAscDialectNameSpace << opType << " ,"; | 43 | os << mlir::asc::kAscDialectNameSpace << opType << " ,"; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | -void GenOpEmitsDecls::run(raw_ostream &os) | 46 | +void GenOpEmitsDecls::run(raw_ostream& os) |
| 47 | { | 47 | { |
| 48 | raw_indented_ostream ios(os); | 48 | raw_indented_ostream ios(os); |
| 49 | - for (const auto *def : records.getAllDerivedDefinitions("Op")) { | 49 | + for (const auto* def : records.getAllDerivedDefinitions("Op")) { |
| 50 | if (!def->getValueAsBit(mlir::asc::kAutoEmitAttr)) { | 50 | if (!def->getValueAsBit(mlir::asc::kAutoEmitAttr)) { |
| 51 | continue; | 51 | continue; |
| 52 | } | 52 | } |
| @@ -54,6 +54,6 @@ void GenOpEmitsDecls::run(raw_ostream &os) | |||
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | -TableGen::Emitter::OptClass<GenOpEmitsDecls> registration("gen-opemit-decls", | 57 | +TableGen::Emitter::OptClass<GenOpEmitsDecls> |
| 58 | - "Generate op emit methods from MLIR operation decls"); | 58 | + registration("gen-opemit-decls", "Generate op emit methods from MLIR operation decls"); |
| 59 | } // namespace | 59 | } // namespace |
| @@ -29,22 +29,22 @@ using mlir::raw_indented_ostream; | |||
| 29 | 29 | ||
| 30 | namespace { | 30 | namespace { |
| 31 | class GenOpEmitsDefs { | 31 | class GenOpEmitsDefs { |
| 32 | - public: | 32 | +public: |
| 33 | - explicit GenOpEmitsDefs(const RecordKeeper &records) : records(records) {} | 33 | + explicit GenOpEmitsDefs(const RecordKeeper& records) : records(records) {} |
| 34 | - void run(raw_ostream &os); | 34 | + void run(raw_ostream& os); |
| 35 | 35 | ||
| 36 | - private: | 36 | +private: |
| 37 | - const RecordKeeper &records; | 37 | + const RecordKeeper& records; |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | -void printFuncDefine(raw_indented_ostream &os, const Record *def, StringRef opType) | 40 | +void printFuncDefine(raw_indented_ostream& os, const Record* def, StringRef opType) |
| 41 | { | 41 | { |
| 42 | os << mlir::asc::kRetType << mlir::asc::kSpaceSeparated << mlir::asc::kPrintFuncName; | 42 | os << mlir::asc::kRetType << mlir::asc::kSpaceSeparated << mlir::asc::kPrintFuncName; |
| 43 | os << "(CodeEmitter &emitter, "; | 43 | os << "(CodeEmitter &emitter, "; |
| 44 | os << mlir::asc::kAscDialectNameSpace << opType << mlir::asc::kSpaceSeparated << "op) {\n"; | 44 | os << mlir::asc::kAscDialectNameSpace << opType << mlir::asc::kSpaceSeparated << "op) {\n"; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | -std::string capitalizeFirstLetter(const std::string &str) | 47 | +std::string capitalizeFirstLetter(const std::string& str) |
| 48 | { | 48 | { |
| 49 | std::string capStr(str); | 49 | std::string capStr(str); |
| 50 | if (!str.empty()) { | 50 | if (!str.empty()) { |
| @@ -53,7 +53,7 @@ std::string capitalizeFirstLetter(const std::string &str) | |||
| 53 | return capStr; | 53 | return capStr; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | -std::string genGetterName(const std::vector<mlir::asc::VirtualArg> &args, size_t i) | 56 | +std::string genGetterName(const std::vector<mlir::asc::VirtualArg>& args, size_t i) |
| 57 | { | 57 | { |
| 58 | if (i >= args.size()) { | 58 | if (i >= args.size()) { |
| 59 | return std::string(); | 59 | return std::string(); |
| @@ -61,18 +61,15 @@ std::string genGetterName(const std::vector<mlir::asc::VirtualArg> &args, size_t | |||
| 61 | return mlir::asc::kGetFunPrefix.str() + capitalizeFirstLetter(args[i].name); | 61 | return mlir::asc::kGetFunPrefix.str() + capitalizeFirstLetter(args[i].name); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | -bool hasTrait(const Record *def, StringRef traitName) | 64 | +bool hasTrait(const Record* def, StringRef traitName) |
| 65 | { | 65 | { |
| 66 | auto traits = def->getValueAsListOfDefs(mlir::asc::kTraitName); | 66 | auto traits = def->getValueAsListOfDefs(mlir::asc::kTraitName); |
| 67 | - return llvm::any_of(traits, [&](const Record *trait) { return trait->getName() == traitName; }); | 67 | + return llvm::any_of(traits, [&](const Record* trait) { return trait->getName() == traitName; }); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | -void IndentedNewLine(raw_indented_ostream &os) | 70 | +void IndentedNewLine(raw_indented_ostream& os) { os << mlir::asc::kLineBreak << mlir::asc::kIndentationSpace; } |
| 71 | -{ | ||
| 72 | - os << mlir::asc::kLineBreak << mlir::asc::kIndentationSpace; | ||
| 73 | -} | ||
| 74 | 71 | ||
| 75 | -void printInferOperandType(raw_indented_ostream &os, StringRef operand, const std::string &varName) | 72 | +void printInferOperandType(raw_indented_ostream& os, StringRef operand, const std::string& varName) |
| 76 | { | 73 | { |
| 77 | os << "auto " << varName << " = op." << operand << "().getType();"; | 74 | os << "auto " << varName << " = op." << operand << "().getType();"; |
| 78 | IndentedNewLine(os); | 75 | IndentedNewLine(os); |
| @@ -80,7 +77,7 @@ void printInferOperandType(raw_indented_ostream &os, StringRef operand, const st | |||
| 80 | IndentedNewLine(os); | 77 | IndentedNewLine(os); |
| 81 | } | 78 | } |
| 82 | 79 | ||
| 83 | -void printTemplateType(raw_indented_ostream &os, StringRef operand, const std::string &varName) | 80 | +void printTemplateType(raw_indented_ostream& os, StringRef operand, const std::string& varName) |
| 84 | { | 81 | { |
| 85 | os << "auto " << varName << " = op." << operand << "();"; | 82 | os << "auto " << varName << " = op." << operand << "();"; |
| 86 | IndentedNewLine(os); | 83 | IndentedNewLine(os); |
| @@ -88,7 +85,7 @@ void printTemplateType(raw_indented_ostream &os, StringRef operand, const std::s | |||
| 88 | IndentedNewLine(os); | 85 | IndentedNewLine(os); |
| 89 | } | 86 | } |
| 90 | 87 | ||
| 91 | -void printInferElementType(raw_indented_ostream &os, StringRef operand, StringRef typeName, StringRef elementName) | 88 | +void printInferElementType(raw_indented_ostream& os, StringRef operand, StringRef typeName, StringRef elementName) |
| 92 | { | 89 | { |
| 93 | os << " auto " << typeName << " = op." << operand << "().getType();"; | 90 | os << " auto " << typeName << " = op." << operand << "().getType();"; |
| 94 | IndentedNewLine(os); | 91 | IndentedNewLine(os); |
| @@ -98,8 +95,9 @@ void printInferElementType(raw_indented_ostream &os, StringRef operand, StringRe | |||
| 98 | IndentedNewLine(os); | 95 | IndentedNewLine(os); |
| 99 | } | 96 | } |
| 100 | 97 | ||
| 101 | -void printInferEnumType(raw_indented_ostream &os, StringRef operand, StringRef attrType, const std::string &typeName, | 98 | +void printInferEnumType( |
| 102 | - const mlir::asc::VirtualArg &arg) | 99 | + raw_indented_ostream& os, StringRef operand, StringRef attrType, const std::string& typeName, |
| 100 | + const mlir::asc::VirtualArg& arg) | ||
| 103 | { | 101 | { |
| 104 | os << " auto " << typeName << "= op." << operand << "();"; | 102 | os << " auto " << typeName << "= op." << operand << "();"; |
| 105 | IndentedNewLine(os); | 103 | IndentedNewLine(os); |
| @@ -108,7 +106,7 @@ void printInferEnumType(raw_indented_ostream &os, StringRef operand, StringRef a | |||
| 108 | IndentedNewLine(os); | 106 | IndentedNewLine(os); |
| 109 | } | 107 | } |
| 110 | 108 | ||
| 111 | -void printFuncOutputDeclaration(raw_indented_ostream &os) | 109 | +void printFuncOutputDeclaration(raw_indented_ostream& os) |
| 112 | { | 110 | { |
| 113 | os << R"( auto resNum = op.getOperation()->getNumResults(); | 111 | os << R"( auto resNum = op.getOperation()->getNumResults(); |
| 114 | auto& os = emitter.ostream(); | 112 | auto& os = emitter.ostream(); |
| @@ -119,7 +117,7 @@ void printFuncOutputDeclaration(raw_indented_ostream &os) | |||
| 119 | IndentedNewLine(os); | 117 | IndentedNewLine(os); |
| 120 | } | 118 | } |
| 121 | 119 | ||
| 122 | -void printOperand(raw_indented_ostream &os, StringRef operand, const mlir::asc::VirtualArg &arg) | 120 | +void printOperand(raw_indented_ostream& os, StringRef operand, const mlir::asc::VirtualArg& arg) |
| 123 | { | 121 | { |
| 124 | if (arg.optional) { | 122 | if (arg.optional) { |
| 125 | os << "EXEC_IF_TRUE(op." << operand << "(), "; | 123 | os << "EXEC_IF_TRUE(op." << operand << "(), "; |
| @@ -131,31 +129,31 @@ void printOperand(raw_indented_ostream &os, StringRef operand, const mlir::asc:: | |||
| 131 | IndentedNewLine(os); | 129 | IndentedNewLine(os); |
| 132 | } | 130 | } |
| 133 | 131 | ||
| 134 | -void printOperandValue(raw_indented_ostream &os, StringRef operand, const mlir::asc::VirtualArg &arg) | 132 | +void printOperandValue(raw_indented_ostream& os, StringRef operand, const mlir::asc::VirtualArg& arg) |
| 135 | { | 133 | { |
| 136 | os << R"(os << emitter.getOrCreateName(op.)" << operand << "());"; | 134 | os << R"(os << emitter.getOrCreateName(op.)" << operand << "());"; |
| 137 | IndentedNewLine(os); | 135 | IndentedNewLine(os); |
| 138 | } | 136 | } |
| 139 | 137 | ||
| 140 | -void printPointerOperandValue(raw_indented_ostream &os, StringRef operand, const mlir::asc::VirtualArg &arg) | 138 | +void printPointerOperandValue(raw_indented_ostream& os, StringRef operand, const mlir::asc::VirtualArg& arg) |
| 141 | { | 139 | { |
| 142 | os << "os << \"&\" << emitter.getOrCreateName(op." << operand << "());"; | 140 | os << "os << \"&\" << emitter.getOrCreateName(op." << operand << "());"; |
| 143 | IndentedNewLine(os); | 141 | IndentedNewLine(os); |
| 144 | } | 142 | } |
| 145 | 143 | ||
| 146 | -void printPointerToIntOperandValue(raw_indented_ostream &os, StringRef operand, const mlir::asc::VirtualArg &arg) | 144 | +void printPointerToIntOperandValue(raw_indented_ostream& os, StringRef operand, const mlir::asc::VirtualArg& arg) |
| 147 | { | 145 | { |
| 148 | os << "os << \"reinterpret_cast<uint64_t>(\" << emitter.getOrCreateName(op." << operand << "()) << \")\";"; | 146 | os << "os << \"reinterpret_cast<uint64_t>(\" << emitter.getOrCreateName(op." << operand << "()) << \")\";"; |
| 149 | IndentedNewLine(os); | 147 | IndentedNewLine(os); |
| 150 | } | 148 | } |
| 151 | 149 | ||
| 152 | -bool hasTemplateParams(const std::vector<int64_t> ¶mTypes) | 150 | +bool hasTemplateParams(const std::vector<int64_t>& paramTypes) |
| 153 | { | 151 | { |
| 154 | - return std::any_of(paramTypes.cbegin(), paramTypes.cend(), | 152 | + return std::any_of( |
| 155 | - [](const auto &type) { return type > mlir::asc::kNormalType; }); | 153 | + paramTypes.cbegin(), paramTypes.cend(), [](const auto& type) { return type > mlir::asc::kNormalType; }); |
| 156 | } | 154 | } |
| 157 | 155 | ||
| 158 | -void printTemplateCallStart(raw_indented_ostream &os, const std::vector<int64_t> ¶mTypes, bool isMemberFunc) | 156 | +void printTemplateCallStart(raw_indented_ostream& os, const std::vector<int64_t>& paramTypes, bool isMemberFunc) |
| 159 | { | 157 | { |
| 160 | if (isMemberFunc) { | 158 | if (isMemberFunc) { |
| 161 | if (paramTypes[0] != mlir::asc::kNormalType) { | 159 | if (paramTypes[0] != mlir::asc::kNormalType) { |
| @@ -170,8 +168,9 @@ void printTemplateCallStart(raw_indented_ostream &os, const std::vector<int64_t> | |||
| 170 | } | 168 | } |
| 171 | } | 169 | } |
| 172 | 170 | ||
| 173 | -bool printTemplateParam(raw_indented_ostream &os, const Record *def, const std::vector<int64_t> ¶mTypes, | 171 | +bool printTemplateParam( |
| 174 | - const std::vector<mlir::asc::VirtualArg> &args, bool isMemberFunc = false) | 172 | + raw_indented_ostream& os, const Record* def, const std::vector<int64_t>& paramTypes, |
| 173 | + const std::vector<mlir::asc::VirtualArg>& args, bool isMemberFunc = false) | ||
| 175 | { | 174 | { |
| 176 | if (!hasTemplateParams(paramTypes)) { | 175 | if (!hasTemplateParams(paramTypes)) { |
| 177 | return false; | 176 | return false; |
| @@ -191,28 +190,28 @@ bool printTemplateParam(raw_indented_ostream &os, const Record *def, const std:: | |||
| 191 | std::string elementTypeVar = "elType" + std::to_string(i); | 190 | std::string elementTypeVar = "elType" + std::to_string(i); |
| 192 | std::string attrTypeVar = "iAttr" + std::to_string(i); | 191 | std::string attrTypeVar = "iAttr" + std::to_string(i); |
| 193 | switch (paramTypes[i]) { | 192 | switch (paramTypes[i]) { |
| 194 | - case mlir::asc::kInferType: // infer operand type | 193 | + case mlir::asc::kInferType: // infer operand type |
| 195 | - printInferOperandType(os, genGetterName(args, i), templateTypeVar); | 194 | + printInferOperandType(os, genGetterName(args, i), templateTypeVar); |
| 196 | - break; | 195 | + break; |
| 197 | - // infer operand element type, such as get T form LocalTensor<T> | 196 | + // infer operand element type, such as get T form LocalTensor<T> |
| 198 | - case mlir::asc::kInferElementType: | 197 | + case mlir::asc::kInferElementType: |
| 199 | - printInferElementType(os, genGetterName(args, i), templateTypeVar, elementTypeVar); | 198 | + printInferElementType(os, genGetterName(args, i), templateTypeVar, elementTypeVar); |
| 200 | - break; | 199 | + break; |
| 201 | - case mlir::asc::kInferEnumType: // pass by attr | 200 | + case mlir::asc::kInferEnumType: // pass by attr |
| 202 | - printInferEnumType( | 201 | + printInferEnumType( |
| 203 | - os, genGetterName(args, i), | 202 | + os, genGetterName(args, i), |
| 204 | - mlir::asc::removeAscDialectNameSpace(args[i].cppType, def->getValueAsString("cppNamespace")), | 203 | + mlir::asc::removeAscDialectNameSpace(args[i].cppType, def->getValueAsString("cppNamespace")), |
| 205 | - attrTypeVar, args[i]); | 204 | + attrTypeVar, args[i]); |
| 206 | - break; | 205 | + break; |
| 207 | - case mlir::asc::kInferValue: // pass by value | 206 | + case mlir::asc::kInferValue: // pass by value |
| 208 | - printOperandValue(os, genGetterName(args, i), args[i]); | 207 | + printOperandValue(os, genGetterName(args, i), args[i]); |
| 209 | - break; | 208 | + break; |
| 210 | - case mlir::asc::kTemplateType: // pass by template type | 209 | + case mlir::asc::kTemplateType: // pass by template type |
| 211 | - printTemplateType(os, genGetterName(args, i), templateTypeVar); | 210 | + printTemplateType(os, genGetterName(args, i), templateTypeVar); |
| 212 | - break; | 211 | + break; |
| 213 | - case mlir::asc::kInferTypeAttr: // type attribute, use directly as template type | 212 | + case mlir::asc::kInferTypeAttr: // type attribute, use directly as template type |
| 214 | - printTemplateType(os, genGetterName(args, i), templateTypeVar); | 213 | + printTemplateType(os, genGetterName(args, i), templateTypeVar); |
| 215 | - break; | 214 | + break; |
| 216 | } | 215 | } |
| 217 | } | 216 | } |
| 218 | os << mlir::asc::kOutTemplateCallEnd; | 217 | os << mlir::asc::kOutTemplateCallEnd; |
| @@ -220,9 +219,9 @@ bool printTemplateParam(raw_indented_ostream &os, const Record *def, const std:: | |||
| 220 | return true; | 219 | return true; |
| 221 | } | 220 | } |
| 222 | 221 | ||
| 223 | -void printFunctionParam(raw_indented_ostream &os, const Record *def, const std::vector<int64_t> ¶mTypes, | 222 | +void printFunctionParam( |
| 224 | - const std::vector<mlir::asc::VirtualArg> &args, bool hasTemplate = false, | 223 | + raw_indented_ostream& os, const Record* def, const std::vector<int64_t>& paramTypes, |
| 225 | - bool isMemberFunc = false) | 224 | + const std::vector<mlir::asc::VirtualArg>& args, bool hasTemplate = false, bool isMemberFunc = false) |
| 226 | { | 225 | { |
| 227 | size_t i = isMemberFunc ? 1 : 0; | 226 | size_t i = isMemberFunc ? 1 : 0; |
| 228 | if (!hasTemplate) { | 227 | if (!hasTemplate) { |
| @@ -264,7 +263,7 @@ void printFunctionParam(raw_indented_ostream &os, const Record *def, const std:: | |||
| 264 | << "\n}\n"; | 263 | << "\n}\n"; |
| 265 | } | 264 | } |
| 266 | 265 | ||
| 267 | -void printOp(raw_indented_ostream &os, const Record *def) | 266 | +void printOp(raw_indented_ostream& os, const Record* def) |
| 268 | { | 267 | { |
| 269 | const auto opTypeFullName = def->getName(); | 268 | const auto opTypeFullName = def->getName(); |
| 270 | const auto opType = mlir::asc::removeDialectPrefix(opTypeFullName, "AscendC"); | 269 | const auto opType = mlir::asc::removeDialectPrefix(opTypeFullName, "AscendC"); |
| @@ -286,10 +285,10 @@ void printOp(raw_indented_ostream &os, const Record *def) | |||
| 286 | } | 285 | } |
| 287 | } | 286 | } |
| 288 | 287 | ||
| 289 | -void GenOpEmitsDefs::run(raw_ostream &os) | 288 | +void GenOpEmitsDefs::run(raw_ostream& os) |
| 290 | { | 289 | { |
| 291 | raw_indented_ostream ios(os); | 290 | raw_indented_ostream ios(os); |
| 292 | - for (const auto *def : records.getAllDerivedDefinitions("Op")) { | 291 | + for (const auto* def : records.getAllDerivedDefinitions("Op")) { |
| 293 | if (!def->getValueAsBit(mlir::asc::kAutoEmitAttr)) { | 292 | if (!def->getValueAsBit(mlir::asc::kAutoEmitAttr)) { |
| 294 | continue; | 293 | continue; |
| 295 | } | 294 | } |
| @@ -297,7 +296,7 @@ void GenOpEmitsDefs::run(raw_ostream &os) | |||
| 297 | } | 296 | } |
| 298 | } | 297 | } |
| 299 | 298 | ||
| 300 | -TableGen::Emitter::OptClass<GenOpEmitsDefs> registration("gen-opemit-defs", | 299 | +TableGen::Emitter::OptClass<GenOpEmitsDefs> |
| 301 | - "Generate op emit methods from MLIR operation defs"); | 300 | + registration("gen-opemit-defs", "Generate op emit methods from MLIR operation defs"); |
| 302 | 301 | ||
| 303 | } // namespace | 302 | } // namespace |
| @@ -25,23 +25,23 @@ | |||
| 25 | using namespace llvm; | 25 | using namespace llvm; |
| 26 | using mlir::raw_indented_ostream; | 26 | using mlir::raw_indented_ostream; |
| 27 | 27 | ||
| 28 | -cl::opt<std::string> builderClass("builder-class", cl::init("PyOpBuilder"), | 28 | +cl::opt<std::string> builderClass( |
| 29 | - cl::desc("Operation builder class name for 'gen-pybind-defs' action")); | 29 | + "builder-class", cl::init("PyOpBuilder"), cl::desc("Operation builder class name for 'gen-pybind-defs' action")); |
| 30 | 30 | ||
| 31 | namespace { | 31 | namespace { |
| 32 | 32 | ||
| 33 | using TypeNamePair = std::pair<std::string, std::string>; | 33 | using TypeNamePair = std::pair<std::string, std::string>; |
| 34 | 34 | ||
| 35 | class GenPybindDefs { | 35 | class GenPybindDefs { |
| 36 | - const RecordKeeper &records; | 36 | + const RecordKeeper& records; |
| 37 | 37 | ||
| 38 | - public: | 38 | +public: |
| 39 | - explicit GenPybindDefs(const RecordKeeper &records) : records(records) {} | 39 | + explicit GenPybindDefs(const RecordKeeper& records) : records(records) {} |
| 40 | 40 | ||
| 41 | - void run(raw_ostream &os); | 41 | + void run(raw_ostream& os); |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | -void printMethod(raw_indented_ostream &os, const Record *def) | 44 | +void printMethod(raw_indented_ostream& os, const Record* def) |
| 45 | { | 45 | { |
| 46 | if (def->getValueAsBit("skipDefaultBuilders")) { | 46 | if (def->getValueAsBit("skipDefaultBuilders")) { |
| 47 | return; | 47 | return; |
| @@ -59,7 +59,7 @@ void printMethod(raw_indented_ostream &os, const Record *def) | |||
| 59 | os << dialectName; | 59 | os << dialectName; |
| 60 | } | 60 | } |
| 61 | os << '_' << name << "\", [](" << builderClass.getValue() << " &self"; | 61 | os << '_' << name << "\", [](" << builderClass.getValue() << " &self"; |
| 62 | - for (const auto &arg : args) { | 62 | + for (const auto& arg : args) { |
| 63 | os << ", const " << arg.cppType << " &" << arg.name; | 63 | os << ", const " << arg.cppType << " &" << arg.name; |
| 64 | } | 64 | } |
| 65 | os << ") "; | 65 | os << ") "; |
| @@ -72,13 +72,13 @@ void printMethod(raw_indented_ostream &os, const Record *def) | |||
| 72 | os << "return "; | 72 | os << "return "; |
| 73 | } | 73 | } |
| 74 | os << "self.create<" << def->getValueAsString("cppNamespace") << "::" << name << ">("; | 74 | os << "self.create<" << def->getValueAsString("cppNamespace") << "::" << name << ">("; |
| 75 | - interleaveComma(args, os, [&os](const auto &arg) { os << arg.substitution; }); | 75 | + interleaveComma(args, os, [&os](const auto& arg) { os << arg.substitution; }); |
| 76 | os << ");\n"; | 76 | os << ");\n"; |
| 77 | os.unindent() << "}"; | 77 | os.unindent() << "}"; |
| 78 | auto lastRequired = | 78 | auto lastRequired = |
| 79 | - std::find_if(args.rbegin(), args.rend(), [](const mlir::asc::VirtualArg &arg) { return !arg.optional; }); | 79 | + std::find_if(args.rbegin(), args.rend(), [](const mlir::asc::VirtualArg& arg) { return !arg.optional; }); |
| 80 | - std::for_each(lastRequired, args.rend(), [](auto &a) { a.optional = false; }); | 80 | + std::for_each(lastRequired, args.rend(), [](auto& a) { a.optional = false; }); |
| 81 | - for (const auto &arg : args) { | 81 | + for (const auto& arg : args) { |
| 82 | os << ", \"" << arg.name << "\"_a"; | 82 | os << ", \"" << arg.name << "\"_a"; |
| 83 | if (arg.optional) { | 83 | if (arg.optional) { |
| 84 | os << " = " << arg.defaultValue; | 84 | os << " = " << arg.defaultValue; |
| @@ -87,15 +87,15 @@ void printMethod(raw_indented_ostream &os, const Record *def) | |||
| 87 | os << ")\n"; | 87 | os << ")\n"; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | -void GenPybindDefs::run(raw_ostream &os) | 90 | +void GenPybindDefs::run(raw_ostream& os) |
| 91 | { | 91 | { |
| 92 | raw_indented_ostream ios(os); | 92 | raw_indented_ostream ios(os); |
| 93 | - for (const auto *def : records.getAllDerivedDefinitions("Op")) { | 93 | + for (const auto* def : records.getAllDerivedDefinitions("Op")) { |
| 94 | printMethod(ios, def); | 94 | printMethod(ios, def); |
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | -TableGen::Emitter::OptClass<GenPybindDefs> registration("gen-pybind-defs", | 98 | +TableGen::Emitter::OptClass<GenPybindDefs> |
| 99 | - "Generate PyOpBuilder methods from MLIR operation defs"); | 99 | + registration("gen-pybind-defs", "Generate PyOpBuilder methods from MLIR operation defs"); |
| 100 | 100 | ||
| 101 | } // namespace | 101 | } // namespace |
| @@ -27,18 +27,18 @@ namespace { | |||
| 27 | using TypeNamePair = std::pair<std::string, std::string>; | 27 | using TypeNamePair = std::pair<std::string, std::string>; |
| 28 | 28 | ||
| 29 | class GenPybindDefsTypes { | 29 | class GenPybindDefsTypes { |
| 30 | - const RecordKeeper &records; | 30 | + const RecordKeeper& records; |
| 31 | 31 | ||
| 32 | - public: | 32 | +public: |
| 33 | - explicit GenPybindDefsTypes(const RecordKeeper &records) : records(records) {} | 33 | + explicit GenPybindDefsTypes(const RecordKeeper& records) : records(records) {} |
| 34 | 34 | ||
| 35 | - void run(raw_ostream &os); | 35 | + void run(raw_ostream& os); |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | -void GenPybindDefsTypes::run(raw_ostream &os) | 38 | +void GenPybindDefsTypes::run(raw_ostream& os) |
| 39 | { | 39 | { |
| 40 | raw_indented_ostream ios(os); | 40 | raw_indented_ostream ios(os); |
| 41 | - for (const auto *def : records.getAllDerivedDefinitions("APIType")) { | 41 | + for (const auto* def : records.getAllDerivedDefinitions("APIType")) { |
| 42 | if (!def->getValueAsBit("genTypedef")) { | 42 | if (!def->getValueAsBit("genTypedef")) { |
| 43 | continue; | 43 | continue; |
| 44 | } | 44 | } |
| @@ -49,7 +49,7 @@ void GenPybindDefsTypes::run(raw_ostream &os) | |||
| 49 | } | 49 | } |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -TableGen::Emitter::OptClass<GenPybindDefsTypes> registration("gen-pybind-defs-types", | 52 | +TableGen::Emitter::OptClass<GenPybindDefsTypes> |
| 53 | - "Generate PyOpBuilder methods from API Types defs"); | 53 | + registration("gen-pybind-defs-types", "Generate PyOpBuilder methods from API Types defs"); |
| 54 | 54 | ||
| 55 | } // namespace | 55 | } // namespace |
| @@ -16,12 +16,12 @@ using namespace llvm; | |||
| 16 | namespace { | 16 | namespace { |
| 17 | 17 | ||
| 18 | class PrintDecls { | 18 | class PrintDecls { |
| 19 | - const RecordKeeper &records; | 19 | + const RecordKeeper& records; |
| 20 | 20 | ||
| 21 | - public: | 21 | +public: |
| 22 | - explicit PrintDecls(const RecordKeeper &records) : records(records) {} | 22 | + explicit PrintDecls(const RecordKeeper& records) : records(records) {} |
| 23 | 23 | ||
| 24 | - void run(raw_ostream &os) | 24 | + void run(raw_ostream& os) |
| 25 | { | 25 | { |
| 26 | emitSourceFileHeader("Classes and Defs", os); | 26 | emitSourceFileHeader("Classes and Defs", os); |
| 27 | os << records; | 27 | os << records; |
| @@ -24,9 +24,9 @@ StringRef fetchOpClass(StringRef defName) | |||
| 24 | return split.second; | 24 | return split.second; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | -void fetchResults(const DagInit *resultsDag, std::vector<VirtualArg> &dest) | 27 | +void fetchResults(const DagInit* resultsDag, std::vector<VirtualArg>& dest) |
| 28 | { | 28 | { |
| 29 | - auto *outsOp = dyn_cast<DefInit>(resultsDag->getOperator()); | 29 | + auto* outsOp = dyn_cast<DefInit>(resultsDag->getOperator()); |
| 30 | assert(outsOp && outsOp->getDef()->getName() == "outs"); | 30 | assert(outsOp && outsOp->getDef()->getName() == "outs"); |
| 31 | for (unsigned i = 0, e = resultsDag->getNumArgs(); i < e; ++i) { | 31 | for (unsigned i = 0, e = resultsDag->getNumArgs(); i < e; ++i) { |
| 32 | VirtualArg result; | 32 | VirtualArg result; |
| @@ -37,9 +37,9 @@ void fetchResults(const DagInit *resultsDag, std::vector<VirtualArg> &dest) | |||
| 37 | result.name = name; | 37 | result.name = name; |
| 38 | } | 38 | } |
| 39 | result.substitution = result.name; | 39 | result.substitution = result.name; |
| 40 | - auto *init = dyn_cast<DefInit>(resultsDag->getArg(i)); | 40 | + auto* init = dyn_cast<DefInit>(resultsDag->getArg(i)); |
| 41 | assert(init && "argument must have defined types"); | 41 | assert(init && "argument must have defined types"); |
| 42 | - auto *resultDef = init->getDef(); | 42 | + auto* resultDef = init->getDef(); |
| 43 | if (resultDef->isSubClassOf("Variadic")) { | 43 | if (resultDef->isSubClassOf("Variadic")) { |
| 44 | result.cppType = "::std::vector< ::mlir::Type >"; | 44 | result.cppType = "::std::vector< ::mlir::Type >"; |
| 45 | } else { | 45 | } else { |
| @@ -49,9 +49,9 @@ void fetchResults(const DagInit *resultsDag, std::vector<VirtualArg> &dest) | |||
| 49 | } | 49 | } |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -void fetchArguments(const DagInit *argsDag, std::vector<VirtualArg> &dest) | 52 | +void fetchArguments(const DagInit* argsDag, std::vector<VirtualArg>& dest) |
| 53 | { | 53 | { |
| 54 | - auto *insOp = dyn_cast<DefInit>(argsDag->getOperator()); | 54 | + auto* insOp = dyn_cast<DefInit>(argsDag->getOperator()); |
| 55 | assert(insOp && insOp->getDef()->getName() == "ins"); | 55 | assert(insOp && insOp->getDef()->getName() == "ins"); |
| 56 | for (unsigned i = 0, e = argsDag->getNumArgs(); i < e; ++i) { | 56 | for (unsigned i = 0, e = argsDag->getNumArgs(); i < e; ++i) { |
| 57 | VirtualArg arg; | 57 | VirtualArg arg; |
| @@ -62,9 +62,9 @@ void fetchArguments(const DagInit *argsDag, std::vector<VirtualArg> &dest) | |||
| 62 | arg.name = name; | 62 | arg.name = name; |
| 63 | } | 63 | } |
| 64 | arg.substitution = arg.name; | 64 | arg.substitution = arg.name; |
| 65 | - auto *init = dyn_cast<DefInit>(argsDag->getArg(i)); | 65 | + auto* init = dyn_cast<DefInit>(argsDag->getArg(i)); |
| 66 | assert(init && "argument must have defined types"); | 66 | assert(init && "argument must have defined types"); |
| 67 | - auto *argDef = init->getDef(); | 67 | + auto* argDef = init->getDef(); |
| 68 | if (argDef->isSubClassOf("TypeConstraint")) { | 68 | if (argDef->isSubClassOf("TypeConstraint")) { |
| 69 | if (argDef->isSubClassOf("Variadic")) { | 69 | if (argDef->isSubClassOf("Variadic")) { |
| 70 | arg.cppType = "::std::vector< ::mlir::Value >"; | 70 | arg.cppType = "::std::vector< ::mlir::Value >"; |
| @@ -38,9 +38,9 @@ struct VirtualArg { | |||
| 38 | 38 | ||
| 39 | llvm::StringRef fetchOpClass(llvm::StringRef defName); | 39 | llvm::StringRef fetchOpClass(llvm::StringRef defName); |
| 40 | 40 | ||
| 41 | -void fetchResults(const llvm::DagInit *resultsDag, std::vector<VirtualArg> &dest); | 41 | +void fetchResults(const llvm::DagInit* resultsDag, std::vector<VirtualArg>& dest); |
| 42 | 42 | ||
| 43 | -void fetchArguments(const llvm::DagInit *argsDag, std::vector<VirtualArg> &dest); | 43 | +void fetchArguments(const llvm::DagInit* argsDag, std::vector<VirtualArg>& dest); |
| 44 | 44 | ||
| 45 | llvm::StringRef removeDialectPrefix(llvm::StringRef fullName, llvm::StringRef dialectName); | 45 | llvm::StringRef removeDialectPrefix(llvm::StringRef fullName, llvm::StringRef dialectName); |
| 46 | llvm::StringRef removeAscDialectNameSpace(llvm::StringRef fullName, llvm::StringRef ascCppNamespace); | 46 | llvm::StringRef removeAscDialectNameSpace(llvm::StringRef fullName, llvm::StringRef ascCppNamespace); |
| @@ -14,7 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | using namespace llvm; | 15 | using namespace llvm; |
| 16 | 16 | ||
| 17 | -int main(int argc, char **argv) | 17 | +int main(int argc, char** argv) |
| 18 | { | 18 | { |
| 19 | InitLLVM y(argc, argv); | 19 | InitLLVM y(argc, argv); |
| 20 | cl::ParseCommandLineOptions(argc, argv); | 20 | cl::ParseCommandLineOptions(argc, argv); |
| @@ -12,9 +12,9 @@ | |||
| 12 | using namespace mlir; | 12 | using namespace mlir; |
| 13 | using namespace mlir::ascendc; | 13 | using namespace mlir::ascendc; |
| 14 | 14 | ||
| 15 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SimpleSoftMaxOp op) | 15 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SimpleSoftMaxOp op) |
| 16 | { | 16 | { |
| 17 | - auto &os = emitter.ostream(); | 17 | + auto& os = emitter.ostream(); |
| 18 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 18 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 19 | if (failed(emitter.emitType(op.getLoc(), op.getDst().getType().getElementType()))) { | 19 | if (failed(emitter.emitType(op.getLoc(), op.getDst().getType().getElementType()))) { |
| 20 | return failure(); | 20 | return failure(); |
| @@ -26,9 +26,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Simpl | |||
| 26 | return success(); | 26 | return success(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SoftMaxOp op) | 29 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SoftMaxOp op) |
| 30 | { | 30 | { |
| 31 | - auto &os = emitter.ostream(); | 31 | + auto& os = emitter.ostream(); |
| 32 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 32 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 33 | if (failed(emitter.emitType(op.getLoc(), op.getDst().getType().getElementType()))) { | 33 | if (failed(emitter.emitType(op.getLoc(), op.getDst().getType().getElementType()))) { |
| 34 | return failure(); | 34 | return failure(); |
| @@ -15,17 +15,17 @@ using namespace mlir::ascendc; | |||
| 15 | 15 | ||
| 16 | // Resource Management | 16 | // Resource Management |
| 17 | 17 | ||
| 18 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::KfcInitOp op) | 18 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::KfcInitOp op) |
| 19 | { | 19 | { |
| 20 | - auto &os = emitter.ostream(); | 20 | + auto& os = emitter.ostream(); |
| 21 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "(" | 21 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "(" |
| 22 | << emitter.getOrCreateName(op.getWorkspace()) << ")"; | 22 | << emitter.getOrCreateName(op.getWorkspace()) << ")"; |
| 23 | return success(); | 23 | return success(); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::KfcInitObjOp op) | 26 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::KfcInitObjOp op) |
| 27 | { | 27 | { |
| 28 | - auto &os = emitter.ostream(); | 28 | + auto& os = emitter.ostream(); |
| 29 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "(&" | 29 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "(&" |
| 30 | << emitter.getOrCreateName(op.getPipe()) << ", "; | 30 | << emitter.getOrCreateName(op.getPipe()) << ", "; |
| 31 | llvm::interleaveComma(op.getOps(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 31 | llvm::interleaveComma(op.getOps(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| @@ -33,25 +33,25 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::KfcIn | |||
| 33 | return success(); | 33 | return success(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::KfcIsRunOp op) | 36 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::KfcIsRunOp op) |
| 37 | { | 37 | { |
| 38 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 38 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 39 | - auto &os = emitter.ostream(); | 39 | + auto& os = emitter.ostream(); |
| 40 | os << " = " << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "()"; | 40 | os << " = " << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "()"; |
| 41 | return success(); | 41 | return success(); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::KfcRunOp op) | 44 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::KfcRunOp op) |
| 45 | { | 45 | { |
| 46 | - auto &os = emitter.ostream(); | 46 | + auto& os = emitter.ostream(); |
| 47 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "(" | 47 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "(" |
| 48 | << emitter.getOrCreateName(op.getMatmul()) << ")"; | 48 | << emitter.getOrCreateName(op.getMatmul()) << ")"; |
| 49 | return success(); | 49 | return success(); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::KfcQuitOp op) | 52 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::KfcQuitOp op) |
| 53 | { | 53 | { |
| 54 | - auto &os = emitter.ostream(); | 54 | + auto& os = emitter.ostream(); |
| 55 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "()"; | 55 | os << emitter.getOrCreateName(op.getServer()) << "." << op.getAPIName() << "()"; |
| 56 | return success(); | 56 | return success(); |
| 57 | } | 57 | } |
| @@ -17,9 +17,9 @@ using namespace mlir::ascendc; | |||
| 17 | // Other math library operations | 17 | // Other math library operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ExpOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ExpOp op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 23 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 24 | auto resultType = op.getDst().getType().getElementType(); | 24 | auto resultType = op.getDst().getType().getElementType(); |
| 25 | FAIL_OR(emitter.emitType(op.getLoc(), resultType)); | 25 | FAIL_OR(emitter.emitType(op.getLoc(), resultType)); |
| @@ -34,9 +34,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ExpOp | |||
| 34 | return success(); | 34 | return success(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::AxpyOp op) | 37 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::AxpyOp op) |
| 38 | { | 38 | { |
| 39 | - auto &os = emitter.ostream(); | 39 | + auto& os = emitter.ostream(); |
| 40 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 40 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 41 | auto dstType = op.getDst().getType().getElementType(); | 41 | auto dstType = op.getDst().getType().getElementType(); |
| 42 | FAIL_OR(emitter.emitType(op.getLoc(), dstType)); | 42 | FAIL_OR(emitter.emitType(op.getLoc(), dstType)); |
| @@ -54,9 +54,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::AxpyO | |||
| 54 | return success(); | 54 | return success(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CumSumOp op) | 57 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CumSumOp op) |
| 58 | { | 58 | { |
| 59 | - auto &os = emitter.ostream(); | 59 | + auto& os = emitter.ostream(); |
| 60 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 60 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 61 | << emitter.getOrCreateName(op.getLastRow()) << ", " << emitter.getOrCreateName(op.getSrc()); | 61 | << emitter.getOrCreateName(op.getLastRow()) << ", " << emitter.getOrCreateName(op.getSrc()); |
| 62 | if (auto sharedTmpBuffer = op.getSharedTmpBuffer()) { | 62 | if (auto sharedTmpBuffer = op.getSharedTmpBuffer()) { |
| @@ -13,9 +13,9 @@ | |||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | using namespace mlir::ascendc; | 14 | using namespace mlir::ascendc; |
| 15 | 15 | ||
| 16 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::MatmulInitOp op) | 16 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::MatmulInitOp op) |
| 17 | { | 17 | { |
| 18 | - auto &os = emitter.ostream(); | 18 | + auto& os = emitter.ostream(); |
| 19 | os << emitter.getOrCreateName(op.getMatmul()) << "." << op.getAPIName() << "(&" | 19 | os << emitter.getOrCreateName(op.getMatmul()) << "." << op.getAPIName() << "(&" |
| 20 | << emitter.getOrCreateName(op.getCubeTiling()); | 20 | << emitter.getOrCreateName(op.getCubeTiling()); |
| 21 | if (auto pipe = op.getPipe()) { | 21 | if (auto pipe = op.getPipe()) { |
| @@ -25,10 +25,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Matmu | |||
| 25 | return success(); | 25 | return success(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::MatmulGetMatmulApiTilingOp op) | 28 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::MatmulGetMatmulApiTilingOp op) |
| 29 | { | 29 | { |
| 30 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 30 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 31 | - auto &os = emitter.ostream(); | 31 | + auto& os = emitter.ostream(); |
| 32 | os << " = " << op.getAPIName(); | 32 | os << " = " << op.getAPIName(); |
| 33 | FAIL_OR(emitter.emitAscMatmulSimplifiedTemplate(op.getLoc(), op.getMatmulType(), false)); | 33 | FAIL_OR(emitter.emitAscMatmulSimplifiedTemplate(op.getLoc(), op.getMatmulType(), false)); |
| 34 | os << "(" << emitter.getOrCreateName(op.getMmCFG()) << ", " << emitter.getOrCreateName(op.getL1Size()) << ")"; | 34 | os << "(" << emitter.getOrCreateName(op.getMmCFG()) << ", " << emitter.getOrCreateName(op.getL1Size()) << ")"; |
| @@ -36,20 +36,19 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Matmu | |||
| 36 | return success(); | 36 | return success(); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::MatmulEndOp op) | 39 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::MatmulEndOp op) |
| 40 | { | 40 | { |
| 41 | - auto &os = emitter.ostream(); | 41 | + auto& os = emitter.ostream(); |
| 42 | os << emitter.getOrCreateName(op.getMatmul()) << "." << op.getAPIName() << "()"; | 42 | os << emitter.getOrCreateName(op.getMatmul()) << "." << op.getAPIName() << "()"; |
| 43 | return success(); | 43 | return success(); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::RegistMatmulObjOp op) | 46 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::RegistMatmulObjOp op) |
| 47 | { | 47 | { |
| 48 | - auto &os = emitter.ostream(); | 48 | + auto& os = emitter.ostream(); |
| 49 | os << "using namespace " << ascNamespace << ";\n"; | 49 | os << "using namespace " << ascNamespace << ";\n"; |
| 50 | os << op.getAPIName() << "(&" << emitter.getOrCreateName(op.getPipe()) << ", " | 50 | os << op.getAPIName() << "(&" << emitter.getOrCreateName(op.getPipe()) << ", " |
| 51 | - << emitter.getOrCreateName(op.getWorkspace()) << ", " | 51 | + << emitter.getOrCreateName(op.getWorkspace()) << ", " << emitter.getOrCreateName(op.getMatmul()); |
| 52 | - << emitter.getOrCreateName(op.getMatmul()); | ||
| 53 | if (auto tiling = op.getTiling()) { | 52 | if (auto tiling = op.getTiling()) { |
| 54 | os << ", &" << emitter.getOrCreateName(tiling); | 53 | os << ", &" << emitter.getOrCreateName(tiling); |
| 55 | } | 54 | } |
| @@ -13,9 +13,9 @@ | |||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | using namespace mlir::ascendc; | 14 | using namespace mlir::ascendc; |
| 15 | 15 | ||
| 16 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::RmsNormOp op) | 16 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::RmsNormOp op) |
| 17 | { | 17 | { |
| 18 | - auto &os = emitter.ostream(); | 18 | + auto& os = emitter.ostream(); |
| 19 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 19 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 20 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDst().getType().getElementType())); | 20 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDst().getType().getElementType())); |
| 21 | os << ", " << op.getBasicBlock() << ">(" << emitter.getOrCreateName(op.getDst()) << ", " | 21 | os << ", " << op.getBasicBlock() << ">(" << emitter.getOrCreateName(op.getDst()) << ", " |
| @@ -13,9 +13,9 @@ | |||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | using namespace mlir::ascendc; | 14 | using namespace mlir::ascendc; |
| 15 | 15 | ||
| 16 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::QuantOp op) | 16 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::QuantOp op) |
| 17 | { | 17 | { |
| 18 | - auto &os = emitter.ostream(); | 18 | + auto& os = emitter.ostream(); |
| 19 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 19 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 20 | FAIL_OR(emitter.emitType(op.getLoc(), op.getSrcTensor().getType().getElementType())); | 20 | FAIL_OR(emitter.emitType(op.getLoc(), op.getSrcTensor().getType().getElementType())); |
| 21 | os << ", " << op.getIsReuseSource(); | 21 | os << ", " << op.getIsReuseSource(); |
| @@ -17,9 +17,9 @@ using namespace mlir::ascendc; | |||
| 17 | // AIPP Emitters | 17 | // AIPP Emitters |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, SetAippFunctionsOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, SetAippFunctionsOp op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | os << ascNamespace << "::" << op.getAPIName(); | 23 | os << ascNamespace << "::" << op.getAPIName(); |
| 24 | 24 | ||
| 25 | os << "("; | 25 | os << "("; |
| @@ -17,38 +17,34 @@ using namespace mlir::ascendc; | |||
| 17 | // Synchronization operations | 17 | // Synchronization operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::PipeBarrierOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::PipeBarrierOp op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | os << ascNamespace << "::" << op.getAPIName() << "<" << ascendc::stringifyEnum(op.getPipe()).upper() << ">()"; | 23 | os << ascNamespace << "::" << op.getAPIName() << "<" << ascendc::stringifyEnum(op.getPipe()).upper() << ">()"; |
| 24 | return success(); | 24 | return success(); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::WaitFlagOp op) | 27 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::WaitFlagOp op) |
| 28 | { | 28 | { |
| 29 | - auto &os = emitter.ostream(); | 29 | + auto& os = emitter.ostream(); |
| 30 | os << ascNamespace << "::WaitFlag<" << ascNamespace | 30 | os << ascNamespace << "::WaitFlag<" << ascNamespace |
| 31 | << "::HardEvent::" << ascendc::stringifyEnum(op.getEvent()).upper() << ">(" | 31 | << "::HardEvent::" << ascendc::stringifyEnum(op.getEvent()).upper() << ">(" |
| 32 | << emitter.getOrCreateName(op.getEventId()) << ")"; | 32 | << emitter.getOrCreateName(op.getEventId()) << ")"; |
| 33 | return success(); | 33 | return success(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CrossCoreSetFlagOp op) | 36 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CrossCoreSetFlagOp op) |
| 37 | { | 37 | { |
| 38 | - auto &os = emitter.ostream(); | 38 | + auto& os = emitter.ostream(); |
| 39 | - os << ascNamespace << "::CrossCoreSetFlag<" | 39 | + os << ascNamespace << "::CrossCoreSetFlag<" << static_cast<unsigned>(op.getModeId()) << ", " |
| 40 | - << static_cast<unsigned>(op.getModeId()) << ", " | 40 | + << ascendc::stringifyEnum(op.getPipe()).upper() << ">(" << emitter.getOrCreateName(op.getFlagId()) << ")"; |
| 41 | - << ascendc::stringifyEnum(op.getPipe()).upper() | ||
| 42 | - << ">(" << emitter.getOrCreateName(op.getFlagId()) << ")"; | ||
| 43 | return success(); | 41 | return success(); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CrossCoreWaitFlagOp op) | 44 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CrossCoreWaitFlagOp op) |
| 47 | { | 45 | { |
| 48 | - auto &os = emitter.ostream(); | 46 | + auto& os = emitter.ostream(); |
| 49 | - os << ascNamespace << "::CrossCoreWaitFlag<" | 47 | + os << ascNamespace << "::CrossCoreWaitFlag<" << static_cast<unsigned>(op.getModeId()) << ", " |
| 50 | - << static_cast<unsigned>(op.getModeId()) << ", " | 48 | + << ascendc::stringifyEnum(op.getPipe()).upper() << ">(" << emitter.getOrCreateName(op.getFlagId()) << ")"; |
| 51 | - << ascendc::stringifyEnum(op.getPipe()).upper() | ||
| 52 | - << ">(" << emitter.getOrCreateName(op.getFlagId()) << ")"; | ||
| 53 | return success(); | 49 | return success(); |
| 54 | } | 50 | } |
| @@ -40,7 +40,7 @@ mlir::Type inferElementTypeFromAddrList(ValueRange addrList) | |||
| 40 | return nullptr; | 40 | return nullptr; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | - mlir::Operation *definingOp = firstAddr.getDefiningOp(); | 43 | + mlir::Operation* definingOp = firstAddr.getDefiningOp(); |
| 44 | if (definingOp) { | 44 | if (definingOp) { |
| 45 | if (auto getPhyAddrOp = dyn_cast<ascendc::LocalTensorGetPhyAddrOp>(definingOp)) { | 45 | if (auto getPhyAddrOp = dyn_cast<ascendc::LocalTensorGetPhyAddrOp>(definingOp)) { |
| 46 | mlir::Value tensorValue = getPhyAddrOp.getTensor(); | 46 | mlir::Value tensorValue = getPhyAddrOp.getTensor(); |
| @@ -55,14 +55,14 @@ mlir::Type inferElementTypeFromAddrList(ValueRange addrList) | |||
| 55 | mlir::Type inferElementTypeFromAddrTensor(mlir::ascendc::TransDataTo5HDOp op) | 55 | mlir::Type inferElementTypeFromAddrTensor(mlir::ascendc::TransDataTo5HDOp op) |
| 56 | { | 56 | { |
| 57 | for (mlir::Value addrTensor : {op.getDst(), op.getSrc()}) { | 57 | for (mlir::Value addrTensor : {op.getDst(), op.getSrc()}) { |
| 58 | - for (Operation *user : addrTensor.getUsers()) { | 58 | + for (Operation* user : addrTensor.getUsers()) { |
| 59 | if (auto setValueOp = dyn_cast<ascendc::LocalTensorSetValueOp>(user)) { | 59 | if (auto setValueOp = dyn_cast<ascendc::LocalTensorSetValueOp>(user)) { |
| 60 | if (setValueOp.getTensor() != addrTensor) { | 60 | if (setValueOp.getTensor() != addrTensor) { |
| 61 | continue; | 61 | continue; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | mlir::Value valueToSet = setValueOp.getValue(); | 64 | mlir::Value valueToSet = setValueOp.getValue(); |
| 65 | - mlir::Operation *definingOp = valueToSet.getDefiningOp(); | 65 | + mlir::Operation* definingOp = valueToSet.getDefiningOp(); |
| 66 | if (!definingOp) { | 66 | if (!definingOp) { |
| 67 | continue; | 67 | continue; |
| 68 | } | 68 | } |
| @@ -86,9 +86,9 @@ mlir::Type inferElementTypeFromAddrTensor(mlir::ascendc::TransDataTo5HDOp op) | |||
| 86 | // Data Conversion operations | 86 | // Data Conversion operations |
| 87 | //===----------------------------------------------------------------------===// | 87 | //===----------------------------------------------------------------------===// |
| 88 | 88 | ||
| 89 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TransDataTo5HDTensorListOp op) | 89 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TransDataTo5HDTensorListOp op) |
| 90 | { | 90 | { |
| 91 | - auto &os = emitter.ostream(); | 91 | + auto& os = emitter.ostream(); |
| 92 | if (op.getDstList().empty()) | 92 | if (op.getDstList().empty()) |
| 93 | return success(); | 93 | return success(); |
| 94 | 94 | ||
| @@ -121,9 +121,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Trans | |||
| 121 | return success(); | 121 | return success(); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TransDataTo5HDUintListOp op) | 124 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TransDataTo5HDUintListOp op) |
| 125 | { | 125 | { |
| 126 | - auto &os = emitter.ostream(); | 126 | + auto& os = emitter.ostream(); |
| 127 | if (op.getDstList().empty()) | 127 | if (op.getDstList().empty()) |
| 128 | return success(); | 128 | return success(); |
| 129 | 129 | ||
| @@ -154,9 +154,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Trans | |||
| 154 | return success(); | 154 | return success(); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TransDataTo5HDOp op) | 157 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TransDataTo5HDOp op) |
| 158 | { | 158 | { |
| 159 | - auto &os = emitter.ostream(); | 159 | + auto& os = emitter.ostream(); |
| 160 | 160 | ||
| 161 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 161 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 162 | mlir::Type elementType = inferElementTypeFromAddrTensor(op); | 162 | mlir::Type elementType = inferElementTypeFromAddrTensor(op); |
| @@ -16,9 +16,9 @@ using namespace mlir::ascendc; | |||
| 16 | namespace { | 16 | namespace { |
| 17 | 17 | ||
| 18 | template <typename CopyOpTy> | 18 | template <typename CopyOpTy> |
| 19 | -LogicalResult emitCopyTemplateArgs(CodeEmitter &emitter, CopyOpTy op) | 19 | +LogicalResult emitCopyTemplateArgs(CodeEmitter& emitter, CopyOpTy op) |
| 20 | { | 20 | { |
| 21 | - auto &os = emitter.ostream(); | 21 | + auto& os = emitter.ostream(); |
| 22 | 22 | ||
| 23 | os << "<"; | 23 | os << "<"; |
| 24 | auto tensorType = cast<LocalTensorType>(op.getDst().getType()); | 24 | auto tensorType = cast<LocalTensorType>(op.getDst().getType()); |
| @@ -36,9 +36,9 @@ LogicalResult emitCopyTemplateArgs(CodeEmitter &emitter, CopyOpTy op) | |||
| 36 | // Data transfer operations | 36 | // Data transfer operations |
| 37 | //===----------------------------------------------------------------------===// | 37 | //===----------------------------------------------------------------------===// |
| 38 | 38 | ||
| 39 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::DataCopySliceOp op) | 39 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::DataCopySliceOp op) |
| 40 | { | 40 | { |
| 41 | - auto &os = emitter.ostream(); | 41 | + auto& os = emitter.ostream(); |
| 42 | auto dstName = (emitter.getOrCreateName(op.getDst()) + "_slice_info").str(); | 42 | auto dstName = (emitter.getOrCreateName(op.getDst()) + "_slice_info").str(); |
| 43 | auto srcName = (emitter.getOrCreateName(op.getSrc()) + "_slice_info").str(); | 43 | auto srcName = (emitter.getOrCreateName(op.getSrc()) + "_slice_info").str(); |
| 44 | 44 | ||
| @@ -56,9 +56,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::DataC | |||
| 56 | return success(); | 56 | return success(); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CopyL0Op op) | 59 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CopyL0Op op) |
| 60 | { | 60 | { |
| 61 | - auto &os = emitter.ostream(); | 61 | + auto& os = emitter.ostream(); |
| 62 | 62 | ||
| 63 | auto maskName = printMask(emitter, op); | 63 | auto maskName = printMask(emitter, op); |
| 64 | 64 | ||
| @@ -72,9 +72,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CopyL | |||
| 72 | return success(); | 72 | return success(); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CopyL1Op op) | 75 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CopyL1Op op) |
| 76 | { | 76 | { |
| 77 | - auto &os = emitter.ostream(); | 77 | + auto& os = emitter.ostream(); |
| 78 | os << ascNamespace << "::" << op.getAPIName(); | 78 | os << ascNamespace << "::" << op.getAPIName(); |
| 79 | FAIL_OR(emitCopyTemplateArgs(emitter, op)); | 79 | FAIL_OR(emitCopyTemplateArgs(emitter, op)); |
| 80 | 80 | ||
| @@ -17,9 +17,9 @@ using namespace mlir::ascendc; | |||
| 17 | // Debug operations | 17 | // Debug operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::PrintfOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::PrintfOp op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | os << ascNamespace << "::" << op.getAPIName() << "(\"" << op.getDesc() << "\""; | 23 | os << ascNamespace << "::" << op.getAPIName() << "(\"" << op.getDesc() << "\""; |
| 24 | if (!op.getVars().empty()) { | 24 | if (!op.getVars().empty()) { |
| 25 | os << ", "; | 25 | os << ", "; |
| @@ -13,10 +13,9 @@ | |||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | using namespace mlir::ascendc; | 14 | using namespace mlir::ascendc; |
| 15 | 15 | ||
| 16 | - | 16 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TensorDescOp op) |
| 17 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TensorDescOp op) | ||
| 18 | { | 17 | { |
| 19 | - auto &os = emitter.ostream(); | 18 | + auto& os = emitter.ostream(); |
| 20 | if (op->getNumResults() == 1) { | 19 | if (op->getNumResults() == 1) { |
| 21 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 20 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 22 | os << " = "; | 21 | os << " = "; |
| @@ -27,27 +26,23 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Tenso | |||
| 27 | return success(); | 26 | return success(); |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | - | ||
| 31 | LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TensorDescSetShapeAddrOp op) | 29 | LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TensorDescSetShapeAddrOp op) |
| 32 | { | 30 | { |
| 33 | auto& os = emitter.ostream(); | 31 | auto& os = emitter.ostream(); |
| 34 | - os << emitter.getOrCreateName(op.getTensorDesc()) << "." << op.getAPIName() << "(" | 32 | + os << emitter.getOrCreateName(op.getTensorDesc()) << "." << op.getAPIName() << "(" |
| 35 | - << "(uint64_t* )" << emitter.getOrCreateName(op.getShapePtr()) << ")"; | 33 | + << "(uint64_t* )" << emitter.getOrCreateName(op.getShapePtr()) << ")"; |
| 36 | return success(); | 34 | return success(); |
| 37 | } | 35 | } |
| 38 | 36 | ||
| 39 | - | ||
| 40 | LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ListTensorDescV2Op op) | 37 | LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ListTensorDescV2Op op) |
| 41 | { | 38 | { |
| 42 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 39 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 43 | auto& os = emitter.ostream(); | 40 | auto& os = emitter.ostream(); |
| 44 | - os << " = " << "AscendC::ListTensorDesc(" << emitter.getOrCreateName(op.getData()) | 41 | + os << " = " << "AscendC::ListTensorDesc(" << emitter.getOrCreateName(op.getData()) << ", " |
| 45 | - << ", " << emitter.getOrCreateName(op.getLength()) | 42 | + << emitter.getOrCreateName(op.getLength()) << ", " << emitter.getOrCreateName(op.getShapeSize()) << ")"; |
| 46 | - << ", " << emitter.getOrCreateName(op.getShapeSize()) << ")"; | ||
| 47 | return success(); | 43 | return success(); |
| 48 | } | 44 | } |
| 49 | 45 | ||
| 50 | - | ||
| 51 | LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ListTensorDescGetDataPtrOp op) | 46 | LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ListTensorDescGetDataPtrOp op) |
| 52 | { | 47 | { |
| 53 | auto& os = emitter.ostream(); | 48 | auto& os = emitter.ostream(); |
| @@ -16,11 +16,11 @@ using namespace mlir::ascendc; | |||
| 16 | namespace { | 16 | namespace { |
| 17 | 17 | ||
| 18 | struct AippMemberInfo { | 18 | struct AippMemberInfo { |
| 19 | - const char *aippMemberName; | 19 | + const char* aippMemberName; |
| 20 | - const std::vector<const char *> subMemberNames; | 20 | + const std::vector<const char*> subMemberNames; |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | -const AippMemberInfo *getAippMemberInfo(size_t index) | 23 | +const AippMemberInfo* getAippMemberInfo(size_t index) |
| 24 | { | 24 | { |
| 25 | static const std::vector<AippMemberInfo> memberInfos = { | 25 | static const std::vector<AippMemberInfo> memberInfos = { |
| 26 | {"paddingParams", {"paddingMode", "paddingValueCh0", "paddingValueCh1", "paddingValueCh2", "paddingValueCh3"}}, | 26 | {"paddingParams", {"paddingMode", "paddingValueCh0", "paddingValueCh1", "paddingValueCh2", "paddingValueCh3"}}, |
| @@ -42,11 +42,11 @@ const AippMemberInfo *getAippMemberInfo(size_t index) | |||
| 42 | return &memberInfos[index]; | 42 | return &memberInfos[index]; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | -LogicalResult printAippMemberAssignment(CodeEmitter &emitter, ascendc::ConstructOp op, size_t memberIndex) | 45 | +LogicalResult printAippMemberAssignment(CodeEmitter& emitter, ascendc::ConstructOp op, size_t memberIndex) |
| 46 | { | 46 | { |
| 47 | - auto &os = emitter.ostream(); | 47 | + auto& os = emitter.ostream(); |
| 48 | 48 | ||
| 49 | - const AippMemberInfo *memberInfoPtr = getAippMemberInfo(memberIndex); | 49 | + const AippMemberInfo* memberInfoPtr = getAippMemberInfo(memberIndex); |
| 50 | 50 | ||
| 51 | if (!memberInfoPtr) { | 51 | if (!memberInfoPtr) { |
| 52 | return op.emitError("Internal Error: Index out of bounds when accessing AippMemberInfo for member index ") | 52 | return op.emitError("Internal Error: Index out of bounds when accessing AippMemberInfo for member index ") |
| @@ -71,9 +71,9 @@ LogicalResult printAippMemberAssignment(CodeEmitter &emitter, ascendc::Construct | |||
| 71 | return success(); | 71 | return success(); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | -LogicalResult printAippStructConstruction(CodeEmitter &emitter, ascendc::ConstructOp op) | 74 | +LogicalResult printAippStructConstruction(CodeEmitter& emitter, ascendc::ConstructOp op) |
| 75 | { | 75 | { |
| 76 | - auto &os = emitter.ostream(); | 76 | + auto& os = emitter.ostream(); |
| 77 | mlir::Type resultType = op->getResult(0).getType(); | 77 | mlir::Type resultType = op->getResult(0).getType(); |
| 78 | 78 | ||
| 79 | return llvm::TypeSwitch<mlir::Type, LogicalResult>(resultType) | 79 | return llvm::TypeSwitch<mlir::Type, LogicalResult>(resultType) |
| @@ -104,9 +104,10 @@ LogicalResult printAippStructConstruction(CodeEmitter &emitter, ascendc::Constru | |||
| 104 | 104 | ||
| 105 | return success(); | 105 | return success(); |
| 106 | }) | 106 | }) |
| 107 | - .Case<ascendc::AippPaddingParamsType, ascendc::AippSwapParamsType, ascendc::AippSingleLineParamsType, | 107 | + .Case< |
| 108 | - ascendc::AippDataTypeConvParamsType, ascendc::AippChannelPaddingParamsType, | 108 | + ascendc::AippPaddingParamsType, ascendc::AippSwapParamsType, ascendc::AippSingleLineParamsType, |
| 109 | - ascendc::AippColorSpaceConvParamsType>([&](auto type) -> LogicalResult { return success(); }) | 109 | + ascendc::AippDataTypeConvParamsType, ascendc::AippChannelPaddingParamsType, |
| 110 | + ascendc::AippColorSpaceConvParamsType>([&](auto type) -> LogicalResult { return success(); }) | ||
| 110 | .Default([](auto type) -> LogicalResult { return failure(); }); | 111 | .Default([](auto type) -> LogicalResult { return failure(); }); |
| 111 | } | 112 | } |
| 112 | 113 | ||
| @@ -116,13 +117,13 @@ LogicalResult printAippStructConstruction(CodeEmitter &emitter, ascendc::Constru | |||
| 116 | // Other operations | 117 | // Other operations |
| 117 | //===----------------------------------------------------------------------===// | 118 | //===----------------------------------------------------------------------===// |
| 118 | 119 | ||
| 119 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ConstructOp op) | 120 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ConstructOp op) |
| 120 | { | 121 | { |
| 121 | if (succeeded(printAippStructConstruction(emitter, op))) { | 122 | if (succeeded(printAippStructConstruction(emitter, op))) { |
| 122 | return success(); | 123 | return success(); |
| 123 | } | 124 | } |
| 124 | 125 | ||
| 125 | - auto &os = emitter.ostream(); | 126 | + auto& os = emitter.ostream(); |
| 126 | if (op.getIsStatic()) { | 127 | if (op.getIsStatic()) { |
| 127 | os << "static "; | 128 | os << "static "; |
| 128 | } | 129 | } |
| @@ -157,24 +158,24 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Const | |||
| 157 | types.append(op->getOperandTypes().begin(), op->getOperandTypes().end()); | 158 | types.append(op->getOperandTypes().begin(), op->getOperandTypes().end()); |
| 158 | } | 159 | } |
| 159 | llvm::interleaveComma(llvm::zip_equal(op.getOperands(), types), os, [&emitOperand](auto pair) { | 160 | llvm::interleaveComma(llvm::zip_equal(op.getOperands(), types), os, [&emitOperand](auto pair) { |
| 160 | - const auto &[operand, type] = pair; | 161 | + const auto& [operand, type] = pair; |
| 161 | emitOperand(operand, type); | 162 | emitOperand(operand, type); |
| 162 | }); | 163 | }); |
| 163 | os << '}'; | 164 | os << '}'; |
| 164 | return success(); | 165 | return success(); |
| 165 | } | 166 | } |
| 166 | 167 | ||
| 167 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::FftsCrossCoreSyncOp op) | 168 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::FftsCrossCoreSyncOp op) |
| 168 | { | 169 | { |
| 169 | - auto &os = emitter.ostream(); | 170 | + auto& os = emitter.ostream(); |
| 170 | os << "ffts_cross_core_sync(" << ascendc::stringifyEnum(op.getPipe()).upper() << ", " | 171 | os << "ffts_cross_core_sync(" << ascendc::stringifyEnum(op.getPipe()).upper() << ", " |
| 171 | << emitter.getOrCreateName(op.getConfig()) << ")"; | 172 | << emitter.getOrCreateName(op.getConfig()) << ")"; |
| 172 | return success(); | 173 | return success(); |
| 173 | } | 174 | } |
| 174 | 175 | ||
| 175 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetMrgSortResultOp op) | 176 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GetMrgSortResultOp op) |
| 176 | { | 177 | { |
| 177 | - auto &os = emitter.ostream(); | 178 | + auto& os = emitter.ostream(); |
| 178 | Value mrgSortList1Value = op.getMrgSortList1(); | 179 | Value mrgSortList1Value = op.getMrgSortList1(); |
| 179 | Value mrgSortList2Value = op.getMrgSortList2(); | 180 | Value mrgSortList2Value = op.getMrgSortList2(); |
| 180 | Value mrgSortList3Value = op.getMrgSortList3(); | 181 | Value mrgSortList3Value = op.getMrgSortList3(); |
| @@ -186,59 +187,55 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetMr | |||
| 186 | os << "uint16_t " << emitter.getOrCreateName(mrgSortList4Value) << ";\n"; | 187 | os << "uint16_t " << emitter.getOrCreateName(mrgSortList4Value) << ";\n"; |
| 187 | 188 | ||
| 188 | os << ascNamespace << "::" << op.getAPIName(); | 189 | os << ascNamespace << "::" << op.getAPIName(); |
| 189 | - os << "(" << emitter.getOrCreateName(mrgSortList1Value); | 190 | + os << "(" << emitter.getOrCreateName(mrgSortList1Value); |
| 190 | os << ", " << emitter.getOrCreateName(mrgSortList2Value); | 191 | os << ", " << emitter.getOrCreateName(mrgSortList2Value); |
| 191 | os << ", " << emitter.getOrCreateName(mrgSortList3Value); | 192 | os << ", " << emitter.getOrCreateName(mrgSortList3Value); |
| 192 | os << ", " << emitter.getOrCreateName(mrgSortList4Value) << ")"; | 193 | os << ", " << emitter.getOrCreateName(mrgSortList4Value) << ")"; |
| 193 | - | 194 | + |
| 194 | return success(); | 195 | return success(); |
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::MrgSortOp op) | 198 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::MrgSortOp op) |
| 198 | { | 199 | { |
| 199 | - static int elementCountListCounter = 0; | 200 | + static int elementCountListCounter = 0; |
| 200 | - auto uniqueId = std::to_string(elementCountListCounter++); | 201 | + auto uniqueId = std::to_string(elementCountListCounter++); |
| 201 | - auto& os = emitter.ostream(); | 202 | + auto& os = emitter.ostream(); |
| 202 | - auto elementCountListName = (emitter.getOrCreateName(op.getDst()) + "_element_count_list_" + uniqueId).str(); | 203 | + auto elementCountListName = (emitter.getOrCreateName(op.getDst()) + "_element_count_list_" + uniqueId).str(); |
| 203 | - auto sortedNumName = (emitter.getOrCreateName(op.getDst()) + "_sorted_num_" + uniqueId).str(); | 204 | + auto sortedNumName = (emitter.getOrCreateName(op.getDst()) + "_sorted_num_" + uniqueId).str(); |
| 204 | - os << "uint16_t " << elementCountListName << "[] = {"; | 205 | + os << "uint16_t " << elementCountListName << "[] = {"; |
| 205 | - llvm::interleaveComma(op.getElementCountList(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 206 | + llvm::interleaveComma(op.getElementCountList(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| 206 | - os << "};\n"; | 207 | + os << "};\n"; |
| 207 | - os << "uint32_t " << sortedNumName << "[] = {"; | 208 | + os << "uint32_t " << sortedNumName << "[] = {"; |
| 208 | - llvm::interleaveComma(op.getSortedNum(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 209 | + llvm::interleaveComma(op.getSortedNum(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| 209 | - os << "};\n"; | 210 | + os << "};\n"; |
| 210 | - os << ascNamespace << "::" << op.getAPIName(); | 211 | + os << ascNamespace << "::" << op.getAPIName(); |
| 211 | - auto tensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 212 | + auto tensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 212 | - os << "<"; | 213 | + os << "<"; |
| 213 | - FAIL_OR(emitter.emitType(op.getLoc(), tensorType)); | 214 | + FAIL_OR(emitter.emitType(op.getLoc(), tensorType)); |
| 214 | - os << ", " << op.getIsExhaustedSuspension() << ">" | 215 | + os << ", " << op.getIsExhaustedSuspension() << ">" |
| 215 | - << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 216 | + << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSortList()) << ", " |
| 216 | - << emitter.getOrCreateName(op.getSortList()) << ", " | 217 | + << elementCountListName << ", " << sortedNumName << ", " << emitter.getOrCreateName(op.getValidBit()) << ", " |
| 217 | - << elementCountListName << ", " << sortedNumName << ", " | 218 | + << emitter.getOrCreateName(op.getRepeatTime()) << ")"; |
| 218 | - << emitter.getOrCreateName(op.getValidBit()) << ", " | ||
| 219 | - << emitter.getOrCreateName(op.getRepeatTime()) << ")"; | ||
| 220 | return success(); | 219 | return success(); |
| 221 | } | 220 | } |
| 222 | 221 | ||
| 223 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SortOp op) | 222 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SortOp op) |
| 224 | { | 223 | { |
| 225 | - auto& os = emitter.ostream(); | 224 | + auto& os = emitter.ostream(); |
| 226 | - os << ascNamespace << "::" << op.getAPIName(); | 225 | + os << ascNamespace << "::" << op.getAPIName(); |
| 227 | - auto tensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 226 | + auto tensorType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 228 | - os << "<"; | 227 | + os << "<"; |
| 229 | - FAIL_OR(emitter.emitType(op.getLoc(), tensorType)); | 228 | + FAIL_OR(emitter.emitType(op.getLoc(), tensorType)); |
| 230 | - os << ", " << op.getIsFullSort() << ">" | 229 | + os << ", " << op.getIsFullSort() << ">" |
| 231 | - << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 230 | + << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getConcat()) << ", " |
| 232 | - << emitter.getOrCreateName(op.getConcat()) << ", " | 231 | + << emitter.getOrCreateName(op.getIndex()) << ", " << emitter.getOrCreateName(op.getTmp()) << ", " |
| 233 | - << emitter.getOrCreateName(op.getIndex()) << ", " | 232 | + << emitter.getOrCreateName(op.getRepeatTime()) << ")"; |
| 234 | - << emitter.getOrCreateName(op.getTmp()) << ", " | ||
| 235 | - << emitter.getOrCreateName(op.getRepeatTime()) << ")"; | ||
| 236 | return success(); | 233 | return success(); |
| 237 | } | 234 | } |
| 238 | 235 | ||
| 239 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::PopStackBufferOp op) | 236 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::PopStackBufferOp op) |
| 240 | { | 237 | { |
| 241 | - auto &os = emitter.ostream(); | 238 | + auto& os = emitter.ostream(); |
| 242 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 239 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 243 | FAIL_OR(emitter.emitType(op.getLoc(), op.getTensor().getType().getElementType())); | 240 | FAIL_OR(emitter.emitType(op.getLoc(), op.getTensor().getType().getElementType())); |
| 244 | os << ", "; | 241 | os << ", "; |
| @@ -247,54 +244,50 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::PopSt | |||
| 247 | return success(); | 244 | return success(); |
| 248 | } | 245 | } |
| 249 | 246 | ||
| 250 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SetFftsBaseAddrOp op) | 247 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SetFftsBaseAddrOp op) |
| 251 | { | 248 | { |
| 252 | - auto &os = emitter.ostream(); | 249 | + auto& os = emitter.ostream(); |
| 253 | os << "set_ffts_base_addr(*" << emitter.getOrCreateName(op.getOperand()) << ")"; | 250 | os << "set_ffts_base_addr(*" << emitter.getOrCreateName(op.getOperand()) << ")"; |
| 254 | return success(); | 251 | return success(); |
| 255 | } | 252 | } |
| 256 | 253 | ||
| 257 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, LLVM::UndefOp op) | 254 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, LLVM::UndefOp op) |
| 258 | { | 255 | { |
| 259 | return emitter.emitVariableDeclaration(op->getResult(0), false); | 256 | return emitter.emitVariableDeclaration(op->getResult(0), false); |
| 260 | } | 257 | } |
| 261 | 258 | ||
| 262 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ResetMaskOp op); | 259 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ResetMaskOp op); |
| 263 | 260 | ||
| 264 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::FixpipeOp op) | 261 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::FixpipeOp op) |
| 265 | { | 262 | { |
| 266 | - auto &os = emitter.ostream(); | 263 | + auto& os = emitter.ostream(); |
| 267 | FAIL_OR(printFixpipeTemplate(emitter, op)); | 264 | FAIL_OR(printFixpipeTemplate(emitter, op)); |
| 268 | - os << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 265 | + os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 269 | - << emitter.getOrCreateName(op.getSrc()) << ", " | ||
| 270 | << emitter.getOrCreateName(op.getIntriParams()) << ")"; | 266 | << emitter.getOrCreateName(op.getIntriParams()) << ")"; |
| 271 | return success(); | 267 | return success(); |
| 272 | } | 268 | } |
| 273 | 269 | ||
| 274 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::FixpipeWithWorkspaceOp op) | 270 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::FixpipeWithWorkspaceOp op) |
| 275 | { | 271 | { |
| 276 | - auto &os = emitter.ostream(); | 272 | + auto& os = emitter.ostream(); |
| 277 | FAIL_OR(printFixpipeTemplate(emitter, op)); | 273 | FAIL_OR(printFixpipeTemplate(emitter, op)); |
| 278 | - os << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 274 | + os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 279 | - << emitter.getOrCreateName(op.getSrc()) << ", " | 275 | + << emitter.getOrCreateName(op.getCbufWorkspace()) << ", " << emitter.getOrCreateName(op.getIntriParams()) << ")"; |
| 280 | - << emitter.getOrCreateName(op.getCbufWorkspace()) << ", " | ||
| 281 | - << emitter.getOrCreateName(op.getIntriParams()) << ")"; | ||
| 282 | return success(); | 276 | return success(); |
| 283 | } | 277 | } |
| 284 | 278 | ||
| 285 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetStoreAtomicConfigOp op) | 279 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GetStoreAtomicConfigOp op) |
| 286 | { | 280 | { |
| 287 | - auto &os = emitter.ostream(); | 281 | + auto& os = emitter.ostream(); |
| 288 | Value atomicTypeValue = op.getAtomicType(); | 282 | Value atomicTypeValue = op.getAtomicType(); |
| 289 | Value atomicOpValue = op.getAtomicOp(); | 283 | Value atomicOpValue = op.getAtomicOp(); |
| 290 | 284 | ||
| 291 | - | ||
| 292 | os << "uint16_t " << emitter.getOrCreateName(atomicTypeValue) << ";\n"; | 285 | os << "uint16_t " << emitter.getOrCreateName(atomicTypeValue) << ";\n"; |
| 293 | os << "uint16_t " << emitter.getOrCreateName(atomicOpValue) << ";\n"; | 286 | os << "uint16_t " << emitter.getOrCreateName(atomicOpValue) << ";\n"; |
| 294 | 287 | ||
| 295 | os << ascNamespace << "::" << op.getAPIName(); | 288 | os << ascNamespace << "::" << op.getAPIName(); |
| 296 | - os << "(" << emitter.getOrCreateName(atomicTypeValue); | 289 | + os << "(" << emitter.getOrCreateName(atomicTypeValue); |
| 297 | os << ", " << emitter.getOrCreateName(atomicOpValue) << ")"; | 290 | os << ", " << emitter.getOrCreateName(atomicOpValue) << ")"; |
| 298 | - | 291 | + |
| 299 | return success(); | 292 | return success(); |
| 300 | } | 293 | } |
| @@ -17,9 +17,9 @@ using namespace mlir::ascendc; | |||
| 17 | // Scalar operations | 17 | // Scalar operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ScalarCastOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ScalarCastOp op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDtype())); | 23 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDtype())); |
| 24 | os << " " << emitter.getOrCreateName(op.getValueOut()) << " = "; | 24 | os << " " << emitter.getOrCreateName(op.getValueOut()) << " = "; |
| 25 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 25 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -17,18 +17,18 @@ using namespace mlir::ascendc; | |||
| 17 | // Memory swap and workspace operations | 17 | // Memory swap and workspace operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetSysWorkspacePtrOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GetSysWorkspacePtrOp op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType(), true)); | 22 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType(), true)); |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | os << " " << emitter.getOrCreateName(op.getResult()); | 24 | os << " " << emitter.getOrCreateName(op.getResult()); |
| 25 | os << " = " << op.getAPIName() << "()"; | 25 | os << " = " << op.getAPIName() << "()"; |
| 26 | return success(); | 26 | return success(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SetSysWorkspaceOp op) | 29 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SetSysWorkspaceOp op) |
| 30 | { | 30 | { |
| 31 | - auto &os = emitter.ostream(); | 31 | + auto& os = emitter.ostream(); |
| 32 | os << ascNamespace << "::" << op.getAPIName() << "("; | 32 | os << ascNamespace << "::" << op.getAPIName() << "("; |
| 33 | os << "reinterpret_cast<"; | 33 | os << "reinterpret_cast<"; |
| 34 | FAIL_OR(emitter.emitType(op.getLoc(), op.getWorkspace().getType(), true)); | 34 | FAIL_OR(emitter.emitType(op.getLoc(), op.getWorkspace().getType(), true)); |
| @@ -17,10 +17,10 @@ using namespace mlir::ascendc; | |||
| 17 | // System Variable operations | 17 | // System Variable operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetBlockIdxOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GetBlockIdxOp op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | os << " = static_cast<"; | 24 | os << " = static_cast<"; |
| 25 | if (failed(emitter.emitType(op.getLoc(), op.getType()))) { | 25 | if (failed(emitter.emitType(op.getLoc(), op.getType()))) { |
| 26 | return failure(); | 26 | return failure(); |
| @@ -29,10 +29,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetBl | |||
| 29 | return success(); | 29 | return success(); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GetBlockNumOp op) | 32 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GetBlockNumOp op) |
| 33 | { | 33 | { |
| 34 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 34 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 35 | - auto &os = emitter.ostream(); | 35 | + auto& os = emitter.ostream(); |
| 36 | os << " = static_cast<"; | 36 | os << " = static_cast<"; |
| 37 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 37 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 38 | os << ">(" << ascNamespace << "::" << op.getAPIName() << "())"; | 38 | os << ">(" << ascNamespace << "::" << op.getAPIName() << "())"; |
| @@ -13,9 +13,9 @@ | |||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | using namespace mlir::ascendc; | 14 | using namespace mlir::ascendc; |
| 15 | 15 | ||
| 16 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::BilinearInterpolationL0Op op) | 16 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::BilinearInterpolationL0Op op) |
| 17 | { | 17 | { |
| 18 | - auto &os = emitter.ostream(); | 18 | + auto& os = emitter.ostream(); |
| 19 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 19 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 20 | << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getSrc0Offset()) << ", " | 20 | << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getSrc0Offset()) << ", " |
| 21 | << emitter.getOrCreateName(op.getSrc1()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " | 21 | << emitter.getOrCreateName(op.getSrc1()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " |
| @@ -25,9 +25,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Bilin | |||
| 25 | return success(); | 25 | return success(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::BilinearInterpolationL1Op op) | 28 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::BilinearInterpolationL1Op op) |
| 29 | { | 29 | { |
| 30 | - auto &os = emitter.ostream(); | 30 | + auto& os = emitter.ostream(); |
| 31 | auto maskName = printMask(emitter, op); | 31 | auto maskName = printMask(emitter, op); |
| 32 | 32 | ||
| 33 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 33 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| @@ -19,44 +19,45 @@ using namespace mlir::ascendc; | |||
| 19 | // Compare operations | 19 | // Compare operations |
| 20 | //===----------------------------------------------------------------------===// | 20 | //===----------------------------------------------------------------------===// |
| 21 | 21 | ||
| 22 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, CompareL1Op op){ | 22 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, CompareL1Op op) |
| 23 | +{ | ||
| 23 | auto& os = emitter.ostream(); | 24 | auto& os = emitter.ostream(); |
| 24 | auto maskName = (emitter.getOrCreateName(op.getDst()) + "_mask_list").str(); | 25 | auto maskName = (emitter.getOrCreateName(op.getDst()) + "_mask_list").str(); |
| 25 | os << "uint64_t " << maskName << "[] = {"; | 26 | os << "uint64_t " << maskName << "[] = {"; |
| 26 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 27 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| 27 | os << "};\n"; | 28 | os << "};\n"; |
| 28 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 29 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 29 | - << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getSrc1()) << ", " | 30 | + << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getSrc1()) << ", " << ascNamespace |
| 30 | - << ascNamespace << "::CMPMODE::" << ascendc::stringifyEnum(op.getCmpMode()) << ", " | 31 | + << "::CMPMODE::" << ascendc::stringifyEnum(op.getCmpMode()) << ", " << maskName << ", " |
| 31 | - << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 32 | + << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 32 | - << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | ||
| 33 | return success(); | 33 | return success(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, CompareRL1Op op){ | 36 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, CompareRL1Op op) |
| 37 | +{ | ||
| 37 | auto& os = emitter.ostream(); | 38 | auto& os = emitter.ostream(); |
| 38 | auto maskName = (emitter.getOrCreateName(op.getSrc0()) + "_mask_list").str(); | 39 | auto maskName = (emitter.getOrCreateName(op.getSrc0()) + "_mask_list").str(); |
| 39 | os << "uint64_t " << maskName << "[] = {"; | 40 | os << "uint64_t " << maskName << "[] = {"; |
| 40 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 41 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| 41 | os << "};\n"; | 42 | os << "};\n"; |
| 42 | - os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getSrc0()) << ", " | 43 | + os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getSrc0()) << ", " |
| 43 | - << emitter.getOrCreateName(op.getSrc1()) << ", " | 44 | + << emitter.getOrCreateName(op.getSrc1()) << ", " << ascNamespace |
| 44 | - << ascNamespace << "::CMPMODE::" << ascendc::stringifyEnum(op.getCmpMode()) << ", " | 45 | + << "::CMPMODE::" << ascendc::stringifyEnum(op.getCmpMode()) << ", " << maskName << ", " |
| 45 | - << maskName << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | 46 | + << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 46 | return success(); | 47 | return success(); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, CompareScalarL1Op op){ | 50 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, CompareScalarL1Op op) |
| 51 | +{ | ||
| 50 | auto& os = emitter.ostream(); | 52 | auto& os = emitter.ostream(); |
| 51 | auto maskName = (emitter.getOrCreateName(op.getDst()) + "_mask_list").str(); | 53 | auto maskName = (emitter.getOrCreateName(op.getDst()) + "_mask_list").str(); |
| 52 | os << "uint64_t " << maskName << "[] = {"; | 54 | os << "uint64_t " << maskName << "[] = {"; |
| 53 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); | 55 | llvm::interleaveComma(op.getMask(), os, [&](Value operand) { os << emitter.getOrCreateName(operand); }); |
| 54 | os << "};\n"; | 56 | os << "};\n"; |
| 55 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 57 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 56 | - << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getSrc1Scalar()) << ", " | 58 | + << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getSrc1Scalar()) << ", " |
| 57 | - << ascNamespace << "::CMPMODE::" << ascendc::stringifyEnum(op.getCmpMode()) << ", " | 59 | + << ascNamespace << "::CMPMODE::" << ascendc::stringifyEnum(op.getCmpMode()) << ", " << maskName << ", " |
| 58 | - << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 60 | + << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 59 | - << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | ||
| 60 | return success(); | 61 | return success(); |
| 61 | } | 62 | } |
| 62 | 63 | ||
| @@ -64,26 +65,26 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, CompareScalarL | |||
| 64 | // Select operations | 65 | // Select operations |
| 65 | //===----------------------------------------------------------------------===// | 66 | //===----------------------------------------------------------------------===// |
| 66 | 67 | ||
| 67 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, SelectScalarL1Op op){ | 68 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, SelectScalarL1Op op) |
| 69 | +{ | ||
| 68 | auto& os = emitter.ostream(); | 70 | auto& os = emitter.ostream(); |
| 69 | auto maskName = printMask(emitter, op); | 71 | auto maskName = printMask(emitter, op); |
| 70 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 72 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 71 | - << emitter.getOrCreateName(op.getSelMask()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " | 73 | + << emitter.getOrCreateName(op.getSelMask()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " |
| 72 | - << emitter.getOrCreateName(op.getSrc1()) << ", " | 74 | + << emitter.getOrCreateName(op.getSrc1()) << ", " << ascNamespace |
| 73 | - << ascNamespace << "::SELMODE::" << ascendc::stringifyEnum(op.getSelMode()) << ", " | 75 | + << "::SELMODE::" << ascendc::stringifyEnum(op.getSelMode()) << ", " << maskName << ", " |
| 74 | - << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 76 | + << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 75 | - << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | ||
| 76 | return success(); | 77 | return success(); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, SelectL1Op op){ | 80 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, SelectL1Op op) |
| 81 | +{ | ||
| 80 | auto& os = emitter.ostream(); | 82 | auto& os = emitter.ostream(); |
| 81 | auto maskName = printMask(emitter, op); | 83 | auto maskName = printMask(emitter, op); |
| 82 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 84 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 83 | - << emitter.getOrCreateName(op.getSelMask()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " | 85 | + << emitter.getOrCreateName(op.getSelMask()) << ", " << emitter.getOrCreateName(op.getSrc0()) << ", " |
| 84 | - << emitter.getOrCreateName(op.getSrc1()) << ", " | 86 | + << emitter.getOrCreateName(op.getSrc1()) << ", " << ascNamespace |
| 85 | - << ascNamespace << "::SELMODE::" << ascendc::stringifyEnum(op.getSelMode()) << ", " | 87 | + << "::SELMODE::" << ascendc::stringifyEnum(op.getSelMode()) << ", " << maskName << ", " |
| 86 | - << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 88 | + << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 87 | - << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | ||
| 88 | return success(); | 89 | return success(); |
| 89 | } | 90 | } |
| @@ -18,9 +18,9 @@ using namespace mlir::ascendc; | |||
| 18 | // Duplicate operations | 18 | // Duplicate operations |
| 19 | //===----------------------------------------------------------------------===// | 19 | //===----------------------------------------------------------------------===// |
| 20 | 20 | ||
| 21 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::DuplicateL0Op op) | 21 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::DuplicateL0Op op) |
| 22 | { | 22 | { |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 24 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| 25 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getScalar()) << ", " | 25 | os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getScalar()) << ", " |
| 26 | << emitter.getOrCreateName(op.getMask()) << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | 26 | << emitter.getOrCreateName(op.getMask()) << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " |
| @@ -29,9 +29,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Dupli | |||
| 29 | return success(); | 29 | return success(); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::DuplicateL1Op op) | 32 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::DuplicateL1Op op) |
| 33 | { | 33 | { |
| 34 | - auto &os = emitter.ostream(); | 34 | + auto& os = emitter.ostream(); |
| 35 | auto maskName = printMask(emitter, op); | 35 | auto maskName = printMask(emitter, op); |
| 36 | 36 | ||
| 37 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); | 37 | FAIL_OR(printIsSetMaskTemplate(emitter, op)); |
| @@ -42,9 +42,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Dupli | |||
| 42 | return success(); | 42 | return success(); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::DuplicateL2Op op) | 45 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::DuplicateL2Op op) |
| 46 | { | 46 | { |
| 47 | - auto &os = emitter.ostream(); | 47 | + auto& os = emitter.ostream(); |
| 48 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 48 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 49 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; | 49 | << emitter.getOrCreateName(op.getScalar()) << ", " << emitter.getOrCreateName(op.getCalCount()) << ")"; |
| 50 | return success(); | 50 | return success(); |
| @@ -17,9 +17,9 @@ using namespace mlir::ascendc; | |||
| 17 | // Gatherb operations | 17 | // Gatherb operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GatherbL0Op op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GatherbL0Op op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 23 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 24 | << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getOffset()) << ", " | 24 | << emitter.getOrCreateName(op.getSrc0()) << ", " << emitter.getOrCreateName(op.getOffset()) << ", " |
| 25 | << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; | 25 | << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| @@ -30,9 +30,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Gathe | |||
| 30 | // Gather operations | 30 | // Gather operations |
| 31 | //===----------------------------------------------------------------------===// | 31 | //===----------------------------------------------------------------------===// |
| 32 | 32 | ||
| 33 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GatherL0Op op) | 33 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GatherL0Op op) |
| 34 | { | 34 | { |
| 35 | - auto &os = emitter.ostream(); | 35 | + auto& os = emitter.ostream(); |
| 36 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 36 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 37 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getSrcOffset()) << ", " | 37 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getSrcOffset()) << ", " |
| 38 | << emitter.getOrCreateName(op.getSrcBaseAddr()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " | 38 | << emitter.getOrCreateName(op.getSrcBaseAddr()) << ", " << emitter.getOrCreateName(op.getMask()) << ", " |
| @@ -40,9 +40,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Gathe | |||
| 40 | return success(); | 40 | return success(); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GatherL1Op op) | 43 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GatherL1Op op) |
| 44 | { | 44 | { |
| 45 | - auto &os = emitter.ostream(); | 45 | + auto& os = emitter.ostream(); |
| 46 | auto maskName = printMask(emitter, op); | 46 | auto maskName = printMask(emitter, op); |
| 47 | 47 | ||
| 48 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 48 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| @@ -52,9 +52,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Gathe | |||
| 52 | return success(); | 52 | return success(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GatherL2Op op) | 55 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GatherL2Op op) |
| 56 | { | 56 | { |
| 57 | - auto &os = emitter.ostream(); | 57 | + auto& os = emitter.ostream(); |
| 58 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 58 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 59 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getSrcOffset()) << ", " | 59 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getSrcOffset()) << ", " |
| 60 | << emitter.getOrCreateName(op.getSrcBaseAddr()) << ", " << emitter.getOrCreateName(op.getCount()) << ")"; | 60 | << emitter.getOrCreateName(op.getSrcBaseAddr()) << ", " << emitter.getOrCreateName(op.getCount()) << ")"; |
| @@ -17,13 +17,12 @@ using namespace mlir::ascendc; | |||
| 17 | // GatherMask operations | 17 | // GatherMask operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GatherMaskOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GatherMaskOp op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | Value rsvdCntVal = op.getRsvdCnt(); | 23 | Value rsvdCntVal = op.getRsvdCnt(); |
| 24 | os << "uint64_t " << emitter.getOrCreateName(rsvdCntVal) << ";\n"; | 24 | os << "uint64_t " << emitter.getOrCreateName(rsvdCntVal) << ";\n"; |
| 25 | 25 | ||
| 26 | - | ||
| 27 | auto dstType = op.getDst().getType(); | 26 | auto dstType = op.getDst().getType(); |
| 28 | auto src1PatternType = op.getSrc1Pattern().getType(); | 27 | auto src1PatternType = op.getSrc1Pattern().getType(); |
| 29 | if (auto dstLocalTensorType = dyn_cast<ascendc::LocalTensorType>(dstType)) { | 28 | if (auto dstLocalTensorType = dyn_cast<ascendc::LocalTensorType>(dstType)) { |
| @@ -18,9 +18,9 @@ using namespace mlir::ascendc; | |||
| 18 | // BlockReduceSum operations | 18 | // BlockReduceSum operations |
| 19 | //===----------------------------------------------------------------------===// | 19 | //===----------------------------------------------------------------------===// |
| 20 | 20 | ||
| 21 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::BlockReduceSumL1Op op) | 21 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::BlockReduceSumL1Op op) |
| 22 | { | 22 | { |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | auto maskName = printMask(emitter, op); | 24 | auto maskName = printMask(emitter, op); |
| 25 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 25 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 26 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getRepeatTime()) << ", " | 26 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getRepeatTime()) << ", " |
| @@ -34,9 +34,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Block | |||
| 34 | // BlockReduceMax operations | 34 | // BlockReduceMax operations |
| 35 | //===----------------------------------------------------------------------===// | 35 | //===----------------------------------------------------------------------===// |
| 36 | 36 | ||
| 37 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::BlockReduceMaxL1Op op) | 37 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::BlockReduceMaxL1Op op) |
| 38 | { | 38 | { |
| 39 | - auto &os = emitter.ostream(); | 39 | + auto& os = emitter.ostream(); |
| 40 | 40 | ||
| 41 | auto maskName = printMask(emitter, op); | 41 | auto maskName = printMask(emitter, op); |
| 42 | 42 | ||
| @@ -51,9 +51,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Block | |||
| 51 | // BlockReduceMin operations | 51 | // BlockReduceMin operations |
| 52 | //===----------------------------------------------------------------------===// | 52 | //===----------------------------------------------------------------------===// |
| 53 | 53 | ||
| 54 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::BlockReduceMinL1Op op) | 54 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::BlockReduceMinL1Op op) |
| 55 | { | 55 | { |
| 56 | - auto &os = emitter.ostream(); | 56 | + auto& os = emitter.ostream(); |
| 57 | 57 | ||
| 58 | auto maskName = printMask(emitter, op); | 58 | auto maskName = printMask(emitter, op); |
| 59 | 59 | ||
| @@ -70,9 +70,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Block | |||
| 70 | //===----------------------------------------------------------------------===// | 70 | //===----------------------------------------------------------------------===// |
| 71 | // PairReduceSum operations | 71 | // PairReduceSum operations |
| 72 | //===----------------------------------------------------------------------===// | 72 | //===----------------------------------------------------------------------===// |
| 73 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::PairReduceSumL1Op op) | 73 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::PairReduceSumL1Op op) |
| 74 | { | 74 | { |
| 75 | - auto &os = emitter.ostream(); | 75 | + auto& os = emitter.ostream(); |
| 76 | auto maskName = printMask(emitter, op); | 76 | auto maskName = printMask(emitter, op); |
| 77 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 77 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 78 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getRepeatTime()) << ", " | 78 | << emitter.getOrCreateName(op.getSrc()) << ", " << emitter.getOrCreateName(op.getRepeatTime()) << ", " |
| @@ -86,9 +86,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::PairR | |||
| 86 | // ReduceMax operations | 86 | // ReduceMax operations |
| 87 | //===----------------------------------------------------------------------===// | 87 | //===----------------------------------------------------------------------===// |
| 88 | 88 | ||
| 89 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ReduceMaxL1Op op) | 89 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ReduceMaxL1Op op) |
| 90 | { | 90 | { |
| 91 | - auto &os = emitter.ostream(); | 91 | + auto& os = emitter.ostream(); |
| 92 | 92 | ||
| 93 | auto maskName = printMask(emitter, op); | 93 | auto maskName = printMask(emitter, op); |
| 94 | 94 | ||
| @@ -103,9 +103,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Reduc | |||
| 103 | // ReduceMin operations | 103 | // ReduceMin operations |
| 104 | //===----------------------------------------------------------------------===// | 104 | //===----------------------------------------------------------------------===// |
| 105 | 105 | ||
| 106 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ReduceMinL1Op op) | 106 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ReduceMinL1Op op) |
| 107 | { | 107 | { |
| 108 | - auto &os = emitter.ostream(); | 108 | + auto& os = emitter.ostream(); |
| 109 | 109 | ||
| 110 | auto maskName = printMask(emitter, op); | 110 | auto maskName = printMask(emitter, op); |
| 111 | 111 | ||
| @@ -120,9 +120,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Reduc | |||
| 120 | // ReduceSum operations | 120 | // ReduceSum operations |
| 121 | //===----------------------------------------------------------------------===// | 121 | //===----------------------------------------------------------------------===// |
| 122 | 122 | ||
| 123 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ReduceSumL1Op op) | 123 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ReduceSumL1Op op) |
| 124 | { | 124 | { |
| 125 | - auto &os = emitter.ostream(); | 125 | + auto& os = emitter.ostream(); |
| 126 | 126 | ||
| 127 | auto maskName = printMask(emitter, op); | 127 | auto maskName = printMask(emitter, op); |
| 128 | 128 | ||
| @@ -139,9 +139,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Reduc | |||
| 139 | 139 | ||
| 140 | namespace { | 140 | namespace { |
| 141 | template <typename OpType> | 141 | template <typename OpType> |
| 142 | -LogicalResult printWholeReduceMaxMinCommon(CodeEmitter &emitter, OpType op) | 142 | +LogicalResult printWholeReduceMaxMinCommon(CodeEmitter& emitter, OpType op) |
| 143 | { | 143 | { |
| 144 | - auto &os = emitter.ostream(); | 144 | + auto& os = emitter.ostream(); |
| 145 | auto maskName = printMask(emitter, op); | 145 | auto maskName = printMask(emitter, op); |
| 146 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 146 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 147 | << emitter.getOrCreateName(op.getSrc()) << ", " << maskName << ", " | 147 | << emitter.getOrCreateName(op.getSrc()) << ", " << maskName << ", " |
| @@ -152,12 +152,12 @@ LogicalResult printWholeReduceMaxMinCommon(CodeEmitter &emitter, OpType op) | |||
| 152 | } | 152 | } |
| 153 | } // namespace | 153 | } // namespace |
| 154 | 154 | ||
| 155 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::WholeReduceMaxL1Op op) | 155 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::WholeReduceMaxL1Op op) |
| 156 | { | 156 | { |
| 157 | return printWholeReduceMaxMinCommon(emitter, op); | 157 | return printWholeReduceMaxMinCommon(emitter, op); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::WholeReduceMinL1Op op) | 160 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::WholeReduceMinL1Op op) |
| 161 | { | 161 | { |
| 162 | return printWholeReduceMaxMinCommon(emitter, op); | 162 | return printWholeReduceMaxMinCommon(emitter, op); |
| 163 | } | 163 | } |
| @@ -165,9 +165,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Whole | |||
| 165 | //===----------------------------------------------------------------------===// | 165 | //===----------------------------------------------------------------------===// |
| 166 | // WholeReduceSum operations | 166 | // WholeReduceSum operations |
| 167 | //===----------------------------------------------------------------------===// | 167 | //===----------------------------------------------------------------------===// |
| 168 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::WholeReduceSumL1Op op) | 168 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::WholeReduceSumL1Op op) |
| 169 | { | 169 | { |
| 170 | - auto &os = emitter.ostream(); | 170 | + auto& os = emitter.ostream(); |
| 171 | auto maskName = printMask(emitter, op); | 171 | auto maskName = printMask(emitter, op); |
| 172 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 172 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| 173 | << emitter.getOrCreateName(op.getSrc()) << ", " << maskName << ", " | 173 | << emitter.getOrCreateName(op.getSrc()) << ", " << maskName << ", " |
| @@ -17,9 +17,9 @@ using namespace mlir::ascendc; | |||
| 17 | // Scatter operations | 17 | // Scatter operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ScatterL1Op op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ScatterL1Op op) |
| 21 | { | 21 | { |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | auto maskName = printMask(emitter, op); | 23 | auto maskName = printMask(emitter, op); |
| 24 | 24 | ||
| 25 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 25 | os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getDst()) << ", " |
| @@ -18,36 +18,31 @@ using namespace mlir::ascendc; | |||
| 18 | // Type conversion operations | 18 | // Type conversion operations |
| 19 | //===----------------------------------------------------------------------===// | 19 | //===----------------------------------------------------------------------===// |
| 20 | 20 | ||
| 21 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastL0Op op) | 21 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CastL0Op op) |
| 22 | { | 22 | { |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | FAIL_OR(printCastL01Template(emitter, op)); | 24 | FAIL_OR(printCastL01Template(emitter, op)); |
| 25 | - os << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 25 | + os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) |
| 26 | - << emitter.getOrCreateName(op.getSrc()) | 26 | + << ", AscendC::RoundMode::" << stringifyRoundMode(op.getRoundMode()) << ", " |
| 27 | - << ", AscendC::RoundMode::" << stringifyRoundMode(op.getRoundMode()) | 27 | + << emitter.getOrCreateName(op.getMask()) << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " |
| 28 | - << ", " << emitter.getOrCreateName(op.getMask()) << ", " << emitter.getOrCreateName(op.getRepeatTimes()) | 28 | + << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 29 | - << ", " << emitter.getOrCreateName(op.getRepeatParams()) | ||
| 30 | - << ")"; | ||
| 31 | return success(); | 29 | return success(); |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 34 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastL1Op op) | 32 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CastL1Op op) |
| 35 | { | 33 | { |
| 36 | - auto &os = emitter.ostream(); | 34 | + auto& os = emitter.ostream(); |
| 37 | - auto maskName = printMask(emitter, op); | 35 | + auto maskName = printMask(emitter, op); |
| 38 | FAIL_OR(printCastL01Template(emitter, op)); | 36 | FAIL_OR(printCastL01Template(emitter, op)); |
| 39 | - os << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 37 | + os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) |
| 40 | - << emitter.getOrCreateName(op.getSrc()) | 38 | + << ", AscendC::RoundMode::" << stringifyRoundMode(op.getRoundMode()) << ", " << maskName << ", " |
| 41 | - << ", AscendC::RoundMode::" << stringifyRoundMode(op.getRoundMode()) | 39 | + << emitter.getOrCreateName(op.getRepeatTimes()) << ", " << emitter.getOrCreateName(op.getRepeatParams()) << ")"; |
| 42 | - << ", " << maskName << ", " << emitter.getOrCreateName(op.getRepeatTimes()) << ", " | ||
| 43 | - << emitter.getOrCreateName(op.getRepeatParams()) | ||
| 44 | - << ")"; | ||
| 45 | return success(); | 40 | return success(); |
| 46 | } | 41 | } |
| 47 | 42 | ||
| 48 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastL2Op op) | 43 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CastL2Op op) |
| 49 | { | 44 | { |
| 50 | - auto &os = emitter.ostream(); | 45 | + auto& os = emitter.ostream(); |
| 51 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); | 46 | auto dstType = cast<ascendc::LocalTensorType>(op.getDst().getType()).getElementType(); |
| 52 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); | 47 | auto srcType = cast<ascendc::LocalTensorType>(op.getSrc().getType()).getElementType(); |
| 53 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 48 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| @@ -55,43 +50,42 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastL | |||
| 55 | os << ", "; | 50 | os << ", "; |
| 56 | FAIL_OR(emitter.emitType(op.getLoc(), srcType)); | 51 | FAIL_OR(emitter.emitType(op.getLoc(), srcType)); |
| 57 | os << ">"; | 52 | os << ">"; |
| 58 | - os << "(" << emitter.getOrCreateName(op.getDst()) << ", " | 53 | + os << "(" << emitter.getOrCreateName(op.getDst()) << ", " << emitter.getOrCreateName(op.getSrc()) << ", " |
| 59 | - << emitter.getOrCreateName(op.getSrc()) << ", " | ||
| 60 | << "AscendC::RoundMode::" << stringifyRoundMode(op.getRoundMode()) << ", " | 54 | << "AscendC::RoundMode::" << stringifyRoundMode(op.getRoundMode()) << ", " |
| 61 | << emitter.getOrCreateName(op.getCalCount()) << ")"; | 55 | << emitter.getOrCreateName(op.getCalCount()) << ")"; |
| 62 | return success(); | 56 | return success(); |
| 63 | } | 57 | } |
| 64 | 58 | ||
| 65 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastDeqL0Op op) | 59 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CastDeqL0Op op) |
| 66 | { | 60 | { |
| 67 | - auto &os = emitter.ostream(); | 61 | + auto& os = emitter.ostream(); |
| 68 | FAIL_OR(printCastDeqL01Template(emitter, op)); | 62 | FAIL_OR(printCastDeqL01Template(emitter, op)); |
| 69 | printUnaryL0Params(emitter, op); | 63 | printUnaryL0Params(emitter, op); |
| 70 | return success(); | 64 | return success(); |
| 71 | } | 65 | } |
| 72 | 66 | ||
| 73 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastDeqL1Op op) | 67 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CastDeqL1Op op) |
| 74 | { | 68 | { |
| 75 | - auto &os = emitter.ostream(); | 69 | + auto& os = emitter.ostream(); |
| 76 | auto maskName = printMask(emitter, op); | 70 | auto maskName = printMask(emitter, op); |
| 77 | FAIL_OR(printCastDeqL01Template(emitter, op)); | 71 | FAIL_OR(printCastDeqL01Template(emitter, op)); |
| 78 | printUnaryL1Params(emitter, op, maskName); | 72 | printUnaryL1Params(emitter, op, maskName); |
| 79 | return success(); | 73 | return success(); |
| 80 | } | 74 | } |
| 81 | 75 | ||
| 82 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::CastDeqL2Op op) | 76 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::CastDeqL2Op op) |
| 83 | { | 77 | { |
| 84 | - auto &os = emitter.ostream(); | 78 | + auto& os = emitter.ostream(); |
| 85 | FAIL_OR(printCastDeqL2Template(emitter, op)); | 79 | FAIL_OR(printCastDeqL2Template(emitter, op)); |
| 86 | printUnaryL2Params(emitter, op); | 80 | printUnaryL2Params(emitter, op); |
| 87 | return success(); | 81 | return success(); |
| 88 | } | 82 | } |
| 89 | 83 | ||
| 90 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SetDeqScaleL4Op op) { | 84 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SetDeqScaleL4Op op) |
| 91 | - auto &os = emitter.ostream(); | 85 | +{ |
| 92 | - os << ascNamespace << "::" << op.getAPIName() << "(" | 86 | + auto& os = emitter.ostream(); |
| 93 | - << emitter.getOrCreateName(op.getVdeq()) << ", " | 87 | + os << ascNamespace << "::" << op.getAPIName() << "(" << emitter.getOrCreateName(op.getVdeq()) << ", " |
| 94 | << emitter.getOrCreateName(op.getVdeqInfo()) << ")"; | 88 | << emitter.getOrCreateName(op.getVdeqInfo()) << ")"; |
| 95 | - | 89 | + |
| 96 | return success(); | 90 | return success(); |
| 97 | } | 91 | } |
| @@ -46,7 +46,7 @@ constexpr uint32_t BATCHOUTMODE_MULTI_BATCH_ONE = 1; | |||
| 46 | constexpr uint32_t BATCHOUTMODE_DYNAMIC_VALUE = 2; | 46 | constexpr uint32_t BATCHOUTMODE_DYNAMIC_VALUE = 2; |
| 47 | } // namespace | 47 | } // namespace |
| 48 | 48 | ||
| 49 | -void CodeEmitter::emitTPosition(raw_ostream &os, ascendc::TPosition pos) | 49 | +void CodeEmitter::emitTPosition(raw_ostream& os, ascendc::TPosition pos) |
| 50 | { | 50 | { |
| 51 | if (pos == ascendc::TPosition::GM) | 51 | if (pos == ascendc::TPosition::GM) |
| 52 | os << ascNamespace << "::TPosition::GM"; | 52 | os << ascNamespace << "::TPosition::GM"; |
| @@ -76,7 +76,7 @@ void CodeEmitter::emitTPosition(raw_ostream &os, ascendc::TPosition pos) | |||
| 76 | llvm_unreachable("unexpected ascendc::TPosition value"); | 76 | llvm_unreachable("unexpected ascendc::TPosition value"); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | -void CodeEmitter::emitCubeFormat(raw_ostream &os, ascendc::CubeFormat format) | 79 | +void CodeEmitter::emitCubeFormat(raw_ostream& os, ascendc::CubeFormat format) |
| 80 | { | 80 | { |
| 81 | if (format == ascendc::CubeFormat::ND) | 81 | if (format == ascendc::CubeFormat::ND) |
| 82 | os << "CubeFormat::ND"; | 82 | os << "CubeFormat::ND"; |
| @@ -98,7 +98,7 @@ void CodeEmitter::emitCubeFormat(raw_ostream &os, ascendc::CubeFormat format) | |||
| 98 | llvm_unreachable("unexpected ascendc::CubeFormat value"); | 98 | llvm_unreachable("unexpected ascendc::CubeFormat value"); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | -void CodeEmitter::emitLayoutMode(raw_ostream &os, ascendc::LayoutMode layout) | 101 | +void CodeEmitter::emitLayoutMode(raw_ostream& os, ascendc::LayoutMode layout) |
| 102 | { | 102 | { |
| 103 | if (layout == ascendc::LayoutMode::NONE) | 103 | if (layout == ascendc::LayoutMode::NONE) |
| 104 | os << "LayoutMode::NONE"; | 104 | os << "LayoutMode::NONE"; |
| @@ -114,7 +114,7 @@ void CodeEmitter::emitLayoutMode(raw_ostream &os, ascendc::LayoutMode layout) | |||
| 114 | llvm_unreachable("unexpected ascendc::LayoutMode value"); | 114 | llvm_unreachable("unexpected ascendc::LayoutMode value"); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | -CodeEmitter::CodeEmitter(raw_ostream &os) : os(os) | 117 | +CodeEmitter::CodeEmitter(raw_ostream& os) : os(os) |
| 118 | { | 118 | { |
| 119 | createTypeEmitMapper(); | 119 | createTypeEmitMapper(); |
| 120 | createAttributeEmitMapper(); | 120 | createAttributeEmitMapper(); |
| @@ -229,7 +229,7 @@ LogicalResult CodeEmitter::emitDenseFPElementsAttr(Location loc, Attribute attr) | |||
| 229 | { | 229 | { |
| 230 | auto dense = dyn_cast<DenseFPElementsAttr>(attr); | 230 | auto dense = dyn_cast<DenseFPElementsAttr>(attr); |
| 231 | os << '{'; | 231 | os << '{'; |
| 232 | - interleaveComma(dense, os, [&](const APFloat &val) { printFloat(val); }); | 232 | + interleaveComma(dense, os, [&](const APFloat& val) { printFloat(val); }); |
| 233 | os << '}'; | 233 | os << '}'; |
| 234 | return success(); | 234 | return success(); |
| 235 | } | 235 | } |
| @@ -238,14 +238,14 @@ LogicalResult CodeEmitter::emitDenseIntElementsAttr(Location loc, Attribute attr | |||
| 238 | auto dense = dyn_cast<DenseIntElementsAttr>(attr); | 238 | auto dense = dyn_cast<DenseIntElementsAttr>(attr); |
| 239 | if (auto iType = dyn_cast<IntegerType>(cast<TensorType>(dense.getType()).getElementType())) { | 239 | if (auto iType = dyn_cast<IntegerType>(cast<TensorType>(dense.getType()).getElementType())) { |
| 240 | os << '{'; | 240 | os << '{'; |
| 241 | - interleaveComma(dense, os, | 241 | + interleaveComma( |
| 242 | - [&](const APInt &val) { printInt(val, shouldMapToUnsigned(iType.getSignedness())); }); | 242 | + dense, os, [&](const APInt& val) { printInt(val, shouldMapToUnsigned(iType.getSignedness())); }); |
| 243 | os << '}'; | 243 | os << '}'; |
| 244 | return success(); | 244 | return success(); |
| 245 | } | 245 | } |
| 246 | if (auto iType = dyn_cast<IndexType>(cast<TensorType>(dense.getType()).getElementType())) { | 246 | if (auto iType = dyn_cast<IndexType>(cast<TensorType>(dense.getType()).getElementType())) { |
| 247 | os << '{'; | 247 | os << '{'; |
| 248 | - interleaveComma(dense, os, [&](const APInt &val) { printInt(val, false); }); | 248 | + interleaveComma(dense, os, [&](const APInt& val) { printInt(val, false); }); |
| 249 | os << '}'; | 249 | os << '}'; |
| 250 | return success(); | 250 | return success(); |
| 251 | } | 251 | } |
| @@ -291,7 +291,7 @@ StringRef CodeEmitter::getOrCreateName(Value val) | |||
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | /// Return the existing or a new label for a Block. | 293 | /// Return the existing or a new label for a Block. |
| 294 | -StringRef CodeEmitter::getOrCreateName(Block &block) | 294 | +StringRef CodeEmitter::getOrCreateName(Block& block) |
| 295 | { | 295 | { |
| 296 | if (!blockMapper.count(&block)) | 296 | if (!blockMapper.count(&block)) |
| 297 | blockMapper.insert(&block, formatv("label{0}", ++nameStack.labelInScopeCount.top())); | 297 | blockMapper.insert(&block, formatv("label{0}", ++nameStack.labelInScopeCount.top())); |
| @@ -301,26 +301,20 @@ StringRef CodeEmitter::getOrCreateName(Block &block) | |||
| 301 | bool CodeEmitter::shouldMapToUnsigned(IntegerType::SignednessSemantics val) | 301 | bool CodeEmitter::shouldMapToUnsigned(IntegerType::SignednessSemantics val) |
| 302 | { | 302 | { |
| 303 | switch (val) { | 303 | switch (val) { |
| 304 | - case IntegerType::Signless: | 304 | + case IntegerType::Signless: |
| 305 | - case IntegerType::Signed: | 305 | + case IntegerType::Signed: |
| 306 | - return false; | 306 | + return false; |
| 307 | - case IntegerType::Unsigned: | 307 | + case IntegerType::Unsigned: |
| 308 | - return true; | 308 | + return true; |
| 309 | } | 309 | } |
| 310 | llvm_unreachable("Unexpected IntegerType::SignednessSemantics"); | 310 | llvm_unreachable("Unexpected IntegerType::SignednessSemantics"); |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | -bool CodeEmitter::hasValueInScope(Value val) | 313 | +bool CodeEmitter::hasValueInScope(Value val) { return valueMapper.count(val); } |
| 314 | -{ | ||
| 315 | - return valueMapper.count(val); | ||
| 316 | -} | ||
| 317 | 314 | ||
| 318 | -bool CodeEmitter::hasBlockLabel(Block &block) | 315 | +bool CodeEmitter::hasBlockLabel(Block& block) { return blockMapper.count(&block); } |
| 319 | -{ | ||
| 320 | - return blockMapper.count(&block); | ||
| 321 | -} | ||
| 322 | 316 | ||
| 323 | -void CodeEmitter::printInt(const APInt &value, bool isUnsigned) | 317 | +void CodeEmitter::printInt(const APInt& value, bool isUnsigned) |
| 324 | { | 318 | { |
| 325 | if (value.getBitWidth() == 1) { | 319 | if (value.getBitWidth() == 1) { |
| 326 | if (value.getBoolValue()) | 320 | if (value.getBoolValue()) |
| @@ -335,21 +329,21 @@ void CodeEmitter::printInt(const APInt &value, bool isUnsigned) | |||
| 335 | } | 329 | } |
| 336 | } | 330 | } |
| 337 | 331 | ||
| 338 | -void CodeEmitter::printFloat(const APFloat &value) | 332 | +void CodeEmitter::printFloat(const APFloat& value) |
| 339 | { | 333 | { |
| 340 | if (value.isFinite()) { | 334 | if (value.isFinite()) { |
| 341 | SmallString<SMALL_STRING_LENGTH> strValue; | 335 | SmallString<SMALL_STRING_LENGTH> strValue; |
| 342 | // Use default values of toString except don't truncate zeros. | 336 | // Use default values of toString except don't truncate zeros. |
| 343 | value.toString(strValue, 0, 0, false); | 337 | value.toString(strValue, 0, 0, false); |
| 344 | switch (llvm::APFloatBase::SemanticsToEnum(value.getSemantics())) { | 338 | switch (llvm::APFloatBase::SemanticsToEnum(value.getSemantics())) { |
| 345 | - case llvm::APFloatBase::S_IEEEsingle: | 339 | + case llvm::APFloatBase::S_IEEEsingle: |
| 346 | - os << "(float)"; | 340 | + os << "(float)"; |
| 347 | - break; | 341 | + break; |
| 348 | - case llvm::APFloatBase::S_IEEEdouble: | 342 | + case llvm::APFloatBase::S_IEEEdouble: |
| 349 | - os << "(double)"; | 343 | + os << "(double)"; |
| 350 | - break; | 344 | + break; |
| 351 | - default: | 345 | + default: |
| 352 | - break; | 346 | + break; |
| 353 | }; | 347 | }; |
| 354 | os << strValue; | 348 | os << strValue; |
| 355 | } else if (value.isNaN()) { | 349 | } else if (value.isNaN()) { |
| @@ -371,7 +365,7 @@ LogicalResult CodeEmitter::emitAttribute(Location loc, Attribute attr) | |||
| 371 | } | 365 | } |
| 372 | } | 366 | } |
| 373 | 367 | ||
| 374 | -LogicalResult CodeEmitter::emitOperands(Operation &op) | 368 | +LogicalResult CodeEmitter::emitOperands(Operation& op) |
| 375 | { | 369 | { |
| 376 | auto emitOperand = [&](Value result) -> LogicalResult { | 370 | auto emitOperand = [&](Value result) -> LogicalResult { |
| 377 | if (!hasValueInScope(result)) | 371 | if (!hasValueInScope(result)) |
| @@ -395,31 +389,31 @@ LogicalResult CodeEmitter::emitVariableDeclaration(OpResult opResult, bool trail | |||
| 395 | return success(); | 389 | return success(); |
| 396 | } | 390 | } |
| 397 | 391 | ||
| 398 | -static bool isValidToken(const std::string::value_type &token) | 392 | +static bool isValidToken(const std::string::value_type& token) |
| 399 | { | 393 | { |
| 400 | return (token >= 'A' && token <= 'Z') || (token >= 'a' && token <= 'z') || (token >= '0' && token <= '9') || | 394 | return (token >= 'A' && token <= 'Z') || (token >= 'a' && token <= 'z') || (token >= '0' && token <= '9') || |
| 401 | token == '_'; | 395 | token == '_'; |
| 402 | } | 396 | } |
| 403 | 397 | ||
| 404 | -LogicalResult CodeEmitter::emitAssignPrefix(Operation &op) | 398 | +LogicalResult CodeEmitter::emitAssignPrefix(Operation& op) |
| 405 | { | 399 | { |
| 406 | switch (op.getNumResults()) { | 400 | switch (op.getNumResults()) { |
| 407 | - case 0: | 401 | + case 0: |
| 408 | - break; | 402 | + break; |
| 409 | - case 1: { | 403 | + case 1: { |
| 410 | - OpResult result = op.getResult(0); | 404 | + OpResult result = op.getResult(0); |
| 411 | - if (failed(emitVariableDeclaration(result, /*trailingSemicolon=*/false))) | 405 | + if (failed(emitVariableDeclaration(result, /*trailingSemicolon=*/false))) |
| 412 | - return failure(); | 406 | + return failure(); |
| 413 | - os << " = "; | 407 | + os << " = "; |
| 414 | - break; | 408 | + break; |
| 415 | - } | 409 | + } |
| 416 | - default: | 410 | + default: |
| 417 | - llvm_unreachable("emission for multiple results is not implemented"); | 411 | + llvm_unreachable("emission for multiple results is not implemented"); |
| 418 | } | 412 | } |
| 419 | return success(); | 413 | return success(); |
| 420 | } | 414 | } |
| 421 | 415 | ||
| 422 | -LogicalResult CodeEmitter::emitLabel(Block &block) | 416 | +LogicalResult CodeEmitter::emitLabel(Block& block) |
| 423 | { | 417 | { |
| 424 | if (!hasBlockLabel(block)) | 418 | if (!hasBlockLabel(block)) |
| 425 | return block.getParentOp()->emitError("label for block not found"); | 419 | return block.getParentOp()->emitError("label for block not found"); |
| @@ -432,30 +426,30 @@ LogicalResult CodeEmitter::emitLabel(Block &block) | |||
| 432 | void CodeEmitter::emitAddressSpace(ascendc::AddressSpace addressSpace) | 426 | void CodeEmitter::emitAddressSpace(ascendc::AddressSpace addressSpace) |
| 433 | { | 427 | { |
| 434 | switch (addressSpace) { | 428 | switch (addressSpace) { |
| 435 | - case ascendc::AddressSpace::Default: | 429 | + case ascendc::AddressSpace::Default: |
| 436 | - // print nothing | 430 | + // print nothing |
| 437 | - break; | 431 | + break; |
| 438 | - case ascendc::AddressSpace::gm: | 432 | + case ascendc::AddressSpace::gm: |
| 439 | - os << "__gm__ "; | 433 | + os << "__gm__ "; |
| 440 | - break; | 434 | + break; |
| 441 | - case ascendc::AddressSpace::ca: | 435 | + case ascendc::AddressSpace::ca: |
| 442 | - os << "__ca__ "; | 436 | + os << "__ca__ "; |
| 443 | - break; | 437 | + break; |
| 444 | - case ascendc::AddressSpace::cb: | 438 | + case ascendc::AddressSpace::cb: |
| 445 | - os << "__cb__ "; | 439 | + os << "__cb__ "; |
| 446 | - break; | 440 | + break; |
| 447 | - case ascendc::AddressSpace::cc: | 441 | + case ascendc::AddressSpace::cc: |
| 448 | - os << "__cc__ "; | 442 | + os << "__cc__ "; |
| 449 | - break; | 443 | + break; |
| 450 | - case ascendc::AddressSpace::ubuf: | 444 | + case ascendc::AddressSpace::ubuf: |
| 451 | - os << "__ubuf__ "; | 445 | + os << "__ubuf__ "; |
| 452 | - break; | 446 | + break; |
| 453 | - case ascendc::AddressSpace::cbuf: | 447 | + case ascendc::AddressSpace::cbuf: |
| 454 | - os << "__cbuf__ "; | 448 | + os << "__cbuf__ "; |
| 455 | - break; | 449 | + break; |
| 456 | - case ascendc::AddressSpace::fbuf: | 450 | + case ascendc::AddressSpace::fbuf: |
| 457 | - os << "__fbuf__ "; | 451 | + os << "__fbuf__ "; |
| 458 | - break; | 452 | + break; |
| 459 | } | 453 | } |
| 460 | } | 454 | } |
| 461 | 455 | ||
| @@ -621,7 +615,7 @@ LogicalResult CodeEmitter::emitAscLocalTensorType(Location loc, Type type, bool | |||
| 621 | return success(); | 615 | return success(); |
| 622 | } | 616 | } |
| 623 | 617 | ||
| 624 | -void CodeEmitter::emitMatmulConfig(raw_ostream &os, ascendc::MatmulConfigAttr config) | 618 | +void CodeEmitter::emitMatmulConfig(raw_ostream& os, ascendc::MatmulConfigAttr config) |
| 625 | { | 619 | { |
| 626 | os << "constexpr static MatmulConfig CFG{"; | 620 | os << "constexpr static MatmulConfig CFG{"; |
| 627 | os << config.getDoNorm().getValue(); | 621 | os << config.getDoNorm().getValue(); |
| @@ -864,39 +858,39 @@ LogicalResult CodeEmitter::emitAscMatmulType(Location loc, Type type, bool emitA | |||
| 864 | return emitAscMatmulTypeTemplate(loc, type, emitAsUnsigned); | 858 | return emitAscMatmulTypeTemplate(loc, type, emitAsUnsigned); |
| 865 | } | 859 | } |
| 866 | 860 | ||
| 867 | -LogicalResult CodeEmitter::emitIntegerType(IntegerType &iType, Location loc, Type type, bool emitAsUnsigned) | 861 | +LogicalResult CodeEmitter::emitIntegerType(IntegerType& iType, Location loc, Type type, bool emitAsUnsigned) |
| 868 | { | 862 | { |
| 869 | switch (iType.getWidth()) { | 863 | switch (iType.getWidth()) { |
| 870 | - case DTYPE_BIT_WIDTH_1: | 864 | + case DTYPE_BIT_WIDTH_1: |
| 871 | - return (os << "bool"), success(); | 865 | + return (os << "bool"), success(); |
| 872 | - case DTYPE_BIT_WIDTH_8: | 866 | + case DTYPE_BIT_WIDTH_8: |
| 873 | - case DTYPE_BIT_WIDTH_16: | 867 | + case DTYPE_BIT_WIDTH_16: |
| 874 | - case DTYPE_BIT_WIDTH_32: | 868 | + case DTYPE_BIT_WIDTH_32: |
| 875 | - case DTYPE_BIT_WIDTH_64: | 869 | + case DTYPE_BIT_WIDTH_64: |
| 876 | - if (shouldMapToUnsigned(iType.getSignedness()) || emitAsUnsigned) | 870 | + if (shouldMapToUnsigned(iType.getSignedness()) || emitAsUnsigned) |
| 877 | - return (os << "uint" << iType.getWidth() << "_t"), success(); | 871 | + return (os << "uint" << iType.getWidth() << "_t"), success(); |
| 878 | - else | 872 | + else |
| 879 | - return (os << "int" << iType.getWidth() << "_t"), success(); | 873 | + return (os << "int" << iType.getWidth() << "_t"), success(); |
| 880 | - default: | 874 | + default: |
| 881 | - return emitError(loc, "cannot emit integer type ") << type; | 875 | + return emitError(loc, "cannot emit integer type ") << type; |
| 882 | } | 876 | } |
| 883 | } | 877 | } |
| 884 | 878 | ||
| 885 | -LogicalResult CodeEmitter::emitFloatType(FloatType &fType, Location loc, Type type, bool emitAsUnsigned) | 879 | +LogicalResult CodeEmitter::emitFloatType(FloatType& fType, Location loc, Type type, bool emitAsUnsigned) |
| 886 | { | 880 | { |
| 887 | switch (fType.getWidth()) { | 881 | switch (fType.getWidth()) { |
| 888 | - case DTYPE_BIT_WIDTH_16: | 882 | + case DTYPE_BIT_WIDTH_16: |
| 889 | - return (os << "half"), success(); | 883 | + return (os << "half"), success(); |
| 890 | - case DTYPE_BIT_WIDTH_32: | 884 | + case DTYPE_BIT_WIDTH_32: |
| 891 | - return (os << "float"), success(); | 885 | + return (os << "float"), success(); |
| 892 | - case DTYPE_BIT_WIDTH_64: | 886 | + case DTYPE_BIT_WIDTH_64: |
| 893 | - return (os << "double"), success(); | 887 | + return (os << "double"), success(); |
| 894 | - default: | 888 | + default: |
| 895 | - return emitError(loc, "cannot emit float type ") << type; | 889 | + return emitError(loc, "cannot emit float type ") << type; |
| 896 | } | 890 | } |
| 897 | } | 891 | } |
| 898 | 892 | ||
| 899 | -LogicalResult CodeEmitter::emitBaseMemRefType(BaseMemRefType &pType, Location loc, Type type, bool emitAsUnsigned) | 893 | +LogicalResult CodeEmitter::emitBaseMemRefType(BaseMemRefType& pType, Location loc, Type type, bool emitAsUnsigned) |
| 900 | { | 894 | { |
| 901 | if (auto attr = pType.getMemorySpace()) { | 895 | if (auto attr = pType.getMemorySpace()) { |
| 902 | auto value = static_cast<uint8_t>(cast<IntegerAttr>(attr).getInt()); | 896 | auto value = static_cast<uint8_t>(cast<IntegerAttr>(attr).getInt()); |
| @@ -963,12 +957,12 @@ LogicalResult CodeEmitter::emitAscMrgSortSrcListType(Location loc, Type type, bo | |||
| 963 | LogicalResult CodeEmitter::emitTypes(Location loc, ArrayRef<Type> types) | 957 | LogicalResult CodeEmitter::emitTypes(Location loc, ArrayRef<Type> types) |
| 964 | { | 958 | { |
| 965 | switch (types.size()) { | 959 | switch (types.size()) { |
| 966 | - case 0: | 960 | + case 0: |
| 967 | - os << "void"; | 961 | + os << "void"; |
| 968 | - return success(); | 962 | + return success(); |
| 969 | - case DTYPE_BIT_WIDTH_1: | 963 | + case DTYPE_BIT_WIDTH_1: |
| 970 | - return emitType(loc, types.front()); | 964 | + return emitType(loc, types.front()); |
| 971 | - default: | 965 | + default: |
| 972 | - llvm_unreachable("unsupported emission of types array"); | 966 | + llvm_unreachable("unsupported emission of types array"); |
| 973 | } | 967 | } |
| 974 | } | 968 | } |
| @@ -16,10 +16,10 @@ namespace { | |||
| 16 | constexpr uint32_t TYPE_WIDTH_16 = 16; | 16 | constexpr uint32_t TYPE_WIDTH_16 = 16; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | -LogicalResult mlir::printConstantOp(CodeEmitter &emitter, Operation *operation, Attribute value) | 19 | +LogicalResult mlir::printConstantOp(CodeEmitter& emitter, Operation* operation, Attribute value) |
| 20 | { | 20 | { |
| 21 | OpResult result = operation->getResult(0); | 21 | OpResult result = operation->getResult(0); |
| 22 | - auto &os = emitter.ostream(); | 22 | + auto& os = emitter.ostream(); |
| 23 | auto fType = dyn_cast_or_null<FloatType>(operation->getResult(0).getType()); | 23 | auto fType = dyn_cast_or_null<FloatType>(operation->getResult(0).getType()); |
| 24 | if (!fType || fType.getWidth() != TYPE_WIDTH_16) { | 24 | if (!fType || fType.getWidth() != TYPE_WIDTH_16) { |
| 25 | os << "constexpr "; | 25 | os << "constexpr "; |
| @@ -28,8 +28,9 @@ LogicalResult mlir::printConstantOp(CodeEmitter &emitter, Operation *operation, | |||
| 28 | if (auto oAttr = dyn_cast<emitc::OpaqueAttr>(value)) { | 28 | if (auto oAttr = dyn_cast<emitc::OpaqueAttr>(value)) { |
| 29 | if (oAttr.getValue().empty()) { | 29 | if (oAttr.getValue().empty()) { |
| 30 | // The semicolon gets printed by the emitOperation function. | 30 | // The semicolon gets printed by the emitOperation function. |
| 31 | - return emitter.emitVariableDeclaration(result, | 31 | + return emitter.emitVariableDeclaration( |
| 32 | - /*trailingSemicolon=*/false); | 32 | + result, |
| 33 | + /*trailingSemicolon=*/false); | ||
| 33 | } | 34 | } |
| 34 | } | 35 | } |
| 35 | 36 | ||
| @@ -44,9 +45,9 @@ LogicalResult mlir::printConstantOp(CodeEmitter &emitter, Operation *operation, | |||
| 44 | // Mask operations | 45 | // Mask operations |
| 45 | //===----------------------------------------------------------------------===// | 46 | //===----------------------------------------------------------------------===// |
| 46 | 47 | ||
| 47 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SetVectorMaskL0Op op) | 48 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SetVectorMaskL0Op op) |
| 48 | { | 49 | { |
| 49 | - auto &os = emitter.ostream(); | 50 | + auto& os = emitter.ostream(); |
| 50 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 51 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 51 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDtype(), true)); | 52 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDtype(), true)); |
| 52 | os << ", " << ascNamespace << "::MaskMode::" << ascendc::stringifyEnum(op.getMode()).upper(); | 53 | os << ", " << ascNamespace << "::MaskMode::" << ascendc::stringifyEnum(op.getMode()).upper(); |
| @@ -54,9 +55,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SetVe | |||
| 54 | return success(); | 55 | return success(); |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::SetVectorMaskL1Op op) | 58 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::SetVectorMaskL1Op op) |
| 58 | { | 59 | { |
| 59 | - auto &os = emitter.ostream(); | 60 | + auto& os = emitter.ostream(); |
| 60 | os << ascNamespace << "::" << op.getAPIName() << "<"; | 61 | os << ascNamespace << "::" << op.getAPIName() << "<"; |
| 61 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDtype(), true)); | 62 | FAIL_OR(emitter.emitType(op.getLoc(), op.getDtype(), true)); |
| 62 | os << ", " << ascNamespace << "::MaskMode::" << ascendc::stringifyEnum(op.getMode()).upper(); | 63 | os << ", " << ascNamespace << "::MaskMode::" << ascendc::stringifyEnum(op.getMode()).upper(); |
| @@ -17,18 +17,18 @@ using namespace mlir::ascendc; | |||
| 17 | // GlobalTensor operations | 17 | // GlobalTensor operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GlobalTensorSubIndexOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GlobalTensorSubIndexOp op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "[" << emitter.getOrCreateName(op.getIndex()) << "]"; | 24 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "[" << emitter.getOrCreateName(op.getIndex()) << "]"; |
| 25 | return success(); | 25 | return success(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::GlobalTensorBracketOp op) | 28 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::GlobalTensorBracketOp op) |
| 29 | { | 29 | { |
| 30 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 30 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 31 | - auto &os = emitter.ostream(); | 31 | + auto& os = emitter.ostream(); |
| 32 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "(" << emitter.getOrCreateName(op.getIndex()) << ")"; | 32 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "(" << emitter.getOrCreateName(op.getIndex()) << ")"; |
| 33 | return success(); | 33 | return success(); |
| 34 | } | 34 | } |
| @@ -17,10 +17,10 @@ using namespace mlir::ascendc; | |||
| 17 | // LocalTensor operations | 17 | // LocalTensor operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::LocalTensorV2Op op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::LocalTensorV2Op op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | auto resultType = op.getResult().getType().getElementType(); | 24 | auto resultType = op.getResult().getType().getElementType(); |
| 25 | os << " = " | 25 | os << " = " |
| 26 | << "AscendC::LocalTensor" | 26 | << "AscendC::LocalTensor" |
| @@ -32,10 +32,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Local | |||
| 32 | return success(); | 32 | return success(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::LocalTensorReinterpretCastOp op) | 35 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::LocalTensorReinterpretCastOp op) |
| 36 | { | 36 | { |
| 37 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 37 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 38 | - auto &os = emitter.ostream(); | 38 | + auto& os = emitter.ostream(); |
| 39 | os << " = " << emitter.getOrCreateName(op.getIn()) << "." << op.getAPIName() << "<"; | 39 | os << " = " << emitter.getOrCreateName(op.getIn()) << "." << op.getAPIName() << "<"; |
| 40 | Type elType = op.getOut().getType().getElementType(); | 40 | Type elType = op.getOut().getType().getElementType(); |
| 41 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 41 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -43,18 +43,18 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Local | |||
| 43 | return success(); | 43 | return success(); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::LocalTensorSubIndexOp op) | 46 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::LocalTensorSubIndexOp op) |
| 47 | { | 47 | { |
| 48 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 48 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 49 | - auto &os = emitter.ostream(); | 49 | + auto& os = emitter.ostream(); |
| 50 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "[" << emitter.getOrCreateName(op.getIndex()) << "]"; | 50 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "[" << emitter.getOrCreateName(op.getIndex()) << "]"; |
| 51 | return success(); | 51 | return success(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::LocalTensorBracketOp op) | 54 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::LocalTensorBracketOp op) |
| 55 | { | 55 | { |
| 56 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 56 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 57 | - auto &os = emitter.ostream(); | 57 | + auto& os = emitter.ostream(); |
| 58 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "(" << emitter.getOrCreateName(op.getIndex()) << ")"; | 58 | os << " = " << emitter.getOrCreateName(op.getTensor()) << "(" << emitter.getOrCreateName(op.getIndex()) << ")"; |
| 59 | return success(); | 59 | return success(); |
| 60 | } | 60 | } |
| @@ -17,7 +17,7 @@ using namespace mlir::ascendc; | |||
| 17 | // ShapeInfo operations | 17 | // ShapeInfo operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ShapeInfoShapeOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ShapeInfoShapeOp op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitAssignPrefix(*op)); | 22 | FAIL_OR(emitter.emitAssignPrefix(*op)); |
| 23 | emitter.ostream() << emitter.getOrCreateName(op.getBase()) << ".shape[" << emitter.getOrCreateName(op.getDim()) | 23 | emitter.ostream() << emitter.getOrCreateName(op.getBase()) << ".shape[" << emitter.getOrCreateName(op.getDim()) |
| @@ -25,7 +25,7 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::Shape | |||
| 25 | return success(); | 25 | return success(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ShapeInfoOriginalShapeOp op) | 28 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ShapeInfoOriginalShapeOp op) |
| 29 | { | 29 | { |
| 30 | FAIL_OR(emitter.emitAssignPrefix(*op)); | 30 | FAIL_OR(emitter.emitAssignPrefix(*op)); |
| 31 | emitter.ostream() << emitter.getOrCreateName(op.getBase()) << ".originalShape[" | 31 | emitter.ostream() << emitter.getOrCreateName(op.getBase()) << ".originalShape[" |
| @@ -20,9 +20,9 @@ using namespace mlir::emitasc; | |||
| 20 | // EmitAsc operations | 20 | // EmitAsc operations |
| 21 | //===----------------------------------------------------------------------===// | 21 | //===----------------------------------------------------------------------===// |
| 22 | 22 | ||
| 23 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::CallOpaqueOp op) | 23 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::CallOpaqueOp op) |
| 24 | { | 24 | { |
| 25 | - auto &os = emitter.ostream(); | 25 | + auto& os = emitter.ostream(); |
| 26 | 26 | ||
| 27 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 27 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 28 | os << op.getCallee() << '('; | 28 | os << op.getCallee() << '('; |
| @@ -32,12 +32,12 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::CallO | |||
| 32 | return success(); | 32 | return success(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::CopyStructOp op) | 35 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::CopyStructOp op) |
| 36 | { | 36 | { |
| 37 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 37 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 38 | auto base = emitter.getOrCreateName(op.getBase()); | 38 | auto base = emitter.getOrCreateName(op.getBase()); |
| 39 | auto result = emitter.getOrCreateName(op.getResult()); | 39 | auto result = emitter.getOrCreateName(op.getResult()); |
| 40 | - auto &os = emitter.ostream(); | 40 | + auto& os = emitter.ostream(); |
| 41 | os << ' ' << result << ";\n"; | 41 | os << ' ' << result << ";\n"; |
| 42 | os << "for (size_t i = 0; i < sizeof(" << result << "); i++) {\n"; | 42 | os << "for (size_t i = 0; i < sizeof(" << result << "); i++) {\n"; |
| 43 | os.indent() << "auto byte = reinterpret_cast<"; | 43 | os.indent() << "auto byte = reinterpret_cast<"; |
| @@ -53,17 +53,17 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::CopyS | |||
| 53 | return success(); | 53 | return success(); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::DereferenceOp op) | 56 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::DereferenceOp op) |
| 57 | { | 57 | { |
| 58 | - auto &os = emitter.ostream(); | 58 | + auto& os = emitter.ostream(); |
| 59 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 59 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 60 | os << "& " << emitter.getOrCreateName(op.getResult()) << " = *" << emitter.getOrCreateName(op.getBase()); | 60 | os << "& " << emitter.getOrCreateName(op.getResult()) << " = *" << emitter.getOrCreateName(op.getBase()); |
| 61 | return success(); | 61 | return success(); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::MemberOp op) | 64 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::MemberOp op) |
| 65 | { | 65 | { |
| 66 | - auto &os = emitter.ostream(); | 66 | + auto& os = emitter.ostream(); |
| 67 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 67 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 68 | os << emitter.getOrCreateName(op.getBase()); | 68 | os << emitter.getOrCreateName(op.getBase()); |
| 69 | if (isa<MemRefType>(op.getBase().getType())) | 69 | if (isa<MemRefType>(op.getBase().getType())) |
| @@ -74,9 +74,9 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Membe | |||
| 74 | return success(); | 74 | return success(); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::MemberPtrOp op) | 77 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::MemberPtrOp op) |
| 78 | { | 78 | { |
| 79 | - auto &os = emitter.ostream(); | 79 | + auto& os = emitter.ostream(); |
| 80 | 80 | ||
| 81 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 81 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 82 | os << "reinterpret_cast<"; | 82 | os << "reinterpret_cast<"; |
| @@ -92,9 +92,9 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Membe | |||
| 92 | return success(); | 92 | return success(); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::DeclarePyStructOp op) | 95 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::DeclarePyStructOp op) |
| 96 | { | 96 | { |
| 97 | - auto &os = emitter.ostream(); | 97 | + auto& os = emitter.ostream(); |
| 98 | os << "#pragma pack(push, 8)\n"; | 98 | os << "#pragma pack(push, 8)\n"; |
| 99 | auto pType = dyn_cast<emitasc::PyStructType>(op.getPystruct()); | 99 | auto pType = dyn_cast<emitasc::PyStructType>(op.getPystruct()); |
| 100 | os << "struct " << pType.getNameAttr().getValue() << " {\n"; | 100 | os << "struct " << pType.getNameAttr().getValue() << " {\n"; |
| @@ -109,9 +109,9 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Decla | |||
| 109 | return success(); | 109 | return success(); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::MemberRefOp op) | 112 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::MemberRefOp op) |
| 113 | { | 113 | { |
| 114 | - auto &os = emitter.ostream(); | 114 | + auto& os = emitter.ostream(); |
| 115 | 115 | ||
| 116 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 116 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 117 | os << "& " << emitter.getOrCreateName(op.getResult()) << " = reinterpret_cast<"; | 117 | os << "& " << emitter.getOrCreateName(op.getResult()) << " = reinterpret_cast<"; |
| @@ -127,10 +127,10 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Membe | |||
| 127 | return success(); | 127 | return success(); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::PtrOffsetOp op) | 130 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::PtrOffsetOp op) |
| 131 | { | 131 | { |
| 132 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 132 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 133 | - auto &os = emitter.ostream(); | 133 | + auto& os = emitter.ostream(); |
| 134 | os << emitter.getOrCreateName(op.getBase()) << " + "; | 134 | os << emitter.getOrCreateName(op.getBase()) << " + "; |
| 135 | if (auto offset = op.getDynamicOffset()) { | 135 | if (auto offset = op.getDynamicOffset()) { |
| 136 | os << emitter.getOrCreateName(offset); | 136 | os << emitter.getOrCreateName(offset); |
| @@ -140,9 +140,9 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::PtrOf | |||
| 140 | return success(); | 140 | return success(); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::ReinterpretCastOp op) | 143 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::ReinterpretCastOp op) |
| 144 | { | 144 | { |
| 145 | - auto &os = emitter.ostream(); | 145 | + auto& os = emitter.ostream(); |
| 146 | 146 | ||
| 147 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 147 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 148 | os << "reinterpret_cast<"; | 148 | os << "reinterpret_cast<"; |
| @@ -152,18 +152,18 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Reint | |||
| 152 | return success(); | 152 | return success(); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::SetMemberOp op) | 155 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::SetMemberOp op) |
| 156 | { | 156 | { |
| 157 | - auto &os = emitter.ostream(); | 157 | + auto& os = emitter.ostream(); |
| 158 | os << emitter.getOrCreateName(op.getBase()) << "." << op.getField() << " = " | 158 | os << emitter.getOrCreateName(op.getBase()) << "." << op.getField() << " = " |
| 159 | << emitter.getOrCreateName(op.getValue()); | 159 | << emitter.getOrCreateName(op.getValue()); |
| 160 | 160 | ||
| 161 | return success(); | 161 | return success(); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::VariableOp op) | 164 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::VariableOp op) |
| 165 | { | 165 | { |
| 166 | - auto &os = emitter.ostream(); | 166 | + auto& os = emitter.ostream(); |
| 167 | auto loc = op.getLoc(); | 167 | auto loc = op.getLoc(); |
| 168 | auto res = op.getResult(); | 168 | auto res = op.getResult(); |
| 169 | auto resType = res.getType(); | 169 | auto resType = res.getType(); |
| @@ -186,9 +186,9 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Varia | |||
| 186 | return success(); | 186 | return success(); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | -LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::VerbatimOp op) | 189 | +LogicalResult mlir::emitasc::printOperation(CodeEmitter& emitter, emitasc::VerbatimOp op) |
| 190 | { | 190 | { |
| 191 | - auto &os = emitter.ostream(); | 191 | + auto& os = emitter.ostream(); |
| 192 | auto args = op.getArgs(); | 192 | auto args = op.getArgs(); |
| 193 | auto code = op.getValue(); | 193 | auto code = op.getValue(); |
| 194 | if (args.empty()) { | 194 | if (args.empty()) { |
| @@ -199,7 +199,7 @@ LogicalResult mlir::emitasc::printOperation(CodeEmitter &emitter, emitasc::Verba | |||
| 199 | result.reserve(2 * code.size()); // the factor of 2 is used to ensure sufficient space. | 199 | result.reserve(2 * code.size()); // the factor of 2 is used to ensure sufficient space. |
| 200 | size_t i = 1; | 200 | size_t i = 1; |
| 201 | size_t rem = 0; | 201 | size_t rem = 0; |
| 202 | - const char *data = code.data(); | 202 | + const char* data = code.data(); |
| 203 | while (i < code.size()) { | 203 | while (i < code.size()) { |
| 204 | if (code[i - 1] != '$') { | 204 | if (code[i - 1] != '$') { |
| 205 | i++; | 205 | i++; |
| @@ -17,14 +17,11 @@ using namespace mlir; | |||
| 17 | 17 | ||
| 18 | using llvm::formatv; | 18 | using llvm::formatv; |
| 19 | 19 | ||
| 20 | -EmitNameStack::EmitNameStack() | 20 | +EmitNameStack::EmitNameStack() { labelInScopeCount.push(0); } |
| 21 | -{ | ||
| 22 | - labelInScopeCount.push(0); | ||
| 23 | -} | ||
| 24 | 21 | ||
| 25 | void EmitNameStack::pushScope() | 22 | void EmitNameStack::pushScope() |
| 26 | { | 23 | { |
| 27 | - for (auto &[_, scope] : valueInScopeCount) { | 24 | + for (auto& [_, scope] : valueInScopeCount) { |
| 28 | scope.push(scope.top()); | 25 | scope.push(scope.top()); |
| 29 | } | 26 | } |
| 30 | labelInScopeCount.push(labelInScopeCount.top()); | 27 | labelInScopeCount.push(labelInScopeCount.top()); |
| @@ -32,17 +29,17 @@ void EmitNameStack::pushScope() | |||
| 32 | 29 | ||
| 33 | void EmitNameStack::popScope() | 30 | void EmitNameStack::popScope() |
| 34 | { | 31 | { |
| 35 | - for (auto &[_, scope] : valueInScopeCount) { | 32 | + for (auto& [_, scope] : valueInScopeCount) { |
| 36 | scope.pop(); | 33 | scope.pop(); |
| 37 | } | 34 | } |
| 38 | labelInScopeCount.pop(); | 35 | labelInScopeCount.pop(); |
| 39 | } | 36 | } |
| 40 | 37 | ||
| 41 | -EmitNameStack::CountStack &EmitNameStack::getCountStack(const std::string &prefix) | 38 | +EmitNameStack::CountStack& EmitNameStack::getCountStack(const std::string& prefix) |
| 42 | { | 39 | { |
| 43 | auto it = valueInScopeCount.find(prefix); | 40 | auto it = valueInScopeCount.find(prefix); |
| 44 | if (it == valueInScopeCount.end()) { | 41 | if (it == valueInScopeCount.end()) { |
| 45 | - auto &stack = valueInScopeCount[prefix]; | 42 | + auto& stack = valueInScopeCount[prefix]; |
| 46 | for (size_t i = 0; i < labelInScopeCount.size(); i++) | 43 | for (size_t i = 0; i < labelInScopeCount.size(); i++) |
| 47 | stack.push(0); | 44 | stack.push(0); |
| 48 | return stack; | 45 | return stack; |
| @@ -52,7 +49,7 @@ EmitNameStack::CountStack &EmitNameStack::getCountStack(const std::string &prefi | |||
| 52 | 49 | ||
| 53 | std::string EmitNameStack::getNameForEmission(Value val) | 50 | std::string EmitNameStack::getNameForEmission(Value val) |
| 54 | { | 51 | { |
| 55 | - auto getName = [&](const std::string &prefix) -> std::string { | 52 | + auto getName = [&](const std::string& prefix) -> std::string { |
| 56 | return prefix + std::to_string(++getCountStack(prefix).top()); | 53 | return prefix + std::to_string(++getCountStack(prefix).top()); |
| 57 | }; | 54 | }; |
| 58 | auto getDefaultName = [&]() -> std::string { return getName("v"); }; | 55 | auto getDefaultName = [&]() -> std::string { return getName("v"); }; |
| @@ -17,17 +17,17 @@ constexpr uint32_t BIT_WIDTH_32 = 32; | |||
| 17 | constexpr uint32_t BIT_WIDTH_16 = 16; | 17 | constexpr uint32_t BIT_WIDTH_16 = 16; |
| 18 | } // namespace | 18 | } // namespace |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::ConstantOp constantOp) | 20 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::ConstantOp constantOp) |
| 21 | { | 21 | { |
| 22 | - Operation *operation = constantOp.getOperation(); | 22 | + Operation* operation = constantOp.getOperation(); |
| 23 | Attribute value = constantOp.getValue(); | 23 | Attribute value = constantOp.getValue(); |
| 24 | 24 | ||
| 25 | return printConstantOp(emitter, operation, value); | 25 | return printConstantOp(emitter, operation, value); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::MulUIExtendedOp op) | 28 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::MulUIExtendedOp op) |
| 29 | { | 29 | { |
| 30 | - auto &os = emitter.ostream(); | 30 | + auto& os = emitter.ostream(); |
| 31 | auto resultType = op->getResult(1).getType(); | 31 | auto resultType = op->getResult(1).getType(); |
| 32 | auto lhs = emitter.getOrCreateName(op.getLhs()); | 32 | auto lhs = emitter.getOrCreateName(op.getLhs()); |
| 33 | auto rhs = emitter.getOrCreateName(op.getRhs()); | 33 | auto rhs = emitter.getOrCreateName(op.getRhs()); |
| @@ -50,110 +50,110 @@ LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::MulUIExtendedOp | |||
| 50 | return success(); | 50 | return success(); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::CmpIOp op) | 53 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::CmpIOp op) |
| 54 | { | 54 | { |
| 55 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { | 55 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { |
| 56 | return failure(); | 56 | return failure(); |
| 57 | } | 57 | } |
| 58 | - auto &os = emitter.ostream(); | 58 | + auto& os = emitter.ostream(); |
| 59 | os << emitter.getOrCreateName(op.getLhs()) << " "; | 59 | os << emitter.getOrCreateName(op.getLhs()) << " "; |
| 60 | switch (op.getPredicate()) { | 60 | switch (op.getPredicate()) { |
| 61 | - case arith::CmpIPredicate::eq: | 61 | + case arith::CmpIPredicate::eq: |
| 62 | - os << "=="; | 62 | + os << "=="; |
| 63 | - break; | 63 | + break; |
| 64 | - case arith::CmpIPredicate::ne: | 64 | + case arith::CmpIPredicate::ne: |
| 65 | - os << "!="; | 65 | + os << "!="; |
| 66 | - break; | 66 | + break; |
| 67 | - case arith::CmpIPredicate::sle: | 67 | + case arith::CmpIPredicate::sle: |
| 68 | - case arith::CmpIPredicate::ule: | 68 | + case arith::CmpIPredicate::ule: |
| 69 | - os << "<="; | 69 | + os << "<="; |
| 70 | - break; | 70 | + break; |
| 71 | - case arith::CmpIPredicate::slt: | 71 | + case arith::CmpIPredicate::slt: |
| 72 | - case arith::CmpIPredicate::ult: | 72 | + case arith::CmpIPredicate::ult: |
| 73 | - os << "<"; | 73 | + os << "<"; |
| 74 | - break; | 74 | + break; |
| 75 | - case arith::CmpIPredicate::sge: | 75 | + case arith::CmpIPredicate::sge: |
| 76 | - case arith::CmpIPredicate::uge: | 76 | + case arith::CmpIPredicate::uge: |
| 77 | - os << ">="; | 77 | + os << ">="; |
| 78 | - break; | 78 | + break; |
| 79 | - case arith::CmpIPredicate::sgt: | 79 | + case arith::CmpIPredicate::sgt: |
| 80 | - case arith::CmpIPredicate::ugt: | 80 | + case arith::CmpIPredicate::ugt: |
| 81 | - os << ">"; | 81 | + os << ">"; |
| 82 | - break; | 82 | + break; |
| 83 | } | 83 | } |
| 84 | os << " " << emitter.getOrCreateName(op.getRhs()); | 84 | os << " " << emitter.getOrCreateName(op.getRhs()); |
| 85 | return success(); | 85 | return success(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::CmpFOp op) | 88 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::CmpFOp op) |
| 89 | { | 89 | { |
| 90 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { | 90 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { |
| 91 | return failure(); | 91 | return failure(); |
| 92 | } | 92 | } |
| 93 | - auto &os = emitter.ostream(); | 93 | + auto& os = emitter.ostream(); |
| 94 | os << emitter.getOrCreateName(op.getLhs()) << " "; | 94 | os << emitter.getOrCreateName(op.getLhs()) << " "; |
| 95 | switch (op.getPredicate()) { | 95 | switch (op.getPredicate()) { |
| 96 | - case arith::CmpFPredicate::OEQ: | 96 | + case arith::CmpFPredicate::OEQ: |
| 97 | - case arith::CmpFPredicate::UEQ: | 97 | + case arith::CmpFPredicate::UEQ: |
| 98 | - os << "=="; | 98 | + os << "=="; |
| 99 | - break; | 99 | + break; |
| 100 | - case arith::CmpFPredicate::ONE: | 100 | + case arith::CmpFPredicate::ONE: |
| 101 | - case arith::CmpFPredicate::UNE: | 101 | + case arith::CmpFPredicate::UNE: |
| 102 | - os << "!="; | 102 | + os << "!="; |
| 103 | - break; | 103 | + break; |
| 104 | - case arith::CmpFPredicate::OLE: | 104 | + case arith::CmpFPredicate::OLE: |
| 105 | - case arith::CmpFPredicate::ULE: | 105 | + case arith::CmpFPredicate::ULE: |
| 106 | - os << "<="; | 106 | + os << "<="; |
| 107 | - break; | 107 | + break; |
| 108 | - case arith::CmpFPredicate::OLT: | 108 | + case arith::CmpFPredicate::OLT: |
| 109 | - case arith::CmpFPredicate::ULT: | 109 | + case arith::CmpFPredicate::ULT: |
| 110 | - os << "<"; | 110 | + os << "<"; |
| 111 | - break; | 111 | + break; |
| 112 | - case arith::CmpFPredicate::OGE: | 112 | + case arith::CmpFPredicate::OGE: |
| 113 | - case arith::CmpFPredicate::UGE: | 113 | + case arith::CmpFPredicate::UGE: |
| 114 | - os << ">="; | 114 | + os << ">="; |
| 115 | - break; | 115 | + break; |
| 116 | - case arith::CmpFPredicate::OGT: | 116 | + case arith::CmpFPredicate::OGT: |
| 117 | - case arith::CmpFPredicate::UGT: | 117 | + case arith::CmpFPredicate::UGT: |
| 118 | - os << ">"; | 118 | + os << ">"; |
| 119 | - break; | 119 | + break; |
| 120 | - case arith::CmpFPredicate::AlwaysFalse: | 120 | + case arith::CmpFPredicate::AlwaysFalse: |
| 121 | - case arith::CmpFPredicate::AlwaysTrue: | 121 | + case arith::CmpFPredicate::AlwaysTrue: |
| 122 | - case arith::CmpFPredicate::ORD: | 122 | + case arith::CmpFPredicate::ORD: |
| 123 | - case arith::CmpFPredicate::UNO: | 123 | + case arith::CmpFPredicate::UNO: |
| 124 | - llvm_unreachable("unsupported predicate in arith.cmpf operation"); | 124 | + llvm_unreachable("unsupported predicate in arith.cmpf operation"); |
| 125 | } | 125 | } |
| 126 | os << " " << emitter.getOrCreateName(op.getRhs()); | 126 | os << " " << emitter.getOrCreateName(op.getRhs()); |
| 127 | return success(); | 127 | return success(); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::BitcastOp op) | 130 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::BitcastOp op) |
| 131 | { | 131 | { |
| 132 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 132 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 133 | - auto &os = emitter.ostream(); | 133 | + auto& os = emitter.ostream(); |
| 134 | os << "*reinterpret_cast<"; | 134 | os << "*reinterpret_cast<"; |
| 135 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 135 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 136 | os << "*>(&" << emitter.getOrCreateName(op.getIn()) << ")"; | 136 | os << "*>(&" << emitter.getOrCreateName(op.getIn()) << ")"; |
| 137 | return success(); | 137 | return success(); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::SelectOp op) | 140 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::SelectOp op) |
| 141 | { | 141 | { |
| 142 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { | 142 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { |
| 143 | return failure(); | 143 | return failure(); |
| 144 | } | 144 | } |
| 145 | - auto &os = emitter.ostream(); | 145 | + auto& os = emitter.ostream(); |
| 146 | os << emitter.getOrCreateName(op.getCondition()) << " ? " << emitter.getOrCreateName(op.getTrueValue()) << " : " | 146 | os << emitter.getOrCreateName(op.getCondition()) << " ? " << emitter.getOrCreateName(op.getTrueValue()) << " : " |
| 147 | << emitter.getOrCreateName(op.getFalseValue()); | 147 | << emitter.getOrCreateName(op.getFalseValue()); |
| 148 | return success(); | 148 | return success(); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, arith::IndexCastOp op) | 151 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, arith::IndexCastOp op) |
| 152 | { | 152 | { |
| 153 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { | 153 | if (failed(emitter.emitAssignPrefix(*op.getOperation()))) { |
| 154 | return failure(); | 154 | return failure(); |
| 155 | } | 155 | } |
| 156 | - auto &os = emitter.ostream(); | 156 | + auto& os = emitter.ostream(); |
| 157 | os << "static_cast<"; | 157 | os << "static_cast<"; |
| 158 | if (failed(emitter.emitType(op.getLoc(), op.getOut().getType()))) { | 158 | if (failed(emitter.emitType(op.getLoc(), op.getOut().getType()))) { |
| 159 | return failure(); | 159 | return failure(); |
| @@ -12,26 +12,26 @@ | |||
| 12 | 12 | ||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | 14 | ||
| 15 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, emitc::ConstantOp constantOp) | 15 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, emitc::ConstantOp constantOp) |
| 16 | { | 16 | { |
| 17 | - Operation *operation = constantOp.getOperation(); | 17 | + Operation* operation = constantOp.getOperation(); |
| 18 | Attribute value = constantOp.getValue(); | 18 | Attribute value = constantOp.getValue(); |
| 19 | 19 | ||
| 20 | return printConstantOp(emitter, operation, value); | 20 | return printConstantOp(emitter, operation, value); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, emitc::VariableOp variableOp) | 23 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, emitc::VariableOp variableOp) |
| 24 | { | 24 | { |
| 25 | - Operation *operation = variableOp.getOperation(); | 25 | + Operation* operation = variableOp.getOperation(); |
| 26 | Attribute value = variableOp.getValue(); | 26 | Attribute value = variableOp.getValue(); |
| 27 | 27 | ||
| 28 | return printConstantOp(emitter, operation, value); | 28 | return printConstantOp(emitter, operation, value); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, emitc::CastOp castOp) | 31 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, emitc::CastOp castOp) |
| 32 | { | 32 | { |
| 33 | - raw_ostream &os = emitter.ostream(); | 33 | + raw_ostream& os = emitter.ostream(); |
| 34 | - Operation &op = *castOp.getOperation(); | 34 | + Operation& op = *castOp.getOperation(); |
| 35 | 35 | ||
| 36 | if (failed(emitter.emitAssignPrefix(op))) { | 36 | if (failed(emitter.emitAssignPrefix(op))) { |
| 37 | return failure(); | 37 | return failure(); |
| @@ -46,15 +46,15 @@ LogicalResult mlir::printOperation(CodeEmitter &emitter, emitc::CastOp castOp) | |||
| 46 | return success(); | 46 | return success(); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, emitc::VerbatimOp verbatimOp) | 49 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, emitc::VerbatimOp verbatimOp) |
| 50 | { | 50 | { |
| 51 | emitter.ostream() << verbatimOp.getValue(); | 51 | emitter.ostream() << verbatimOp.getValue(); |
| 52 | return success(); | 52 | return success(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, emitc::IncludeOp includeOp) | 55 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, emitc::IncludeOp includeOp) |
| 56 | { | 56 | { |
| 57 | - raw_ostream &os = emitter.ostream(); | 57 | + raw_ostream& os = emitter.ostream(); |
| 58 | 58 | ||
| 59 | os << "#include "; | 59 | os << "#include "; |
| 60 | if (includeOp.getIsStandardInclude()) { | 60 | if (includeOp.getIsStandardInclude()) { |
| @@ -12,21 +12,21 @@ | |||
| 12 | 12 | ||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | 14 | ||
| 15 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::ConstantOp constantOp) | 15 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, func::ConstantOp constantOp) |
| 16 | { | 16 | { |
| 17 | - Operation *operation = constantOp.getOperation(); | 17 | + Operation* operation = constantOp.getOperation(); |
| 18 | Attribute value = constantOp.getValueAttr(); | 18 | Attribute value = constantOp.getValueAttr(); |
| 19 | 19 | ||
| 20 | return printConstantOp(codeEmitter, operation, value); | 20 | return printConstantOp(codeEmitter, operation, value); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::CallOp callOp) | 23 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, func::CallOp callOp) |
| 24 | { | 24 | { |
| 25 | if (failed(codeEmitter.emitAssignPrefix(*callOp.getOperation()))) { | 25 | if (failed(codeEmitter.emitAssignPrefix(*callOp.getOperation()))) { |
| 26 | return failure(); | 26 | return failure(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | - raw_ostream &os = codeEmitter.ostream(); | 29 | + raw_ostream& os = codeEmitter.ostream(); |
| 30 | os << callOp.getCallee() << "("; | 30 | os << callOp.getCallee() << "("; |
| 31 | if (failed(codeEmitter.emitOperands(*callOp.getOperation()))) { | 31 | if (failed(codeEmitter.emitOperands(*callOp.getOperation()))) { |
| 32 | return failure(); | 32 | return failure(); |
| @@ -35,22 +35,22 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::CallOp callOp | |||
| 35 | return success(); | 35 | return success(); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::ReturnOp returnOp) | 38 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, func::ReturnOp returnOp) |
| 39 | { | 39 | { |
| 40 | - raw_ostream &os = codeEmitter.ostream(); | 40 | + raw_ostream& os = codeEmitter.ostream(); |
| 41 | os << "return"; | 41 | os << "return"; |
| 42 | switch (returnOp.getNumOperands()) { | 42 | switch (returnOp.getNumOperands()) { |
| 43 | - case 0: | 43 | + case 0: |
| 44 | - return success(); | 44 | + return success(); |
| 45 | - case 1: | 45 | + case 1: |
| 46 | - os << " " << codeEmitter.getOrCreateName(returnOp.getOperand(0)); | 46 | + os << " " << codeEmitter.getOrCreateName(returnOp.getOperand(0)); |
| 47 | - return success(codeEmitter.hasValueInScope(returnOp.getOperand(0))); | 47 | + return success(codeEmitter.hasValueInScope(returnOp.getOperand(0))); |
| 48 | - default: | 48 | + default: |
| 49 | - llvm_unreachable("emission for multiple results is not implemented"); | 49 | + llvm_unreachable("emission for multiple results is not implemented"); |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::FuncOp functionOp) | 53 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, func::FuncOp functionOp) |
| 54 | { | 54 | { |
| 55 | // We need to declare variables at top if the function has multiple blocks. | 55 | // We need to declare variables at top if the function has multiple blocks. |
| 56 | if (functionOp.getBlocks().size() > 1) { | 56 | if (functionOp.getBlocks().size() > 1) { |
| @@ -58,7 +58,7 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::FuncOp functi | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | CodeEmitter::Scope scope(codeEmitter); | 60 | CodeEmitter::Scope scope(codeEmitter); |
| 61 | - auto &os = codeEmitter.ostream(); | 61 | + auto& os = codeEmitter.ostream(); |
| 62 | 62 | ||
| 63 | bool isMainFunction = functionOp->hasAttr(ascendc::attr::global); | 63 | bool isMainFunction = functionOp->hasAttr(ascendc::attr::global); |
| 64 | auto args = functionOp.getArguments(); | 64 | auto args = functionOp.getArguments(); |
| @@ -77,15 +77,15 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::FuncOp functi | |||
| 77 | os << ") {\n"; | 77 | os << ") {\n"; |
| 78 | os.indent(); | 78 | os.indent(); |
| 79 | 79 | ||
| 80 | - Region::BlockListType &blocks = functionOp.getBlocks(); | 80 | + Region::BlockListType& blocks = functionOp.getBlocks(); |
| 81 | // Create label names for basic blocks. | 81 | // Create label names for basic blocks. |
| 82 | - for (Block &block : blocks) { | 82 | + for (Block& block : blocks) { |
| 83 | codeEmitter.getOrCreateName(block); | 83 | codeEmitter.getOrCreateName(block); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | // Declare variables for basic block arguments. | 86 | // Declare variables for basic block arguments. |
| 87 | - for (Block &block : llvm::drop_begin(blocks)) { | 87 | + for (Block& block : llvm::drop_begin(blocks)) { |
| 88 | - for (BlockArgument &arg : block.getArguments()) { | 88 | + for (BlockArgument& arg : block.getArguments()) { |
| 89 | if (codeEmitter.hasValueInScope(arg)) { | 89 | if (codeEmitter.hasValueInScope(arg)) { |
| 90 | return functionOp.emitOpError(" block argument #") << arg.getArgNumber() << " is out of scope"; | 90 | return functionOp.emitOpError(" block argument #") << arg.getArgNumber() << " is out of scope"; |
| 91 | } | 91 | } |
| @@ -96,12 +96,12 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, func::FuncOp functi | |||
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | - for (Block &block : blocks) { | 99 | + for (Block& block : blocks) { |
| 100 | // Only print a label if the block has predecessors. | 100 | // Only print a label if the block has predecessors. |
| 101 | if (!block.hasNoPredecessors() && failed(codeEmitter.emitLabel(block))) { | 101 | if (!block.hasNoPredecessors() && failed(codeEmitter.emitLabel(block))) { |
| 102 | return failure(); | 102 | return failure(); |
| 103 | } | 103 | } |
| 104 | - for (Operation &op : block.getOperations()) { | 104 | + for (Operation& op : block.getOperations()) { |
| 105 | if (failed(emitOperation(codeEmitter, op, needsSemicolon(op)))) { | 105 | if (failed(emitOperation(codeEmitter, op, needsSemicolon(op)))) { |
| 106 | return failure(); | 106 | return failure(); |
| 107 | } | 107 | } |
| @@ -12,11 +12,11 @@ | |||
| 12 | 12 | ||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | 14 | ||
| 15 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, math::FmaOp op) | 15 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, math::FmaOp op) |
| 16 | { | 16 | { |
| 17 | FAIL_OR(isScalarOperation(op)); | 17 | FAIL_OR(isScalarOperation(op)); |
| 18 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 18 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| 19 | - auto &os = emitter.ostream(); | 19 | + auto& os = emitter.ostream(); |
| 20 | auto lhs = emitter.getOrCreateName(op.getOperand(0)); | 20 | auto lhs = emitter.getOrCreateName(op.getOperand(0)); |
| 21 | auto mhs = emitter.getOrCreateName(op.getOperand(1)); | 21 | auto mhs = emitter.getOrCreateName(op.getOperand(1)); |
| 22 | auto rhs = emitter.getOrCreateName(op.getOperand(2)); | 22 | auto rhs = emitter.getOrCreateName(op.getOperand(2)); |
| @@ -24,7 +24,7 @@ LogicalResult mlir::printOperation(CodeEmitter &emitter, math::FmaOp op) | |||
| 24 | return success(); | 24 | return success(); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, math::CopySignOp op) | 27 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, math::CopySignOp op) |
| 28 | { | 28 | { |
| 29 | FAIL_OR(isScalarOperation(op)); | 29 | FAIL_OR(isScalarOperation(op)); |
| 30 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); | 30 | FAIL_OR(emitter.emitAssignPrefix(*op.getOperation())); |
| @@ -12,11 +12,11 @@ | |||
| 12 | 12 | ||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | 14 | ||
| 15 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::AllocaOp op) | 15 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, memref::AllocaOp op) |
| 16 | { | 16 | { |
| 17 | auto mrType = op.getMemref().getType(); | 17 | auto mrType = op.getMemref().getType(); |
| 18 | FAIL_OR(emitter.emitType(op.getLoc(), mrType.getElementType(), op->hasAttr(ascendc::attr::emitAsUnsigned))); | 18 | FAIL_OR(emitter.emitType(op.getLoc(), mrType.getElementType(), op->hasAttr(ascendc::attr::emitAsUnsigned))); |
| 19 | - auto &os = emitter.ostream(); | 19 | + auto& os = emitter.ostream(); |
| 20 | os << " " << emitter.getOrCreateName(op.getResult()); | 20 | os << " " << emitter.getOrCreateName(op.getResult()); |
| 21 | for (int64_t dim : mrType.getShape()) { | 21 | for (int64_t dim : mrType.getShape()) { |
| 22 | os << "[" << dim << "]"; | 22 | os << "[" << dim << "]"; |
| @@ -24,12 +24,12 @@ LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::AllocaOp op) | |||
| 24 | return success(); | 24 | return success(); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::LoadOp op) | 27 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, memref::LoadOp op) |
| 28 | { | 28 | { |
| 29 | if (failed(emitter.emitAssignPrefix(*op))) { | 29 | if (failed(emitter.emitAssignPrefix(*op))) { |
| 30 | return failure(); | 30 | return failure(); |
| 31 | } | 31 | } |
| 32 | - auto &os = emitter.ostream(); | 32 | + auto& os = emitter.ostream(); |
| 33 | os << emitter.getOrCreateName(op.getMemref()); | 33 | os << emitter.getOrCreateName(op.getMemref()); |
| 34 | for (Value index : op.getIndices()) { | 34 | for (Value index : op.getIndices()) { |
| 35 | os << "[" << emitter.getOrCreateName(index) << "]"; | 35 | os << "[" << emitter.getOrCreateName(index) << "]"; |
| @@ -37,9 +37,9 @@ LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::LoadOp op) | |||
| 37 | return success(); | 37 | return success(); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::StoreOp op) | 40 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, memref::StoreOp op) |
| 41 | { | 41 | { |
| 42 | - auto &os = emitter.ostream(); | 42 | + auto& os = emitter.ostream(); |
| 43 | os << emitter.getOrCreateName(op.getMemref()); | 43 | os << emitter.getOrCreateName(op.getMemref()); |
| 44 | for (Value index : op.getIndices()) { | 44 | for (Value index : op.getIndices()) { |
| 45 | os << "[" << emitter.getOrCreateName(index) << "]"; | 45 | os << "[" << emitter.getOrCreateName(index) << "]"; |
| @@ -48,10 +48,10 @@ LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::StoreOp op) | |||
| 48 | return success(); | 48 | return success(); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | -LogicalResult mlir::printOperation(CodeEmitter &emitter, memref::CastOp op) | 51 | +LogicalResult mlir::printOperation(CodeEmitter& emitter, memref::CastOp op) |
| 52 | { | 52 | { |
| 53 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 53 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 54 | - auto &os = emitter.ostream(); | 54 | + auto& os = emitter.ostream(); |
| 55 | os << " = reinterpret_cast<"; | 55 | os << " = reinterpret_cast<"; |
| 56 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 56 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 57 | os << ">(" << emitter.getOrCreateName(op.getSource()) << ")"; | 57 | os << ">(" << emitter.getOrCreateName(op.getSource()) << ")"; |
| @@ -12,9 +12,9 @@ | |||
| 12 | 12 | ||
| 13 | using namespace mlir; | 13 | using namespace mlir; |
| 14 | 14 | ||
| 15 | -LogicalResult mlir::emitBlock(CodeEmitter &codeEmitter, Block &block) | 15 | +LogicalResult mlir::emitBlock(CodeEmitter& codeEmitter, Block& block) |
| 16 | { | 16 | { |
| 17 | - for (auto &op : block) { | 17 | + for (auto& op : block) { |
| 18 | if (isa<scf::YieldOp>(op) && op.getNumOperands() == 0) { | 18 | if (isa<scf::YieldOp>(op) && op.getNumOperands() == 0) { |
| 19 | continue; | 19 | continue; |
| 20 | } | 20 | } |
| @@ -23,9 +23,9 @@ LogicalResult mlir::emitBlock(CodeEmitter &codeEmitter, Block &block) | |||
| 23 | return success(); | 23 | return success(); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::ForOp forOp) | 26 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, scf::ForOp forOp) |
| 27 | { | 27 | { |
| 28 | - raw_indented_ostream &os = codeEmitter.ostream(); | 28 | + raw_indented_ostream& os = codeEmitter.ostream(); |
| 29 | 29 | ||
| 30 | OperandRange operands = forOp.getInitArgs(); | 30 | OperandRange operands = forOp.getInitArgs(); |
| 31 | Block::BlockArgListType iterArgs = forOp.getRegionIterArgs(); | 31 | Block::BlockArgListType iterArgs = forOp.getRegionIterArgs(); |
| @@ -56,7 +56,7 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::ForOp forOp) | |||
| 56 | os << " += " << codeEmitter.getOrCreateName(forOp.getStep()) << ") {\n"; | 56 | os << " += " << codeEmitter.getOrCreateName(forOp.getStep()) << ") {\n"; |
| 57 | os.indent(); | 57 | os.indent(); |
| 58 | 58 | ||
| 59 | - Region &forRegion = forOp.getRegion(); | 59 | + Region& forRegion = forOp.getRegion(); |
| 60 | auto regionOps = forRegion.getOps(); | 60 | auto regionOps = forRegion.getOps(); |
| 61 | 61 | ||
| 62 | // We skip the trailing yield op because this updates the result variables | 62 | // We skip the trailing yield op because this updates the result variables |
| @@ -64,7 +64,7 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::ForOp forOp) | |||
| 64 | // the end of a loop iteration and set the result variables after the for | 64 | // the end of a loop iteration and set the result variables after the for |
| 65 | // loop. | 65 | // loop. |
| 66 | for (auto it = regionOps.begin(); std::next(it) != regionOps.end(); ++it) { | 66 | for (auto it = regionOps.begin(); std::next(it) != regionOps.end(); ++it) { |
| 67 | - Operation &op = *it; | 67 | + Operation& op = *it; |
| 68 | if (failed(emitOperation(codeEmitter, op, needsSemicolon(op)))) { | 68 | if (failed(emitOperation(codeEmitter, op, needsSemicolon(op)))) { |
| 69 | return failure(); | 69 | return failure(); |
| 70 | } | 70 | } |
| @@ -85,21 +85,21 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::ForOp forOp) | |||
| 85 | llvm::interleave( | 85 | llvm::interleave( |
| 86 | llvm::zip(results, iterArgs), | 86 | llvm::zip(results, iterArgs), |
| 87 | [&](auto pair) { | 87 | [&](auto pair) { |
| 88 | - auto &[result, iterArg] = pair; | 88 | + auto& [result, iterArg] = pair; |
| 89 | os << codeEmitter.getOrCreateName(result) << " = " << codeEmitter.getOrCreateName(iterArg) << ";"; | 89 | os << codeEmitter.getOrCreateName(result) << " = " << codeEmitter.getOrCreateName(iterArg) << ";"; |
| 90 | }, | 90 | }, |
| 91 | [&] { os << "\n"; }); | 91 | [&] { os << "\n"; }); |
| 92 | return success(); | 92 | return success(); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::IfOp ifOp) | 95 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, scf::IfOp ifOp) |
| 96 | { | 96 | { |
| 97 | - auto &os = codeEmitter.ostream(); | 97 | + auto& os = codeEmitter.ostream(); |
| 98 | 98 | ||
| 99 | for (OpResult result : ifOp.getResults()) { | 99 | for (OpResult result : ifOp.getResults()) { |
| 100 | - if (failed(codeEmitter.emitVariableDeclaration(result, | 100 | + if (failed(codeEmitter.emitVariableDeclaration( |
| 101 | - /*trailingSemicolon=*/true))) | 101 | + result, |
| 102 | - { | 102 | + /*trailingSemicolon=*/true))) { |
| 103 | return failure(); | 103 | return failure(); |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| @@ -120,12 +120,12 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::IfOp ifOp) | |||
| 120 | return success(); | 120 | return success(); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::IndexSwitchOp op) | 123 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, scf::IndexSwitchOp op) |
| 124 | { | 124 | { |
| 125 | for (auto result : op.getResults()) { | 125 | for (auto result : op.getResults()) { |
| 126 | FAIL_OR(codeEmitter.emitVariableDeclaration(result, true)); | 126 | FAIL_OR(codeEmitter.emitVariableDeclaration(result, true)); |
| 127 | } | 127 | } |
| 128 | - auto &os = codeEmitter.ostream(); | 128 | + auto& os = codeEmitter.ostream(); |
| 129 | os << "switch(" << codeEmitter.getOrCreateName(op.getArg()) << ") {\n"; | 129 | os << "switch(" << codeEmitter.getOrCreateName(op.getArg()) << ") {\n"; |
| 130 | for (auto [i, value] : llvm::enumerate(op.getCases())) { | 130 | for (auto [i, value] : llvm::enumerate(op.getCases())) { |
| 131 | os << "case " << value << ": {\n"; | 131 | os << "case " << value << ": {\n"; |
| @@ -140,10 +140,10 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::IndexSwitchOp | |||
| 140 | return success(); | 140 | return success(); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::YieldOp yieldOp) | 143 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, scf::YieldOp yieldOp) |
| 144 | { | 144 | { |
| 145 | - auto &os = codeEmitter.ostream(); | 145 | + auto& os = codeEmitter.ostream(); |
| 146 | - Operation *parentOp = yieldOp->getParentOp(); | 146 | + Operation* parentOp = yieldOp->getParentOp(); |
| 147 | return interleaveWithError( | 147 | return interleaveWithError( |
| 148 | llvm::zip(parentOp->getResults(), yieldOp.getOperands()), | 148 | llvm::zip(parentOp->getResults(), yieldOp.getOperands()), |
| 149 | [&](auto pair) -> LogicalResult { | 149 | [&](auto pair) -> LogicalResult { |
| @@ -156,12 +156,12 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::YieldOp yieldO | |||
| 156 | [&] { os << "\n"; }); | 156 | [&] { os << "\n"; }); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::ConditionOp conditionOp) | 159 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, scf::ConditionOp conditionOp) |
| 160 | { | 160 | { |
| 161 | - raw_indented_ostream &os = codeEmitter.ostream(); | 161 | + raw_indented_ostream& os = codeEmitter.ostream(); |
| 162 | os << "if (!" << codeEmitter.getOrCreateName(conditionOp.getCondition()) << ") {\n"; | 162 | os << "if (!" << codeEmitter.getOrCreateName(conditionOp.getCondition()) << ") {\n"; |
| 163 | os.indent(); | 163 | os.indent(); |
| 164 | - Operation &parentOp = *conditionOp.getOperation()->getParentOp(); | 164 | + Operation& parentOp = *conditionOp.getOperation()->getParentOp(); |
| 165 | if (auto whileOp = dyn_cast<scf::WhileOp>(parentOp)) { | 165 | if (auto whileOp = dyn_cast<scf::WhileOp>(parentOp)) { |
| 166 | for (auto [result, arg] : llvm::zip(whileOp.getResults(), conditionOp.getArgs())) { | 166 | for (auto [result, arg] : llvm::zip(whileOp.getResults(), conditionOp.getArgs())) { |
| 167 | os << codeEmitter.getOrCreateName(result) << " = " << codeEmitter.getOrCreateName(arg) << ";\n"; | 167 | os << codeEmitter.getOrCreateName(result) << " = " << codeEmitter.getOrCreateName(arg) << ";\n"; |
| @@ -173,9 +173,9 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::ConditionOp co | |||
| 173 | return success(); | 173 | return success(); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | -LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::WhileOp whileOp) | 176 | +LogicalResult mlir::printOperation(CodeEmitter& codeEmitter, scf::WhileOp whileOp) |
| 177 | { | 177 | { |
| 178 | - auto &os = codeEmitter.ostream(); | 178 | + auto& os = codeEmitter.ostream(); |
| 179 | for (OpResult result : whileOp.getResults()) { | 179 | for (OpResult result : whileOp.getResults()) { |
| 180 | FAIL_OR(codeEmitter.emitVariableDeclaration(result, true)); | 180 | FAIL_OR(codeEmitter.emitVariableDeclaration(result, true)); |
| 181 | } | 181 | } |
| @@ -186,7 +186,7 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::WhileOp whileO | |||
| 186 | } | 186 | } |
| 187 | os << "while (true) {\n"; | 187 | os << "while (true) {\n"; |
| 188 | os.indent(); | 188 | os.indent(); |
| 189 | - for (Operation &op : whileOp.getBefore().getOps()) { | 189 | + for (Operation& op : whileOp.getBefore().getOps()) { |
| 190 | FAIL_OR(emitOperation(codeEmitter, op, /*trailingSemicolon=*/true)); | 190 | FAIL_OR(emitOperation(codeEmitter, op, /*trailingSemicolon=*/true)); |
| 191 | } | 191 | } |
| 192 | auto afterArgs = whileOp.getAfterArguments(); | 192 | auto afterArgs = whileOp.getAfterArguments(); |
| @@ -195,7 +195,7 @@ LogicalResult mlir::printOperation(CodeEmitter &codeEmitter, scf::WhileOp whileO | |||
| 195 | FAIL_OR(codeEmitter.emitType(whileOp.getLoc(), arg.getType())); | 195 | FAIL_OR(codeEmitter.emitType(whileOp.getLoc(), arg.getType())); |
| 196 | os << " " << codeEmitter.getOrCreateName(arg) << " = " << codeEmitter.getOrCreateName(init) << ";\n"; | 196 | os << " " << codeEmitter.getOrCreateName(arg) << " = " << codeEmitter.getOrCreateName(init) << ";\n"; |
| 197 | } | 197 | } |
| 198 | - for (Operation &op : whileOp.getAfter().getOps()) { | 198 | + for (Operation& op : whileOp.getAfter().getOps()) { |
| 199 | if (auto yield = dyn_cast<scf::YieldOp>(op)) { | 199 | if (auto yield = dyn_cast<scf::YieldOp>(op)) { |
| 200 | for (auto [result, operand] : llvm::zip(beforeArgs, yield.getOperands())) | 200 | for (auto [result, operand] : llvm::zip(beforeArgs, yield.getOperands())) |
| 201 | os << codeEmitter.getOrCreateName(result) << " = " << codeEmitter.getOrCreateName(operand) << ";\n"; | 201 | os << codeEmitter.getOrCreateName(result) << " = " << codeEmitter.getOrCreateName(operand) << ";\n"; |
| @@ -17,10 +17,10 @@ using namespace mlir::ascendc; | |||
| 17 | // Buffer operations (TBuf) | 17 | // Buffer operations (TBuf) |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TBufGetTensorOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TBufGetTensorOp op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | os << " = " << emitter.getOrCreateName(op.getBuffer()) << "." << op.getAPIName() << "<"; | 24 | os << " = " << emitter.getOrCreateName(op.getBuffer()) << "." << op.getAPIName() << "<"; |
| 25 | Type elType = op.getTensor().getType().getElementType(); | 25 | Type elType = op.getTensor().getType().getElementType(); |
| 26 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 26 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -32,10 +32,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TBufG | |||
| 32 | return success(); | 32 | return success(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TBufGetWithOffsetOp op) | 35 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TBufGetWithOffsetOp op) |
| 36 | { | 36 | { |
| 37 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 37 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 38 | - auto &os = emitter.ostream(); | 38 | + auto& os = emitter.ostream(); |
| 39 | os << " = " << emitter.getOrCreateName(op.getBuffer()) << "." << op.getAPIName() << "<"; | 39 | os << " = " << emitter.getOrCreateName(op.getBuffer()) << "." << op.getAPIName() << "<"; |
| 40 | Type elType = op.getTensor().getType().getElementType(); | 40 | Type elType = op.getTensor().getType().getElementType(); |
| 41 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 41 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -17,10 +17,10 @@ using namespace mlir::ascendc; | |||
| 17 | // TQueQind operations | 17 | // TQueQind operations |
| 18 | //===----------------------------------------------------------------------===// | 18 | //===----------------------------------------------------------------------===// |
| 19 | 19 | ||
| 20 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueBindAllocTensorOp op) | 20 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TQueBindAllocTensorOp op) |
| 21 | { | 21 | { |
| 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 22 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 23 | - auto &os = emitter.ostream(); | 23 | + auto& os = emitter.ostream(); |
| 24 | os << " = " << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; | 24 | os << " = " << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; |
| 25 | Type elType = op.getTensor().getType().getElementType(); | 25 | Type elType = op.getTensor().getType().getElementType(); |
| 26 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 26 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -28,9 +28,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueB | |||
| 28 | return success(); | 28 | return success(); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueBindAllocTensorInPlaceOp op) | 31 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TQueBindAllocTensorInPlaceOp op) |
| 32 | { | 32 | { |
| 33 | - auto &os = emitter.ostream(); | 33 | + auto& os = emitter.ostream(); |
| 34 | os << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; | 34 | os << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; |
| 35 | Type elType = op.getTensor().getType().getElementType(); | 35 | Type elType = op.getTensor().getType().getElementType(); |
| 36 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 36 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -38,10 +38,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueB | |||
| 38 | return success(); | 38 | return success(); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueBindDequeTensorOp op) | 41 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TQueBindDequeTensorOp op) |
| 42 | { | 42 | { |
| 43 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 43 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 44 | - auto &os = emitter.ostream(); | 44 | + auto& os = emitter.ostream(); |
| 45 | os << " = " << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; | 45 | os << " = " << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; |
| 46 | Type elType = op.getTensor().getType().getElementType(); | 46 | Type elType = op.getTensor().getType().getElementType(); |
| 47 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 47 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -49,9 +49,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueB | |||
| 49 | return success(); | 49 | return success(); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueBindDequeTensorInPlaceOp op) | 52 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TQueBindDequeTensorInPlaceOp op) |
| 53 | { | 53 | { |
| 54 | - auto &os = emitter.ostream(); | 54 | + auto& os = emitter.ostream(); |
| 55 | os << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; | 55 | os << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; |
| 56 | Type elType = op.getTensor().getType().getElementType(); | 56 | Type elType = op.getTensor().getType().getElementType(); |
| 57 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); | 57 | FAIL_OR(emitter.emitType(op.getLoc(), elType)); |
| @@ -59,10 +59,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueB | |||
| 59 | return success(); | 59 | return success(); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueBindDequeTensorPosOp op) | 62 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TQueBindDequeTensorPosOp op) |
| 63 | { | 63 | { |
| 64 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); | 64 | FAIL_OR(emitter.emitVariableDeclaration(op->getResult(0), false)); |
| 65 | - auto &os = emitter.ostream(); | 65 | + auto& os = emitter.ostream(); |
| 66 | os << " = " << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; | 66 | os << " = " << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; |
| 67 | CodeEmitter::emitTPosition(os, op.getSrcUserPos()); | 67 | CodeEmitter::emitTPosition(os, op.getSrcUserPos()); |
| 68 | os << ", "; | 68 | os << ", "; |
| @@ -74,9 +74,9 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueB | |||
| 74 | return success(); | 74 | return success(); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueBindEnqueTensorPosOp op) | 77 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::TQueBindEnqueTensorPosOp op) |
| 78 | { | 78 | { |
| 79 | - auto &os = emitter.ostream(); | 79 | + auto& os = emitter.ostream(); |
| 80 | os << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; | 80 | os << emitter.getOrCreateName(op.getQueue()) << "." << op.getAPIName() << "<"; |
| 81 | CodeEmitter::emitTPosition(os, op.getSrcUserPos()); | 81 | CodeEmitter::emitTPosition(os, op.getSrcUserPos()); |
| 82 | os << ", "; | 82 | os << ", "; |
| @@ -85,10 +85,10 @@ LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::TQueB | |||
| 85 | return success(); | 85 | return success(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | -LogicalResult mlir::ascendc::printOperation(CodeEmitter &emitter, ascendc::ToQueBindOp op) | 88 | +LogicalResult mlir::ascendc::printOperation(CodeEmitter& emitter, ascendc::ToQueBindOp op) |
| 89 | { | 89 | { |
| 90 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); | 90 | FAIL_OR(emitter.emitType(op.getLoc(), op.getType())); |
| 91 | - auto &os = emitter.ostream(); | 91 | + auto& os = emitter.ostream(); |
| 92 | os << "& " << emitter.getOrCreateName(op.getResult()) << " = " << emitter.getOrCreateName(op.getOperand()); | 92 | os << "& " << emitter.getOrCreateName(op.getResult()) << " = " << emitter.getOrCreateName(op.getOperand()); |
| 93 | return success(); | 93 | return success(); |
| 94 | } | 94 | } |
| @@ -55,11 +55,11 @@ | |||
| 55 | using namespace mlir; | 55 | using namespace mlir; |
| 56 | 56 | ||
| 57 | namespace { | 57 | namespace { |
| 58 | -LogicalResult printOperation(CodeEmitter &emitter, ModuleOp moduleOp) | 58 | +LogicalResult printOperation(CodeEmitter& emitter, ModuleOp moduleOp) |
| 59 | { | 59 | { |
| 60 | CodeEmitter::Scope scope(emitter); | 60 | CodeEmitter::Scope scope(emitter); |
| 61 | 61 | ||
| 62 | - for (Operation &op : moduleOp) { | 62 | + for (Operation& op : moduleOp) { |
| 63 | if (failed(emitOperation(emitter, op, /*trailingSemicolon=*/false))) { | 63 | if (failed(emitOperation(emitter, op, /*trailingSemicolon=*/false))) { |
| 64 | return failure(); | 64 | return failure(); |
| 65 | } | 65 | } |
| @@ -67,10 +67,7 @@ LogicalResult printOperation(CodeEmitter &emitter, ModuleOp moduleOp) | |||
| 67 | return success(); | 67 | return success(); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | -LogicalResult printOperation(CodeEmitter &emitter, ascendc::NoOp op) | 70 | +LogicalResult printOperation(CodeEmitter& emitter, ascendc::NoOp op) { return success(); } |
| 71 | -{ | ||
| 72 | - return success(); | ||
| 73 | -} | ||
| 74 | 71 | ||
| 75 | using PrintableOpTypes = std::tuple< | 72 | using PrintableOpTypes = std::tuple< |
| 76 | // Builtin ops | 73 | // Builtin ops |
| @@ -133,14 +130,13 @@ using PrintableOpTypes = std::tuple< | |||
| 133 | // Dump tensor operations | 130 | // Dump tensor operations |
| 134 | ascendc::PrintfOp, | 131 | ascendc::PrintfOp, |
| 135 | // TensorDesc operations | 132 | // TensorDesc operations |
| 136 | - ascendc::TensorDescOp, ascendc::TensorDescSetShapeAddrOp, | 133 | + ascendc::TensorDescOp, ascendc::TensorDescSetShapeAddrOp, |
| 137 | // ListTensorDesc operations | 134 | // ListTensorDesc operations |
| 138 | ascendc::ListTensorDescV2Op, ascendc::ListTensorDescGetDataPtrOp, | 135 | ascendc::ListTensorDescV2Op, ascendc::ListTensorDescGetDataPtrOp, |
| 139 | // Other operations | 136 | // Other operations |
| 140 | ascendc::ConstructOp, ascendc::AscendIsAICOp, ascendc::AscendIsAIVOp, LLVM::UndefOp, ascendc::FftsCrossCoreSyncOp, | 137 | ascendc::ConstructOp, ascendc::AscendIsAICOp, ascendc::AscendIsAIVOp, LLVM::UndefOp, ascendc::FftsCrossCoreSyncOp, |
| 141 | - ascendc::SetFftsBaseAddrOp, ascendc::PopStackBufferOp, | 138 | + ascendc::SetFftsBaseAddrOp, ascendc::PopStackBufferOp, ascendc::GetMrgSortResultOp, ascendc::MrgSortOp, |
| 142 | - ascendc::GetMrgSortResultOp, ascendc::MrgSortOp, ascendc::SortOp, | 139 | + ascendc::SortOp, ascendc::FixpipeOp, ascendc::FixpipeWithWorkspaceOp, ascendc::GetStoreAtomicConfigOp, |
| 143 | - ascendc::FixpipeOp, ascendc::FixpipeWithWorkspaceOp, ascendc::GetStoreAtomicConfigOp, | ||
| 144 | // Scalar operations | 140 | // Scalar operations |
| 145 | ascendc::ScalarCastOp, | 141 | ascendc::ScalarCastOp, |
| 146 | // Swap and workspace operations | 142 | // Swap and workspace operations |
| @@ -190,8 +186,8 @@ using PrintableOpTypes = std::tuple< | |||
| 190 | // VectorTernaryScalarL2Op | 186 | // VectorTernaryScalarL2Op |
| 191 | ascendc::AxpyL2Op, | 187 | ascendc::AxpyL2Op, |
| 192 | // VecCmpSel (Select) operations | 188 | // VecCmpSel (Select) operations |
| 193 | - ascendc::CompareL1Op, ascendc::CompareRL1Op, ascendc::CompareScalarL1Op, | 189 | + ascendc::CompareL1Op, ascendc::CompareRL1Op, ascendc::CompareScalarL1Op, ascendc::SelectScalarL1Op, |
| 194 | - ascendc::SelectScalarL1Op, ascendc::SelectL1Op, | 190 | + ascendc::SelectL1Op, |
| 195 | // Duplicate operations | 191 | // Duplicate operations |
| 196 | ascendc::DuplicateL0Op, ascendc::DuplicateL1Op, ascendc::DuplicateL2Op, | 192 | ascendc::DuplicateL0Op, ascendc::DuplicateL1Op, ascendc::DuplicateL2Op, |
| 197 | // Vector gather operations | 193 | // Vector gather operations |
| @@ -242,16 +238,16 @@ using PrintableOpTypes = std::tuple< | |||
| 242 | ascendc::NoOp>; | 238 | ascendc::NoOp>; |
| 243 | 239 | ||
| 244 | template <typename TypeSwitchT, size_t I, typename TupleT, typename CallbackT> | 240 | template <typename TypeSwitchT, size_t I, typename TupleT, typename CallbackT> |
| 245 | -void addCaseByIndex(TypeSwitchT &typeSwitch, CallbackT &&callback) | 241 | +void addCaseByIndex(TypeSwitchT& typeSwitch, CallbackT&& callback) |
| 246 | { | 242 | { |
| 247 | using ElemType = std::tuple_element_t<I, TupleT>; | 243 | using ElemType = std::tuple_element_t<I, TupleT>; |
| 248 | typeSwitch.template Case<ElemType>([&callback](auto op) { return callback(op); }); | 244 | typeSwitch.template Case<ElemType>([&callback](auto op) { return callback(op); }); |
| 249 | } | 245 | } |
| 250 | 246 | ||
| 251 | template <typename TypeSwitchT, typename TupleT, typename CallbackT, size_t... Is> | 247 | template <typename TypeSwitchT, typename TupleT, typename CallbackT, size_t... Is> |
| 252 | -void addCasesImpl(TypeSwitchT &typeSwitch, TupleT &&, CallbackT &&callback, std::index_sequence<Is...>) | 248 | +void addCasesImpl(TypeSwitchT& typeSwitch, TupleT&&, CallbackT&& callback, std::index_sequence<Is...>) |
| 253 | { | 249 | { |
| 254 | - using addCaseFunc = void (*)(TypeSwitchT &, CallbackT &); | 250 | + using addCaseFunc = void (*)(TypeSwitchT&, CallbackT&); |
| 255 | static addCaseFunc caseFunc[] = {&addCaseByIndex<TypeSwitchT, Is, std::decay_t<TupleT>, CallbackT>...}; | 251 | static addCaseFunc caseFunc[] = {&addCaseByIndex<TypeSwitchT, Is, std::decay_t<TupleT>, CallbackT>...}; |
| 256 | for (size_t i = 0; i < sizeof...(Is); ++i) { | 252 | for (size_t i = 0; i < sizeof...(Is); ++i) { |
| 257 | caseFunc[i](typeSwitch, callback); | 253 | caseFunc[i](typeSwitch, callback); |
| @@ -259,10 +255,10 @@ void addCasesImpl(TypeSwitchT &typeSwitch, TupleT &&, CallbackT &&callback, std: | |||
| 259 | } | 255 | } |
| 260 | 256 | ||
| 261 | template <typename TypeSwitchT, typename TupleT, typename CallbackT> | 257 | template <typename TypeSwitchT, typename TupleT, typename CallbackT> |
| 262 | -void addCases(TypeSwitchT &typeSwitch, const TupleT &tuple, const CallbackT &callback) | 258 | +void addCases(TypeSwitchT& typeSwitch, const TupleT& tuple, const CallbackT& callback) |
| 263 | { | 259 | { |
| 264 | constexpr auto size = std::tuple_size_v<std::decay_t<TupleT>>; | 260 | constexpr auto size = std::tuple_size_v<std::decay_t<TupleT>>; |
| 265 | - addCasesImpl(typeSwitch, tuple, callback, std::make_index_sequence<size> {}); | 261 | + addCasesImpl(typeSwitch, tuple, callback, std::make_index_sequence<size>{}); |
| 266 | } | 262 | } |
| 267 | } // namespace | 263 | } // namespace |
| 268 | 264 | ||
| @@ -272,7 +268,7 @@ namespace ascendc { | |||
| 272 | 268 | ||
| 273 | } // namespace ascendc | 269 | } // namespace ascendc |
| 274 | } // namespace mlir | 270 | } // namespace mlir |
| 275 | -LogicalResult emitOperation(CodeEmitter &emitter, Operation &op, bool trailingSemicolon) | 271 | +LogicalResult emitOperation(CodeEmitter& emitter, Operation& op, bool trailingSemicolon) |
| 276 | { | 272 | { |
| 277 | if (auto apiOp = dyn_cast<ascendc::APIOp>(op)) { | 273 | if (auto apiOp = dyn_cast<ascendc::APIOp>(op)) { |
| 278 | auto comment = apiOp.getComment(); | 274 | auto comment = apiOp.getComment(); |
| @@ -280,15 +276,15 @@ LogicalResult emitOperation(CodeEmitter &emitter, Operation &op, bool trailingSe | |||
| 280 | emitter.ostream() << "// " << comment << "\n"; | 276 | emitter.ostream() << "// " << comment << "\n"; |
| 281 | } | 277 | } |
| 282 | } | 278 | } |
| 283 | - llvm::TypeSwitch<Operation *, LogicalResult> typeSwitch(&op); | 279 | + llvm::TypeSwitch<Operation*, LogicalResult> typeSwitch(&op); |
| 284 | auto callback = [&](auto opNode) -> LogicalResult { | 280 | auto callback = [&](auto opNode) -> LogicalResult { |
| 285 | using OpType = std::decay_t<decltype(opNode)>; | 281 | using OpType = std::decay_t<decltype(opNode)>; |
| 286 | return printOperation(emitter, opNode); | 282 | return printOperation(emitter, opNode); |
| 287 | }; | 283 | }; |
| 288 | 284 | ||
| 289 | - addCases(typeSwitch, PrintableOpTypes {}, callback); | 285 | + addCases(typeSwitch, PrintableOpTypes{}, callback); |
| 290 | LogicalResult status = typeSwitch.Default( | 286 | LogicalResult status = typeSwitch.Default( |
| 291 | - [&](Operation *op) -> LogicalResult { return op->emitOpError("unable to find printer for op"); }); | 287 | + [&](Operation* op) -> LogicalResult { return op->emitOpError("unable to find printer for op"); }); |
| 292 | if (failed(status)) { | 288 | if (failed(status)) { |
| 293 | return failure(); | 289 | return failure(); |
| 294 | } | 290 | } |
| @@ -296,7 +292,7 @@ LogicalResult emitOperation(CodeEmitter &emitter, Operation &op, bool trailingSe | |||
| 296 | return success(); | 292 | return success(); |
| 297 | } | 293 | } |
| 298 | 294 | ||
| 299 | -LogicalResult mlir::translateToAscendC(Operation *op, raw_ostream &os) | 295 | +LogicalResult mlir::translateToAscendC(Operation* op, raw_ostream& os) |
| 300 | { | 296 | { |
| 301 | CodeEmitter emitter(os); | 297 | CodeEmitter emitter(os); |
| 302 | return emitOperation(emitter, *op, /*trailingSemicolon=*/false); | 298 | return emitOperation(emitter, *op, /*trailingSemicolon=*/false); |
| @@ -18,7 +18,7 @@ namespace py = pybind11; | |||
| 18 | 18 | ||
| 19 | namespace pybind11 { | 19 | namespace pybind11 { |
| 20 | namespace asc { | 20 | namespace asc { |
| 21 | -void pyasc_init_enums(py::module &m) | 21 | +void pyasc_init_enums(py::module& m) |
| 22 | { | 22 | { |
| 23 | using namespace matmul_tiling; | 23 | using namespace matmul_tiling; |
| 24 | 24 | ||
| @@ -19,15 +19,16 @@ namespace py = pybind11; | |||
| 19 | 19 | ||
| 20 | namespace pybind11 { | 20 | namespace pybind11 { |
| 21 | namespace asc { | 21 | namespace asc { |
| 22 | -void pyasc_init_matmul_api_tiling(py::module &m) | 22 | +void pyasc_init_matmul_api_tiling(py::module& m) |
| 23 | { | 23 | { |
| 24 | using namespace matmul_tiling; | 24 | using namespace matmul_tiling; |
| 25 | 25 | ||
| 26 | // MatmulConfigParams struct | 26 | // MatmulConfigParams struct |
| 27 | py::class_<MatmulConfigParams>(m, "MatmulConfigParams", py::module_local()) | 27 | py::class_<MatmulConfigParams>(m, "MatmulConfigParams", py::module_local()) |
| 28 | - .def(py::init<int32_t, bool, ScheduleType, MatrixTraverse, bool>(), "mm_config_type"_a = 1, | 28 | + .def( |
| 29 | - "enable_l1_cache_ub"_a = false, "schedule_type"_a = ScheduleType::INNER_PRODUCT, | 29 | + py::init<int32_t, bool, ScheduleType, MatrixTraverse, bool>(), "mm_config_type"_a = 1, |
| 30 | - "traverse"_a = MatrixTraverse::NOSET, "en_vec_nd2nz"_a = false) | 30 | + "enable_l1_cache_ub"_a = false, "schedule_type"_a = ScheduleType::INNER_PRODUCT, |
| 31 | + "traverse"_a = MatrixTraverse::NOSET, "en_vec_nd2nz"_a = false) | ||
| 31 | .def_readwrite("mm_config_type", &MatmulConfigParams::mmConfigType) | 32 | .def_readwrite("mm_config_type", &MatmulConfigParams::mmConfigType) |
| 32 | .def_readwrite("enable_l1_cache_ub", &MatmulConfigParams::enableL1CacheUB) | 33 | .def_readwrite("enable_l1_cache_ub", &MatmulConfigParams::enableL1CacheUB) |
| 33 | .def_readwrite("schedule_type", &MatmulConfigParams::scheduleType) | 34 | .def_readwrite("schedule_type", &MatmulConfigParams::scheduleType) |
| @@ -38,7 +39,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 38 | py::class_<MatmulApiTilingBase>(m, "MatmulApiTilingBase", py::module_local()) | 39 | py::class_<MatmulApiTilingBase>(m, "MatmulApiTilingBase", py::module_local()) |
| 39 | // Enable methods | 40 | // Enable methods |
| 40 | .def( | 41 | .def( |
| 41 | - "enable_bias", [](MatmulApiTilingBase &self, bool isBiasIn) { return self.EnableBias(isBiasIn); }, | 42 | + "enable_bias", [](MatmulApiTilingBase& self, bool isBiasIn) { return self.EnableBias(isBiasIn); }, |
| 42 | "is_bias_in"_a = false, | 43 | "is_bias_in"_a = false, |
| 43 | R"doc( | 44 | R"doc( |
| 44 | 设置Bias是否参与运算,设置的信息必须与Kernel侧保持一致。 | 45 | 设置Bias是否参与运算,设置的信息必须与Kernel侧保持一致。 |
| @@ -77,7 +78,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 77 | )doc") | 78 | )doc") |
| 78 | // Get methods | 79 | // Get methods |
| 79 | .def( | 80 | .def( |
| 80 | - "get_base_k", [](MatmulApiTilingBase &self) { return self.GetBaseK(); }, | 81 | + "get_base_k", [](MatmulApiTilingBase& self) { return self.GetBaseK(); }, |
| 81 | R"doc( | 82 | R"doc( |
| 82 | 获取Tiling计算得到的baseK值。 | 83 | 获取Tiling计算得到的baseK值。 |
| 83 | 84 | ||
| @@ -115,7 +116,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 115 | bask_k = tiling.get_base_k() | 116 | bask_k = tiling.get_base_k() |
| 116 | )doc") | 117 | )doc") |
| 117 | .def( | 118 | .def( |
| 118 | - "get_base_m", [](MatmulApiTilingBase &self) { return self.GetBaseM(); }, | 119 | + "get_base_m", [](MatmulApiTilingBase& self) { return self.GetBaseM(); }, |
| 119 | R"doc( | 120 | R"doc( |
| 120 | 获取Tiling计算得到的baseM值。 | 121 | 获取Tiling计算得到的baseM值。 |
| 121 | 122 | ||
| @@ -153,7 +154,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 153 | bask_m = tiling.get_base_m() | 154 | bask_m = tiling.get_base_m() |
| 154 | )doc") | 155 | )doc") |
| 155 | .def( | 156 | .def( |
| 156 | - "get_base_n", [](MatmulApiTilingBase &self) { return self.GetBaseN(); }, | 157 | + "get_base_n", [](MatmulApiTilingBase& self) { return self.GetBaseN(); }, |
| 157 | R"doc( | 158 | R"doc( |
| 158 | 获取Tiling计算得到的baseN值。 | 159 | 获取Tiling计算得到的baseN值。 |
| 159 | 160 | ||
| @@ -192,11 +193,11 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 192 | )doc") | 193 | )doc") |
| 193 | .def( | 194 | .def( |
| 194 | "get_tiling", | 195 | "get_tiling", |
| 195 | - [](MatmulApiTilingBase &self, py::object &tiling) { | 196 | + [](MatmulApiTilingBase& self, py::object& tiling) { |
| 196 | py::object method = tiling.attr("addressof"); | 197 | py::object method = tiling.attr("addressof"); |
| 197 | py::object result = method(); | 198 | py::object result = method(); |
| 198 | auto cpp_int = py::cast<size_t>(result); | 199 | auto cpp_int = py::cast<size_t>(result); |
| 199 | - auto *tiling_new = reinterpret_cast<TCubeTiling *>(cpp_int); | 200 | + auto* tiling_new = reinterpret_cast<TCubeTiling*>(cpp_int); |
| 200 | return self.GetTiling(*tiling_new); | 201 | return self.GetTiling(*tiling_new); |
| 201 | }, | 202 | }, |
| 202 | "tiling"_a, | 203 | "tiling"_a, |
| @@ -243,7 +244,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 243 | // Set methods | 244 | // Set methods |
| 244 | .def( | 245 | .def( |
| 245 | "set_a_layout", | 246 | "set_a_layout", |
| 246 | - [](MatmulApiTilingBase &self, int32_t b, int32_t s, int32_t n, int32_t g, int32_t d) { | 247 | + [](MatmulApiTilingBase& self, int32_t b, int32_t s, int32_t n, int32_t g, int32_t d) { |
| 247 | return self.SetALayout(b, s, n, g, d); | 248 | return self.SetALayout(b, s, n, g, d); |
| 248 | }, | 249 | }, |
| 249 | "b"_a, "s"_a, "n"_a, "g"_a, "d"_a, | 250 | "b"_a, "s"_a, "n"_a, "g"_a, "d"_a, |
| @@ -315,7 +316,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 315 | )doc") | 316 | )doc") |
| 316 | .def( | 317 | .def( |
| 317 | "set_a_type", | 318 | "set_a_type", |
| 318 | - [](MatmulApiTilingBase &self, TPosition pos, CubeFormat type, DataType dataType, bool isTrans) { | 319 | + [](MatmulApiTilingBase& self, TPosition pos, CubeFormat type, DataType dataType, bool isTrans) { |
| 319 | return self.SetAType(pos, type, dataType, isTrans); | 320 | return self.SetAType(pos, type, dataType, isTrans); |
| 320 | }, | 321 | }, |
| 321 | "pos"_a, "type"_a, "data_type"_a, "is_trans"_a, | 322 | "pos"_a, "type"_a, "data_type"_a, "is_trans"_a, |
| @@ -360,7 +361,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 360 | )doc") | 361 | )doc") |
| 361 | .def( | 362 | .def( |
| 362 | "set_b_layout", | 363 | "set_b_layout", |
| 363 | - [](MatmulApiTilingBase &self, int32_t b, int32_t s, int32_t n, int32_t g, int32_t d) { | 364 | + [](MatmulApiTilingBase& self, int32_t b, int32_t s, int32_t n, int32_t g, int32_t d) { |
| 364 | return self.SetBLayout(b, s, n, g, d); | 365 | return self.SetBLayout(b, s, n, g, d); |
| 365 | }, | 366 | }, |
| 366 | "b"_a, "s"_a, "n"_a, "g"_a, "d"_a, | 367 | "b"_a, "s"_a, "n"_a, "g"_a, "d"_a, |
| @@ -432,7 +433,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 432 | )doc") | 433 | )doc") |
| 433 | .def( | 434 | .def( |
| 434 | "set_b_type", | 435 | "set_b_type", |
| 435 | - [](MatmulApiTilingBase &self, TPosition pos, CubeFormat type, DataType dataType, bool isTrans) { | 436 | + [](MatmulApiTilingBase& self, TPosition pos, CubeFormat type, DataType dataType, bool isTrans) { |
| 436 | return self.SetBType(pos, type, dataType, isTrans); | 437 | return self.SetBType(pos, type, dataType, isTrans); |
| 437 | }, | 438 | }, |
| 438 | "pos"_a, "type"_a, "data_type"_a, "is_trans"_a, | 439 | "pos"_a, "type"_a, "data_type"_a, "is_trans"_a, |
| @@ -477,7 +478,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 477 | )doc") | 478 | )doc") |
| 478 | .def( | 479 | .def( |
| 479 | "set_batch_info_for_normal", | 480 | "set_batch_info_for_normal", |
| 480 | - [](MatmulApiTilingBase &self, int32_t batchA, int32_t batchB, int32_t m, int32_t n, int32_t k) { | 481 | + [](MatmulApiTilingBase& self, int32_t batchA, int32_t batchB, int32_t m, int32_t n, int32_t k) { |
| 481 | return self.SetBatchInfoForNormal(batchA, batchB, m, n, k); | 482 | return self.SetBatchInfoForNormal(batchA, batchB, m, n, k); |
| 482 | }, | 483 | }, |
| 483 | "batch_a"_a, "batch_b"_a, "m"_a, "n"_a, "k"_a, | 484 | "batch_a"_a, "batch_b"_a, "m"_a, "n"_a, "k"_a, |
| @@ -533,7 +534,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 533 | ret = tiling.get_tiling(tiling_data) | 534 | ret = tiling.get_tiling(tiling_data) |
| 534 | )doc") | 535 | )doc") |
| 535 | .def( | 536 | .def( |
| 536 | - "set_batch_num", [](MatmulApiTilingBase &self, int32_t batch) { return self.SetBatchNum(batch); }, | 537 | + "set_batch_num", [](MatmulApiTilingBase& self, int32_t batch) { return self.SetBatchNum(batch); }, |
| 537 | "batch"_a, | 538 | "batch"_a, |
| 538 | R"doc( | 539 | R"doc( |
| 539 | 设置多Batch计算的最大Batch数,最大Batch数为A矩阵batchA和B矩阵batchB中的最大值。 | 540 | 设置多Batch计算的最大Batch数,最大Batch数为A矩阵batchA和B矩阵batchB中的最大值。 |
| @@ -599,7 +600,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 599 | )doc") | 600 | )doc") |
| 600 | .def( | 601 | .def( |
| 601 | "set_bias_type", | 602 | "set_bias_type", |
| 602 | - [](MatmulApiTilingBase &self, TPosition pos, CubeFormat type, DataType dataType) { | 603 | + [](MatmulApiTilingBase& self, TPosition pos, CubeFormat type, DataType dataType) { |
| 603 | return self.SetBiasType(pos, type, dataType); | 604 | return self.SetBiasType(pos, type, dataType); |
| 604 | }, | 605 | }, |
| 605 | "pos"_a, "type"_a, "data_type"_a, | 606 | "pos"_a, "type"_a, "data_type"_a, |
| @@ -642,7 +643,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 642 | )doc") | 643 | )doc") |
| 643 | .def( | 644 | .def( |
| 644 | "set_buffer_space", | 645 | "set_buffer_space", |
| 645 | - [](MatmulApiTilingBase &self, int32_t l1Size, int32_t l0CSize, int32_t ubSize, int32_t btSize) { | 646 | + [](MatmulApiTilingBase& self, int32_t l1Size, int32_t l0CSize, int32_t ubSize, int32_t btSize) { |
| 646 | return self.SetBufferSpace(l1Size, l0CSize, ubSize, btSize); | 647 | return self.SetBufferSpace(l1Size, l0CSize, ubSize, btSize); |
| 647 | }, | 648 | }, |
| 648 | "l1_size"_a = -1, "l0_c_size"_a = -1, "ub_size"_a = -1, "bt_size"_a = -1, | 649 | "l1_size"_a = -1, "l0_c_size"_a = -1, "ub_size"_a = -1, "bt_size"_a = -1, |
| @@ -687,7 +688,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 687 | )doc") | 688 | )doc") |
| 688 | .def( | 689 | .def( |
| 689 | "set_c_layout", | 690 | "set_c_layout", |
| 690 | - [](MatmulApiTilingBase &self, int32_t b, int32_t s, int32_t n, int32_t g, int32_t d) { | 691 | + [](MatmulApiTilingBase& self, int32_t b, int32_t s, int32_t n, int32_t g, int32_t d) { |
| 691 | return self.SetCLayout(b, s, n, g, d); | 692 | return self.SetCLayout(b, s, n, g, d); |
| 692 | }, | 693 | }, |
| 693 | "b"_a, "s"_a, "n"_a, "g"_a, "d"_a, | 694 | "b"_a, "s"_a, "n"_a, "g"_a, "d"_a, |
| @@ -759,7 +760,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 759 | )doc") | 760 | )doc") |
| 760 | .def( | 761 | .def( |
| 761 | "set_c_type", | 762 | "set_c_type", |
| 762 | - [](MatmulApiTilingBase &self, TPosition pos, CubeFormat type, DataType dataType) { | 763 | + [](MatmulApiTilingBase& self, TPosition pos, CubeFormat type, DataType dataType) { |
| 763 | return self.SetCType(pos, type, dataType); | 764 | return self.SetCType(pos, type, dataType); |
| 764 | }, | 765 | }, |
| 765 | "pos"_a, "type"_a, "data_type"_a, | 766 | "pos"_a, "type"_a, "data_type"_a, |
| @@ -804,7 +805,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 804 | )doc") | 805 | )doc") |
| 805 | .def( | 806 | .def( |
| 806 | "set_dequant_type", | 807 | "set_dequant_type", |
| 807 | - [](MatmulApiTilingBase &self, DequantType dequantType) { return self.SetDequantType(dequantType); }, | 808 | + [](MatmulApiTilingBase& self, DequantType dequantType) { return self.SetDequantType(dequantType); }, |
| 808 | "dequant_type"_a, | 809 | "dequant_type"_a, |
| 809 | R"doc( | 810 | R"doc( |
| 810 | 该接口用于设置量化或反量化的模式。 | 811 | 该接口用于设置量化或反量化的模式。 |
| @@ -849,7 +850,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 849 | )doc") | 850 | )doc") |
| 850 | .def( | 851 | .def( |
| 851 | "set_double_buffer", | 852 | "set_double_buffer", |
| 852 | - [](MatmulApiTilingBase &self, bool a, bool b, bool c, bool bias, bool transND2NZ, bool transNZ2ND) { | 853 | + [](MatmulApiTilingBase& self, bool a, bool b, bool c, bool bias, bool transND2NZ, bool transNZ2ND) { |
| 853 | return self.SetDoubleBuffer(a, b, c, bias, transND2NZ, transNZ2ND); | 854 | return self.SetDoubleBuffer(a, b, c, bias, transND2NZ, transNZ2ND); |
| 854 | }, | 855 | }, |
| 855 | "a"_a, "b"_a, "c"_a, "bias"_a, "trans_nd2nz"_a = true, "trans_nz2nd"_a = true, | 856 | "a"_a, "b"_a, "c"_a, "bias"_a, "trans_nd2nz"_a = true, "trans_nz2nd"_a = true, |
| @@ -872,7 +873,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 872 | )doc") | 873 | )doc") |
| 873 | .def( | 874 | .def( |
| 874 | "set_fix_split", | 875 | "set_fix_split", |
| 875 | - [](MatmulApiTilingBase &self, int32_t baseMIn, int32_t baseNIn, int32_t baseKIn) { | 876 | + [](MatmulApiTilingBase& self, int32_t baseMIn, int32_t baseNIn, int32_t baseKIn) { |
| 876 | return self.SetFixSplit(baseMIn, baseNIn, baseKIn); | 877 | return self.SetFixSplit(baseMIn, baseNIn, baseKIn); |
| 877 | }, | 878 | }, |
| 878 | "base_m_in"_a = -1, "base_n_in"_a = -1, "base_k_in"_a = -1, | 879 | "base_m_in"_a = -1, "base_n_in"_a = -1, "base_k_in"_a = -1, |
| @@ -918,7 +919,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 918 | ret = tiling.get_tiling(tiling_data) | 919 | ret = tiling.get_tiling(tiling_data) |
| 919 | )doc") | 920 | )doc") |
| 920 | .def( | 921 | .def( |
| 921 | - "set_mad_type", [](MatmulApiTilingBase &self, MatrixMadType madType) { return self.SetMadType(madType); }, | 922 | + "set_mad_type", [](MatmulApiTilingBase& self, MatrixMadType madType) { return self.SetMadType(madType); }, |
| 922 | "mad_type"_a, | 923 | "mad_type"_a, |
| 923 | R"doc( | 924 | R"doc( |
| 924 | 设置是否使能HF32模式。当前版本暂不支持。 | 925 | 设置是否使能HF32模式。当前版本暂不支持。 |
| @@ -939,7 +940,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 939 | )doc") | 940 | )doc") |
| 940 | .def( | 941 | .def( |
| 941 | "set_matmul_config_params", | 942 | "set_matmul_config_params", |
| 942 | - [](MatmulApiTilingBase &self, int32_t mmConfigType, bool enableL1CacheUB, ScheduleType scheduleType, | 943 | + [](MatmulApiTilingBase& self, int32_t mmConfigType, bool enableL1CacheUB, ScheduleType scheduleType, |
| 943 | MatrixTraverse traverse, bool enVecND2NZ) { | 944 | MatrixTraverse traverse, bool enVecND2NZ) { |
| 944 | return self.SetMatmulConfigParams(mmConfigType, enableL1CacheUB, scheduleType, traverse, enVecND2NZ); | 945 | return self.SetMatmulConfigParams(mmConfigType, enableL1CacheUB, scheduleType, traverse, enVecND2NZ); |
| 945 | }, | 946 | }, |
| @@ -997,13 +998,13 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 997 | )doc") | 998 | )doc") |
| 998 | .def( | 999 | .def( |
| 999 | "set_matmul_config_params", | 1000 | "set_matmul_config_params", |
| 1000 | - [](MatmulApiTilingBase &self, const MatmulConfigParams &configParams) { | 1001 | + [](MatmulApiTilingBase& self, const MatmulConfigParams& configParams) { |
| 1001 | return self.SetMatmulConfigParams(configParams); | 1002 | return self.SetMatmulConfigParams(configParams); |
| 1002 | }, | 1003 | }, |
| 1003 | "config_params"_a) | 1004 | "config_params"_a) |
| 1004 | .def( | 1005 | .def( |
| 1005 | "set_org_shape", | 1006 | "set_org_shape", |
| 1006 | - [](MatmulApiTilingBase &self, int32_t orgMIn, int32_t orgNIn, int32_t orgKIn) { | 1007 | + [](MatmulApiTilingBase& self, int32_t orgMIn, int32_t orgNIn, int32_t orgKIn) { |
| 1007 | return self.SetOrgShape(orgMIn, orgNIn, orgKIn); | 1008 | return self.SetOrgShape(orgMIn, orgNIn, orgKIn); |
| 1008 | }, | 1009 | }, |
| 1009 | "org_m_in"_a, "org_n_in"_a, "org_k_in"_a, | 1010 | "org_m_in"_a, "org_n_in"_a, "org_k_in"_a, |
| @@ -1053,13 +1054,13 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1053 | )doc") | 1054 | )doc") |
| 1054 | .def( | 1055 | .def( |
| 1055 | "set_org_shape", | 1056 | "set_org_shape", |
| 1056 | - [](MatmulApiTilingBase &self, int32_t orgMIn, int32_t orgNIn, int32_t orgKaIn, int32_t orgKbIn) { | 1057 | + [](MatmulApiTilingBase& self, int32_t orgMIn, int32_t orgNIn, int32_t orgKaIn, int32_t orgKbIn) { |
| 1057 | return self.SetOrgShape(orgMIn, orgNIn, orgKaIn, orgKbIn); | 1058 | return self.SetOrgShape(orgMIn, orgNIn, orgKaIn, orgKbIn); |
| 1058 | }, | 1059 | }, |
| 1059 | "org_m_in"_a, "org_n_in"_a, "org_ka_in"_a, "org_kb_in"_a) | 1060 | "org_m_in"_a, "org_n_in"_a, "org_ka_in"_a, "org_kb_in"_a) |
| 1060 | .def( | 1061 | .def( |
| 1061 | "set_shape", | 1062 | "set_shape", |
| 1062 | - [](MatmulApiTilingBase &self, int32_t m, int32_t n, int32_t k) { return self.SetShape(m, n, k); }, "m"_a, | 1063 | + [](MatmulApiTilingBase& self, int32_t m, int32_t n, int32_t k) { return self.SetShape(m, n, k); }, "m"_a, |
| 1063 | "n"_a, "k"_a, | 1064 | "n"_a, "k"_a, |
| 1064 | R"doc( | 1065 | R"doc( |
| 1065 | 设置Matmul计算的形状m、n、k,该形状可以为原始完整矩阵或其局部矩阵,单位为元素。该形状的矩阵乘可以由单核或多核计算完成。 | 1066 | 设置Matmul计算的形状m、n、k,该形状可以为原始完整矩阵或其局部矩阵,单位为元素。该形状的矩阵乘可以由单核或多核计算完成。 |
| @@ -1099,7 +1100,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1099 | ret = tiling.get_tiling(tiling_data) | 1100 | ret = tiling.get_tiling(tiling_data) |
| 1100 | )doc") | 1101 | )doc") |
| 1101 | .def( | 1102 | .def( |
| 1102 | - "set_sparse", [](MatmulApiTilingBase &self, bool isSparceIn) { return self.SetSparse(isSparceIn); }, | 1103 | + "set_sparse", [](MatmulApiTilingBase& self, bool isSparceIn) { return self.SetSparse(isSparceIn); }, |
| 1103 | "is_sparce_in"_a = false, | 1104 | "is_sparce_in"_a = false, |
| 1104 | R"doc( | 1105 | R"doc( |
| 1105 | 设置Matmul的使用场景是否为Sparse Matmul场景。 | 1106 | 设置Matmul的使用场景是否为Sparse Matmul场景。 |
| @@ -1143,7 +1144,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1143 | )doc") | 1144 | )doc") |
| 1144 | .def( | 1145 | .def( |
| 1145 | "set_traverse", | 1146 | "set_traverse", |
| 1146 | - [](MatmulApiTilingBase &self, MatrixTraverse traverse) { return self.SetTraverse(traverse); }, "traverse"_a, | 1147 | + [](MatmulApiTilingBase& self, MatrixTraverse traverse) { return self.SetTraverse(traverse); }, "traverse"_a, |
| 1147 | R"doc( | 1148 | R"doc( |
| 1148 | 设置固定的Matmul计算方向,M轴优先还是N轴优先。 | 1149 | 设置固定的Matmul计算方向,M轴优先还是N轴优先。 |
| 1149 | 1150 | ||
| @@ -1182,7 +1183,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1182 | )doc") | 1183 | )doc") |
| 1183 | .def( | 1184 | .def( |
| 1184 | "set_split_range", | 1185 | "set_split_range", |
| 1185 | - [](MatmulApiTilingBase &self, int32_t maxBaseM, int32_t maxBaseN, int32_t maxBaseK, int32_t minBaseM, | 1186 | + [](MatmulApiTilingBase& self, int32_t maxBaseM, int32_t maxBaseN, int32_t maxBaseK, int32_t minBaseM, |
| 1186 | int32_t minBaseN, int32_t minBaseK) { | 1187 | int32_t minBaseN, int32_t minBaseK) { |
| 1187 | return self.SetSplitRange(maxBaseM, maxBaseN, maxBaseK, minBaseM, minBaseN, minBaseK); | 1188 | return self.SetSplitRange(maxBaseM, maxBaseN, maxBaseK, minBaseM, minBaseN, minBaseK); |
| 1188 | }, | 1189 | }, |
| @@ -1218,8 +1219,9 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1218 | 1219 | ||
| 1219 | // MatmulApiTiling class | 1220 | // MatmulApiTiling class |
| 1220 | py::class_<MatmulApiTiling, MatmulApiTilingBase>(m, "MatmulApiTiling", py::module_local()) | 1221 | py::class_<MatmulApiTiling, MatmulApiTilingBase>(m, "MatmulApiTiling", py::module_local()) |
| 1221 | - .def(py::init<const platform_ascendc::PlatformAscendC &>(), | 1222 | + .def( |
| 1222 | - R"doc( | 1223 | + py::init<const platform_ascendc::PlatformAscendC&>(), |
| 1224 | + R"doc( | ||
| 1223 | 创建MatmulApiTiling对象。 | 1225 | 创建MatmulApiTiling对象。 |
| 1224 | 1226 | ||
| 1225 | **对应的Ascend C函数原型** | 1227 | **对应的Ascend C函数原型** |
| @@ -1263,8 +1265,9 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1263 | 1265 | ||
| 1264 | // MultiCoreMatmulTiling class | 1266 | // MultiCoreMatmulTiling class |
| 1265 | py::class_<MultiCoreMatmulTiling, MatmulApiTilingBase>(m, "MultiCoreMatmulTiling", py::module_local()) | 1267 | py::class_<MultiCoreMatmulTiling, MatmulApiTilingBase>(m, "MultiCoreMatmulTiling", py::module_local()) |
| 1266 | - .def(py::init<const platform_ascendc::PlatformAscendC &>(), | 1268 | + .def( |
| 1267 | - R"doc( | 1269 | + py::init<const platform_ascendc::PlatformAscendC&>(), |
| 1270 | + R"doc( | ||
| 1268 | 创建MultiCoreMatmulTiling对象。 | 1271 | 创建MultiCoreMatmulTiling对象。 |
| 1269 | 1272 | ||
| 1270 | **对应的Ascend C函数原型** | 1273 | **对应的Ascend C函数原型** |
| @@ -1308,7 +1311,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1308 | // Enable methods | 1311 | // Enable methods |
| 1309 | .def( | 1312 | .def( |
| 1310 | "enable_multi_core_split_k", | 1313 | "enable_multi_core_split_k", |
| 1311 | - [](MultiCoreMatmulTiling &self, bool flag) { return self.EnableMultiCoreSplitK(flag); }, "flag"_a, | 1314 | + [](MultiCoreMatmulTiling& self, bool flag) { return self.EnableMultiCoreSplitK(flag); }, "flag"_a, |
| 1312 | R"doc( | 1315 | R"doc( |
| 1313 | 多核场景,通过该接口使能切K轴。不调用该接口的情况下,默认不切K轴。在GetTiling接口调用前使用。 | 1316 | 多核场景,通过该接口使能切K轴。不调用该接口的情况下,默认不切K轴。在GetTiling接口调用前使用。 |
| 1314 | 1317 | ||
| @@ -1351,7 +1354,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1351 | // Get methods | 1354 | // Get methods |
| 1352 | .def( | 1355 | .def( |
| 1353 | "get_core_num", | 1356 | "get_core_num", |
| 1354 | - [](MultiCoreMatmulTiling &self) -> py::object { | 1357 | + [](MultiCoreMatmulTiling& self) -> py::object { |
| 1355 | int32_t dim, mDim, nDim; | 1358 | int32_t dim, mDim, nDim; |
| 1356 | auto ret = self.GetCoreNum(dim, mDim, nDim); | 1359 | auto ret = self.GetCoreNum(dim, mDim, nDim); |
| 1357 | if (ret != 0) { | 1360 | if (ret != 0) { |
| @@ -1402,7 +1405,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1402 | )doc") | 1405 | )doc") |
| 1403 | .def( | 1406 | .def( |
| 1404 | "get_single_shape", | 1407 | "get_single_shape", |
| 1405 | - [](MultiCoreMatmulTiling &self) -> py::object { | 1408 | + [](MultiCoreMatmulTiling& self) -> py::object { |
| 1406 | int32_t shapeM, shapeN, shapeK; | 1409 | int32_t shapeM, shapeN, shapeK; |
| 1407 | auto ret = self.GetSingleShape(shapeM, shapeN, shapeK); | 1410 | auto ret = self.GetSingleShape(shapeM, shapeN, shapeK); |
| 1408 | if (ret != 0) { | 1411 | if (ret != 0) { |
| @@ -1459,7 +1462,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1459 | // Set methods | 1462 | // Set methods |
| 1460 | .def( | 1463 | .def( |
| 1461 | "set_align_split", | 1464 | "set_align_split", |
| 1462 | - [](MultiCoreMatmulTiling &self, int32_t alignM, int32_t alignN, int32_t alignK) { | 1465 | + [](MultiCoreMatmulTiling& self, int32_t alignM, int32_t alignN, int32_t alignK) { |
| 1463 | return self.SetAlignSplit(alignM, alignN, alignK); | 1466 | return self.SetAlignSplit(alignM, alignN, alignK); |
| 1464 | }, | 1467 | }, |
| 1465 | "align_m"_a, "align_n"_a, "align_k"_a, | 1468 | "align_m"_a, "align_n"_a, "align_k"_a, |
| @@ -1503,7 +1506,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1503 | ret1 = tiling.get_tiling(tiling_data) | 1506 | ret1 = tiling.get_tiling(tiling_data) |
| 1504 | )doc") | 1507 | )doc") |
| 1505 | .def( | 1508 | .def( |
| 1506 | - "set_dim", [](MultiCoreMatmulTiling &self, int32_t dim) { return self.SetDim(dim); }, "dim"_a, | 1509 | + "set_dim", [](MultiCoreMatmulTiling& self, int32_t dim) { return self.SetDim(dim); }, "dim"_a, |
| 1507 | R"doc( | 1510 | R"doc( |
| 1508 | 设置多核Matmul时,参与运算的核数。 | 1511 | 设置多核Matmul时,参与运算的核数。 |
| 1509 | 1512 | ||
| @@ -1543,7 +1546,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1543 | )doc") | 1546 | )doc") |
| 1544 | .def( | 1547 | .def( |
| 1545 | "set_single_shape", | 1548 | "set_single_shape", |
| 1546 | - [](MultiCoreMatmulTiling &self, int32_t singleMIn, int32_t singleNIn, int32_t singleKIn) { | 1549 | + [](MultiCoreMatmulTiling& self, int32_t singleMIn, int32_t singleNIn, int32_t singleKIn) { |
| 1547 | return self.SetSingleShape(singleMIn, singleNIn, singleKIn); | 1550 | return self.SetSingleShape(singleMIn, singleNIn, singleKIn); |
| 1548 | }, | 1551 | }, |
| 1549 | "single_m_in"_a = -1, "single_n_in"_a = -1, "single_k_in"_a = -1, | 1552 | "single_m_in"_a = -1, "single_n_in"_a = -1, "single_k_in"_a = -1, |
| @@ -1588,7 +1591,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1588 | )doc") | 1591 | )doc") |
| 1589 | .def( | 1592 | .def( |
| 1590 | "set_single_range", | 1593 | "set_single_range", |
| 1591 | - [](MultiCoreMatmulTiling &self, int32_t maxM, int32_t maxN, int32_t maxK, int32_t minM, int32_t minN, | 1594 | + [](MultiCoreMatmulTiling& self, int32_t maxM, int32_t maxN, int32_t maxK, int32_t minM, int32_t minN, |
| 1592 | int32_t minK) { return self.SetSingleRange(maxM, maxN, maxK, minM, minN, minK); }, | 1595 | int32_t minK) { return self.SetSingleRange(maxM, maxN, maxK, minM, minN, minK); }, |
| 1593 | "max_m"_a = -1, "max_n"_a = -1, "max_k"_a = -1, "min_m"_a = -1, "min_n"_a = -1, "min_k"_a = -1, | 1596 | "max_m"_a = -1, "max_n"_a = -1, "max_k"_a = -1, "min_m"_a = -1, "min_n"_a = -1, "min_k"_a = -1, |
| 1594 | R"doc( | 1597 | R"doc( |
| @@ -1636,8 +1639,9 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1636 | 1639 | ||
| 1637 | // BatchMatmulTiling class | 1640 | // BatchMatmulTiling class |
| 1638 | py::class_<BatchMatmulTiling, MatmulApiTilingBase>(m, "BatchMatmulTiling", py::module_local()) | 1641 | py::class_<BatchMatmulTiling, MatmulApiTilingBase>(m, "BatchMatmulTiling", py::module_local()) |
| 1639 | - .def(py::init<const platform_ascendc::PlatformAscendC &>(), | 1642 | + .def( |
| 1640 | - R"doc( | 1643 | + py::init<const platform_ascendc::PlatformAscendC&>(), |
| 1644 | + R"doc( | ||
| 1641 | 创建BatchMatmulTiling对象。 | 1645 | 创建BatchMatmulTiling对象。 |
| 1642 | 1646 | ||
| 1643 | **对应的Ascend C函数原型** | 1647 | **对应的Ascend C函数原型** |
| @@ -1681,7 +1685,7 @@ void pyasc_init_matmul_api_tiling(py::module &m) | |||
| 1681 | // Get methods | 1685 | // Get methods |
| 1682 | .def( | 1686 | .def( |
| 1683 | "get_core_num", | 1687 | "get_core_num", |
| 1684 | - [](BatchMatmulTiling &self) -> py::object { | 1688 | + [](BatchMatmulTiling& self) -> py::object { |
| 1685 | int32_t dim, mDim, nDim, batchCoreM, batchCoreN; | 1689 | int32_t dim, mDim, nDim, batchCoreM, batchCoreN; |
| 1686 | auto ret = self.GetCoreNum(dim, mDim, nDim, batchCoreM, batchCoreN); | 1690 | auto ret = self.GetCoreNum(dim, mDim, nDim, batchCoreM, batchCoreN); |
| 1687 | if (ret != 0) { | 1691 | if (ret != 0) { |
| @@ -15,9 +15,9 @@ namespace py = pybind11; | |||
| 15 | 15 | ||
| 16 | namespace pybind11 { | 16 | namespace pybind11 { |
| 17 | namespace asc { | 17 | namespace asc { |
| 18 | -void pyasc_init_enums(py::module &m); | 18 | +void pyasc_init_enums(py::module& m); |
| 19 | -void pyasc_init_matmul_api_tiling(py::module &m); | 19 | +void pyasc_init_matmul_api_tiling(py::module& m); |
| 20 | -void pyasc_init_platform(py::module &m); | 20 | +void pyasc_init_platform(py::module& m); |
| 21 | } // namespace asc | 21 | } // namespace asc |
| 22 | } // namespace pybind11 | 22 | } // namespace pybind11 |
| 23 | namespace { | 23 | namespace { |
| @@ -17,7 +17,7 @@ namespace py = pybind11; | |||
| 17 | 17 | ||
| 18 | namespace pybind11 { | 18 | namespace pybind11 { |
| 19 | namespace asc { | 19 | namespace asc { |
| 20 | -void pyasc_init_platform(py::module &m) | 20 | +void pyasc_init_platform(py::module& m) |
| 21 | { | 21 | { |
| 22 | using ret = py::return_value_policy; | 22 | using ret = py::return_value_policy; |
| 23 | using namespace platform_ascendc; | 23 | using namespace platform_ascendc; |
| @@ -30,7 +30,7 @@ void pyasc_init_platform(py::module &m) | |||
| 30 | "get_instance", []() { return PlatformAscendCManager::GetInstance(); }, ret::reference) | 30 | "get_instance", []() { return PlatformAscendCManager::GetInstance(); }, ret::reference) |
| 31 | .def_static( | 31 | .def_static( |
| 32 | "get_instance", | 32 | "get_instance", |
| 33 | - [](const std::string &socVersion) { return PlatformAscendCManager::GetInstance(socVersion.c_str()); }, | 33 | + [](const std::string& socVersion) { return PlatformAscendCManager::GetInstance(socVersion.c_str()); }, |
| 34 | ret::reference, "soc_version"_a); | 34 | ret::reference, "soc_version"_a); |
| 35 | } | 35 | } |
| 36 | } // namespace asc | 36 | } // namespace asc |
| @@ -20,8 +20,8 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | -#include "experiment/msprof/toolchain/prof_api.h" | 23 | +#include "experiment/msprof/toolchain/prof_api.h" |
| 24 | -#include "experiment/msprof/toolchain/prof_data_config.h" | 24 | +#include "experiment/msprof/toolchain/prof_data_config.h" |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | 27 | ||
| @@ -30,13 +30,13 @@ static unsigned int msprofFlagL0 = 0; | |||
| 30 | static unsigned int msprofFlagL1 = 0; | 30 | static unsigned int msprofFlagL1 = 0; |
| 31 | 31 | ||
| 32 | extern "C" { | 32 | extern "C" { |
| 33 | -int ProfCtrlHandle(unsigned int ctrlType, void *ctrlData, unsigned int dataLen) | 33 | +int ProfCtrlHandle(unsigned int ctrlType, void* ctrlData, unsigned int dataLen) |
| 34 | { | 34 | { |
| 35 | if (ctrlType != PROF_CTRL_SWITCH || ctrlData == nullptr || dataLen < sizeof(MsprofCommandHandle)) { | 35 | if (ctrlType != PROF_CTRL_SWITCH || ctrlData == nullptr || dataLen < sizeof(MsprofCommandHandle)) { |
| 36 | return 1; | 36 | return 1; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | - MsprofCommandHandle *handle = static_cast<MsprofCommandHandle *>(ctrlData); | 39 | + MsprofCommandHandle* handle = static_cast<MsprofCommandHandle*>(ctrlData); |
| 40 | const uint64_t profSwitch = handle->profSwitch; | 40 | const uint64_t profSwitch = handle->profSwitch; |
| 41 | const uint64_t profType = handle->type; | 41 | const uint64_t profType = handle->type; |
| 42 | if (profType == PROF_COMMANDHANDLE_TYPE_START) { | 42 | if (profType == PROF_COMMANDHANDLE_TYPE_START) { |
| @@ -63,7 +63,7 @@ int ProfCtrlHandle(unsigned int ctrlType, void *ctrlData, unsigned int dataLen) | |||
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | -static PyObject *aclInit(PyObject *self, PyObject *args) | 66 | +static PyObject* aclInit(PyObject* self, PyObject* args) |
| 67 | { | 67 | { |
| 68 | aclError ret = aclInit(nullptr); | 68 | aclError ret = aclInit(nullptr); |
| 69 | if (PyErr_Occurred()) { | 69 | if (PyErr_Occurred()) { |
| @@ -73,7 +73,7 @@ static PyObject *aclInit(PyObject *self, PyObject *args) | |||
| 73 | return Py_BuildValue("i", ret); | 73 | return Py_BuildValue("i", ret); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | -static PyObject *aclFinalize(PyObject *self, PyObject *args) | 76 | +static PyObject* aclFinalize(PyObject* self, PyObject* args) |
| 77 | { | 77 | { |
| 78 | aclError ret = aclFinalize(); | 78 | aclError ret = aclFinalize(); |
| 79 | if (PyErr_Occurred()) { | 79 | if (PyErr_Occurred()) { |
| @@ -83,7 +83,7 @@ static PyObject *aclFinalize(PyObject *self, PyObject *args) | |||
| 83 | return Py_BuildValue("i", ret); | 83 | return Py_BuildValue("i", ret); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | -static PyObject *MsprofSysCycleTime(PyObject *self, PyObject *args) | 86 | +static PyObject* MsprofSysCycleTime(PyObject* self, PyObject* args) |
| 87 | { | 87 | { |
| 88 | if (!msprofFlagL0 && !msprofFlagL1) { | 88 | if (!msprofFlagL0 && !msprofFlagL1) { |
| 89 | return Py_BuildValue("k", 0); | 89 | return Py_BuildValue("k", 0); |
| @@ -98,7 +98,7 @@ static PyObject *MsprofSysCycleTime(PyObject *self, PyObject *args) | |||
| 98 | return Py_BuildValue("k", time); | 98 | return Py_BuildValue("k", time); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | -static PyObject *MsprofReportApi(PyObject *self, PyObject *args) | 101 | +static PyObject* MsprofReportApi(PyObject* self, PyObject* args) |
| 102 | { | 102 | { |
| 103 | if (!msprofFlagL0 && !msprofFlagL1) { | 103 | if (!msprofFlagL0 && !msprofFlagL1) { |
| 104 | return Py_BuildValue("i", 1); | 104 | return Py_BuildValue("i", 1); |
| @@ -106,7 +106,7 @@ static PyObject *MsprofReportApi(PyObject *self, PyObject *args) | |||
| 106 | 106 | ||
| 107 | unsigned long start = 0; | 107 | unsigned long start = 0; |
| 108 | unsigned long end = 0; | 108 | unsigned long end = 0; |
| 109 | - const char *opName = ""; | 109 | + const char* opName = ""; |
| 110 | 110 | ||
| 111 | if (!PyArg_ParseTuple(args, "kks", &start, &end, &opName)) { | 111 | if (!PyArg_ParseTuple(args, "kks", &start, &end, &opName)) { |
| 112 | return nullptr; | 112 | return nullptr; |
| @@ -132,14 +132,14 @@ static PyObject *MsprofReportApi(PyObject *self, PyObject *args) | |||
| 132 | return Py_BuildValue("i", ret); | 132 | return Py_BuildValue("i", ret); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | -static PyObject *MsprofReportCompactInfo(PyObject *self, PyObject *args) | 135 | +static PyObject* MsprofReportCompactInfo(PyObject* self, PyObject* args) |
| 136 | { | 136 | { |
| 137 | if (!msprofFlagL1) { | 137 | if (!msprofFlagL1) { |
| 138 | return Py_BuildValue("i", 1); | 138 | return Py_BuildValue("i", 1); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | unsigned long time; | 141 | unsigned long time; |
| 142 | - const char *opName; | 142 | + const char* opName; |
| 143 | unsigned int blockNum; | 143 | unsigned int blockNum; |
| 144 | unsigned int taskType; | 144 | unsigned int taskType; |
| 145 | 145 | ||
| @@ -167,13 +167,13 @@ static PyObject *MsprofReportCompactInfo(PyObject *self, PyObject *args) | |||
| 167 | return Py_BuildValue("i", ret); | 167 | return Py_BuildValue("i", ret); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | -static PyObject *MsprofReportAdditionalInfo(PyObject *self, PyObject *args) | 170 | +static PyObject* MsprofReportAdditionalInfo(PyObject* self, PyObject* args) |
| 171 | { | 171 | { |
| 172 | if (!msprofFlagL1) { | 172 | if (!msprofFlagL1) { |
| 173 | return Py_BuildValue("i", 1); | 173 | return Py_BuildValue("i", 1); |
| 174 | } | 174 | } |
| 175 | unsigned long time; | 175 | unsigned long time; |
| 176 | - const char *opName; | 176 | + const char* opName; |
| 177 | if (!PyArg_ParseTuple(args, "ks", &time, &opName)) { | 177 | if (!PyArg_ParseTuple(args, "ks", &time, &opName)) { |
| 178 | return nullptr; | 178 | return nullptr; |
| 179 | } | 179 | } |
| @@ -186,10 +186,10 @@ static PyObject *MsprofReportAdditionalInfo(PyObject *self, PyObject *args) | |||
| 186 | tensorInfo.type = MSPROF_REPORT_NODE_TENSOR_INFO_TYPE; | 186 | tensorInfo.type = MSPROF_REPORT_NODE_TENSOR_INFO_TYPE; |
| 187 | tensorInfo.threadId = threadId; | 187 | tensorInfo.threadId = threadId; |
| 188 | tensorInfo.timeStamp = time; | 188 | tensorInfo.timeStamp = time; |
| 189 | - auto profTensorData = reinterpret_cast<MsprofTensorInfo *>(tensorInfo.data); | 189 | + auto profTensorData = reinterpret_cast<MsprofTensorInfo*>(tensorInfo.data); |
| 190 | profTensorData->opName = hashId; | 190 | profTensorData->opName = hashId; |
| 191 | 191 | ||
| 192 | - int32_t ret = MsprofReportAdditionalInfo(false, static_cast<void *>(&tensorInfo), sizeof(MsprofAdditionalInfo)); | 192 | + int32_t ret = MsprofReportAdditionalInfo(false, static_cast<void*>(&tensorInfo), sizeof(MsprofAdditionalInfo)); |
| 193 | if (PyErr_Occurred()) { | 193 | if (PyErr_Occurred()) { |
| 194 | return nullptr; | 194 | return nullptr; |
| 195 | } | 195 | } |
| @@ -210,7 +210,7 @@ static PyModuleDef ModuleDef = {PyModuleDef_HEAD_INIT, "npu_utils", "Npu utils", | |||
| 210 | 210 | ||
| 211 | PyMODINIT_FUNC PyInit_npu_utils(void) | 211 | PyMODINIT_FUNC PyInit_npu_utils(void) |
| 212 | { | 212 | { |
| 213 | - PyObject *m = PyModule_Create(&ModuleDef); | 213 | + PyObject* m = PyModule_Create(&ModuleDef); |
| 214 | if (m == nullptr) { | 214 | if (m == nullptr) { |
| 215 | return nullptr; | 215 | return nullptr; |
| 216 | } | 216 | } |
| @@ -11,11 +11,11 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | namespace Adx { | 13 | namespace Adx { |
| 14 | -void AdumpPrintWorkSpace(const void *workSpaceAddr, const size_t dumpWorkSpaceSize, void *stream, const char *opType); | 14 | +void AdumpPrintWorkSpace(const void* workSpaceAddr, const size_t dumpWorkSpaceSize, void* stream, const char* opType); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | -extern "C" void PrintWorkSpace(const void *workSpaceAddr, const size_t dumpWorkSpaceSize, void *stream, | 17 | +extern "C" void |
| 18 | - const char *opType) | 18 | +PrintWorkSpace(const void* workSpaceAddr, const size_t dumpWorkSpaceSize, void* stream, const char* opType) |
| 19 | { | 19 | { |
| 20 | Adx::AdumpPrintWorkSpace(workSpaceAddr, dumpWorkSpaceSize, stream, opType); | 20 | Adx::AdumpPrintWorkSpace(workSpaceAddr, dumpWorkSpaceSize, stream, opType); |
| 21 | } | 21 | } |
| @@ -20,10 +20,7 @@ extern "C" { | |||
| 20 | * @brief get chipType | 20 | * @brief get chipType |
| 21 | * @return RT_ERROR_NONE for ok | 21 | * @return RT_ERROR_NONE for ok |
| 22 | */ | 22 | */ |
| 23 | -RTS_API rtError_t GetSocVersionWrapper(char_t *ver, const uint32_t maxLen) | 23 | +RTS_API rtError_t GetSocVersionWrapper(char_t* ver, const uint32_t maxLen) { return rtGetSocVersion(ver, maxLen); } |
| 24 | -{ | ||
| 25 | - return rtGetSocVersion(ver, maxLen); | ||
| 26 | -} | ||
| 27 | 24 | ||
| 28 | /** | 25 | /** |
| 29 | * @ingroup dvrt_dev | 26 | * @ingroup dvrt_dev |
| @@ -32,10 +29,7 @@ RTS_API rtError_t GetSocVersionWrapper(char_t *ver, const uint32_t maxLen) | |||
| 32 | * @return RT_ERROR_NONE for ok | 29 | * @return RT_ERROR_NONE for ok |
| 33 | * @return RT_ERROR_INVALID_VALUE for error input | 30 | * @return RT_ERROR_INVALID_VALUE for error input |
| 34 | */ | 31 | */ |
| 35 | -RTS_API rtError_t GetDeviceCountWrapper(int32_t *cnt) | 32 | +RTS_API rtError_t GetDeviceCountWrapper(int32_t* cnt) { return rtGetDeviceCount(cnt); } |
| 36 | -{ | ||
| 37 | - return rtGetDeviceCount(cnt); | ||
| 38 | -} | ||
| 39 | 33 | ||
| 40 | /** | 34 | /** |
| 41 | * @ingroup dvrt_dev | 35 | * @ingroup dvrt_dev |
| @@ -69,7 +63,7 @@ RTS_API rtError_t GetDeviceCountWrapper(int32_t *cnt) | |||
| 69 | * @return RT_ERROR_NONE for ok | 63 | * @return RT_ERROR_NONE for ok |
| 70 | * @return RT_ERROR_DRV_ERR for error | 64 | * @return RT_ERROR_DRV_ERR for error |
| 71 | */ | 65 | */ |
| 72 | -RTS_API rtError_t GetDeviceInfoWrapper(uint32_t deviceId, int32_t moduleType, int32_t infoType, int64_t *val) | 66 | +RTS_API rtError_t GetDeviceInfoWrapper(uint32_t deviceId, int32_t moduleType, int32_t infoType, int64_t* val) |
| 73 | { | 67 | { |
| 74 | return rtGetDeviceInfo(deviceId, moduleType, infoType, val); | 68 | return rtGetDeviceInfo(deviceId, moduleType, infoType, val); |
| 75 | } | 69 | } |
| @@ -80,10 +74,7 @@ RTS_API rtError_t GetDeviceInfoWrapper(uint32_t deviceId, int32_t moduleType, in | |||
| 80 | * @return RT_ERROR_NONE for ok | 74 | * @return RT_ERROR_NONE for ok |
| 81 | * @return RT_ERROR_INVALID_VALUE for error input | 75 | * @return RT_ERROR_INVALID_VALUE for error input |
| 82 | */ | 76 | */ |
| 83 | -RTS_API rtError_t DeviceResetWrapper(int32_t devId) | 77 | +RTS_API rtError_t DeviceResetWrapper(int32_t devId) { return rtDeviceReset(devId); } |
| 84 | -{ | ||
| 85 | - return rtDeviceReset(devId); | ||
| 86 | -} | ||
| 87 | 78 | ||
| 88 | /** | 79 | /** |
| 89 | * @ingroup dvrt_dev | 80 | * @ingroup dvrt_dev |
| @@ -92,10 +83,7 @@ RTS_API rtError_t DeviceResetWrapper(int32_t devId) | |||
| 92 | * @return RT_ERROR_NONE for ok | 83 | * @return RT_ERROR_NONE for ok |
| 93 | * @return RT_ERROR_INVALID_VALUE for error input | 84 | * @return RT_ERROR_INVALID_VALUE for error input |
| 94 | */ | 85 | */ |
| 95 | -RTS_API rtError_t SetDeviceWrapper(int32_t devId) | 86 | +RTS_API rtError_t SetDeviceWrapper(int32_t devId) { return rtSetDevice(devId); } |
| 96 | -{ | ||
| 97 | - return rtSetDevice(devId); | ||
| 98 | -} | ||
| 99 | 87 | ||
| 100 | /** | 88 | /** |
| 101 | * @ingroup dvrt_stream | 89 | * @ingroup dvrt_stream |
| @@ -105,10 +93,7 @@ RTS_API rtError_t SetDeviceWrapper(int32_t devId) | |||
| 105 | * @return RT_ERROR_NONE for ok | 93 | * @return RT_ERROR_NONE for ok |
| 106 | * @return RT_ERROR_INVALID_VALUE for error input | 94 | * @return RT_ERROR_INVALID_VALUE for error input |
| 107 | */ | 95 | */ |
| 108 | -RTS_API rtError_t StreamCreateWrapper(rtStream_t *stm, int32_t priority) | 96 | +RTS_API rtError_t StreamCreateWrapper(rtStream_t* stm, int32_t priority) { return rtStreamCreate(stm, priority); } |
| 109 | -{ | ||
| 110 | - return rtStreamCreate(stm, priority); | ||
| 111 | -} | ||
| 112 | 97 | ||
| 113 | /** | 98 | /** |
| 114 | * @ingroup dvrt_stream | 99 | * @ingroup dvrt_stream |
| @@ -117,10 +102,7 @@ RTS_API rtError_t StreamCreateWrapper(rtStream_t *stm, int32_t priority) | |||
| 117 | * @return RT_ERROR_NONE for ok | 102 | * @return RT_ERROR_NONE for ok |
| 118 | * @return RT_ERROR_INVALID_VALUE for error input | 103 | * @return RT_ERROR_INVALID_VALUE for error input |
| 119 | */ | 104 | */ |
| 120 | -RTS_API rtError_t StreamDestroyWrapper(rtStream_t stm) | 105 | +RTS_API rtError_t StreamDestroyWrapper(rtStream_t stm) { return rtStreamDestroy(stm); } |
| 121 | -{ | ||
| 122 | - return rtStreamDestroy(stm); | ||
| 123 | -} | ||
| 124 | 106 | ||
| 125 | /** | 107 | /** |
| 126 | * @ingroup rt_kernel | 108 | * @ingroup rt_kernel |
| @@ -130,7 +112,7 @@ RTS_API rtError_t StreamDestroyWrapper(rtStream_t stm) | |||
| 130 | * @return RT_ERROR_NONE for ok | 112 | * @return RT_ERROR_NONE for ok |
| 131 | * @return RT_ERROR_INVALID_VALUE for error input | 113 | * @return RT_ERROR_INVALID_VALUE for error input |
| 132 | */ | 114 | */ |
| 133 | -RTS_API rtError_t DevBinaryRegisterWrapper(const rtDevBinary_t *bin, void **hdl) | 115 | +RTS_API rtError_t DevBinaryRegisterWrapper(const rtDevBinary_t* bin, void** hdl) |
| 134 | { | 116 | { |
| 135 | return rtDevBinaryRegister(bin, hdl); | 117 | return rtDevBinaryRegister(bin, hdl); |
| 136 | } | 118 | } |
| @@ -142,10 +124,7 @@ RTS_API rtError_t DevBinaryRegisterWrapper(const rtDevBinary_t *bin, void **hdl) | |||
| 142 | * @return RT_ERROR_NONE for ok | 124 | * @return RT_ERROR_NONE for ok |
| 143 | * @return RT_ERROR_INVALID_VALUE for error input | 125 | * @return RT_ERROR_INVALID_VALUE for error input |
| 144 | */ | 126 | */ |
| 145 | -RTS_API rtError_t DevBinaryUnRegisterWrapper(void *hdl) | 127 | +RTS_API rtError_t DevBinaryUnRegisterWrapper(void* hdl) { return rtDevBinaryUnRegister(hdl); } |
| 146 | -{ | ||
| 147 | - return rtDevBinaryUnRegister(hdl); | ||
| 148 | -} | ||
| 149 | 128 | ||
| 150 | /** | 129 | /** |
| 151 | * @ingroup rt_kernel | 130 | * @ingroup rt_kernel |
| @@ -158,8 +137,8 @@ RTS_API rtError_t DevBinaryUnRegisterWrapper(void *hdl) | |||
| 158 | * @return RT_ERROR_NONE for ok | 137 | * @return RT_ERROR_NONE for ok |
| 159 | * @return RT_ERROR_INVALID_VALUE for error input | 138 | * @return RT_ERROR_INVALID_VALUE for error input |
| 160 | */ | 139 | */ |
| 161 | -RTS_API rtError_t FunctionRegisterWrapper(void *binHandle, const void *stubFunc, const char_t *stubName, | 140 | +RTS_API rtError_t FunctionRegisterWrapper( |
| 162 | - const void *kernelInfoExt, uint32_t funcMode) | 141 | + void* binHandle, const void* stubFunc, const char_t* stubName, const void* kernelInfoExt, uint32_t funcMode) |
| 163 | { | 142 | { |
| 164 | return rtFunctionRegister(binHandle, stubFunc, stubName, kernelInfoExt, funcMode); | 143 | return rtFunctionRegister(binHandle, stubFunc, stubName, kernelInfoExt, funcMode); |
| 165 | } | 144 | } |
| @@ -174,7 +153,7 @@ RTS_API rtError_t FunctionRegisterWrapper(void *binHandle, const void *stubFunc, | |||
| 174 | * @return RT_ERROR_NONE for ok | 153 | * @return RT_ERROR_NONE for ok |
| 175 | * @return RT_ERROR_INVALID_VALUE for error input | 154 | * @return RT_ERROR_INVALID_VALUE for error input |
| 176 | */ | 155 | */ |
| 177 | -RTS_API rtError_t MallocWrapper(void **devPtr, uint64_t size, rtMemType_t type, const uint16_t moduleId) | 156 | +RTS_API rtError_t MallocWrapper(void** devPtr, uint64_t size, rtMemType_t type, const uint16_t moduleId) |
| 178 | { | 157 | { |
| 179 | return rtMalloc(devPtr, size, type, moduleId); | 158 | return rtMalloc(devPtr, size, type, moduleId); |
| 180 | } | 159 | } |
| @@ -190,7 +169,7 @@ RTS_API rtError_t MallocWrapper(void **devPtr, uint64_t size, rtMemType_t type, | |||
| 190 | * @return RT_ERROR_NONE for ok | 169 | * @return RT_ERROR_NONE for ok |
| 191 | * @return RT_ERROR_INVALID_VALUE for error input | 170 | * @return RT_ERROR_INVALID_VALUE for error input |
| 192 | */ | 171 | */ |
| 193 | -RTS_API rtError_t MemcpyWrapper(void *dst, uint64_t destMax, const void *src, uint64_t cnt, rtMemcpyKind_t kind) | 172 | +RTS_API rtError_t MemcpyWrapper(void* dst, uint64_t destMax, const void* src, uint64_t cnt, rtMemcpyKind_t kind) |
| 194 | { | 173 | { |
| 195 | return rtMemcpy(dst, destMax, src, cnt, kind); | 174 | return rtMemcpy(dst, destMax, src, cnt, kind); |
| 196 | } | 175 | } |
| @@ -207,8 +186,8 @@ RTS_API rtError_t MemcpyWrapper(void *dst, uint64_t destMax, const void *src, ui | |||
| 207 | * @return RT_ERROR_NONE for ok | 186 | * @return RT_ERROR_NONE for ok |
| 208 | * @return RT_ERROR_INVALID_VALUE for error input | 187 | * @return RT_ERROR_INVALID_VALUE for error input |
| 209 | */ | 188 | */ |
| 210 | -RTS_API rtError_t KernelLaunchWrapper(const void *stubFunc, uint32_t blockNum, void *args, uint32_t argsSize, | 189 | +RTS_API rtError_t KernelLaunchWrapper( |
| 211 | - rtSmDesc_t *smDesc, rtStream_t stm) | 190 | + const void* stubFunc, uint32_t blockNum, void* args, uint32_t argsSize, rtSmDesc_t* smDesc, rtStream_t stm) |
| 212 | { | 191 | { |
| 213 | return rtKernelLaunch(stubFunc, blockNum, args, argsSize, smDesc, stm); | 192 | return rtKernelLaunch(stubFunc, blockNum, args, argsSize, smDesc, stm); |
| 214 | } | 193 | } |
| @@ -233,10 +212,7 @@ RTS_API rtError_t StreamSynchronizeWithTimeoutWrapper(rtStream_t stm, int32_t ti | |||
| 233 | * @return RT_ERROR_NONE for ok | 212 | * @return RT_ERROR_NONE for ok |
| 234 | * @return RT_ERROR_INVALID_VALUE for error input | 213 | * @return RT_ERROR_INVALID_VALUE for error input |
| 235 | */ | 214 | */ |
| 236 | -RTS_API rtError_t StreamSynchronizeWrapper(rtStream_t stm) | 215 | +RTS_API rtError_t StreamSynchronizeWrapper(rtStream_t stm) { return rtStreamSynchronize(stm); } |
| 237 | -{ | ||
| 238 | - return rtStreamSynchronize(stm); | ||
| 239 | -} | ||
| 240 | 216 | ||
| 241 | /** | 217 | /** |
| 242 | * @ingroup dvrt_mem | 218 | * @ingroup dvrt_mem |
| @@ -245,10 +221,7 @@ RTS_API rtError_t StreamSynchronizeWrapper(rtStream_t stm) | |||
| 245 | * @return RT_ERROR_NONE for ok | 221 | * @return RT_ERROR_NONE for ok |
| 246 | * @return RT_ERROR_INVALID_VALUE for error input | 222 | * @return RT_ERROR_INVALID_VALUE for error input |
| 247 | */ | 223 | */ |
| 248 | -RTS_API rtError_t FreeWrapper(void *devPtr) | 224 | +RTS_API rtError_t FreeWrapper(void* devPtr) { return rtFree(devPtr); } |
| 249 | -{ | ||
| 250 | - return rtFree(devPtr); | ||
| 251 | -} | ||
| 252 | 225 | ||
| 253 | /** | 226 | /** |
| 254 | * @ingroup dvrt_dev | 227 | * @ingroup dvrt_dev |
| @@ -256,15 +229,9 @@ RTS_API rtError_t FreeWrapper(void *devPtr) | |||
| 256 | * @return RT_ERROR_NONE for ok | 229 | * @return RT_ERROR_NONE for ok |
| 257 | * @return RT_ERROR_INVALID_VALUE for error input | 230 | * @return RT_ERROR_INVALID_VALUE for error input |
| 258 | */ | 231 | */ |
| 259 | -RTS_API rtError_t DeviceSynchronizeWrapper(void) | 232 | +RTS_API rtError_t DeviceSynchronizeWrapper(void) { return rtDeviceSynchronize(); } |
| 260 | -{ | ||
| 261 | - return rtDeviceSynchronize(); | ||
| 262 | -} | ||
| 263 | 233 | ||
| 264 | -RTS_API rtError_t GetC2cCtrlAddrWrapper(uint64_t *addr, uint32_t *len) | 234 | +RTS_API rtError_t GetC2cCtrlAddrWrapper(uint64_t* addr, uint32_t* len) { return rtGetC2cCtrlAddr(addr, len); } |
| 265 | -{ | ||
| 266 | - return rtGetC2cCtrlAddr(addr, len); | ||
| 267 | -} | ||
| 268 | 235 | ||
| 269 | /** | 236 | /** |
| 270 | * @ingroup profiling_base | 237 | * @ingroup profiling_base |
| @@ -274,8 +241,5 @@ RTS_API rtError_t GetC2cCtrlAddrWrapper(uint64_t *addr, uint32_t *len) | |||
| 274 | * @return RT_ERROR_NONE for ok | 241 | * @return RT_ERROR_NONE for ok |
| 275 | * @return ACL_ERROR_RT_PARAM_INVALID for error input | 242 | * @return ACL_ERROR_RT_PARAM_INVALID for error input |
| 276 | */ | 243 | */ |
| 277 | -RTS_API rtError_t ProfSetProSwitchWrapper(void *data, uint32_t len) | 244 | +RTS_API rtError_t ProfSetProSwitchWrapper(void* data, uint32_t len) { return rtProfSetProSwitch(data, len); } |
| 278 | -{ | ||
| 279 | - return rtProfSetProSwitch(data, len); | ||
| 280 | -} | ||
| 281 | } | 245 | } |
| @@ -88,7 +88,7 @@ std::optional<SmallVector<emitasc::KernelArgument>> getKernelArgAttrs(ModuleOp o | |||
| 88 | 88 | ||
| 89 | namespace pybind11 { | 89 | namespace pybind11 { |
| 90 | namespace asc { | 90 | namespace asc { |
| 91 | -void pyasc_bind_enums(py::module &m) | 91 | +void pyasc_bind_enums(py::module& m) |
| 92 | { | 92 | { |
| 93 | using ret = py::return_value_policy; | 93 | using ret = py::return_value_policy; |
| 94 | using namespace pybind11::literals; | 94 | using namespace pybind11::literals; |
| @@ -152,8 +152,8 @@ void pyasc_bind_enums(py::module &m) | |||
| 152 | .value("ORDER_INDEX_VALUE", ascendc::ReduceOrder::ORDER_INDEX_VALUE) | 152 | .value("ORDER_INDEX_VALUE", ascendc::ReduceOrder::ORDER_INDEX_VALUE) |
| 153 | .value("ORDER_ONLY_VALUE", ascendc::ReduceOrder::ORDER_ONLY_VALUE) | 153 | .value("ORDER_ONLY_VALUE", ascendc::ReduceOrder::ORDER_ONLY_VALUE) |
| 154 | .value("ORDER_ONLY_INDEX", ascendc::ReduceOrder::ORDER_ONLY_INDEX) | 154 | .value("ORDER_ONLY_INDEX", ascendc::ReduceOrder::ORDER_ONLY_INDEX) |
| 155 | - .def_static("symbolize", | 155 | + .def_static( |
| 156 | - [](uint8_t v) -> ascendc::ReduceOrder { return static_cast<ascendc::ReduceOrder>(v); }); | 156 | + "symbolize", [](uint8_t v) -> ascendc::ReduceOrder { return static_cast<ascendc::ReduceOrder>(v); }); |
| 157 | 157 | ||
| 158 | py::enum_<ascendc::RoundMode>(m, "RoundMode", py::module_local()) | 158 | py::enum_<ascendc::RoundMode>(m, "RoundMode", py::module_local()) |
| 159 | .value("CAST_NONE", ascendc::RoundMode::CAST_NONE) | 159 | .value("CAST_NONE", ascendc::RoundMode::CAST_NONE) |
| @@ -166,8 +166,8 @@ void pyasc_bind_enums(py::module &m) | |||
| 166 | .def_static("symbolize", [](uint8_t v) -> ascendc::RoundMode { return static_cast<ascendc::RoundMode>(v); }); | 166 | .def_static("symbolize", [](uint8_t v) -> ascendc::RoundMode { return static_cast<ascendc::RoundMode>(v); }); |
| 167 | 167 | ||
| 168 | py::enum_<ascendc::TPosition>(m, "TPosition", py::module_local()) | 168 | py::enum_<ascendc::TPosition>(m, "TPosition", py::module_local()) |
| 169 | - .def_static("symbolize", | 169 | + .def_static( |
| 170 | - [](uint8_t pos) -> ascendc::TPosition { return static_cast<ascendc::TPosition>(pos); }); | 170 | + "symbolize", [](uint8_t pos) -> ascendc::TPosition { return static_cast<ascendc::TPosition>(pos); }); |
| 171 | 171 | ||
| 172 | py::enum_<ascendc::CMPMODE>(m, "CMPMODE", py::module_local()) | 172 | py::enum_<ascendc::CMPMODE>(m, "CMPMODE", py::module_local()) |
| 173 | .value("LT", ascendc::CMPMODE::LT) | 173 | .value("LT", ascendc::CMPMODE::LT) |
| @@ -176,26 +176,24 @@ void pyasc_bind_enums(py::module &m) | |||
| 176 | .value("LE", ascendc::CMPMODE::LE) | 176 | .value("LE", ascendc::CMPMODE::LE) |
| 177 | .value("GE", ascendc::CMPMODE::GE) | 177 | .value("GE", ascendc::CMPMODE::GE) |
| 178 | .value("NE", ascendc::CMPMODE::NE) | 178 | .value("NE", ascendc::CMPMODE::NE) |
| 179 | - .def_static("symbolize", [](uint8_t cmp_mode) -> ascendc::CMPMODE { | 179 | + .def_static( |
| 180 | - return static_cast<ascendc::CMPMODE>(cmp_mode); | 180 | + "symbolize", [](uint8_t cmp_mode) -> ascendc::CMPMODE { return static_cast<ascendc::CMPMODE>(cmp_mode); }); |
| 181 | - }); | ||
| 182 | 181 | ||
| 183 | py::enum_<ascendc::SELMODE>(m, "SELMODE", py::module_local()) | 182 | py::enum_<ascendc::SELMODE>(m, "SELMODE", py::module_local()) |
| 184 | .value("VSEL_CMPMASK_SPR", ascendc::SELMODE::VSEL_CMPMASK_SPR) | 183 | .value("VSEL_CMPMASK_SPR", ascendc::SELMODE::VSEL_CMPMASK_SPR) |
| 185 | .value("VSEL_TENSOR_SCALAR_MODE", ascendc::SELMODE::VSEL_TENSOR_SCALAR_MODE) | 184 | .value("VSEL_TENSOR_SCALAR_MODE", ascendc::SELMODE::VSEL_TENSOR_SCALAR_MODE) |
| 186 | .value("VSEL_TENSOR_TENSOR_MODE", ascendc::SELMODE::VSEL_TENSOR_TENSOR_MODE) | 185 | .value("VSEL_TENSOR_TENSOR_MODE", ascendc::SELMODE::VSEL_TENSOR_TENSOR_MODE) |
| 187 | - .def_static("symbolize", [](uint8_t sel_mode) -> ascendc::SELMODE { | 186 | + .def_static( |
| 188 | - return static_cast<ascendc::SELMODE>(sel_mode); | 187 | + "symbolize", [](uint8_t sel_mode) -> ascendc::SELMODE { return static_cast<ascendc::SELMODE>(sel_mode); }); |
| 189 | - }); | ||
| 190 | } | 188 | } |
| 191 | 189 | ||
| 192 | -void pyasc_bind_context_and_dialect(py::module &m) | 190 | +void pyasc_bind_context_and_dialect(py::module& m) |
| 193 | { | 191 | { |
| 194 | py::class_<MLIRContext>(m, "Context", py::module_local()) | 192 | py::class_<MLIRContext>(m, "Context", py::module_local()) |
| 195 | .def(py::init<>()) | 193 | .def(py::init<>()) |
| 196 | - .def("disable_multithreading", [](MLIRContext &self) { self.disableMultithreading(); }); | 194 | + .def("disable_multithreading", [](MLIRContext& self) { self.disableMultithreading(); }); |
| 197 | 195 | ||
| 198 | - m.def("load_dialects", [](MLIRContext &context) { | 196 | + m.def("load_dialects", [](MLIRContext& context) { |
| 199 | DialectRegistry registry; | 197 | DialectRegistry registry; |
| 200 | registry.insert< | 198 | registry.insert< |
| 201 | // | 199 | // |
| @@ -212,39 +210,42 @@ void pyasc_bind_context_and_dialect(py::module &m) | |||
| 212 | }); | 210 | }); |
| 213 | } | 211 | } |
| 214 | 212 | ||
| 215 | -void pyasc_bind_type(py::module &m) | 213 | +void pyasc_bind_type(py::module& m) |
| 216 | { | 214 | { |
| 217 | using namespace pybind11::literals; | 215 | using namespace pybind11::literals; |
| 218 | py::class_<Type>(m, "Type", py::module_local()) | 216 | py::class_<Type>(m, "Type", py::module_local()) |
| 219 | - .def("is_integer", [](Type &self) -> bool { return self.isInteger(); }) | 217 | + .def("is_integer", [](Type& self) -> bool { return self.isInteger(); }) |
| 220 | .def("is_index", &Type::isIndex) | 218 | .def("is_index", &Type::isIndex) |
| 221 | - .def("__eq__", | 219 | + .def( |
| 222 | - [](Type &self, py::object &other) { | 220 | + "__eq__", |
| 223 | - Type *other_ty = py::cast<Type *>(other); | 221 | + [](Type& self, py::object& other) { |
| 224 | - return (other_ty != nullptr) && (*other_ty == self); | 222 | + Type* other_ty = py::cast<Type*>(other); |
| 225 | - }) | 223 | + return (other_ty != nullptr) && (*other_ty == self); |
| 226 | - .def("__ne__", | 224 | + }) |
| 227 | - [](Type &self, py::object &other) { | 225 | + .def( |
| 228 | - Type *other_ty = py::cast<Type *>(other); | 226 | + "__ne__", |
| 229 | - return (other_ty == nullptr) || (*other_ty != self); | 227 | + [](Type& self, py::object& other) { |
| 230 | - }) | 228 | + Type* other_ty = py::cast<Type*>(other); |
| 231 | - .def("get_py_name", | 229 | + return (other_ty == nullptr) || (*other_ty != self); |
| 232 | - [](Type &self) -> std::optional<std::string> { | 230 | + }) |
| 233 | - if (isa<IntegerType>(self)) { | 231 | + .def( |
| 234 | - std::string name = self.isUnsignedInteger() ? "uint" : "int"; | 232 | + "get_py_name", |
| 235 | - name += std::to_string(self.getIntOrFloatBitWidth()); | 233 | + [](Type& self) -> std::optional<std::string> { |
| 236 | - return name; | 234 | + if (isa<IntegerType>(self)) { |
| 237 | - } | 235 | + std::string name = self.isUnsignedInteger() ? "uint" : "int"; |
| 238 | - if (isa<FloatType>(self)) { | 236 | + name += std::to_string(self.getIntOrFloatBitWidth()); |
| 239 | - std::string name = "float"; | 237 | + return name; |
| 240 | - name += std::to_string(self.getIntOrFloatBitWidth()); | 238 | + } |
| 241 | - return name; | 239 | + if (isa<FloatType>(self)) { |
| 242 | - } | 240 | + std::string name = "float"; |
| 243 | - if (isa<NoneType>(self)) | 241 | + name += std::to_string(self.getIntOrFloatBitWidth()); |
| 244 | - return "void"; | 242 | + return name; |
| 245 | - return std::nullopt; | 243 | + } |
| 246 | - }) | 244 | + if (isa<NoneType>(self)) |
| 247 | - .def("__str__", [](Type &self) { | 245 | + return "void"; |
| 246 | + return std::nullopt; | ||
| 247 | + }) | ||
| 248 | + .def("__str__", [](Type& self) { | ||
| 248 | std::string str; | 249 | std::string str; |
| 249 | llvm::raw_string_ostream os(str); | 250 | llvm::raw_string_ostream os(str); |
| 250 | self.print(os); | 251 | self.print(os); |
| @@ -253,29 +254,30 @@ void pyasc_bind_type(py::module &m) | |||
| 253 | }); | 254 | }); |
| 254 | } | 255 | } |
| 255 | 256 | ||
| 256 | -void pyasc_bind_memref(py::module &m) | 257 | +void pyasc_bind_memref(py::module& m) |
| 257 | { | 258 | { |
| 258 | using namespace pybind11::literals; | 259 | using namespace pybind11::literals; |
| 259 | - m.def("get_element_type", [](const Type &shapedType) -> Type { | 260 | + m.def("get_element_type", [](const Type& shapedType) -> Type { |
| 260 | auto type = llvm::dyn_cast_if_present<ShapedType>(shapedType); | 261 | auto type = llvm::dyn_cast_if_present<ShapedType>(shapedType); |
| 261 | if (!type) | 262 | if (!type) |
| 262 | throw std::runtime_error("get_element_type(): must be shaped type"); | 263 | throw std::runtime_error("get_element_type(): must be shaped type"); |
| 263 | return type.getElementType(); | 264 | return type.getElementType(); |
| 264 | }); | 265 | }); |
| 265 | 266 | ||
| 266 | - m.def("get_shape", [](const Type &shapedType) -> std::vector<int64_t> { | 267 | + m.def("get_shape", [](const Type& shapedType) -> std::vector<int64_t> { |
| 267 | auto type = llvm::dyn_cast_if_present<ShapedType>(shapedType); | 268 | auto type = llvm::dyn_cast_if_present<ShapedType>(shapedType); |
| 268 | if (!type) | 269 | if (!type) |
| 269 | throw std::runtime_error("get_shape(): must be shaped type"); | 270 | throw std::runtime_error("get_shape(): must be shaped type"); |
| 270 | return type.getShape().vec(); | 271 | return type.getShape().vec(); |
| 271 | }); | 272 | }); |
| 272 | 273 | ||
| 273 | - m.def("get_vector_type", | 274 | + m.def("get_vector_type", [](Type& elementType, std::vector<int64_t>& shape) -> Type { |
| 274 | - [](Type &elementType, std::vector<int64_t> &shape) -> Type { return VectorType::get(shape, elementType); }); | 275 | + return VectorType::get(shape, elementType); |
| 276 | + }); | ||
| 275 | 277 | ||
| 276 | m.def( | 278 | m.def( |
| 277 | "get_memref_type", | 279 | "get_memref_type", |
| 278 | - [](Type &elementType, const std::variant<std::vector<int64_t>, int64_t> &shape, | 280 | + [](Type& elementType, const std::variant<std::vector<int64_t>, int64_t>& shape, |
| 279 | std::optional<int64_t> addressSpace) -> Type { | 281 | std::optional<int64_t> addressSpace) -> Type { |
| 280 | Attribute memorySpace; | 282 | Attribute memorySpace; |
| 281 | if (auto as = addressSpace.value_or(0)) { | 283 | if (auto as = addressSpace.value_or(0)) { |
| @@ -285,15 +287,15 @@ void pyasc_bind_memref(py::module &m) | |||
| 285 | if (std::holds_alternative<int64_t>(shape)) { | 287 | if (std::holds_alternative<int64_t>(shape)) { |
| 286 | sh.push_back(std::get<int64_t>(shape)); | 288 | sh.push_back(std::get<int64_t>(shape)); |
| 287 | } else { | 289 | } else { |
| 288 | - const auto &shapeVec = std::get<std::vector<int64_t>>(shape); | 290 | + const auto& shapeVec = std::get<std::vector<int64_t>>(shape); |
| 289 | sh.append(shapeVec.begin(), shapeVec.end()); | 291 | sh.append(shapeVec.begin(), shapeVec.end()); |
| 290 | } | 292 | } |
| 291 | - return MemRefType::get(sh, elementType, AffineMap {}, memorySpace); | 293 | + return MemRefType::get(sh, elementType, AffineMap{}, memorySpace); |
| 292 | }, | 294 | }, |
| 293 | "element_type"_a, "shape"_a, "address_space"_a = py::none()); | 295 | "element_type"_a, "shape"_a, "address_space"_a = py::none()); |
| 294 | m.def( | 296 | m.def( |
| 295 | "get_unranked_memref_type", | 297 | "get_unranked_memref_type", |
| 296 | - [](Type &elementType, std::optional<int64_t> addressSpace) -> Type { | 298 | + [](Type& elementType, std::optional<int64_t> addressSpace) -> Type { |
| 297 | Attribute memorySpace; | 299 | Attribute memorySpace; |
| 298 | if (auto as = addressSpace.value_or(0)) | 300 | if (auto as = addressSpace.value_or(0)) |
| 299 | memorySpace = IntegerAttr::get(IntegerType::get(elementType.getContext(), INDEX_64), as); | 301 | memorySpace = IntegerAttr::get(IntegerType::get(elementType.getContext(), INDEX_64), as); |
| @@ -302,30 +304,32 @@ void pyasc_bind_memref(py::module &m) | |||
| 302 | "element_type"_a, "address_space"_a = py::none()); | 304 | "element_type"_a, "address_space"_a = py::none()); |
| 303 | } | 305 | } |
| 304 | 306 | ||
| 305 | -void pyasc_bind_tensor_type(py::module &m) | 307 | +void pyasc_bind_tensor_type(py::module& m) |
| 306 | { | 308 | { |
| 307 | using namespace pybind11::literals; | 309 | using namespace pybind11::literals; |
| 308 | - m.def("get_global_tensor_type", [](Type &elementType, std::vector<int64_t> &shape) -> Type { | 310 | + m.def("get_global_tensor_type", [](Type& elementType, std::vector<int64_t>& shape) -> Type { |
| 309 | return ascendc::GlobalTensorType::get(shape, elementType); | 311 | return ascendc::GlobalTensorType::get(shape, elementType); |
| 310 | }); | 312 | }); |
| 311 | 313 | ||
| 312 | - m.def("get_global_tensor_type", | 314 | + m.def("get_global_tensor_type", [](Type& elementType) -> Type { |
| 313 | - [](Type &elementType) -> Type { return ascendc::GlobalTensorType::get(elementType); }); | 315 | + return ascendc::GlobalTensorType::get(elementType); |
| 316 | + }); | ||
| 314 | 317 | ||
| 315 | - m.def("get_local_tensor_type", [](Type &elementType, std::vector<int64_t> &shape) -> Type { | 318 | + m.def("get_local_tensor_type", [](Type& elementType, std::vector<int64_t>& shape) -> Type { |
| 316 | return ascendc::LocalTensorType::get(shape, elementType); | 319 | return ascendc::LocalTensorType::get(shape, elementType); |
| 317 | }); | 320 | }); |
| 318 | 321 | ||
| 319 | - m.def("get_local_tensor_type", | 322 | + m.def( |
| 320 | - [](Type &elementType) -> Type { return ascendc::LocalTensorType::get(elementType); }); | 323 | + "get_local_tensor_type", [](Type& elementType) -> Type { return ascendc::LocalTensorType::get(elementType); }); |
| 321 | 324 | ||
| 322 | - m.def("get_opaque_type_name", | 325 | + m.def("get_opaque_type_name", [](Type& type) -> std::string { |
| 323 | - [](Type &type) -> std::string { return cast<emitc::OpaqueType>(type).getValue().str(); }); | 326 | + return cast<emitc::OpaqueType>(type).getValue().str(); |
| 327 | + }); | ||
| 324 | } | 328 | } |
| 325 | 329 | ||
| 326 | -void pyasc_bind_location(py::module &m) | 330 | +void pyasc_bind_location(py::module& m) |
| 327 | { | 331 | { |
| 328 | - py::class_<Location>(m, "Location", py::module_local()).def("__str__", [](Location &self) { | 332 | + py::class_<Location>(m, "Location", py::module_local()).def("__str__", [](Location& self) { |
| 329 | std::string str; | 333 | std::string str; |
| 330 | llvm::raw_string_ostream os(str); | 334 | llvm::raw_string_ostream os(str); |
| 331 | self.print(os); | 335 | self.print(os); |
| @@ -333,43 +337,44 @@ void pyasc_bind_location(py::module &m) | |||
| 333 | }); | 337 | }); |
| 334 | } | 338 | } |
| 335 | 339 | ||
| 336 | -void pyasc_bind_value(py::module &m) | 340 | +void pyasc_bind_value(py::module& m) |
| 337 | { | 341 | { |
| 338 | using ret = py::return_value_policy; | 342 | using ret = py::return_value_policy; |
| 339 | py::class_<Value>(m, "Value", py::module_local()) | 343 | py::class_<Value>(m, "Value", py::module_local()) |
| 340 | .def("get_context", &Value::getContext, ret::reference) | 344 | .def("get_context", &Value::getContext, ret::reference) |
| 341 | .def( | 345 | .def( |
| 342 | "get_defining_op", | 346 | "get_defining_op", |
| 343 | - [](Value &self) -> std::optional<Operation *> { | 347 | + [](Value& self) -> std::optional<Operation*> { |
| 344 | - auto *def = self.getDefiningOp(); | 348 | + auto* def = self.getDefiningOp(); |
| 345 | if (def) | 349 | if (def) |
| 346 | return def; | 350 | return def; |
| 347 | return std::nullopt; | 351 | return std::nullopt; |
| 348 | }, | 352 | }, |
| 349 | ret::reference) | 353 | ret::reference) |
| 350 | - .def("replace_all_uses_with", [](Value &self, Value &newValue) { self.replaceAllUsesWith(newValue); }) | 354 | + .def("replace_all_uses_with", [](Value& self, Value& newValue) { self.replaceAllUsesWith(newValue); }) |
| 351 | - .def("replace_uses_in_block", | 355 | + .def( |
| 352 | - [](Value &self, Block *block, Value &newValue) { | 356 | + "replace_uses_in_block", |
| 353 | - self.replaceUsesWithIf(newValue, [block](OpOperand &opnd) -> bool { | 357 | + [](Value& self, Block* block, Value& newValue) { |
| 354 | - auto *op = opnd.getOwner(); | 358 | + self.replaceUsesWithIf(newValue, [block](OpOperand& opnd) -> bool { |
| 355 | - Block *parentBlock = op->getBlock(); | 359 | + auto* op = opnd.getOwner(); |
| 356 | - while (parentBlock) { | 360 | + Block* parentBlock = op->getBlock(); |
| 357 | - if (parentBlock == block) | 361 | + while (parentBlock) { |
| 358 | - return true; | 362 | + if (parentBlock == block) |
| 359 | - if (auto *parentOp = parentBlock->getParentOp()) | 363 | + return true; |
| 360 | - parentBlock = parentOp->getBlock(); | 364 | + if (auto* parentOp = parentBlock->getParentOp()) |
| 361 | - else | 365 | + parentBlock = parentOp->getBlock(); |
| 362 | - parentBlock = nullptr; | 366 | + else |
| 363 | - } | 367 | + parentBlock = nullptr; |
| 364 | - return false; | 368 | + } |
| 365 | - }); | 369 | + return false; |
| 366 | - }) | 370 | + }); |
| 371 | + }) | ||
| 367 | .def("get_type", &Value::getType) | 372 | .def("get_type", &Value::getType) |
| 368 | .def("dump", &Value::dump) | 373 | .def("dump", &Value::dump) |
| 369 | - .def("id", [](Value &self) { return reinterpret_cast<uint64_t>(self.getImpl()); }); | 374 | + .def("id", [](Value& self) { return reinterpret_cast<uint64_t>(self.getImpl()); }); |
| 370 | } | 375 | } |
| 371 | 376 | ||
| 372 | -void pyasc_bind_region(py::module &m) | 377 | +void pyasc_bind_region(py::module& m) |
| 373 | { | 378 | { |
| 374 | using ret = py::return_value_policy; | 379 | using ret = py::return_value_policy; |
| 375 | py::class_<OpResult, Value>(m, "OpResult", py::module_local()); | 380 | py::class_<OpResult, Value>(m, "OpResult", py::module_local()); |
| @@ -378,51 +383,53 @@ void pyasc_bind_region(py::module &m) | |||
| 378 | .def("get_parent_region", &Region::getParentRegion, ret::reference) | 383 | .def("get_parent_region", &Region::getParentRegion, ret::reference) |
| 379 | .def( | 384 | .def( |
| 380 | "get_block", | 385 | "get_block", |
| 381 | - [](Region &self, unsigned index) -> Block & { | 386 | + [](Region& self, unsigned index) -> Block& { |
| 382 | if (index >= self.getBlocks().size()) | 387 | if (index >= self.getBlocks().size()) |
| 383 | throw std::runtime_error("block index is out of range"); | 388 | throw std::runtime_error("block index is out of range"); |
| 384 | return *std::next(self.begin(), index); | 389 | return *std::next(self.begin(), index); |
| 385 | }, | 390 | }, |
| 386 | ret::reference) | 391 | ret::reference) |
| 387 | - .def("size", [](Region &self) { return self.getBlocks().size(); }) | 392 | + .def("size", [](Region& self) { return self.getBlocks().size(); }) |
| 388 | .def("empty", &Region::empty) | 393 | .def("empty", &Region::empty) |
| 389 | - .def("id", [](Region &self) { return (uint64_t)&self; }); | 394 | + .def("id", [](Region& self) { return (uint64_t)&self; }); |
| 390 | } | 395 | } |
| 391 | 396 | ||
| 392 | -void pyasc_bind_blocks(py::module &m) | 397 | +void pyasc_bind_blocks(py::module& m) |
| 393 | { | 398 | { |
| 394 | using ret = py::return_value_policy; | 399 | using ret = py::return_value_policy; |
| 395 | py::class_<Block>(m, "Block", py::module_local()) | 400 | py::class_<Block>(m, "Block", py::module_local()) |
| 396 | .def(py::init()) | 401 | .def(py::init()) |
| 397 | .def("dump", &Block::dump) | 402 | .def("dump", &Block::dump) |
| 398 | - .def("id", [](Block &self) { return (uint64_t)&self; }) | 403 | + .def("id", [](Block& self) { return (uint64_t)&self; }) |
| 399 | .def("has_terminator", &Block::mightHaveTerminator) | 404 | .def("has_terminator", &Block::mightHaveTerminator) |
| 400 | .def("get_terminator", &Block::getTerminator, ret::reference) | 405 | .def("get_terminator", &Block::getTerminator, ret::reference) |
| 401 | - .def("add_argument", | 406 | + .def( |
| 402 | - [](Block &self, Type &type) -> BlockArgument { | 407 | + "add_argument", |
| 403 | - return self.addArgument(type, UnknownLoc::get(type.getContext())); | 408 | + [](Block& self, Type& type) -> BlockArgument { |
| 404 | - }) | 409 | + return self.addArgument(type, UnknownLoc::get(type.getContext())); |
| 410 | + }) | ||
| 405 | .def("get_argument", &Block::getArgument) | 411 | .def("get_argument", &Block::getArgument) |
| 406 | - .def("get_arguments", [](Block &self) -> std::vector<BlockArgument> { return self.getArguments().vec(); }) | 412 | + .def("get_arguments", [](Block& self) -> std::vector<BlockArgument> { return self.getArguments().vec(); }) |
| 407 | - .def("merge_block_before", | 413 | + .def( |
| 408 | - [](Block &self, Block &dst) { | 414 | + "merge_block_before", |
| 409 | - // See RewriterBase::mergeBlocks() | 415 | + [](Block& self, Block& dst) { |
| 410 | - if (self.getNumArguments() != 0) | 416 | + // See RewriterBase::mergeBlocks() |
| 411 | - throw std::runtime_error("Unable to merge block with arguments"); | 417 | + if (self.getNumArguments() != 0) |
| 412 | - dst.getOperations().splice(dst.begin(), self.getOperations()); | 418 | + throw std::runtime_error("Unable to merge block with arguments"); |
| 413 | - self.dropAllUses(); | 419 | + dst.getOperations().splice(dst.begin(), self.getOperations()); |
| 414 | - if (self.getParent()) | 420 | + self.dropAllUses(); |
| 415 | - self.erase(); | 421 | + if (self.getParent()) |
| 416 | - }) | 422 | + self.erase(); |
| 423 | + }) | ||
| 417 | .def("clear", &Block::clear) | 424 | .def("clear", &Block::clear) |
| 418 | .def("erase", &Block::erase); | 425 | .def("erase", &Block::erase); |
| 419 | } | 426 | } |
| 420 | 427 | ||
| 421 | -void pyasc_bind_inline_block(py::module &m) | 428 | +void pyasc_bind_inline_block(py::module& m) |
| 422 | { | 429 | { |
| 423 | m.def( | 430 | m.def( |
| 424 | "inline_block_at_end", | 431 | "inline_block_at_end", |
| 425 | - [](Block *src, Block *dst, const std::optional<std::vector<Value>> &args) { | 432 | + [](Block* src, Block* dst, const std::optional<std::vector<Value>>& args) { |
| 426 | // See RewriterBase::inlineBlockBefore() | 433 | // See RewriterBase::inlineBlockBefore() |
| 427 | ValueRange argValues({}); | 434 | ValueRange argValues({}); |
| 428 | if (args) | 435 | if (args) |
| @@ -443,27 +450,28 @@ void pyasc_bind_inline_block(py::module &m) | |||
| 443 | "src"_a, "dst"_a, "args"_a = py::none()); | 450 | "src"_a, "dst"_a, "args"_a = py::none()); |
| 444 | } | 451 | } |
| 445 | 452 | ||
| 446 | -void pyasc_bind_attritube(py::module &m) | 453 | +void pyasc_bind_attritube(py::module& m) |
| 447 | { | 454 | { |
| 448 | using ret = py::return_value_policy; | 455 | using ret = py::return_value_policy; |
| 449 | py::class_<Attribute>(m, "Attribute", py::module_local()) | 456 | py::class_<Attribute>(m, "Attribute", py::module_local()) |
| 450 | .def("dump", &Attribute::dump) | 457 | .def("dump", &Attribute::dump) |
| 451 | - .def("id", [](Attribute &self) { return reinterpret_cast<uint64_t>(self.getAsOpaquePointer()); }); | 458 | + .def("id", [](Attribute& self) { return reinterpret_cast<uint64_t>(self.getAsOpaquePointer()); }); |
| 452 | 459 | ||
| 453 | py::class_<ArrayAttr, Attribute>(m, "ArrayAttr", py::module_local()); | 460 | py::class_<ArrayAttr, Attribute>(m, "ArrayAttr", py::module_local()); |
| 454 | 461 | ||
| 455 | - m.def("get_type_attr", [](const Type &type) -> Attribute { return TypeAttr::get(type); }); | 462 | + m.def("get_type_attr", [](const Type& type) -> Attribute { return TypeAttr::get(type); }); |
| 456 | } | 463 | } |
| 457 | 464 | ||
| 458 | -void pyasc_bind_operation(py::module &m) | 465 | +void pyasc_bind_operation(py::module& m) |
| 459 | { | 466 | { |
| 460 | using ret = py::return_value_policy; | 467 | using ret = py::return_value_policy; |
| 461 | py::class_<Operation, std::unique_ptr<Operation, py::nodelete>>(m, "Operation", py::module_local()) | 468 | py::class_<Operation, std::unique_ptr<Operation, py::nodelete>>(m, "Operation", py::module_local()) |
| 462 | - .def("get_name", | 469 | + .def( |
| 463 | - [](Operation &self) { | 470 | + "get_name", |
| 464 | - llvm::StringRef opName = self.getName().getStringRef(); | 471 | + [](Operation& self) { |
| 465 | - return opName.str(); | 472 | + llvm::StringRef opName = self.getName().getStringRef(); |
| 466 | - }) | 473 | + return opName.str(); |
| 474 | + }) | ||
| 467 | .def("get_num_operands", &Operation::getNumOperands) | 475 | .def("get_num_operands", &Operation::getNumOperands) |
| 468 | .def("get_operand", &Operation::getOperand) | 476 | .def("get_operand", &Operation::getOperand) |
| 469 | .def("get_num_results", &Operation::getNumResults) | 477 | .def("get_num_results", &Operation::getNumResults) |
| @@ -471,30 +479,34 @@ void pyasc_bind_operation(py::module &m) | |||
| 471 | .def("get_num_regions", &Operation::getNumRegions) | 479 | .def("get_num_regions", &Operation::getNumRegions) |
| 472 | .def("get_region", &Operation::getRegion, ret::reference) | 480 | .def("get_region", &Operation::getRegion, ret::reference) |
| 473 | .def("get_block", &Operation::getBlock, ret::reference) | 481 | .def("get_block", &Operation::getBlock, ret::reference) |
| 474 | - .def("has_unit_attr", | 482 | + .def( |
| 475 | - [](Operation &self, const std::string &name) -> bool { return self.hasAttrOfType<UnitAttr>(name); }) | 483 | + "has_unit_attr", |
| 476 | - .def("get_str_attr", | 484 | + [](Operation& self, const std::string& name) -> bool { return self.hasAttrOfType<UnitAttr>(name); }) |
| 477 | - [](Operation &self, const std::string &name) -> std::optional<std::string> { | 485 | + .def( |
| 478 | - auto ret = self.getAttrOfType<StringAttr>(name); | 486 | + "get_str_attr", |
| 479 | - if (!ret) | 487 | + [](Operation& self, const std::string& name) -> std::optional<std::string> { |
| 480 | - return std::nullopt; | 488 | + auto ret = self.getAttrOfType<StringAttr>(name); |
| 481 | - return ret.getValue().str(); | 489 | + if (!ret) |
| 482 | - }) | 490 | + return std::nullopt; |
| 483 | - .def("get_bool_attr", | 491 | + return ret.getValue().str(); |
| 484 | - [](Operation &self, const std::string &name) -> std::optional<bool> { | 492 | + }) |
| 485 | - auto ret = self.getAttrOfType<BoolAttr>(name); | 493 | + .def( |
| 486 | - if (!ret) | 494 | + "get_bool_attr", |
| 487 | - return std::nullopt; | 495 | + [](Operation& self, const std::string& name) -> std::optional<bool> { |
| 488 | - return ret.getValue(); | 496 | + auto ret = self.getAttrOfType<BoolAttr>(name); |
| 489 | - }) | 497 | + if (!ret) |
| 490 | - .def("get_integer_attr", | 498 | + return std::nullopt; |
| 491 | - [](Operation &self, const std::string &name) -> py::object { | 499 | + return ret.getValue(); |
| 492 | - auto ret = self.getAttrOfType<IntegerAttr>(name); | 500 | + }) |
| 493 | - if (!ret) | 501 | + .def( |
| 494 | - return py::none(); | 502 | + "get_integer_attr", |
| 495 | - return py::int_(ret.getValue().getSExtValue()); | 503 | + [](Operation& self, const std::string& name) -> py::object { |
| 496 | - }) | 504 | + auto ret = self.getAttrOfType<IntegerAttr>(name); |
| 497 | - .def("get_flat_symbol_ref_attr", [](Operation &self, const std::string &name) -> py::object { | 505 | + if (!ret) |
| 506 | + return py::none(); | ||
| 507 | + return py::int_(ret.getValue().getSExtValue()); | ||
| 508 | + }) | ||
| 509 | + .def("get_flat_symbol_ref_attr", [](Operation& self, const std::string& name) -> py::object { | ||
| 498 | auto ret = self.getAttrOfType<FlatSymbolRefAttr>(name); | 510 | auto ret = self.getAttrOfType<FlatSymbolRefAttr>(name); |
| 499 | if (!ret) | 511 | if (!ret) |
| 500 | return py::none(); | 512 | return py::none(); |
| @@ -502,112 +514,118 @@ void pyasc_bind_operation(py::module &m) | |||
| 502 | }); | 514 | }); |
| 503 | } | 515 | } |
| 504 | 516 | ||
| 505 | -void pyasc_bind_opstate(py::module &m) | 517 | +void pyasc_bind_opstate(py::module& m) |
| 506 | { | 518 | { |
| 507 | using ret = py::return_value_policy; | 519 | using ret = py::return_value_policy; |
| 508 | py::class_<OpState>(m, "OpState", py::module_local()) | 520 | py::class_<OpState>(m, "OpState", py::module_local()) |
| 509 | .def("get_context", &OpState::getContext, ret::reference) | 521 | .def("get_context", &OpState::getContext, ret::reference) |
| 510 | - .def("set_attr", [](OpState &self, std::string &name, Attribute &attr) { self->setAttr(name, attr); }) | 522 | + .def("set_attr", [](OpState& self, std::string& name, Attribute& attr) { self->setAttr(name, attr); }) |
| 511 | - .def("get_num_results", [](OpState &self) -> unsigned { return self->getNumResults(); }) | 523 | + .def("get_num_results", [](OpState& self) -> unsigned { return self->getNumResults(); }) |
| 512 | - .def("get_result", | 524 | + .def( |
| 513 | - [](OpState &self, unsigned idx) -> Value { | 525 | + "get_result", |
| 514 | - if (idx >= self->getNumResults()) | 526 | + [](OpState& self, unsigned idx) -> Value { |
| 515 | - throw pybind11::index_error("Op result index out of range"); | 527 | + if (idx >= self->getNumResults()) |
| 516 | - return self->getResult(idx); | 528 | + throw pybind11::index_error("Op result index out of range"); |
| 517 | - }) | 529 | + return self->getResult(idx); |
| 530 | + }) | ||
| 518 | .def( | 531 | .def( |
| 519 | "get_region", | 532 | "get_region", |
| 520 | - [](OpState &self, unsigned idx) -> Region & { | 533 | + [](OpState& self, unsigned idx) -> Region& { |
| 521 | if (idx >= self->getNumRegions()) | 534 | if (idx >= self->getNumRegions()) |
| 522 | throw pybind11::index_error("Op region index out of range"); | 535 | throw pybind11::index_error("Op region index out of range"); |
| 523 | return self->getRegion(idx); | 536 | return self->getRegion(idx); |
| 524 | }, | 537 | }, |
| 525 | ret::reference) | 538 | ret::reference) |
| 526 | - .def("dump", [](OpState &self) { self->dump(); }) | 539 | + .def("dump", [](OpState& self) { self->dump(); }) |
| 527 | - .def("__str__", | 540 | + .def( |
| 528 | - [](OpState &self) -> std::string { | 541 | + "__str__", |
| 529 | - std::string str; | 542 | + [](OpState& self) -> std::string { |
| 530 | - llvm::raw_string_ostream os(str); | 543 | + std::string str; |
| 531 | - auto printingFlags = getOpPrintingFlags(); | 544 | + llvm::raw_string_ostream os(str); |
| 532 | - self->print(os, printingFlags); | 545 | + auto printingFlags = getOpPrintingFlags(); |
| 533 | - return str; | 546 | + self->print(os, printingFlags); |
| 534 | - }) | 547 | + return str; |
| 535 | - .def("append_operand", [](OpState &self, Value &val) { self->insertOperands(self->getNumOperands(), val); }) | 548 | + }) |
| 536 | - .def("verify", [](OpState &self) -> bool { return succeeded(verify(self.getOperation())); }) | 549 | + .def("append_operand", [](OpState& self, Value& val) { self->insertOperands(self->getNumOperands(), val); }) |
| 550 | + .def("verify", [](OpState& self) -> bool { return succeeded(verify(self.getOperation())); }) | ||
| 537 | .def_property_readonly("op", &OpState::getOperation, ret::reference); | 551 | .def_property_readonly("op", &OpState::getOperation, ret::reference); |
| 538 | } | 552 | } |
| 539 | 553 | ||
| 540 | -void pyasc_bind_moduleop(py::module &m) | 554 | +void pyasc_bind_moduleop(py::module& m) |
| 541 | { | 555 | { |
| 542 | using ret = py::return_value_policy; | 556 | using ret = py::return_value_policy; |
| 543 | py::class_<ModuleOp, OpState>(m, "ModuleOp", py::module_local()) | 557 | py::class_<ModuleOp, OpState>(m, "ModuleOp", py::module_local()) |
| 544 | .def("dump", &ModuleOp::dump) | 558 | .def("dump", &ModuleOp::dump) |
| 545 | .def( | 559 | .def( |
| 546 | - "get_body", [](ModuleOp &self) -> Block * { return self.getBody(); }, ret::reference) | 560 | + "get_body", [](ModuleOp& self) -> Block* { return self.getBody(); }, ret::reference) |
| 547 | .def( | 561 | .def( |
| 548 | "has_function", | 562 | "has_function", |
| 549 | - [](ModuleOp &self, const std::string &name, const std::optional<Type> &type) -> bool { | 563 | + [](ModuleOp& self, const std::string& name, const std::optional<Type>& type) -> bool { |
| 550 | - auto *op = SymbolTable::lookupSymbolIn(self, name); | 564 | + auto* op = SymbolTable::lookupSymbolIn(self, name); |
| 551 | if (auto funcOp = dyn_cast_if_present<func::FuncOp>(op)) | 565 | if (auto funcOp = dyn_cast_if_present<func::FuncOp>(op)) |
| 552 | return !type || funcOp.getFunctionType() == *type; | 566 | return !type || funcOp.getFunctionType() == *type; |
| 553 | return false; | 567 | return false; |
| 554 | }, | 568 | }, |
| 555 | "name"_a, "type"_a = py::none()) | 569 | "name"_a, "type"_a = py::none()) |
| 556 | - .def("need_insert_sync", | 570 | + .def( |
| 557 | - [](ModuleOp &self) { | 571 | + "need_insert_sync", |
| 558 | - auto result = self.walk([](ascendc::LocalTensorAutoOp) { return WalkResult::interrupt(); }); | 572 | + [](ModuleOp& self) { |
| 559 | - return result.wasInterrupted(); | 573 | + auto result = self.walk([](ascendc::LocalTensorAutoOp) { return WalkResult::interrupt(); }); |
| 560 | - }) | 574 | + return result.wasInterrupted(); |
| 561 | - .def("erase", [](ModuleOp &self) { self->erase(); }); | 575 | + }) |
| 576 | + .def("erase", [](ModuleOp& self) { self->erase(); }); | ||
| 562 | } | 577 | } |
| 563 | 578 | ||
| 564 | -void pyasc_bind_funcop(py::module &m) | 579 | +void pyasc_bind_funcop(py::module& m) |
| 565 | { | 580 | { |
| 566 | using ret = py::return_value_policy; | 581 | using ret = py::return_value_policy; |
| 567 | py::class_<func::FuncOp, OpState>(m, "FuncOp", py::module_local()) | 582 | py::class_<func::FuncOp, OpState>(m, "FuncOp", py::module_local()) |
| 568 | - .def("get_arg", | 583 | + .def( |
| 569 | - [](func::FuncOp &self, unsigned idx) -> BlockArgument { | 584 | + "get_arg", |
| 570 | - if (idx >= self.getNumArguments()) | 585 | + [](func::FuncOp& self, unsigned idx) -> BlockArgument { |
| 571 | - throw pybind11::index_error("Function argument index out of range"); | 586 | + if (idx >= self.getNumArguments()) |
| 572 | - return self.getArgument(idx); | 587 | + throw pybind11::index_error("Function argument index out of range"); |
| 573 | - }) | 588 | + return self.getArgument(idx); |
| 589 | + }) | ||
| 574 | .def("get_num_args", &func::FuncOp::getNumArguments) | 590 | .def("get_num_args", &func::FuncOp::getNumArguments) |
| 575 | .def( | 591 | .def( |
| 576 | - "add_entry_block", [](func::FuncOp &self) -> Block * { return self.addEntryBlock(); }, ret::reference) | 592 | + "add_entry_block", [](func::FuncOp& self) -> Block* { return self.addEntryBlock(); }, ret::reference) |
| 577 | - .def("set_type", | ||
| 578 | - [](func::FuncOp &self, const Type &funcType) { | ||
| 579 | - auto type = dyn_cast<FunctionType>(funcType); | ||
| 580 | - if (!type) | ||
| 581 | - throw std::runtime_error("set_type(): must be FunctionType"); | ||
| 582 | - self.setFunctionType(type); | ||
| 583 | - }) | ||
| 584 | - .def("set_arg_names", | ||
| 585 | - [](func::FuncOp &self, const std::vector<std::string> &names) { | ||
| 586 | - if (names.size() != self.getNumArguments()) | ||
| 587 | - throw std::runtime_error("Number of names must be equal to number of arguments"); | ||
| 588 | - for (unsigned i = 0; i < names.size(); i++) { | ||
| 589 | - auto arg = self.getArgument(i); | ||
| 590 | - auto name = StringAttr::get(self.getContext(), names[i]); | ||
| 591 | - arg.setLoc(NameLoc::get(name, arg.getLoc())); | ||
| 592 | - } | ||
| 593 | - }) | ||
| 594 | .def( | 593 | .def( |
| 595 | - "get_body", [](func::FuncOp &self) -> Block & { return self.getFunctionBody().front(); }, ret::reference) | 594 | + "set_type", |
| 596 | - .def("make_aicore", | 595 | + [](func::FuncOp& self, const Type& funcType) { |
| 597 | - [](func::FuncOp &self) { self->setAttr(ascendc::attr::aicore, UnitAttr::get(self.getContext())); }) | 596 | + auto type = dyn_cast<FunctionType>(funcType); |
| 598 | - .def("make_global", [](func::FuncOp &self) { | 597 | + if (!type) |
| 598 | + throw std::runtime_error("set_type(): must be FunctionType"); | ||
| 599 | + self.setFunctionType(type); | ||
| 600 | + }) | ||
| 601 | + .def( | ||
| 602 | + "set_arg_names", | ||
| 603 | + [](func::FuncOp& self, const std::vector<std::string>& names) { | ||
| 604 | + if (names.size() != self.getNumArguments()) | ||
| 605 | + throw std::runtime_error("Number of names must be equal to number of arguments"); | ||
| 606 | + for (unsigned i = 0; i < names.size(); i++) { | ||
| 607 | + auto arg = self.getArgument(i); | ||
| 608 | + auto name = StringAttr::get(self.getContext(), names[i]); | ||
| 609 | + arg.setLoc(NameLoc::get(name, arg.getLoc())); | ||
| 610 | + } | ||
| 611 | + }) | ||
| 612 | + .def( | ||
| 613 | + "get_body", [](func::FuncOp& self) -> Block& { return self.getFunctionBody().front(); }, ret::reference) | ||
| 614 | + .def( | ||
| 615 | + "make_aicore", | ||
| 616 | + [](func::FuncOp& self) { self->setAttr(ascendc::attr::aicore, UnitAttr::get(self.getContext())); }) | ||
| 617 | + .def("make_global", [](func::FuncOp& self) { | ||
| 599 | self.setPublic(); | 618 | self.setPublic(); |
| 600 | self->setAttr(ascendc::attr::global, UnitAttr::get(self.getContext())); | 619 | self->setAttr(ascendc::attr::global, UnitAttr::get(self.getContext())); |
| 601 | }); | 620 | }); |
| 602 | } | 621 | } |
| 603 | 622 | ||
| 604 | -void pyasc_bind_scfop(py::module &m) | 623 | +void pyasc_bind_scfop(py::module& m) |
| 605 | { | 624 | { |
| 606 | using ret = py::return_value_policy; | 625 | using ret = py::return_value_policy; |
| 607 | py::class_<scf::ForOp, OpState>(m, "ForOp", py::module_local()) | 626 | py::class_<scf::ForOp, OpState>(m, "ForOp", py::module_local()) |
| 608 | .def("get_induction_var", &scf::ForOp::getInductionVar) | 627 | .def("get_induction_var", &scf::ForOp::getInductionVar) |
| 609 | - .def( | 628 | + .def("get_body", [](scf::ForOp& self) -> Block* { return self.getBody(); }, ret::reference); |
| 610 | - "get_body", [](scf::ForOp &self) -> Block * { return self.getBody(); }, ret::reference); | ||
| 611 | py::class_<scf::IfOp, OpState>(m, "IfOp", py::module_local()) | 629 | py::class_<scf::IfOp, OpState>(m, "IfOp", py::module_local()) |
| 612 | .def("get_then_block", &scf::IfOp::thenBlock, ret::reference) | 630 | .def("get_then_block", &scf::IfOp::thenBlock, ret::reference) |
| 613 | .def("get_else_block", &scf::IfOp::elseBlock, ret::reference) | 631 | .def("get_else_block", &scf::IfOp::elseBlock, ret::reference) |
| @@ -620,13 +638,13 @@ void pyasc_bind_scfop(py::module &m) | |||
| 620 | py::class_<scf::ConditionOp, OpState>(m, "ConditionOp", py::module_local()); | 638 | py::class_<scf::ConditionOp, OpState>(m, "ConditionOp", py::module_local()); |
| 621 | } | 639 | } |
| 622 | 640 | ||
| 623 | -void pyasc_bind_kernel_argument(py::module &m) | 641 | +void pyasc_bind_kernel_argument(py::module& m) |
| 624 | { | 642 | { |
| 625 | py::enum_<emitasc::KernelArgument>(m, "KernelArgument", py::module_local()) | 643 | py::enum_<emitasc::KernelArgument>(m, "KernelArgument", py::module_local()) |
| 626 | .value("Explicit", emitasc::KernelArgument::Explicit) | 644 | .value("Explicit", emitasc::KernelArgument::Explicit) |
| 627 | .value("FftsAddr", emitasc::KernelArgument::FftsAddr); | 645 | .value("FftsAddr", emitasc::KernelArgument::FftsAddr); |
| 628 | 646 | ||
| 629 | - m.def("get_kernel_arg_attrs", [](ModuleOp &mod) -> py::object { | 647 | + m.def("get_kernel_arg_attrs", [](ModuleOp& mod) -> py::object { |
| 630 | auto kernelArgs = getKernelArgAttrs(mod); | 648 | auto kernelArgs = getKernelArgAttrs(mod); |
| 631 | if (!kernelArgs) { | 649 | if (!kernelArgs) { |
| 632 | return py::none(); | 650 | return py::none(); |
| @@ -639,7 +657,7 @@ void pyasc_bind_kernel_argument(py::module &m) | |||
| 639 | }); | 657 | }); |
| 640 | } | 658 | } |
| 641 | 659 | ||
| 642 | -void pyasc_init_ir(py::module &&m) | 660 | +void pyasc_init_ir(py::module&& m) |
| 643 | { | 661 | { |
| 644 | pyasc_bind_enums(m); | 662 | pyasc_bind_enums(m); |
| 645 | pyasc_bind_context_and_dialect(m); | 663 | pyasc_bind_context_and_dialect(m); |
| @@ -16,10 +16,10 @@ | |||
| 16 | 16 | ||
| 17 | namespace pybind11 { | 17 | namespace pybind11 { |
| 18 | namespace asc { | 18 | namespace asc { |
| 19 | -void pyasc_init_ir(pybind11::module &&m); // from IR.cpp | 19 | +void pyasc_init_ir(pybind11::module&& m); // from IR.cpp |
| 20 | -void pyasc_init_passes(pybind11::module &&m); // from Passes.cpp | 20 | +void pyasc_init_passes(pybind11::module&& m); // from Passes.cpp |
| 21 | -void pyasc_init_translation(pybind11::module &&m); // from Translation.cpp | 21 | +void pyasc_init_translation(pybind11::module&& m); // from Translation.cpp |
| 22 | -void pyasc_init_ir_builder(pybind11::module &m); | 22 | +void pyasc_init_ir_builder(pybind11::module& m); |
| 23 | } // namespace asc | 23 | } // namespace asc |
| 24 | } // namespace pybind11 | 24 | } // namespace pybind11 |
| 25 | 25 | ||
| @@ -23,54 +23,57 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | -#define DEFINE_ADD_PASS(NAME, CONSTRUCTOR) m.def(NAME, [](PassManager &pm) { pm.addPass(CONSTRUCTOR()); }) | 26 | +#define DEFINE_ADD_PASS(NAME, CONSTRUCTOR) m.def(NAME, [](PassManager& pm) { pm.addPass(CONSTRUCTOR()); }) |
| 27 | 27 | ||
| 28 | -#define DEFINE_ADD_PASS_ON(NEST, NAME, CONSTRUCTOR) \ | 28 | +#define DEFINE_ADD_PASS_ON(NEST, NAME, CONSTRUCTOR) \ |
| 29 | - m.def(NAME, [](PassManager &pm) { pm.addNestedPass<NEST>(CONSTRUCTOR()); }) | 29 | + m.def(NAME, [](PassManager& pm) { pm.addNestedPass<NEST>(CONSTRUCTOR()); }) |
| 30 | 30 | ||
| 31 | namespace py = pybind11; | 31 | namespace py = pybind11; |
| 32 | using namespace mlir; | 32 | using namespace mlir; |
| 33 | 33 | ||
| 34 | namespace { | 34 | namespace { |
| 35 | 35 | ||
| 36 | -void definePassManager(py::module &m) | 36 | +void definePassManager(py::module& m) |
| 37 | { | 37 | { |
| 38 | using namespace pybind11::literals; | 38 | using namespace pybind11::literals; |
| 39 | 39 | ||
| 40 | py::class_<PassManager>(m, "PassManager", py::module_local()) | 40 | py::class_<PassManager>(m, "PassManager", py::module_local()) |
| 41 | - .def(py::init<MLIRContext *>()) | 41 | + .def(py::init<MLIRContext*>()) |
| 42 | - .def("get_pipeline_str", | ||
| 43 | - [](PassManager &self) -> std::string { | ||
| 44 | - std::string result; | ||
| 45 | - llvm::raw_string_ostream os(result); | ||
| 46 | - self.printAsTextualPipeline(os); | ||
| 47 | - os.flush(); | ||
| 48 | - return result; | ||
| 49 | - }) | ||
| 50 | - .def("run", | ||
| 51 | - [](PassManager &self, ModuleOp &mod) { | ||
| 52 | - llvm::SourceMgr sourceMgr; | ||
| 53 | - SourceMgrDiagnosticHandler handler(sourceMgr, self.getContext()); | ||
| 54 | - if (self.run(mod.getOperation()).failed()) | ||
| 55 | - throw std::runtime_error("Failed to run passes"); | ||
| 56 | - }) | ||
| 57 | .def( | 42 | .def( |
| 58 | - "enable_verifier", [](PassManager &self, bool enable) { self.enableVerifier(enable); }, "enable"_a = true) | 43 | + "get_pipeline_str", |
| 59 | - .def("enable_printing", [](PassManager &self) { | 44 | + [](PassManager& self) -> std::string { |
| 45 | + std::string result; | ||
| 46 | + llvm::raw_string_ostream os(result); | ||
| 47 | + self.printAsTextualPipeline(os); | ||
| 48 | + os.flush(); | ||
| 49 | + return result; | ||
| 50 | + }) | ||
| 51 | + .def( | ||
| 52 | + "run", | ||
| 53 | + [](PassManager& self, ModuleOp& mod) { | ||
| 54 | + llvm::SourceMgr sourceMgr; | ||
| 55 | + SourceMgrDiagnosticHandler handler(sourceMgr, self.getContext()); | ||
| 56 | + if (self.run(mod.getOperation()).failed()) | ||
| 57 | + throw std::runtime_error("Failed to run passes"); | ||
| 58 | + }) | ||
| 59 | + .def( | ||
| 60 | + "enable_verifier", [](PassManager& self, bool enable) { self.enableVerifier(enable); }, "enable"_a = true) | ||
| 61 | + .def("enable_printing", [](PassManager& self) { | ||
| 60 | OpPrintingFlags flags; | 62 | OpPrintingFlags flags; |
| 61 | flags.enableDebugInfo(true); | 63 | flags.enableDebugInfo(true); |
| 62 | - self.enableIRPrinting([](Pass *, Operation *) { return true; }, /*shouldPrintBeforePass*/ | 64 | + self.enableIRPrinting( |
| 63 | - [](Pass *, Operation *) { return true; }, /*shouldPrintAfterPass*/ | 65 | + [](Pass*, Operation*) { return true; }, /*shouldPrintBeforePass*/ |
| 64 | - false, /*printModuleScope*/ | 66 | + [](Pass*, Operation*) { return true; }, /*shouldPrintAfterPass*/ |
| 65 | - false, /*printAfterOnlyOnChange*/ | 67 | + false, /*printModuleScope*/ |
| 66 | - true, /*printAfterOnlyOnFailure*/ | 68 | + false, /*printAfterOnlyOnChange*/ |
| 67 | - llvm::errs(), /*out*/ | 69 | + true, /*printAfterOnlyOnFailure*/ |
| 68 | - flags /*opPrintingFlags*/ | 70 | + llvm::errs(), /*out*/ |
| 71 | + flags /*opPrintingFlags*/ | ||
| 69 | ); | 72 | ); |
| 70 | }); | 73 | }); |
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | -void defineCommonPasses(py::module &mod) | 76 | +void defineCommonPasses(py::module& mod) |
| 74 | { | 77 | { |
| 75 | auto m = mod.def_submodule("common"); | 78 | auto m = mod.def_submodule("common"); |
| 76 | DEFINE_ADD_PASS("add_canonicalizer", createCanonicalizerPass); | 79 | DEFINE_ADD_PASS("add_canonicalizer", createCanonicalizerPass); |
| @@ -84,7 +87,7 @@ void defineCommonPasses(py::module &mod) | |||
| 84 | DEFINE_ADD_PASS("add_symbol_dce", createSymbolDCEPass); | 87 | DEFINE_ADD_PASS("add_symbol_dce", createSymbolDCEPass); |
| 85 | } | 88 | } |
| 86 | 89 | ||
| 87 | -void defineAscendCPasses(py::module &mod) | 90 | +void defineAscendCPasses(py::module& mod) |
| 88 | { | 91 | { |
| 89 | using namespace ascendc; | 92 | using namespace ascendc; |
| 90 | auto m = mod.def_submodule("ascendc"); | 93 | auto m = mod.def_submodule("ascendc"); |
| @@ -110,7 +113,7 @@ void defineAscendCPasses(py::module &mod) | |||
| 110 | 113 | ||
| 111 | namespace pybind11 { | 114 | namespace pybind11 { |
| 112 | namespace asc { | 115 | namespace asc { |
| 113 | -void pyasc_init_passes(py::module &&m) | 116 | +void pyasc_init_passes(py::module&& m) |
| 114 | { | 117 | { |
| 115 | definePassManager(m); | 118 | definePassManager(m); |
| 116 | defineCommonPasses(m); | 119 | defineCommonPasses(m); |
| @@ -26,9 +26,9 @@ using namespace mlir; | |||
| 26 | 26 | ||
| 27 | namespace pybind11 { | 27 | namespace pybind11 { |
| 28 | namespace asc { | 28 | namespace asc { |
| 29 | -void pyasc_init_translation(py::module &&m) | 29 | +void pyasc_init_translation(py::module&& m) |
| 30 | { | 30 | { |
| 31 | - m.def("ir_to_ascendc", [](ModuleOp &mod) -> std::string { | 31 | + m.def("ir_to_ascendc", [](ModuleOp& mod) -> std::string { |
| 32 | std::string result; | 32 | std::string result; |
| 33 | llvm::raw_string_ostream os(result); | 33 | llvm::raw_string_ostream os(result); |
| 34 | if (translateToAscendC(mod.getOperation(), os).failed()) | 34 | if (translateToAscendC(mod.getOperation(), os).failed()) |