├── .clang-format ├── .gitignore ├── .gitmodules ├── 1-summary └── 前言.md ├── 10-mlir_opt-and-debug ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ ├── DistributeParallelismInterfaces.td │ │ ├── FusionRegionInterfaces.h │ │ └── FusionRegionInterfaces.td │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp ├── src │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.cpp │ │ │ ├── NorthStarDialect.cpp │ │ │ ├── NorthStarOps.cpp │ │ │ └── NorthStarTypes.cpp │ │ │ └── Transforms │ │ │ ├── ApplyDistributeTransform.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── DeviceRegionFusion.cpp │ │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.cpp │ │ └── FusionRegionInterfaces.cpp │ ├── Tools │ │ ├── CMakeLists.txt │ │ └── NS-opt │ │ │ ├── CMakeLists.txt │ │ │ └── NS-opt.cpp │ └── Utils │ │ ├── CMakeLists.txt │ │ └── File.cpp └── test │ └── softmax.mlir ├── 11-lit_for_test ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ ├── DistributeParallelismInterfaces.td │ │ ├── FusionRegionInterfaces.h │ │ └── FusionRegionInterfaces.td │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp ├── src │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.cpp │ │ │ ├── NorthStarDialect.cpp │ │ │ ├── NorthStarOps.cpp │ │ │ └── NorthStarTypes.cpp │ │ │ └── Transforms │ │ │ ├── ApplyDistributeTransform.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── DeviceRegionFusion.cpp │ │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.cpp │ │ └── FusionRegionInterfaces.cpp │ ├── Tools │ │ ├── CMakeLists.txt │ │ └── NS-opt │ │ │ ├── CMakeLists.txt │ │ │ └── NS-opt.cpp │ └── Utils │ │ ├── CMakeLists.txt │ │ └── File.cpp └── test │ ├── CMakeLists.txt │ ├── NorthStar │ ├── apply-distribute-transform.mlir │ ├── device-region-fusion.mlir │ └── mark-distribute-parallel-parameters.mlir │ ├── lit.cfg.py │ └── lit.site.cfg.py.in ├── 12-operation_lowing_pass ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ ├── NorthStarToLinalg │ │ │ └── NorthStarToLinalg.h │ │ ├── Passes.h │ │ └── Passes.td │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ ├── DistributeParallelismInterfaces.td │ │ ├── FusionRegionInterfaces.h │ │ └── FusionRegionInterfaces.td │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp ├── src │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ └── NorthStarToLinalg │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarToLinalg.cpp │ │ │ └── NorthStarToLinalgPass.cpp │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.cpp │ │ │ ├── NorthStarDialect.cpp │ │ │ ├── NorthStarOps.cpp │ │ │ └── NorthStarTypes.cpp │ │ │ └── Transforms │ │ │ ├── ApplyDistributeTransform.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── DeviceRegionFusion.cpp │ │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.cpp │ │ └── FusionRegionInterfaces.cpp │ ├── Tools │ │ ├── CMakeLists.txt │ │ └── NS-opt │ │ │ ├── CMakeLists.txt │ │ │ └── NS-opt.cpp │ └── Utils │ │ ├── CMakeLists.txt │ │ └── File.cpp └── test │ ├── CMakeLists.txt │ ├── Conversion │ └── north_star_to_linalg.mlir │ ├── NorthStar │ ├── apply-distribute-transform.mlir │ ├── device-region-fusion.mlir │ └── mark-distribute-parallel-parameters.mlir │ ├── lit.cfg.py │ └── lit.site.cfg.py.in ├── 13-pass_manager ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ ├── NorthStarToLinalg │ │ │ └── NorthStarToLinalg.h │ │ ├── Passes.h │ │ └── Passes.td │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ ├── DistributeParallelismInterfaces.td │ │ ├── FusionRegionInterfaces.h │ │ └── FusionRegionInterfaces.td │ ├── Pipelines │ │ └── Pipelines.h │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp ├── src │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ └── NorthStarToLinalg │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarToLinalg.cpp │ │ │ └── NorthStarToLinalgPass.cpp │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.cpp │ │ │ ├── NorthStarDialect.cpp │ │ │ ├── NorthStarOps.cpp │ │ │ └── NorthStarTypes.cpp │ │ │ └── Transforms │ │ │ ├── ApplyDistributeTransform.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── DeviceRegionFusion.cpp │ │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.cpp │ │ └── FusionRegionInterfaces.cpp │ ├── Pipelines │ │ ├── CMakeLists.txt │ │ └── NorthStarBasicPipeline.cpp │ ├── Tools │ │ ├── CMakeLists.txt │ │ └── NS-opt │ │ │ ├── CMakeLists.txt │ │ │ └── NS-opt.cpp │ └── Utils │ │ ├── CMakeLists.txt │ │ └── File.cpp └── test │ ├── CMakeLists.txt │ ├── Conversion │ └── north_star_to_linalg.mlir │ ├── NorthStar │ ├── apply-distribute-transform.mlir │ ├── device-region-fusion.mlir │ └── mark-distribute-parallel-parameters.mlir │ ├── lit.cfg.py │ └── lit.site.cfg.py.in ├── 14-fold_and_canonicalization ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ ├── NorthStarToLinalg │ │ │ └── NorthStarToLinalg.h │ │ ├── Passes.h │ │ └── Passes.td │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ ├── DistributeParallelismInterfaces.td │ │ ├── FusionRegionInterfaces.h │ │ └── FusionRegionInterfaces.td │ ├── Pipelines │ │ └── Pipelines.h │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp ├── src │ ├── CMakeLists.txt │ ├── Conversion │ │ ├── CMakeLists.txt │ │ └── NorthStarToLinalg │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarToLinalg.cpp │ │ │ └── NorthStarToLinalgPass.cpp │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.cpp │ │ │ ├── NorthStarCanonicalize.cpp │ │ │ ├── NorthStarDialect.cpp │ │ │ ├── NorthStarOps.cpp │ │ │ └── NorthStarTypes.cpp │ │ │ └── Transforms │ │ │ ├── ApplyDistributeTransform.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── DeviceRegionFusion.cpp │ │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.cpp │ │ └── FusionRegionInterfaces.cpp │ ├── Pipelines │ │ ├── CMakeLists.txt │ │ └── NorthStarBasicPipeline.cpp │ ├── Tools │ │ ├── CMakeLists.txt │ │ └── NS-opt │ │ │ ├── CMakeLists.txt │ │ │ └── NS-opt.cpp │ └── Utils │ │ ├── CMakeLists.txt │ │ └── File.cpp └── test │ ├── CMakeLists.txt │ ├── Conversion │ └── north_star_to_linalg.mlir │ ├── NorthStar │ ├── apply-distribute-transform.mlir │ ├── canonicalization.mlir │ ├── device-region-fusion.mlir │ ├── fold.mlir │ └── mark-distribute-parallel-parameters.mlir │ ├── lit.cfg.py │ └── lit.site.cfg.py.in ├── 2-define_dialect ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ └── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ ├── CMakeLists.txt │ │ └── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarDialect.h │ │ └── NorthStarDialect.td ├── main.cpp └── src │ ├── CMakeLists.txt │ └── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ ├── CMakeLists.txt │ └── IR │ ├── CMakeLists.txt │ └── NorthStarDialect.cpp ├── 3-define_type ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ └── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ ├── CMakeLists.txt │ │ └── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarDialect.h │ │ ├── NorthStarDialect.td │ │ ├── NorthStarTypes.h │ │ └── NorthStarTypes.td ├── main.cpp └── src │ ├── CMakeLists.txt │ └── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ ├── CMakeLists.txt │ └── IR │ ├── CMakeLists.txt │ ├── NorthStarDialect.cpp │ └── NorthStarTypes.cpp ├── 4-define_attribute ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ └── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ ├── CMakeLists.txt │ │ └── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarAttrs.h │ │ ├── NorthStarAttrs.td │ │ ├── NorthStarDialect.h │ │ ├── NorthStarDialect.td │ │ ├── NorthStarEunms.h │ │ ├── NorthStarEunms.td │ │ ├── NorthStarTypes.h │ │ └── NorthStarTypes.td ├── main.cpp └── src │ ├── CMakeLists.txt │ └── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ ├── CMakeLists.txt │ └── IR │ ├── CMakeLists.txt │ ├── NorthStarAttrs.cpp │ ├── NorthStarDialect.cpp │ └── NorthStarTypes.cpp ├── 5-define_operation ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ └── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ ├── CMakeLists.txt │ │ └── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarAttrs.h │ │ ├── NorthStarAttrs.td │ │ ├── NorthStarConstraints.td │ │ ├── NorthStarDialect.h │ │ ├── NorthStarDialect.td │ │ ├── NorthStarEunms.h │ │ ├── NorthStarEunms.td │ │ ├── NorthStarOps.h │ │ ├── NorthStarOps.td │ │ ├── NorthStarTypes.h │ │ └── NorthStarTypes.td ├── main.cpp └── src │ ├── CMakeLists.txt │ └── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ ├── CMakeLists.txt │ └── IR │ ├── CMakeLists.txt │ ├── NorthStarAttrs.cpp │ ├── NorthStarDialect.cpp │ ├── NorthStarOps.cpp │ └── NorthStarTypes.cpp ├── 6-define_interface ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ └── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ └── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ └── DistributeParallelismInterfaces.td ├── main.cpp └── src │ ├── CMakeLists.txt │ ├── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ │ ├── CMakeLists.txt │ │ └── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarAttrs.cpp │ │ ├── NorthStarDialect.cpp │ │ ├── NorthStarOps.cpp │ │ └── NorthStarTypes.cpp │ └── Interfaces │ ├── CMakeLists.txt │ └── DistributeParallelismInterfaces.cpp ├── 7-ir_struct ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ └── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ └── DistributeParallelismInterfaces.td │ └── Utils │ │ └── File.h ├── main.cpp └── src │ ├── CMakeLists.txt │ ├── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ │ ├── CMakeLists.txt │ │ └── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarAttrs.cpp │ │ ├── NorthStarDialect.cpp │ │ ├── NorthStarOps.cpp │ │ └── NorthStarTypes.cpp │ ├── Interfaces │ ├── CMakeLists.txt │ └── DistributeParallelismInterfaces.cpp │ └── Utils │ ├── CMakeLists.txt │ └── File.cpp ├── 8-define_pass ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ └── DistributeParallelismInterfaces.td │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp └── src │ ├── CMakeLists.txt │ ├── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ │ ├── CMakeLists.txt │ │ ├── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarAttrs.cpp │ │ ├── NorthStarDialect.cpp │ │ ├── NorthStarOps.cpp │ │ └── NorthStarTypes.cpp │ │ └── Transforms │ │ ├── ApplyDistributeTransform.cpp │ │ ├── CMakeLists.txt │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ ├── CMakeLists.txt │ └── DistributeParallelismInterfaces.cpp │ └── Utils │ ├── CMakeLists.txt │ └── File.cpp ├── 9-rewrite_pattern ├── CMakeLists.txt ├── include │ ├── CMakeLists.txt │ ├── Dialect │ │ ├── CMakeLists.txt │ │ └── NorthStar │ │ │ ├── CMakeLists.txt │ │ │ ├── IR │ │ │ ├── CMakeLists.txt │ │ │ ├── NorthStarAttrs.h │ │ │ ├── NorthStarAttrs.td │ │ │ ├── NorthStarConstraints.td │ │ │ ├── NorthStarDialect.h │ │ │ ├── NorthStarDialect.td │ │ │ ├── NorthStarEunms.h │ │ │ ├── NorthStarEunms.td │ │ │ ├── NorthStarOps.h │ │ │ ├── NorthStarOps.td │ │ │ ├── NorthStarTypes.h │ │ │ └── NorthStarTypes.td │ │ │ └── Transforms │ │ │ ├── CMakeLists.txt │ │ │ ├── Passes.h │ │ │ └── Passes.td │ ├── Interfaces │ │ ├── CMakeLists.txt │ │ ├── DistributeParallelismInterfaces.h │ │ ├── DistributeParallelismInterfaces.td │ │ ├── FusionRegionInterfaces.h │ │ └── FusionRegionInterfaces.td │ └── Utils │ │ ├── File.h │ │ └── Key.h ├── main.cpp └── src │ ├── CMakeLists.txt │ ├── Dialect │ ├── CMakeLists.txt │ └── NorthStar │ │ ├── CMakeLists.txt │ │ ├── IR │ │ ├── CMakeLists.txt │ │ ├── NorthStarAttrs.cpp │ │ ├── NorthStarDialect.cpp │ │ ├── NorthStarOps.cpp │ │ └── NorthStarTypes.cpp │ │ └── Transforms │ │ ├── ApplyDistributeTransform.cpp │ │ ├── CMakeLists.txt │ │ ├── DeviceRegionFusion.cpp │ │ └── MarkDistributeParallelParameters.cpp │ ├── Interfaces │ ├── CMakeLists.txt │ ├── DistributeParallelismInterfaces.cpp │ └── FusionRegionInterfaces.cpp │ └── Utils │ ├── CMakeLists.txt │ └── File.cpp ├── CMakeLists.txt ├── LICENSE ├── a.txt ├── readme.md ├── third_party └── CMakeLists.txt └── 教程内容.md /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .vscode 3 | .cache 4 | .clangd 5 | DeepSeek-V3 6 | DeepGEMM 7 | .clang-format 8 | cuda-python.py 9 | .log.txt 10 | 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | # git submodule update --init --recursive --progress 2 | [submodule "third_party/llvm-project"] 3 | path = third_party/llvm-project 4 | url = https://mirrors.tuna.tsinghua.edu.cn/git/llvm-project.git 5 | branch = llvmorg-19.1.7 6 | -------------------------------------------------------------------------------- /1-summary/前言.md: -------------------------------------------------------------------------------- 1 | 这篇教程的目的是MLIR的基础教程,快速了解MLIR框架的用法和功能。 2 | 3 | ### 简介: 4 | 5 | MLIR它起源一方面是由于深度学习框架的兴起,因为不同的深度学习框架(TF,torch)都会有计算图的概念,于是为了优化计算图的运行,就需要图编译,于是每个框架都会自己实现图编译系统,甚至会为每一种后端去实现相应的编译软件。 6 | 7 | 于是带来了软件碎片化的问题,因为每款”图编译器“都会有很多通用的地方,但是由于实现方式不同,导致无法复用。MLIR它就是提供了一套可复用的基础设施来尝试解决这个问题。 8 | 9 | MLIR更像是一套Dialect系统,包括定义Dialect内部的Operation,Type,Attribute,Interface以及Dialect之间的转换一套基础设施。 10 | 11 | ### 大纲: 12 | 13 | 主要内容是:定义一个名为”北极星“的方言,去完成一个softmax 算子数据并行下的编译与运行。考虑到没有相应的通讯库,以及多卡的条件,所以实际的通运和数据都只是模拟运行的。 14 | 15 | 第一阶段:定义”北极星”方言,包括类型,属性,以及接口。以及MLIR IR的结构。 16 | 17 | 第二阶段:实现IR的Pass以及变换。 18 | 19 | 第三个阶段:利用lit测试框架进行测试。 20 | 21 | 第四个阶段:进行方言的转换,将”北极星“方言下降到LLVM IR。 22 | 23 | 第五阶段:执行 “数据并行”条件下softmax算子。 24 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 10) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} 8 | MLIRNorthStarDialect${ch_num} 9 | MLIRNorthStarTransforms${ch_num} 10 | MLIRTutorialUtils${ch_num} 11 | MLIRGPUDialect 12 | MLIRFuncDialect 13 | MLIRSCFDialect 14 | MLIRLinalgDialect 15 | MLIRParser 16 | MLIRPass 17 | ) 18 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | 5 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #include "Interfaces/FusionRegionInterfaces.h" 21 | #define GET_OP_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 23 | #undef FIX 24 | 25 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 26 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | set(LLVM_TARGET_DEFINITIONS FusionRegionInterfaces.td) 9 | mlir_tablegen(FusionRegionOpInterfaces.h.inc -gen-op-interface-decls) 10 | mlir_tablegen(FusionRegionOpInterfaces.cpp.inc -gen-op-interface-defs) 11 | add_public_tablegen_target(MLIRFusionRegionInterfacesIncGen${ch_num}) 12 | 13 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Interfaces/FusionRegionInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_FUSION_REGION_INTERFACES_H 16 | #define INTERFACES_FUSION_REGION_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/FusionRegionOpInterfaces.h.inc" 22 | #undef FIX 23 | #endif // INTERFACES_FUSION_REGION_INTERFACES_H -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | 23 | #endif // UTILS_MLIR_UTILS_KEY_H 24 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | add_subdirectory(Tools) 5 | 6 | 7 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | MLIRFusionRegionInterfaces${ch_num} 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | DeviceRegionFusion.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarPassesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRNorthStarDialect${ch_num} 12 | MLIRPass 13 | MLIRTransforms 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | DistributeParallelismInterfaces.cpp 3 | FusionRegionInterfaces.cpp 4 | ) 5 | 6 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 7 | DistributeParallelismInterfaces.cpp 8 | 9 | DEPENDS 10 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 11 | 12 | LINK_LIBS PUBLIC 13 | MLIRIR 14 | ) 15 | 16 | add_mlir_library(MLIRFusionRegionInterfaces${ch_num} 17 | FusionRegionInterfaces.cpp 18 | 19 | DEPENDS 20 | MLIRFusionRegionInterfacesIncGen${ch_num} 21 | 22 | LINK_LIBS PUBLIC 23 | MLIRIR 24 | ) 25 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Interfaces/FusionRegionInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/FusionRegionInterfaces.h" 15 | #include 16 | 17 | #include "Interfaces/FusionRegionOpInterfaces.cpp.inc" -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NS-opt) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Tools/NS-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(LIBS 3 | ${dialect_libs} 4 | ${conversion_libs} 5 | ${extension_libs} 6 | 7 | MLIRAffineAnalysis 8 | MLIRAnalysis 9 | MLIRCastInterfaces 10 | MLIRDialect 11 | MLIROptLib 12 | MLIRParser 13 | MLIRPass 14 | MLIRTransforms 15 | MLIRTransformUtils 16 | MLIRSupport 17 | MLIRIR 18 | 19 | # TODO: Remove when registerAllGPUToLLVMIRTranslations is no longer 20 | # registered directly in mlir-opt.cpp. 21 | MLIRToLLVMIRTranslationRegistration 22 | MLIRNorthStarDialect${ch_num} 23 | MLIRNorthStarTransforms${ch_num} 24 | MLIRTutorialUtils${ch_num} 25 | MLIRCAPIDebug 26 | ) 27 | 28 | add_mlir_tool(NS-opt${ch_num} 29 | NS-opt.cpp 30 | 31 | DEPENDS 32 | ${LIBS} 33 | ) 34 | target_link_libraries("NS-opt${ch_num}" PRIVATE ${LIBS}) 35 | llvm_update_compile_flags(NS-opt${ch_num}) 36 | 37 | mlir_check_all_link_libraries(NS-opt${ch_num}) 38 | export_executable_symbols_for_plugins(NS-opt${ch_num}) 39 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /10-mlir_opt-and-debug/test/softmax.mlir: -------------------------------------------------------------------------------- 1 | 2 | module @NorthStar { 3 | func.func @main(%arg0: !north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> attributes {dp_attr = #north_star.DP, host_func} { 4 | %0 = "north_star.softmax"(%arg0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 5 | %1 = "north_star.softmax"(%0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 6 | return %1 : !north_star.ns_tensor<5x?x?xf32,0> 7 | } 8 | } -------------------------------------------------------------------------------- /11-lit_for_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 11) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | set(TUTORIA_TOOL_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/Tools/NS-opt) 5 | set(TUTORIA_NS_OPT ${TUTORIA_TOOL_DIR}/NS-opt${ch_num}) 6 | add_subdirectory(include) 7 | add_subdirectory(src) 8 | add_executable(CH-${ch_num} "main.cpp") 9 | target_link_libraries(CH-${ch_num} 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRNorthStarTransforms${ch_num} 12 | MLIRTutorialUtils${ch_num} 13 | MLIRGPUDialect 14 | MLIRFuncDialect 15 | MLIRSCFDialect 16 | MLIRLinalgDialect 17 | MLIRParser 18 | MLIRPass 19 | ) 20 | add_subdirectory(test) 21 | -------------------------------------------------------------------------------- /11-lit_for_test/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | 5 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #include "Interfaces/FusionRegionInterfaces.h" 21 | #define GET_OP_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 23 | #undef FIX 24 | 25 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 26 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /11-lit_for_test/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | set(LLVM_TARGET_DEFINITIONS FusionRegionInterfaces.td) 9 | mlir_tablegen(FusionRegionOpInterfaces.h.inc -gen-op-interface-decls) 10 | mlir_tablegen(FusionRegionOpInterfaces.cpp.inc -gen-op-interface-defs) 11 | add_public_tablegen_target(MLIRFusionRegionInterfacesIncGen${ch_num}) 12 | 13 | -------------------------------------------------------------------------------- /11-lit_for_test/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /11-lit_for_test/include/Interfaces/FusionRegionInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_FUSION_REGION_INTERFACES_H 16 | #define INTERFACES_FUSION_REGION_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/FusionRegionOpInterfaces.h.inc" 22 | #undef FIX 23 | #endif // INTERFACES_FUSION_REGION_INTERFACES_H -------------------------------------------------------------------------------- /11-lit_for_test/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | 23 | #endif // UTILS_MLIR_UTILS_KEY_H 24 | -------------------------------------------------------------------------------- /11-lit_for_test/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | add_subdirectory(Tools) 5 | 6 | 7 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | MLIRFusionRegionInterfaces${ch_num} 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | DeviceRegionFusion.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarPassesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRNorthStarDialect${ch_num} 12 | MLIRPass 13 | MLIRTransforms 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | DistributeParallelismInterfaces.cpp 3 | FusionRegionInterfaces.cpp 4 | ) 5 | 6 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 7 | DistributeParallelismInterfaces.cpp 8 | 9 | DEPENDS 10 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 11 | 12 | LINK_LIBS PUBLIC 13 | MLIRIR 14 | ) 15 | 16 | add_mlir_library(MLIRFusionRegionInterfaces${ch_num} 17 | FusionRegionInterfaces.cpp 18 | 19 | DEPENDS 20 | MLIRFusionRegionInterfacesIncGen${ch_num} 21 | 22 | LINK_LIBS PUBLIC 23 | MLIRIR 24 | ) 25 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" -------------------------------------------------------------------------------- /11-lit_for_test/src/Interfaces/FusionRegionInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/FusionRegionInterfaces.h" 15 | #include 16 | 17 | #include "Interfaces/FusionRegionOpInterfaces.cpp.inc" -------------------------------------------------------------------------------- /11-lit_for_test/src/Tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NS-opt) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Tools/NS-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(LIBS 3 | ${dialect_libs} 4 | ${conversion_libs} 5 | ${extension_libs} 6 | 7 | MLIRAffineAnalysis 8 | MLIRAnalysis 9 | MLIRCastInterfaces 10 | MLIRDialect 11 | MLIROptLib 12 | MLIRParser 13 | MLIRPass 14 | MLIRTransforms 15 | MLIRTransformUtils 16 | MLIRSupport 17 | MLIRIR 18 | 19 | # TODO: Remove when registerAllGPUToLLVMIRTranslations is no longer 20 | # registered directly in mlir-opt.cpp. 21 | MLIRToLLVMIRTranslationRegistration 22 | MLIRNorthStarDialect${ch_num} 23 | MLIRNorthStarTransforms${ch_num} 24 | MLIRTutorialUtils${ch_num} 25 | ) 26 | add_mlir_tool(NS-opt${ch_num} 27 | NS-opt.cpp 28 | 29 | DEPENDS 30 | ${LIBS} 31 | ) 32 | target_link_libraries("NS-opt${ch_num}" PRIVATE ${LIBS}) 33 | llvm_update_compile_flags(NS-opt${ch_num}) 34 | 35 | mlir_check_all_link_libraries(NS-opt${ch_num}) 36 | export_executable_symbols_for_plugins(NS-opt${ch_num}) 37 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /11-lit_for_test/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /11-lit_for_test/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 配置lit套件设置 2 | configure_lit_site_cfg( 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 4 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py 5 | MAIN_CONFIG 6 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py 7 | ) 8 | # 9 | set(TEST_DEPENDS 10 | FileCheck count not 11 | NS-opt${ch_num} 12 | ) 13 | 14 | add_lit_testsuite(check-ch-${ch_num} "Running the lit regression tests..." 15 | ${CMAKE_CURRENT_BINARY_DIR} 16 | DEPENDS ${TEST_DEPENDS} 17 | ) 18 | set_target_properties(check-ch-${ch_num} PROPERTIES FOLDER "test") 19 | 20 | -------------------------------------------------------------------------------- /11-lit_for_test/test/NorthStar/mark-distribute-parallel-parameters.mlir: -------------------------------------------------------------------------------- 1 | // RUN: ns-opt %s --mark-distribute-parallel-parameters="DP=5 TP=1" | FileCheck %s 2 | 3 | module @NorthStar { 4 | // CHECK-LABEL: func @main( 5 | // CHECK-SAME: #north_star.DP) -> !north_star.ns_tensor<5x?x?xf32,0> attributes {dp_attr = #north_star.DP, host_func} { 7 | %0 = "north_star.softmax"(%arg0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 8 | %1 = "north_star.softmax"(%0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 9 | return %1 : !north_star.ns_tensor<5x?x?xf32,0> 10 | } 11 | } -------------------------------------------------------------------------------- /12-operation_lowing_pass/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 12) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | set(TUTORIA_TOOL_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/Tools/NS-opt) 5 | set(TUTORIA_NS_OPT ${TUTORIA_TOOL_DIR}/NS-opt${ch_num}) 6 | add_subdirectory(include) 7 | add_subdirectory(src) 8 | add_executable(CH-${ch_num} "main.cpp") 9 | target_link_libraries(CH-${ch_num} 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRNorthStarTransforms${ch_num} 12 | MLIRTutorialUtils${ch_num} 13 | MLIRGPUDialect 14 | MLIRFuncDialect 15 | MLIRSCFDialect 16 | MLIRLinalgDialect 17 | MLIRParser 18 | MLIRPass 19 | ) 20 | add_subdirectory(test) 21 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | add_subdirectory(Conversion) 4 | 5 | 6 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarConversion) 3 | add_public_tablegen_target(MLIRNorthStarConversionPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarConversionPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Conversion/Passes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef CONVERSION_PASSES_H 17 | #define CONVERSION_PASSES_H 18 | #include "mlir/Pass/Pass.h" 19 | namespace mlir::north_star { 20 | 21 | #define GEN_PASS_DECL 22 | #define GEN_PASS_REGISTRATION 23 | #include "Conversion/Passes.h.inc" 24 | } // namespace mlir::north_star 25 | 26 | #endif // CONVERSION_PASSES_H -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Conversion/Passes.td: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef CONVERSION_PASSES_TD 17 | #define CONVERSION_PASSES_TD 18 | include "mlir/Pass/PassBase.td" 19 | 20 | def ConvertNorthStarToLinalgPass : Pass<"convert-north-satr-to-linalg","::mlir::ModuleOp"> { 21 | let summary = "标记全局并行参数"; 22 | let description = [{ 23 | "标记全局并行参数。"; 24 | }]; 25 | let dependentDialects = [ 26 | "::mlir::north_star::NorthStarDialect", 27 | "::mlir::tensor::TensorDialect", 28 | "::mlir::linalg::LinalgDialect" 29 | ]; 30 | } 31 | 32 | 33 | #endif // CONVERSION_PASSES_TD -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #include "Interfaces/FusionRegionInterfaces.h" 21 | #define GET_OP_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 23 | #undef FIX 24 | 25 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 26 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | set(LLVM_TARGET_DEFINITIONS FusionRegionInterfaces.td) 9 | mlir_tablegen(FusionRegionOpInterfaces.h.inc -gen-op-interface-decls) 10 | mlir_tablegen(FusionRegionOpInterfaces.cpp.inc -gen-op-interface-defs) 11 | add_public_tablegen_target(MLIRFusionRegionInterfacesIncGen${ch_num}) 12 | 13 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Interfaces/FusionRegionInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_FUSION_REGION_INTERFACES_H 16 | #define INTERFACES_FUSION_REGION_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/FusionRegionOpInterfaces.h.inc" 22 | #undef FIX 23 | #endif // INTERFACES_FUSION_REGION_INTERFACES_H -------------------------------------------------------------------------------- /12-operation_lowing_pass/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | inline static const char* KSetDevice = "set_device"; 23 | 24 | #endif // UTILS_MLIR_UTILS_KEY_H 25 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | add_subdirectory(Conversion) 5 | add_subdirectory(Tools) 6 | 7 | 8 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStarToLinalg) 2 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Conversion/NorthStarToLinalg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRNorthStarToLinalg${ch_num} 2 | NorthStarToLinalg.cpp 3 | NorthStarToLinalgPass.cpp 4 | 5 | DEPENDS 6 | MLIRNorthStarConversionPassesIncGen${ch_num} 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRLinalgDialect 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRPass 12 | MLIRTransformUtils 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | MLIRFusionRegionInterfaces${ch_num} 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | DeviceRegionFusion.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarPassesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRNorthStarDialect${ch_num} 12 | MLIRPass 13 | MLIRTransforms 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | DistributeParallelismInterfaces.cpp 3 | FusionRegionInterfaces.cpp 4 | ) 5 | 6 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 7 | DistributeParallelismInterfaces.cpp 8 | 9 | DEPENDS 10 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 11 | 12 | LINK_LIBS PUBLIC 13 | MLIRIR 14 | ) 15 | 16 | add_mlir_library(MLIRFusionRegionInterfaces${ch_num} 17 | FusionRegionInterfaces.cpp 18 | 19 | DEPENDS 20 | MLIRFusionRegionInterfacesIncGen${ch_num} 21 | 22 | LINK_LIBS PUBLIC 23 | MLIRIR 24 | ) 25 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Interfaces/FusionRegionInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/FusionRegionInterfaces.h" 15 | #include 16 | 17 | #include "Interfaces/FusionRegionOpInterfaces.cpp.inc" -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NS-opt) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Tools/NS-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(LIBS 3 | ${dialect_libs} 4 | ${conversion_libs} 5 | ${extension_libs} 6 | 7 | MLIRAffineAnalysis 8 | MLIRAnalysis 9 | MLIRCastInterfaces 10 | MLIRDialect 11 | MLIROptLib 12 | MLIRParser 13 | MLIRPass 14 | MLIRTransforms 15 | MLIRTransformUtils 16 | MLIRSupport 17 | MLIRIR 18 | 19 | # TODO: Remove when registerAllGPUToLLVMIRTranslations is no longer 20 | # registered directly in mlir-opt.cpp. 21 | MLIRToLLVMIRTranslationRegistration 22 | MLIRNorthStarDialect${ch_num} 23 | MLIRNorthStarTransforms${ch_num} 24 | MLIRTutorialUtils${ch_num} 25 | MLIRNorthStarToLinalg${ch_num} 26 | ) 27 | add_mlir_tool(NS-opt${ch_num} 28 | NS-opt.cpp 29 | 30 | DEPENDS 31 | ${LIBS} 32 | ) 33 | target_link_libraries("NS-opt${ch_num}" PRIVATE ${LIBS}) 34 | llvm_update_compile_flags(NS-opt${ch_num}) 35 | 36 | mlir_check_all_link_libraries(NS-opt${ch_num}) 37 | export_executable_symbols_for_plugins(NS-opt${ch_num}) 38 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 配置lit套件设置 2 | configure_lit_site_cfg( 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 4 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py 5 | MAIN_CONFIG 6 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py 7 | ) 8 | # 9 | set(TEST_DEPENDS 10 | FileCheck count not 11 | NS-opt${ch_num} 12 | ) 13 | 14 | add_lit_testsuite(check-ch-${ch_num} "Running the lit regression tests..." 15 | ${CMAKE_CURRENT_BINARY_DIR} 16 | DEPENDS ${TEST_DEPENDS} 17 | ) 18 | set_target_properties(check-ch-${ch_num} PROPERTIES FOLDER "test") 19 | 20 | -------------------------------------------------------------------------------- /12-operation_lowing_pass/test/NorthStar/mark-distribute-parallel-parameters.mlir: -------------------------------------------------------------------------------- 1 | // RUN: ns-opt %s --mark-distribute-parallel-parameters="DP=5 TP=1" | FileCheck %s 2 | 3 | module @NorthStar { 4 | // CHECK-LABEL: func @main( 5 | // CHECK-SAME: #north_star.DP) -> !north_star.ns_tensor<5x?x?xf32,0> attributes {dp_attr = #north_star.DP, host_func} { 7 | %0 = "north_star.softmax"(%arg0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 8 | %1 = "north_star.softmax"(%0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 9 | return %1 : !north_star.ns_tensor<5x?x?xf32,0> 10 | } 11 | } -------------------------------------------------------------------------------- /13-pass_manager/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 13) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | set(TUTORIA_TOOL_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/Tools/NS-opt) 5 | set(TUTORIA_NS_OPT ${TUTORIA_TOOL_DIR}/NS-opt${ch_num}) 6 | add_subdirectory(include) 7 | add_subdirectory(src) 8 | add_executable(CH-${ch_num} "main.cpp") 9 | target_link_libraries(CH-${ch_num} 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRNorthStarTransforms${ch_num} 12 | MLIRTutorialUtils${ch_num} 13 | MLIRGPUDialect 14 | MLIRFuncDialect 15 | MLIRSCFDialect 16 | MLIRLinalgDialect 17 | MLIRParser 18 | MLIRPass 19 | ) 20 | add_subdirectory(test) 21 | -------------------------------------------------------------------------------- /13-pass_manager/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | add_subdirectory(Conversion) 4 | 5 | 6 | -------------------------------------------------------------------------------- /13-pass_manager/include/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarConversion) 3 | add_public_tablegen_target(MLIRNorthStarConversionPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarConversionPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /13-pass_manager/include/Conversion/Passes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef CONVERSION_PASSES_H 17 | #define CONVERSION_PASSES_H 18 | #include "mlir/Pass/Pass.h" 19 | namespace mlir::north_star { 20 | 21 | #define GEN_PASS_DECL 22 | #define GEN_PASS_REGISTRATION 23 | #include "Conversion/Passes.h.inc" 24 | } // namespace mlir::north_star 25 | 26 | #endif // CONVERSION_PASSES_H -------------------------------------------------------------------------------- /13-pass_manager/include/Conversion/Passes.td: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef CONVERSION_PASSES_TD 17 | #define CONVERSION_PASSES_TD 18 | include "mlir/Pass/PassBase.td" 19 | 20 | def ConvertNorthStarToLinalgPass : Pass<"convert-north-satr-to-linalg","::mlir::ModuleOp"> { 21 | let summary = "标记全局并行参数"; 22 | let description = [{ 23 | "标记全局并行参数。"; 24 | }]; 25 | let dependentDialects = [ 26 | "::mlir::north_star::NorthStarDialect", 27 | "::mlir::tensor::TensorDialect", 28 | "::mlir::linalg::LinalgDialect" 29 | ]; 30 | } 31 | 32 | 33 | #endif // CONVERSION_PASSES_TD -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #include "Interfaces/FusionRegionInterfaces.h" 21 | #define GET_OP_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 23 | #undef FIX 24 | 25 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 26 | -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /13-pass_manager/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /13-pass_manager/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | set(LLVM_TARGET_DEFINITIONS FusionRegionInterfaces.td) 9 | mlir_tablegen(FusionRegionOpInterfaces.h.inc -gen-op-interface-decls) 10 | mlir_tablegen(FusionRegionOpInterfaces.cpp.inc -gen-op-interface-defs) 11 | add_public_tablegen_target(MLIRFusionRegionInterfacesIncGen${ch_num}) 12 | 13 | -------------------------------------------------------------------------------- /13-pass_manager/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /13-pass_manager/include/Interfaces/FusionRegionInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_FUSION_REGION_INTERFACES_H 16 | #define INTERFACES_FUSION_REGION_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/FusionRegionOpInterfaces.h.inc" 22 | #undef FIX 23 | #endif // INTERFACES_FUSION_REGION_INTERFACES_H -------------------------------------------------------------------------------- /13-pass_manager/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | inline static const char* KSetDevice = "set_device"; 23 | 24 | #endif // UTILS_MLIR_UTILS_KEY_H 25 | -------------------------------------------------------------------------------- /13-pass_manager/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | add_subdirectory(Conversion) 5 | add_subdirectory(Pipelines) 6 | add_subdirectory(Tools) 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /13-pass_manager/src/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStarToLinalg) 2 | -------------------------------------------------------------------------------- /13-pass_manager/src/Conversion/NorthStarToLinalg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRNorthStarToLinalg${ch_num} 2 | NorthStarToLinalg.cpp 3 | NorthStarToLinalgPass.cpp 4 | 5 | DEPENDS 6 | MLIRNorthStarConversionPassesIncGen${ch_num} 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRLinalgDialect 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRPass 12 | MLIRTransformUtils 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /13-pass_manager/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /13-pass_manager/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /13-pass_manager/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | MLIRFusionRegionInterfaces${ch_num} 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /13-pass_manager/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | DeviceRegionFusion.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarPassesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRNorthStarDialect${ch_num} 12 | MLIRPass 13 | MLIRTransforms 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /13-pass_manager/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | DistributeParallelismInterfaces.cpp 3 | FusionRegionInterfaces.cpp 4 | ) 5 | 6 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 7 | DistributeParallelismInterfaces.cpp 8 | 9 | DEPENDS 10 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 11 | 12 | LINK_LIBS PUBLIC 13 | MLIRIR 14 | ) 15 | 16 | add_mlir_library(MLIRFusionRegionInterfaces${ch_num} 17 | FusionRegionInterfaces.cpp 18 | 19 | DEPENDS 20 | MLIRFusionRegionInterfacesIncGen${ch_num} 21 | 22 | LINK_LIBS PUBLIC 23 | MLIRIR 24 | ) 25 | -------------------------------------------------------------------------------- /13-pass_manager/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" -------------------------------------------------------------------------------- /13-pass_manager/src/Interfaces/FusionRegionInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/FusionRegionInterfaces.h" 15 | #include 16 | 17 | #include "Interfaces/FusionRegionOpInterfaces.cpp.inc" -------------------------------------------------------------------------------- /13-pass_manager/src/Pipelines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRNorthStarPipelines${ch_num} 2 | NorthStarBasicPipeline.cpp 3 | 4 | DEPENDS 5 | 6 | LINK_LIBS PUBLIC 7 | MLIRIR 8 | ) 9 | -------------------------------------------------------------------------------- /13-pass_manager/src/Tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NS-opt) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /13-pass_manager/src/Tools/NS-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(LIBS 3 | ${dialect_libs} 4 | ${conversion_libs} 5 | ${extension_libs} 6 | 7 | MLIRAffineAnalysis 8 | MLIRAnalysis 9 | MLIRCastInterfaces 10 | MLIRDialect 11 | MLIROptLib 12 | MLIRParser 13 | MLIRPass 14 | MLIRTransforms 15 | MLIRTransformUtils 16 | MLIRSupport 17 | MLIRIR 18 | 19 | # TODO: Remove when registerAllGPUToLLVMIRTranslations is no longer 20 | # registered directly in mlir-opt.cpp. 21 | MLIRToLLVMIRTranslationRegistration 22 | MLIRNorthStarDialect${ch_num} 23 | MLIRNorthStarTransforms${ch_num} 24 | MLIRTutorialUtils${ch_num} 25 | MLIRNorthStarToLinalg${ch_num} 26 | MLIRNorthStarPipelines${ch_num} 27 | ) 28 | add_mlir_tool(NS-opt${ch_num} 29 | NS-opt.cpp 30 | 31 | DEPENDS 32 | ${LIBS} 33 | ) 34 | target_link_libraries("NS-opt${ch_num}" PRIVATE ${LIBS}) 35 | llvm_update_compile_flags(NS-opt${ch_num}) 36 | 37 | mlir_check_all_link_libraries(NS-opt${ch_num}) 38 | export_executable_symbols_for_plugins(NS-opt${ch_num}) 39 | -------------------------------------------------------------------------------- /13-pass_manager/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /13-pass_manager/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /13-pass_manager/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 配置lit套件设置 2 | configure_lit_site_cfg( 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 4 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py 5 | MAIN_CONFIG 6 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py 7 | ) 8 | # 9 | set(TEST_DEPENDS 10 | FileCheck count not 11 | NS-opt${ch_num} 12 | ) 13 | 14 | add_lit_testsuite(check-ch-${ch_num} "Running the lit regression tests..." 15 | ${CMAKE_CURRENT_BINARY_DIR} 16 | DEPENDS ${TEST_DEPENDS} 17 | ) 18 | set_target_properties(check-ch-${ch_num} PROPERTIES FOLDER "test") 19 | 20 | -------------------------------------------------------------------------------- /13-pass_manager/test/NorthStar/mark-distribute-parallel-parameters.mlir: -------------------------------------------------------------------------------- 1 | // RUN: ns-opt %s --mark-distribute-parallel-parameters="DP=5 TP=1" | FileCheck %s 2 | 3 | module @NorthStar { 4 | // CHECK-LABEL: func @main( 5 | // CHECK-SAME: #north_star.DP) -> !north_star.ns_tensor<5x?x?xf32,0> attributes {dp_attr = #north_star.DP, host_func} { 7 | %0 = "north_star.softmax"(%arg0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 8 | %1 = "north_star.softmax"(%0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 9 | return %1 : !north_star.ns_tensor<5x?x?xf32,0> 10 | } 11 | } -------------------------------------------------------------------------------- /14-fold_and_canonicalization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 14) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | set(TUTORIA_TOOL_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/Tools/NS-opt) 5 | set(TUTORIA_NS_OPT ${TUTORIA_TOOL_DIR}/NS-opt${ch_num}) 6 | add_subdirectory(include) 7 | add_subdirectory(src) 8 | add_executable(CH-${ch_num} "main.cpp") 9 | target_link_libraries(CH-${ch_num} 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRNorthStarTransforms${ch_num} 12 | MLIRTutorialUtils${ch_num} 13 | MLIRGPUDialect 14 | MLIRFuncDialect 15 | MLIRSCFDialect 16 | MLIRLinalgDialect 17 | MLIRParser 18 | MLIRPass 19 | ) 20 | add_subdirectory(test) 21 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | add_subdirectory(Conversion) 4 | 5 | 6 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarConversion) 3 | add_public_tablegen_target(MLIRNorthStarConversionPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarConversionPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Conversion/Passes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef CONVERSION_PASSES_H 17 | #define CONVERSION_PASSES_H 18 | #include "mlir/Pass/Pass.h" 19 | namespace mlir::north_star { 20 | 21 | #define GEN_PASS_DECL 22 | #define GEN_PASS_REGISTRATION 23 | #include "Conversion/Passes.h.inc" 24 | } // namespace mlir::north_star 25 | 26 | #endif // CONVERSION_PASSES_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Conversion/Passes.td: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef CONVERSION_PASSES_TD 17 | #define CONVERSION_PASSES_TD 18 | include "mlir/Pass/PassBase.td" 19 | 20 | def ConvertNorthStarToLinalgPass : Pass<"convert-north-satr-to-linalg","::mlir::ModuleOp"> { 21 | let summary = "标记全局并行参数"; 22 | let description = [{ 23 | "标记全局并行参数。"; 24 | }]; 25 | let dependentDialects = [ 26 | "::mlir::north_star::NorthStarDialect", 27 | "::mlir::tensor::TensorDialect", 28 | "::mlir::linalg::LinalgDialect" 29 | ]; 30 | } 31 | 32 | 33 | #endif // CONVERSION_PASSES_TD -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #include "Interfaces/FusionRegionInterfaces.h" 21 | #define GET_OP_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 23 | #undef FIX 24 | 25 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 26 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Dialect/NorthStar/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_TRANSFORMS_PASSES_H 17 | #define DIALECT_NORTH_STAR_TRANSFORMS_PASSES_H 18 | #include "mlir/Pass/Pass.h" 19 | namespace mlir::north_star { 20 | 21 | void populateDeviceRegionFusionPatterns(RewritePatternSet &patterns); 22 | 23 | std::unique_ptr<::mlir::Pass> createApplyDistributeTransformPass(); 24 | 25 | #define GEN_PASS_DECL 26 | #define GEN_PASS_REGISTRATION 27 | #include "Dialect/NorthStar/Transforms/Passes.h.inc" 28 | } // namespace mlir::north_star 29 | 30 | #endif // DIALECT_NORTH_STAR_TRANSFORMS_PASSES_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | set(LLVM_TARGET_DEFINITIONS FusionRegionInterfaces.td) 9 | mlir_tablegen(FusionRegionOpInterfaces.h.inc -gen-op-interface-decls) 10 | mlir_tablegen(FusionRegionOpInterfaces.cpp.inc -gen-op-interface-defs) 11 | add_public_tablegen_target(MLIRFusionRegionInterfacesIncGen${ch_num}) 12 | 13 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Interfaces/FusionRegionInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_FUSION_REGION_INTERFACES_H 16 | #define INTERFACES_FUSION_REGION_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/FusionRegionOpInterfaces.h.inc" 22 | #undef FIX 23 | #endif // INTERFACES_FUSION_REGION_INTERFACES_H -------------------------------------------------------------------------------- /14-fold_and_canonicalization/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | inline static const char* KSetDevice = "set_device"; 23 | 24 | #endif // UTILS_MLIR_UTILS_KEY_H 25 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | add_subdirectory(Conversion) 5 | add_subdirectory(Pipelines) 6 | add_subdirectory(Tools) 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Conversion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStarToLinalg) 2 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Conversion/NorthStarToLinalg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_conversion_library(MLIRNorthStarToLinalg${ch_num} 2 | NorthStarToLinalg.cpp 3 | NorthStarToLinalgPass.cpp 4 | 5 | DEPENDS 6 | MLIRNorthStarConversionPassesIncGen${ch_num} 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRLinalgDialect 10 | MLIRNorthStarDialect${ch_num} 11 | MLIRPass 12 | MLIRTransformUtils 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | NorthStarCanonicalize.cpp 7 | 8 | DEPENDS 9 | MLIRNorthStarDialectIncGen${ch_num} 10 | 11 | LINK_LIBS PUBLIC 12 | MLIRIR 13 | MLIRTensorDialect 14 | MLIRDistributeParallelismInterfaces${ch_num} 15 | MLIRFusionRegionInterfaces${ch_num} 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | DeviceRegionFusion.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarPassesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRNorthStarDialect${ch_num} 12 | MLIRPass 13 | MLIRTransforms 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | DistributeParallelismInterfaces.cpp 3 | FusionRegionInterfaces.cpp 4 | ) 5 | 6 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 7 | DistributeParallelismInterfaces.cpp 8 | 9 | DEPENDS 10 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 11 | 12 | LINK_LIBS PUBLIC 13 | MLIRIR 14 | ) 15 | 16 | add_mlir_library(MLIRFusionRegionInterfaces${ch_num} 17 | FusionRegionInterfaces.cpp 18 | 19 | DEPENDS 20 | MLIRFusionRegionInterfacesIncGen${ch_num} 21 | 22 | LINK_LIBS PUBLIC 23 | MLIRIR 24 | ) 25 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Interfaces/FusionRegionInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/FusionRegionInterfaces.h" 15 | #include 16 | 17 | #include "Interfaces/FusionRegionOpInterfaces.cpp.inc" -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Pipelines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRNorthStarPipelines${ch_num} 2 | NorthStarBasicPipeline.cpp 3 | 4 | DEPENDS 5 | 6 | LINK_LIBS PUBLIC 7 | MLIRIR 8 | ) 9 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NS-opt) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Tools/NS-opt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(LIBS 3 | ${dialect_libs} 4 | ${conversion_libs} 5 | ${extension_libs} 6 | 7 | MLIRAffineAnalysis 8 | MLIRAnalysis 9 | MLIRCastInterfaces 10 | MLIRDialect 11 | MLIROptLib 12 | MLIRParser 13 | MLIRPass 14 | MLIRTransforms 15 | MLIRTransformUtils 16 | MLIRSupport 17 | MLIRIR 18 | 19 | # TODO: Remove when registerAllGPUToLLVMIRTranslations is no longer 20 | # registered directly in mlir-opt.cpp. 21 | MLIRToLLVMIRTranslationRegistration 22 | MLIRNorthStarDialect${ch_num} 23 | MLIRNorthStarTransforms${ch_num} 24 | MLIRTutorialUtils${ch_num} 25 | MLIRNorthStarToLinalg${ch_num} 26 | MLIRNorthStarPipelines${ch_num} 27 | ) 28 | add_mlir_tool(NS-opt${ch_num} 29 | NS-opt.cpp 30 | 31 | DEPENDS 32 | ${LIBS} 33 | ) 34 | target_link_libraries("NS-opt${ch_num}" PRIVATE ${LIBS}) 35 | llvm_update_compile_flags(NS-opt${ch_num}) 36 | 37 | mlir_check_all_link_libraries(NS-opt${ch_num}) 38 | export_executable_symbols_for_plugins(NS-opt${ch_num}) 39 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 配置lit套件设置 2 | configure_lit_site_cfg( 3 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 4 | ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py 5 | MAIN_CONFIG 6 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py 7 | ) 8 | # 9 | set(TEST_DEPENDS 10 | FileCheck count not 11 | NS-opt${ch_num} 12 | ) 13 | 14 | add_lit_testsuite(check-ch-${ch_num} "Running the lit regression tests..." 15 | ${CMAKE_CURRENT_BINARY_DIR} 16 | DEPENDS ${TEST_DEPENDS} 17 | ) 18 | set_target_properties(check-ch-${ch_num} PROPERTIES FOLDER "test") 19 | 20 | -------------------------------------------------------------------------------- /14-fold_and_canonicalization/test/NorthStar/fold.mlir: -------------------------------------------------------------------------------- 1 | // RUN: ns-opt %s --split-input-file --inline | FileCheck %s 2 | 3 | // CHECK-LABEL: NorthStar 4 | // CHECK-NOT: north_star.add 5 | module @NorthStar { 6 | func.func @main() -> !north_star.ns_tensor<2x2xf32,0> { 7 | %0 = "north_star.const"() <{value = dense<[[0.000000e+00, 0.000000e+00], [0.000000e+00, 0.000000e+00]]> : !north_star.ns_tensor<2x2xf32,1>}> : () -> !north_star.ns_tensor<2x2xf32,0> 8 | %1 = "north_star.const"() <{value = dense<[[1.000000e+00, 2.000000e+00], [3.000000e+00, 4.000000e+00]]> : !north_star.ns_tensor<2x2xf32,1>}> : () -> !north_star.ns_tensor<2x2xf32,0> 9 | %2 = "north_star.add"(%0, %1) : (!north_star.ns_tensor<2x2xf32,0>, !north_star.ns_tensor<2x2xf32,0>) -> !north_star.ns_tensor<2x2xf32,0> 10 | return %2 : !north_star.ns_tensor<2x2xf32,0> 11 | } 12 | } -------------------------------------------------------------------------------- /14-fold_and_canonicalization/test/NorthStar/mark-distribute-parallel-parameters.mlir: -------------------------------------------------------------------------------- 1 | // RUN: ns-opt %s --mark-distribute-parallel-parameters="DP=5 TP=1" | FileCheck %s 2 | 3 | module @NorthStar { 4 | // CHECK-LABEL: func @main( 5 | // CHECK-SAME: #north_star.DP) -> !north_star.ns_tensor<5x?x?xf32,0> attributes {dp_attr = #north_star.DP, host_func} { 7 | %0 = "north_star.softmax"(%arg0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 8 | %1 = "north_star.softmax"(%0) <{axis = 1 : i64}> : (!north_star.ns_tensor<5x?x?xf32,0>) -> !north_star.ns_tensor<5x?x?xf32,0> 9 | return %1 : !north_star.ns_tensor<5x?x?xf32,0> 10 | } 11 | } -------------------------------------------------------------------------------- /2-define_dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 2) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} MLIRNorthStarDialect${ch_num}) 8 | -------------------------------------------------------------------------------- /2-define_dialect/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /2-define_dialect/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /2-define_dialect/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /2-define_dialect/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarDialect.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | 7 | # 将生成的命令们定义为为target 8 | add_public_tablegen_target(NorthStarDialectIncGen${ch_num}) 9 | 10 | 11 | -------------------------------------------------------------------------------- /2-define_dialect/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_H 16 | #define DIALECT_NORTH_STAR_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_H -------------------------------------------------------------------------------- /2-define_dialect/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Dialect/NorthStar/IR/NorthStarDialect.h" 15 | #include "mlir/IR/DialectRegistry.h" 16 | #include "mlir/IR/MLIRContext.h" 17 | 18 | void CH2() { 19 | // 初始化方言注册器 20 | mlir::DialectRegistry registry; 21 | // 初始化上下文环境 22 | mlir::MLIRContext context(registry); 23 | // 加载/注册方言 24 | auto dialect = context.getOrLoadDialect(); 25 | // 调用方言中的方法 26 | dialect->sayHello(); 27 | } 28 | 29 | int main() { CH2(); } -------------------------------------------------------------------------------- /2-define_dialect/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /2-define_dialect/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /2-define_dialect/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /2-define_dialect/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | 4 | DEPENDS 5 | NorthStarDialectIncGen${ch_num} 6 | 7 | LINK_LIBS PUBLIC 8 | MLIRIR 9 | MLIRTensorDialect 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /3-define_type/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 3) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} MLIRNorthStarDialect${ch_num} MLIRGPUDialect) 8 | -------------------------------------------------------------------------------- /3-define_type/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /3-define_type/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /3-define_type/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /3-define_type/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarTypes.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 将生成的命令们定义为为target 11 | add_public_tablegen_target(NorthStarDialectIncGen${ch_num}) 12 | 13 | 14 | -------------------------------------------------------------------------------- /3-define_type/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_H 16 | #define DIALECT_NORTH_STAR_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_H -------------------------------------------------------------------------------- /3-define_type/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /3-define_type/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /3-define_type/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /3-define_type/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /3-define_type/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | 5 | DEPENDS 6 | NorthStarDialectIncGen${ch_num} 7 | 8 | LINK_LIBS PUBLIC 9 | MLIRIR 10 | MLIRTensorDialect 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /4-define_attribute/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 4) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} MLIRNorthStarDialect${ch_num} MLIRGPUDialect) 8 | -------------------------------------------------------------------------------- /4-define_attribute/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarAttrs.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 将生成的命令们定义为为target 19 | add_public_tablegen_target(NorthStarDialectIncGen${ch_num}) 20 | 21 | 22 | -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define GET_ATTRDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 22 | 23 | #endif // DIALECT_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_H 16 | #define DIALECT_NORTH_STAR_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_H -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /4-define_attribute/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /4-define_attribute/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /4-define_attribute/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /4-define_attribute/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /4-define_attribute/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | 6 | DEPENDS 7 | NorthStarDialectIncGen${ch_num} 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | MLIRTensorDialect 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /5-define_operation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 5) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} MLIRNorthStarDialect${ch_num} MLIRGPUDialect MLIRFuncDialect) 8 | -------------------------------------------------------------------------------- /5-define_operation/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(NorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define GET_ATTRDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 22 | 23 | #endif // DIALECT_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_H 16 | #define DIALECT_NORTH_STAR_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_H -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 20 | #define GET_OP_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_OPS_H 25 | -------------------------------------------------------------------------------- /5-define_operation/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /5-define_operation/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Dialect) 2 | 3 | -------------------------------------------------------------------------------- /5-define_operation/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /5-define_operation/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /5-define_operation/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | NorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /6-define_interface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 6) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} MLIRNorthStarDialect${ch_num} MLIRGPUDialect MLIRFuncDialect) 8 | -------------------------------------------------------------------------------- /6-define_interface/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(NorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_H 16 | #define DIALECT_NORTH_STAR_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_H -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #define GET_OP_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_OPS_H 25 | -------------------------------------------------------------------------------- /6-define_interface/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /6-define_interface/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | -------------------------------------------------------------------------------- /6-define_interface/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /6-define_interface/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | -------------------------------------------------------------------------------- /6-define_interface/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /6-define_interface/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /6-define_interface/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | NorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /6-define_interface/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 2 | DistributeParallelismInterfaces.cpp 3 | 4 | DEPENDS 5 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 6 | 7 | LINK_LIBS PUBLIC 8 | MLIRIR 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /7-ir_struct/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 7) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} 8 | MLIRNorthStarDialect${ch_num} 9 | MLIRTutorialUtils${ch_num} 10 | MLIRGPUDialect 11 | MLIRFuncDialect 12 | MLIRSCFDialect 13 | MLIRLinalgDialect 14 | MLIRParser 15 | ) 16 | -------------------------------------------------------------------------------- /7-ir_struct/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | 5 | -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(NorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_H 16 | #define DIALECT_NORTH_STAR_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_H -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #define GET_OP_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_OPS_H 25 | -------------------------------------------------------------------------------- /7-ir_struct/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /7-ir_struct/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | -------------------------------------------------------------------------------- /7-ir_struct/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /7-ir_struct/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | 5 | 6 | -------------------------------------------------------------------------------- /7-ir_struct/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /7-ir_struct/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | 3 | -------------------------------------------------------------------------------- /7-ir_struct/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | NorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /7-ir_struct/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 2 | DistributeParallelismInterfaces.cpp 3 | 4 | DEPENDS 5 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 6 | 7 | LINK_LIBS PUBLIC 8 | MLIRIR 9 | ) 10 | 11 | -------------------------------------------------------------------------------- /7-ir_struct/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" 25 | void test() { 26 | int DP_nums; 27 | llvm::SmallVector device_ids; 28 | for (auto i : llvm::index_range(0, DP_nums)) { 29 | device_ids.push_back(i); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /7-ir_struct/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | DEPENDS 5 | 6 | LINK_LIBS PUBLIC 7 | MLIRIR 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /7-ir_struct/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /8-define_pass/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 8) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} 8 | MLIRNorthStarDialect${ch_num} 9 | MLIRNorthStarTransforms${ch_num} 10 | MLIRTutorialUtils${ch_num} 11 | MLIRGPUDialect 12 | MLIRFuncDialect 13 | MLIRSCFDialect 14 | MLIRLinalgDialect 15 | MLIRParser 16 | MLIRPass 17 | ) 18 | -------------------------------------------------------------------------------- /8-define_pass/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | 5 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #define GET_OP_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 25 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /8-define_pass/include/Dialect/NorthStar/Transforms/Passes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_TRANSFORMS_PASSES_H 17 | #define DIALECT_NORTH_STAR_TRANSFORMS_PASSES_H 18 | #include "mlir/Pass/Pass.h" 19 | namespace mlir::north_star { 20 | 21 | std::unique_ptr<::mlir::Pass> createApplyDistributeTransformPass(); 22 | 23 | #define GEN_PASS_DECL 24 | #define GEN_PASS_REGISTRATION 25 | #include "Dialect/NorthStar/Transforms/Passes.h.inc" 26 | } // namespace mlir::north_star 27 | 28 | #endif // DIALECT_NORTH_STAR_TRANSFORMS_PASSES_H -------------------------------------------------------------------------------- /8-define_pass/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | -------------------------------------------------------------------------------- /8-define_pass/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /8-define_pass/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | 23 | #endif // UTILS_MLIR_UTILS_KEY_H 24 | -------------------------------------------------------------------------------- /8-define_pass/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | 5 | 6 | -------------------------------------------------------------------------------- /8-define_pass/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /8-define_pass/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /8-define_pass/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /8-define_pass/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | 6 | DEPENDS 7 | MLIRNorthStarPassesIncGen${ch_num} 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRNorthStarDialect${ch_num} 11 | ) 12 | -------------------------------------------------------------------------------- /8-define_pass/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 2 | DistributeParallelismInterfaces.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../Interfaces 6 | 7 | DEPENDS 8 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /8-define_pass/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" 25 | void test() { 26 | int DP_nums; 27 | llvm::SmallVector device_ids; 28 | for (auto i : llvm::index_range(0, DP_nums)) { 29 | device_ids.push_back(i); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /8-define_pass/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /8-define_pass/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /9-rewrite_pattern/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ch_num 9) 2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) 4 | add_subdirectory(include) 5 | add_subdirectory(src) 6 | add_executable(CH-${ch_num} "main.cpp") 7 | target_link_libraries(CH-${ch_num} 8 | MLIRNorthStarDialect${ch_num} 9 | MLIRNorthStarTransforms${ch_num} 10 | MLIRTutorialUtils${ch_num} 11 | MLIRGPUDialect 12 | MLIRFuncDialect 13 | MLIRSCFDialect 14 | MLIRLinalgDialect 15 | MLIRParser 16 | MLIRPass 17 | ) 18 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Interfaces) 2 | add_subdirectory(Dialect) 3 | 4 | 5 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS NorthStarOps.td) 2 | # 生成NorthStar Dialect 的声明 3 | mlir_tablegen(NorthStarDialect.h.inc --gen-dialect-decls -dialect=north_star) 4 | # 生成NorthStar Dialect 的实现 5 | mlir_tablegen(NorthStarDialect.cpp.inc --gen-dialect-defs -dialect=north_star) 6 | # 生成NorthStar Type 的声明 7 | mlir_tablegen(NorthStarTypes.h.inc -gen-typedef-decls -dialect=north_star) 8 | # 生成NorthStar Type 的实现 9 | mlir_tablegen(NorthStarTypes.cpp.inc -gen-typedef-defs -dialect=north_star) 10 | # 生成NorthStar Enums 的声明 11 | mlir_tablegen(NorthStarEunms.h.inc -gen-enum-decls -dialect=north_star) 12 | # 生成NorthStar Enums 的实现 13 | mlir_tablegen(NorthStarEunms.cpp.inc -gen-enum-defs -dialect=north_star) 14 | # 生成NorthStar Attr 的声明 15 | mlir_tablegen(NorthStarAttrs.h.inc -gen-attrdef-decls -dialect=north_star) 16 | # 生成NorthStar Attr 的实现 17 | mlir_tablegen(NorthStarAttrs.cpp.inc -gen-attrdef-defs -dialect=north_star) 18 | # 生成NorthStar Op 的声明 19 | mlir_tablegen(NorthStarOps.h.inc -gen-op-decls -dialect=north_star) 20 | # 生成NorthStar Op 的实现 21 | mlir_tablegen(NorthStarOps.cpp.inc -gen-op-defs -dialect=north_star) 22 | # 将生成的命令们定义为为target 23 | add_public_tablegen_target(MLIRNorthStarDialectIncGen${ch_num}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/IR/NorthStarAttrs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #include "Interfaces/DistributeParallelismInterfaces.h" 21 | #define GET_ATTRDEF_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h.inc" 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_ATTRS_H -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/IR/NorthStarDialect.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #include "Dialect/NorthStar/IR/NorthStarDialect.h.inc" 20 | 21 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_DIALECT_H -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/IR/NorthStarEunms.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 18 | 19 | #include 20 | #include 21 | 22 | #include "llvm/ADT/StringRef.h" 23 | #include "llvm/ADT/StringSwitch.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | #include "mlir/Support/LLVM.h" 26 | 27 | #define FIX 28 | #include "Dialect/NorthStar/IR/NorthStarEunms.h.inc" 29 | #undef FIX 30 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_EUNMS_H 31 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/IR/NorthStarOps.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 17 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 18 | #define FIX 19 | #include "Dialect/NorthStar/IR/NorthStarAttrs.h" 20 | #include "Interfaces/FusionRegionInterfaces.h" 21 | #define GET_OP_CLASSES 22 | #include "Dialect/NorthStar/IR/NorthStarOps.h.inc" 23 | #undef FIX 24 | 25 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_OPS_H 26 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/IR/NorthStarTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 16 | #define DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H 17 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 18 | #include "mlir/IR/MLIRContext.h" 19 | #define FIX 20 | #define GET_TYPEDEF_CLASSES 21 | #include "Dialect/NorthStar/IR/NorthStarTypes.h.inc" 22 | #undef FIX 23 | 24 | #endif // DIALECT_NORTH_STAR_IR_NORTH_STAR_TYPES_H -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS Passes.td) 2 | mlir_tablegen(Passes.h.inc -gen-pass-decls -name NorthStarOpt) 3 | add_public_tablegen_target(MLIRNorthStarPassesIncGen${ch_num}) 4 | add_dependencies(mlir-headers MLIRNorthStarPassesIncGen${ch_num}) 5 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGET_DEFINITIONS DistributeParallelismInterfaces.td) 2 | mlir_tablegen(DistributeParallelismOpInterfaces.h.inc -gen-op-interface-decls) 3 | mlir_tablegen(DistributeParallelismOpInterfaces.cpp.inc -gen-op-interface-defs) 4 | mlir_tablegen(DistributeParallelismAttrInterfaces.h.inc -gen-attr-interface-decls) 5 | mlir_tablegen(DistributeParallelismAttrInterfaces.cpp.inc -gen-attr-interface-defs) 6 | add_public_tablegen_target(MLIRDistributeParallelismInterfacesIncGen${ch_num}) 7 | 8 | set(LLVM_TARGET_DEFINITIONS FusionRegionInterfaces.td) 9 | mlir_tablegen(FusionRegionOpInterfaces.h.inc -gen-op-interface-decls) 10 | mlir_tablegen(FusionRegionOpInterfaces.cpp.inc -gen-op-interface-defs) 11 | add_public_tablegen_target(MLIRFusionRegionInterfacesIncGen${ch_num}) 12 | 13 | -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Interfaces/DistributeParallelismInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 16 | #define INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/DistributeParallelismAttrInterfaces.h.inc" 22 | #include "Interfaces/DistributeParallelismOpInterfaces.h.inc" 23 | #undef FIX 24 | #endif // INTERFACES_DISTRIBUTED_PARALLELISM_INTERFACES_H -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Interfaces/FusionRegionInterfaces.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef INTERFACES_FUSION_REGION_INTERFACES_H 16 | #define INTERFACES_FUSION_REGION_INTERFACES_H 17 | #include "Dialect/NorthStar/IR/NorthStarEunms.h" 18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" 19 | #include "mlir/IR/MLIRContext.h" 20 | #define FIX 21 | #include "Interfaces/FusionRegionOpInterfaces.h.inc" 22 | #undef FIX 23 | #endif // INTERFACES_FUSION_REGION_INTERFACES_H -------------------------------------------------------------------------------- /9-rewrite_pattern/include/Utils/Key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UTILS_MLIR_UTILS_KEY_H 16 | #define UTILS_MLIR_UTILS_KEY_H 17 | 18 | inline static const char* KEntryPointName = "main"; 19 | inline static const char* KDPAttrName = "dp_attr"; 20 | inline static const char* KHostFunc = "host_func"; 21 | inline static const char* KDeviceFunc = "device_kernel"; 22 | 23 | #endif // UTILS_MLIR_UTILS_KEY_H 24 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Utils) 2 | add_subdirectory(Interfaces) 3 | add_subdirectory(Dialect) 4 | 5 | 6 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Dialect/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(NorthStar) 2 | 3 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Dialect/NorthStar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Transforms) 3 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Dialect/NorthStar/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_dialect_library(MLIRNorthStarDialect${ch_num} 2 | NorthStarDialect.cpp 3 | NorthStarTypes.cpp 4 | NorthStarAttrs.cpp 5 | NorthStarOps.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarDialectIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRIR 12 | MLIRTensorDialect 13 | MLIRDistributeParallelismInterfaces${ch_num} 14 | MLIRFusionRegionInterfaces${ch_num} 15 | ) 16 | 17 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Dialect/NorthStar/Transforms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_mlir_dialect_library(MLIRNorthStarTransforms${ch_num} 3 | ApplyDistributeTransform.cpp 4 | MarkDistributeParallelParameters.cpp 5 | DeviceRegionFusion.cpp 6 | 7 | DEPENDS 8 | MLIRNorthStarPassesIncGen${ch_num} 9 | 10 | LINK_LIBS PUBLIC 11 | MLIRNorthStarDialect${ch_num} 12 | MLIRPass 13 | MLIRTransforms 14 | MLIRTransformUtils 15 | ) 16 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_OPTIONAL_SOURCES 2 | DistributeParallelismInterfaces.cpp 3 | FusionRegionInterfaces.cpp 4 | ) 5 | 6 | add_mlir_library(MLIRDistributeParallelismInterfaces${ch_num} 7 | DistributeParallelismInterfaces.cpp 8 | 9 | DEPENDS 10 | MLIRDistributeParallelismInterfacesIncGen${ch_num} 11 | 12 | LINK_LIBS PUBLIC 13 | MLIRIR 14 | ) 15 | 16 | add_mlir_library(MLIRFusionRegionInterfaces${ch_num} 17 | FusionRegionInterfaces.cpp 18 | 19 | DEPENDS 20 | MLIRFusionRegionInterfacesIncGen${ch_num} 21 | 22 | LINK_LIBS PUBLIC 23 | MLIRIR 24 | ) 25 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Interfaces/DistributeParallelismInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/DistributeParallelismInterfaces.h" 15 | 16 | #include 17 | 18 | #include "Interfaces/DistributeParallelismAttrInterfaces.cpp.inc" 19 | #include "Interfaces/DistributeParallelismOpInterfaces.cpp.inc" 20 | #include "Dialect/NorthStar/IR/NorthStarTypes.h" 21 | #include "llvm/ADT/STLExtras.h" 22 | #include "llvm/ADT/SmallVector.h" 23 | #include "llvm/Support/raw_ostream.h" 24 | #include "mlir/IR/Operation.h" -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Interfaces/FusionRegionInterfaces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Interfaces/FusionRegionInterfaces.h" 15 | #include 16 | 17 | #include "Interfaces/FusionRegionOpInterfaces.cpp.inc" -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mlir_library(MLIRTutorialUtils${ch_num} 2 | File.cpp 3 | 4 | ADDITIONAL_HEADER_DIRS 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../include/Utils 6 | 7 | DEPENDS 8 | 9 | LINK_LIBS PUBLIC 10 | MLIRIR 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /9-rewrite_pattern/src/Utils/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2025 时光丶人爱 2 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include "Utils/File.h" 15 | 16 | #include 17 | 18 | #include "llvm/Support/Error.h" 19 | #include "llvm/Support/MemoryBuffer.h" 20 | #include "llvm/Support/SourceMgr.h" 21 | #include "mlir/IR/AsmState.h" 22 | #include "mlir/IR/PatternMatch.h" 23 | #include "mlir/Parser/Parser.h" 24 | 25 | namespace utils::file {} // namespace utils::file 26 | -------------------------------------------------------------------------------- /a.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/violetDelia/MLIR-Tutorial/4242ad765159131fc22d0b240df2b43446f22ccd/a.txt -------------------------------------------------------------------------------- /third_party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_ENABLE_PROJECTS "mlir;clang" CACHE STRING " " FORCE) 2 | set(LLVM_TARGETS_TO_BUILD "Native" CACHE STRING " " FORCE) 3 | add_subdirectory(llvm-project/llvm) -------------------------------------------------------------------------------- /教程内容.md: -------------------------------------------------------------------------------- 1 | 教程指路: 2 | - 主要内容说明 3 | - 自定义Dialect 4 | - Dialect定义以及字段说明。 5 | - 定义 NorthStar Dialect。 6 | - 使用tablegen工具/函数生成相应c代码,以及代码结构简介。 7 | - 构建mlir dialect 库文件。 8 | - 自定义Type 9 | - Builtin Dialect中常用的Type介绍。 10 | - Type定义以及字段说明。 11 | - 定义NSTensor Type 来描述带有设备信息的张量信息。 12 | - 使用tablegen工具/函数生成相应c代码,以及代码结构简介。 13 | - 如何将Type注册到相应的Dialect中,并且对Type进行合法性检验。 14 | - 如何自定义Type的解析和输出函数。 15 | - 自定义Attribute 16 | - Builtin Dialect中常用的attrbute介绍。 17 | - 定义 18 | - 待整理 19 | - mlir-opt工具与debug 20 | - 构建自己的“mlir-opt”工具 21 | - 使用mlir-opt工具运行pass 22 | - 将IR变换的过程dump下来,以便分析优化。以及PassManager进行IR dump。 23 | - mlir-opt输出debug内容,以及自定义debug内容。 24 | 25 | 26 | 27 | 28 | --------------------------------------------------------------------------------