mlir-development
БесплатноБез исполняемых скриптовНе проверенExpertise in MLIR (Multi-Level Intermediate Representation) and CIR (Clang IR) development for domain-specific compilation and high-level optimizations. Use…
Об этом скилле
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-development в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mlir-development?
Expertise in MLIR (Multi-Level Intermediate Representation) and CIR (Clang IR) development for domain-specific compilation and high-level optimizations. Use this skill when building ML compilers, domain-specific languages, or working with multi-level compilation pipelines.
Как установить скилл mlir-development?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mlir-development запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic