Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计提醒

mlir-developmentMLIR 发展

Agent Skill

mlir-development 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

576

周安装

24

GitHub Stars

827

下载量

192
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:mlir-development(MLIR 发展)
来源仓库:https://github.com/gmh5225/awesome-llvm-security
仓库路径:skills/mlir-development
安装命令:
npx skills add https://github.com/gmh5225/awesome-llvm-security --skill mlir-development
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/gmh5225/awesome-llvm-security --skill mlir-development

简介

MLIR 发展技能用于处理 LLVM 生态中的中间表示开发信息。

  • 它协助整理代码变更、Issue 讨论及技术演进脉络。
  • 安装自 awesome-llvm-security 仓库,适用于编译器开发者。
  • 使用前应确认是否涉及敏感安全研究内容的访问权限。
  • mlir-development 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

MLIR Development Skill

This skill covers MLIR (Multi-Level Intermediate Representation) development for building domain-specific compilers and high-level optimization pipelines.

MLIR Overview

What is MLIR?

MLIR is a compiler infrastructure that enables building reusable and extensible compiler components. It provides:

  • Hierarchical, multi-level IR representation
  • Extensible operation and type system
  • Progressive lowering between abstraction levels
  • Rich transformation infrastructure

Architecture

High-Level DSL
     ↓
Domain-Specific Dialects (e.g., TensorFlow, PyTorch)
     ↓
Mid-Level Dialects (e.g., Linalg, Affine)
     ↓
Low-Level Dialects (e.g., LLVM, GPU)
     ↓
Target Code

Core Concepts

Dialects

Dialects are groupings of operations, types, and attributes:

// Define a custom dialect
class MyDialect : public mlir::Dialect {
public:
    explicit MyDialect(mlir::MLIRContext *context)
        : Dialect("my_dialect", context,
                  mlir::TypeID::get<MyDialect>()) {
        addOperations<
            MyAddOp,
            MyMulOp,
            MyFuncOp
        >();
        addTypes<MyTensorType>();
    }

    static llvm::StringRef getDialectNamespace() {
        return "my_dialect";
    }
};

Operations

// Define using ODS (Operation Definition Specification)
// In TableGen file (.td)
def MyAddOp : Op<MyDialect, "add", [Pure]> {
    let summary = "Add two tensors";
    let description = [{
        Performs element-wise addition of two tensors.
    }];

    let arguments = (ins
        AnyTensor:$lhs,
        AnyTensor:$rhs
    );

    let results = (outs
        AnyTensor:$result
    );

    let assemblyFormat = [{
        $lhs `,` $rhs attr-dict `:` type($result)
    }];
}

Types and Attributes

// Custom type definition
class MyTensorType : public mlir::Type::TypeBase<
    MyTensorType, mlir::Type, MyTensorTypeStorage> {
public:
    using Base::Base;

    static MyTensorType get(mlir::MLIRContext *context,
                            llvm::ArrayRef<int64_t> shape,
                            mlir::Type elementType) {
        return Base::get(context, shape, elementType);
    }

    llvm::ArrayRef<int64_t> getShape() const;
    mlir::Type getElementType() const;
};

Writing MLIR Passes

Transform Pass

#include "mlir/Pass/Pass.h"
#include "mlir/IR/PatternMatch.h"

struct MyOptimizationPass
    : public mlir::PassWrapper<MyOptimizationPass,
                                mlir::OperationPass<mlir::func::FuncOp>> {

    void runOnOperation() override {
        mlir::func::FuncOp func = getOperation();

        // Walk all operations
        func.walk([](mlir::Operation *op) {
            // Transform operations
            if (auto addOp = llvm::dyn_cast<MyAddOp>(op)) {
                optimizeAdd(addOp);
            }
        });
    }

    llvm::StringRef getArgument() const final {
        return "my-optimization";
    }

    llvm::StringRef getDescription() const final {
        return "My custom optimization pass";
    }
};

Pattern-Based Rewriting

// Define rewrite pattern
struct SimplifyRedundantAdd : public mlir::OpRewritePattern<MyAddOp> {
    using OpRewritePattern<MyAddOp>::OpRewritePattern;

    mlir::LogicalResult matchAndRewrite(
        MyAddOp op,
        mlir::PatternRewriter &rewriter) const override {

        // Match: add(x, 0) -> x
        if (auto constOp = op.getRhs().getDefiningOp<ConstantOp>()) {
            if (isZero(constOp)) {
                rewriter.replaceOp(op, op.getLhs());
                return mlir::success();
            }
        }
        return mlir::failure();
    }
};

// Apply patterns
void runOnOperation() override {
    mlir::RewritePatternSet patterns(&getContext());
    patterns.add<SimplifyRedundantAdd>(&getContext());

    if (mlir::failed(mlir::applyPatternsAndFoldGreedily(
            getOperation(), std::move(patterns)))) {
        signalPassFailure();
    }
}

Dialect Conversion

Lowering Between Dialects

// Convert high-level ops to lower-level ops
struct MyAddOpLowering : public mlir::OpConversionPattern<MyAddOp> {
    using OpConversionPattern<MyAddOp>::OpConversionPattern;

    mlir::LogicalResult matchAndRewrite(
        MyAddOp op,
        OpAdaptor adaptor,
        mlir::ConversionPatternRewriter &rewriter) const override {

        // Lower to arith dialect
        rewriter.replaceOpWithNewOp<mlir::arith::AddFOp>(
            op, adaptor.getLhs(), adaptor.getRhs());
        return mlir::success();
    }
};

// Conversion pass
struct LowerToArithPass : public mlir::PassWrapper<
    LowerToArithPass,
    mlir::OperationPass<mlir::ModuleOp>> {

    void runOnOperation() override {
        mlir::ConversionTarget target(getContext());
        target.addLegalDialect<mlir::arith::ArithDialect>();
        target.addIllegalDialect<MyDialect>();

        mlir::RewritePatternSet patterns(&getContext());
        patterns.add<MyAddOpLowering>(&getContext());

        if (mlir::failed(mlir::applyPartialConversion(
                getOperation(), target, std::move(patterns)))) {
            signalPassFailure();
        }
    }
};

Built-in Dialects

Affine Dialect

For polyhedral compilation and loop optimizations:

affine.for %i = 0 to 100 {
    affine.for %j = 0 to 100 {
        %val = affine.load %A[%i, %j] : memref<100x100xf32>
        affine.store %val, %B[%j, %i] : memref<100x100xf32>
    }
}

Linalg Dialect

For linear algebra operations:

linalg.matmul ins(%A, %B : tensor<MxKxf32>, tensor<KxNxf32>)
              outs(%C : tensor<MxNxf32>) -> tensor<MxNxf32>

SCF Dialect (Structured Control Flow)

%result = scf.for %i = %lb to %ub step %step iter_args(%sum = %init) {
    %val = memref.load %A[%i] : memref<?xf32>
    %new_sum = arith.addf %sum, %val : f32
    scf.yield %new_sum : f32
}

CIR (Clang IR)

Overview

CIR is an MLIR-based representation for C/C++, providing:

  • Higher-level representation than LLVM IR
  • Better debugging and tooling
  • Language-specific optimizations
// CIR example
cir.func @add(%a: !s32i, %b: !s32i) -> !s32i {
    %result = cir.binop(add, %a, %b) : !s32i
    cir.return %result : !s32i
}

CIR Projects

  • llvm/clangir: Official ClangIR implementation
  • facebookincubator/clangir: Facebook's CIR experiments

ML/AI Compilation

TensorFlow MLIR

// TensorFlow dialect
%result = "tf.MatMul"(%A, %B) {
    transpose_a = false,
    transpose_b = false
} : (tensor<4x8xf32>, tensor<8x16xf32>) -> tensor<4x16xf32>

PyTorch MLIR (torch-mlir)

// Torch dialect
%result = torch.aten.mm %A, %B :
    !torch.vtensor<[4,8],f32>, !torch.vtensor<[8,16],f32>
    -> !torch.vtensor<[4,16],f32>

IREE (Intermediate Representation Execution Environment)

End-to-end MLIR compiler for ML models:

  • Portable deployment
  • Efficient runtime execution
  • Multi-target support (CPU, GPU, TPU)

Testing MLIR

FileCheck Tests

// RUN: mlir-opt %s -my-pass | FileCheck %s

// CHECK-LABEL: func @test_optimization
// CHECK: arith.addi
// CHECK-NOT: my_dialect.add
func @test_optimization(%a: i32, %b: i32) -> i32 {
    %result = my_dialect.add %a, %b : i32
    return %result : i32
}

Unit Testing

TEST(MyDialect, AddOpConstantFolding) {
    mlir::MLIRContext context;
    context.loadDialect<MyDialect>();

    mlir::OpBuilder builder(&context);
    auto loc = builder.getUnknownLoc();

    // Create and test operations
    auto constA = builder.create<ConstantOp>(loc, 5);
    auto constB = builder.create<ConstantOp>(loc, 3);
    auto add = builder.create<MyAddOp>(loc, constA, constB);

    // Verify folding
    EXPECT_TRUE(add.fold().succeeded());
}

Development Tools

mlir-opt

# Run passes
mlir-opt input.mlir -my-pass -o output.mlir

# Convert between dialects
mlir-opt input.mlir -convert-my-to-llvm

# Debug printing
mlir-opt input.mlir -debug-only=my-pass

mlir-translate

# MLIR to LLVM IR
mlir-translate input.mlir --mlir-to-llvmir -o output.ll

# LLVM IR to MLIR
mlir-translate input.ll --import-llvm -o output.mlir

Best Practices

  1. Progressive Lowering: Lower in multiple stages, not directly to LLVM
  2. Preserve Semantics: Each lowering should be semantics-preserving
  3. Use ODS: Define operations in TableGen for consistency
  4. Test Thoroughly: Use FileCheck for transformation tests
  5. Document Dialects: Clear operation semantics documentation

Resources

See MLIR and CIR sections in README.md for tutorials and example projects.

Getting Detailed Information

When you need detailed and up-to-date resource links, tool lists, or project references, fetch the latest data from:

https://raw.githubusercontent.com/gmh5225/awesome-llvm-security/refs/heads/main/README.md

This README contains comprehensive curated lists of:

  • MLIR tutorials and sample dialects (MLIR section)
  • CIR (Clang IR) projects and documentation (CIR section)
  • ML/AI compiler frameworks (torch-mlir, IREE, XLA)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.84%
按下载量换算65

Claude

32.98%
按下载量换算63

Cursor

19.16%
按下载量换算37

Gemini CLI

8.65%
按下载量换算17

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills