Skip to content
/ Magpie Public

A lightweight, general-purpose framework for evaluating GPU kernel correctness and performance.

License

Notifications You must be signed in to change notification settings

AMD-AGI/Magpie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Magpie

A lightweight, general-purpose framework for evaluating GPU kernel correctness and performance.

Features

  • Three Evaluation Modes: Analyze, Compare, Benchmark
  • Heterogeneous Hardware: AMD (HIP) and NVIDIA (CUDA) GPUs
  • Execution Environments: Local, Sandbox Container, and Remote Ray Cluster
  • Hardware Control: Hardware-aware kernel evaluation under controlled execution settings
  • Trace Analysis: TraceLens integration for performance profiling analysis
  • MCP Server: Model Context Protocol integration for AI agents
  • Structured Reports: JSON output for pipeline integration

Requirements

  • Python 3.10+
  • AMD ROCm (HIP) or NVIDIA CUDA toolchain (for kernel compilation/profiling)
  • rocprof-compute (AMD) or ncu (NVIDIA) if you enable performance profiling
  • Docker (required for Benchmark mode)

Installation

From GitHub (Recommended)

# Basic installation
pip install git+https://github.com/AMD-AGI/Magpie.git

From Source (Development)

git clone https://github.com/AMD-AGI/Magpie.git
cd Magpie

# Editable install (recommended for development)
pip install -e .

# Or use make
make install

Quick Start

# Analyze a kernel using a config file
magpie analyze --kernel-config Magpie/kernel_config.yaml.example

# Compare kernels directly
magpie compare kernel_v1.hip kernel_v2.hip

# Benchmark vLLM with torch profiling
magpie benchmark --benchmark-config examples/benchmark_vllm.yaml

# Run MCP server
python -m Magpie.mcp

Note: You can also use python -m Magpie instead of magpie command.

Evaluation Modes

Mode Description Status
Analyze Single kernel evaluation with testcase βœ…
Compare Multi-kernel comparison and ranking βœ…
Benchmark Framework-level benchmarking (vLLM/SGLang) with trace analysis βœ…

πŸ“– See Benchmark Mode Documentation for detailed usage.

Configuration

Framework Config (Magpie/config.yaml)

Key categories:

  • gpu: force device selection and hardware control (power/frequency).
  • scheduler: local/container/remote execution and scheduling behavior.
  • performance: profiling and profiler configuration.
  • logging: log levels and output formatting.

Kernel Config

See Magpie/kernel_config.yaml.example for full examples.

Example Configs

Example configs live in examples/:

Mode Config File Description
Analyze ck_gemm_add.yaml Single kernel evaluation
Compare ck_grouped_gemm_compare.yaml Multi-kernel comparison
Benchmark benchmark_vllm.yaml vLLM benchmark with profiling
Benchmark benchmark_vllm_tracelens.yaml vLLM + TraceLens analysis
Benchmark benchmark_sglang.yaml SGLang benchmark

MCP Server

MCP configuration example: Magpie/mcp/config.json

Available tools:

  • analyze - Analyze kernel correctness and performance
  • compare - Compare multiple kernel implementations
  • hardware_spec - Query GPU hardware specifications
  • configure_gpu - Configure GPU power and frequency
  • discover_kernels - Scan a project and suggest analyzable kernels/configs
  • suggest_optimizations - Suggest performance optimizations from analyze output
  • create_kernel_config - Generate a kernel config YAML for analyze

Development

make install-dev
make lint
make format

Project Structure

β”œβ”€β”€ README.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ .gitignore
β”œβ”€β”€ pyproject.toml       # Package configuration (pip install)
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Makefile
β”œβ”€β”€ examples/            # Example configurations
β”œβ”€β”€ docs/                # Documentation
β”‚   └── benchmark.md     # Benchmark mode documentation
└── Magpie/
    β”œβ”€β”€ __init__.py          # Package initialization
    β”œβ”€β”€ __main__.py          # Entry point for python -m Magpie
    β”œβ”€β”€ main.py              # CLI implementation
    β”œβ”€β”€ config.yaml          # Framework configuration
    β”œβ”€β”€ kernel_config.yaml.example
    β”œβ”€β”€ config/              # Configuration classes
    β”œβ”€β”€ core/                # Core engine components
    β”œβ”€β”€ eval/                # Evaluation pipeline
    β”œβ”€β”€ modes/               # Evaluation modes
    β”‚   β”œβ”€β”€ analyze_eval/    # Single kernel analysis
    β”‚   β”œβ”€β”€ compare_eval/    # Multi-kernel comparison
    β”‚   └── benchmark/       # Framework-level benchmarking
    β”‚       β”œβ”€β”€ benchmarker.py   # Benchmark orchestration
    β”‚       β”œβ”€β”€ config.py        # Benchmark configuration
    β”‚       β”œβ”€β”€ tracelens.py     # TraceLens integration
    β”‚       └── result.py        # Result data structures
    β”œβ”€β”€ mcp/                 # MCP Server
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ __main__.py      # Entry point for python -m Magpie.mcp
    β”‚   β”œβ”€β”€ server.py        # MCP server implementation
    β”‚   └── config.json      # MCP client configuration
    └── utils/               # Utility functions

Overall Architecture Diagram

Overall Architecture

Eval Pipeline

Analyze & Compare

Analyze & Compare Pipeline

Benchmark

Benchmark Pipeline

License

MIT License. See LICENSE.

About

A lightweight, general-purpose framework for evaluating GPU kernel correctness and performance.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published