文件最后提交记录最后更新时间
Disable Torch_Aten_AdaptiveAvgPool2dOp Canonicalize 20 天前
Resolve static code check 19 天前
Resolve static code check 19 天前
Resolve static code check 19 天前
Resolve static code check 19 天前
fix(mfusion): disable aten.clone fold, refine reciprocal canonicalize, and sync torch-mlir patch docs. 20 天前
Clean up compiler warnings 20 天前
mfusion: add ASAN build option and fix issues - Add CMake ENABLE_ASAN, build.sh -a on|off (forces Debug), and setup.py passthrough via ENABLE_ASAN env. - Avoid use-after-free in MatMul fusion patterns: capture Location before replaceOp when logging; same for split debug paths. - Prefer MLOG(DEBUG) over LLVM_DEBUG in FusedOpUtils, Split pass, FuseOpRebuilder; FuseOpSplitter logs via Node::toString. - Node::toString uses OpPrintingFlags assumeVerified + useLocalScope. - Update lit: torch i32 as si32 in MfuseToTorch tests; trim RUN lines (drop -allow-unregistered-dialect / -mlir-print-ir-after-all). 20 天前
Resolve static code check 19 天前
Resolve static code check 19 天前
mfusion: add ASAN build option and fix issues - Add CMake ENABLE_ASAN, build.sh -a on|off (forces Debug), and setup.py passthrough via ENABLE_ASAN env. - Avoid use-after-free in MatMul fusion patterns: capture Location before replaceOp when logging; same for split debug paths. - Prefer MLOG(DEBUG) over LLVM_DEBUG in FusedOpUtils, Split pass, FuseOpRebuilder; FuseOpSplitter logs via Node::toString. - Node::toString uses OpPrintingFlags assumeVerified + useLocalScope. - Update lit: torch i32 as si32 in MfuseToTorch tests; trim RUN lines (drop -allow-unregistered-dialect / -mlir-print-ir-after-all). 20 天前
Package mfusion-opt executable with wheel This change bundles the mfusion-opt tool with the Python wheel package, allowing users to use it directly after installation via mfusion-opt command. Changes: - Add Python entry point script at python/mfusion/tools/opt/__main__.py - Modify setup.py to copy mfusion-opt to _mlir_libs and register console script - Declare MFusionPythonSources.Tools in python/CMakeLists.txt - Skip TorchMLIRPythonSources.Tools in torch-mlir when building embedded to avoid conflict with mfusion's own tools 20 天前
Change pybind11 version 19 天前
mfusion: add ASAN build option and fix issues - Add CMake ENABLE_ASAN, build.sh -a on|off (forces Debug), and setup.py passthrough via ENABLE_ASAN env. - Avoid use-after-free in MatMul fusion patterns: capture Location before replaceOp when logging; same for split debug paths. - Prefer MLOG(DEBUG) over LLVM_DEBUG in FusedOpUtils, Split pass, FuseOpRebuilder; FuseOpSplitter logs via Node::toString. - Node::toString uses OpPrintingFlags assumeVerified + useLocalScope. - Update lit: torch i32 as si32 in MfuseToTorch tests; trim RUN lines (drop -allow-unregistered-dialect / -mlir-print-ir-after-all). 20 天前
README.md

mfusion

基于MLIR的图层算子融合工具。

依赖组件

编译和安装

安装 Python 构建依赖

cd PATH_TO_MFUSION_ROOT_PATH
pip install -r requirements-build.txt

使用 build.sh 脚本构建

cd PATH_TO_MFUSION_ROOT_PATH

print usage by -h (bash build.sh -h):
Usage:
bash build.sh [-a on|off] [-d] [-h] [-i] [-j[n]] [-s path] [-t]

Options:
    -a on|off Enable AddressSanitizer (implies Debug mode), default off
    -d Debug mode, default release mode
    -h Print usage
    -i Incremental build
    -j[n] Set the threads when building (Default: the number of cpu)
    -s Specifies the CMAKE_PREFIX_PATH for dependencies
    -t Enable unit test (Default: disable)

Command Example:
    # First time build
    bash build.sh -j32

    # Reuse prebuilt dependencies through CMAKE_PREFIX_PATH
    bash build.sh -s /path/to/dependency/prefix -j32

    # Incremental build
    bash build.sh -i -j32

    # Build with unit tests
    bash build.sh -t -j32

    # Debug / ASAN build
    bash build.sh -d -j32
    bash build.sh -a on -j32

构建脚本通过 python -m build --wheel --no-isolation 触发 CMake 编译。生成的 wheel 会复制到 output/ 目录。

pip install output/mfusion-*.whl

手动分步构建

cd PATH_TO_MFUSION_ROOT_PATH

export BUILD_JOBS=32
export BUILD_TYPE=Release
export BUILD_TESTS=OFF
export ENABLE_ASAN=OFF

# 可选:通过 CMAKE_PREFIX_PATH 提供已有依赖前缀
export CMAKE_PREFIX_PATH=/path/to/dependency/prefix

python -m build --wheel --no-isolation
mkdir -p output
cp dist/*.whl output/

运行示例

使用 mfusion-opt

安装 wheel 后可以直接使用 Python console script:

mfusion-opt tests/ut/lit/Pipeline/test_mfuse_cluster_then_outline.mlir \
    --mfuse-dvm-cluster \
    --outline-mfuse-fused-subgraphs

也可以直接使用构建目录中的二进制:

build/bin/mfusion-opt tests/ut/lit/Conversion/TorchToMfuse/test_convert_torch_relu.mlir \
    --convert-torch-to-mfuse \
    --canonicalize

使用 Python pipeline

当前支持接入torch inductor后端:

from mfusion.torch.inductor import fuse_and_optimize

optimized_mlir = fuse_and_optimize(torch_mlir_text, kernel_generator="dvm")

kernel_generator 支持 dvmakgbisheng,默认值为 dvm

运行测试

构建测试目标:

bash build.sh -t -j32

运行全部单元测试:

bash tests/run_test.sh -t ut -u all

只运行 lit 或 Python 单元测试:

bash tests/run_test.sh -t ut -u lit
bash tests/run_test.sh -t ut -u python

IR 调试

Python pipeline 支持如下环境变量:

# 打印每个 pipeline stage 的 IR
export MFUSION_PRINT_IR=1

# 保存每个 pipeline stage 的 IR,默认写入当前目录下的 graphs/
export MFUSION_SAVE_IR=1

# 额外保存 torch-fusion / mfuse-fusion 内部子 pass 的 IR
export MFUSION_SAVE_IR=2

# 指定 IR 保存目录
export MFUSION_SAVE_IR_PATH=/path/to/graphs

# level 2 下只保存发生变化的内部子 pass IR
export MFUSION_VERBOSE_IR_DUMP_ON_CHANGE=1

代码格式化

项目上级目录包含 .clang-format,C/C++ 代码按该配置格式化。例如:

git diff --name-only -- '*.cc' '*.h' | xargs -r clang-format -i