zoukankan      html  css  js  c++  java
  • ONNX MLIR方法

    ONNX MLIR方法

    MLIR中的开放式神经网络交换实现。

    Prerequisites

    gcc >= 6.4

    libprotoc >= 3.11.0

    cmake >= 3.15.4

    在UNIX上安装MLIR

    首先,安装MLIR(作为LLVM-Project的一部分):

    git clone https://github.com/llvm/llvm-project.git

    # Check out a specific branch that is known to work with ONNX MLIR.

    cd llvm-project && git checkout 496fb70b141ccbfaba9761294f3b4b97717096a3 && cd ..

    mkdir llvm-project/build

    cd llvm-project/build

    cmake -G Ninja ../llvm

       -DLLVM_ENABLE_PROJECTS=mlir

       -DLLVM_BUILD_EXAMPLES=ON

       -DLLVM_TARGETS_TO_BUILD="host"

       -DCMAKE_BUILD_TYPE=Release

       -DLLVM_ENABLE_ASSERTIONS=ON

       -DLLVM_ENABLE_RTTI=ON

     

    cmake --build . --target -- ${MAKEFLAGS}

    cmake --build . --target check-mlir

    ONNX-MLIR (this project)

    需要设置两个环境变量:

    • LLVM_PROJ_SRC指向llvm-project src目录(例如llvm-project /)。
    • LLVM_PROJ_BUILD指向llvm-project构建目录(例如,llvm-project / build)。

    要构建ONNX-MLIR,使用以下命令:

    same-as-file: <> ({“ref”: “utils/install-onnx-mlir.sh”, “skip-doc”: 2})

    git clone --recursive https://github.com/onnx/onnx-mlir.git

    # Export environment variables pointing to LLVM-Projects.

    export LLVM_PROJ_SRC=$(pwd)/llvm-project/

    export LLVM_PROJ_BUILD=$(pwd)/llvm-project/build

    mkdir onnx-mlir/build && cd onnx-mlir/build

    cmake ..

    cmake --build .

     

    # Run FileCheck tests:

    export LIT_OPTS=-v

    cmake --build . --target check-onnx-lit

    上述命令成功onnx-mlir执行后,可执行文件应出现在bin目录中。

    在Windows上安装

    在Windows上构建onnx-mlir,需要构建一些默认情况下不可用的其它预先条件。

    文件中的说明假定正在使用Visual Studio 2019社区版。建议安装具有C ++桌面开发具有C ++工作负载的Linux开发。这样可以确保拥有编译此工程,及其在Windows上的依赖项所需的所有工具链和库。

    “ VS 2019开发人员命令提示符”开始的外壳程序中运行所有命令。

    Protobuf

    将protobuf构建为静态库。

    set root_dir=%cd%

    git clone --recurse-submodules https://github.com/protocolbuffers/protobuf.git

    cd protobuf

    cd cmake

    cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_WITH_ZLIB=OFF -DCMAKE_INSTALL_PREFIX="%root_dir%protobufinstall"

    call msbuild protobuf.sln /m /p:Configuration=Release

    call msbuild INSTALL.vcxproj /p:Configuration=Release

    在为onnx-mlir运行CMake之前,确保此protobuf的bin目录在PATH中的其它任何目录之前:

    set PATH=%root_dir%protobufinstallin;%PATH%

    PDCurses

    Build a local version of the curses library, used by various commandline tools in onnx-mlir. These instructions assume you use Public Domain Curses.

    Run this from a Visual Studio developer command prompt since you will need access to the appropriate version of Visual Studio’s nmake tool.

    构建curses库的本地版本,供onnx-mlir中的各种命令行工具使用。这些说明假定使用Public Domain Curses

    从Visual Studio开发命令提示符运行此命令,需要访问相应版本的Visual Studio的nmake工具。

    set root_dir=%cd%

    git clone https://github.com/wmcbrine/PDCurses.git

    set PDCURSES_SRCDIR=%root_dir%/PDCurses

    cd PDCurses

    call nmake -f wincon/Makefile.vc

    MLIR

    安装MLIR(作为LLVM-Project的一部分):

    git clone https://github.com/llvm/llvm-project.git

    # Check out a specific branch that is known to work with ONNX MLIR.

    cd llvm-project && git checkout 496fb70b141ccbfaba9761294f3b4b97717096a3 && cd ..

    set root_dir=%cd%

    md llvm-projectuild

    cd llvm-projectuild

    call cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 ..llvm ^

       -DCMAKE_INSTALL_PREFIX="%root_dir%llvm-projectuildinstall" ^

       -DLLVM_ENABLE_PROJECTS=mlir ^

       -DLLVM_BUILD_EXAMPLES=ON ^

       -DLLVM_TARGETS_TO_BUILD="host" ^

       -DCMAKE_BUILD_TYPE=Release ^

       -DLLVM_ENABLE_ASSERTIONS=ON ^

       -DLLVM_ENABLE_RTTI=ON ^

       -DLLVM_ENABLE_ZLIB=OFF

     

    call cmake --build . --config Release --target -- /m

    call cmake --build . --config Release --target install

    call cmake --build . --config Release --target check-mlir

    ONNX-MLIR (this project)

    在构建onnx-mlir之前,需要设置以下环境变量:

    • CURSES_LIB_PATH:curses库的路径(例如c:/ repos / PDCurses)
    • LLVM_PROJ_BUILD:LLVM构建目录的路径(例如c:/ repos / llvm-project / build)
    • LLVM_PROJ_SRC:LLVM源目录的路径(例如c:/ repos / llvm-project)

    该项目使用带lit(LLVM的Integrated Tester)进行单元测试。运行CMake时,使用LLVM_EXTERNAL_LIT定义从LLVM指定lit工具的路径。

    要构建ONNX MLIR,使用以下命令:

    same-as-file: <> ({“ref”: “utils/install-onnx-mlir.cmd”, “skip-doc”: 2})

    git clone --recursive https://github.com/onnx/onnx-mlir.git

     

    REM Export environment variables pointing to LLVM-Projects.

    set root_dir=%cd%

    set CURSES_LIB_PATH=%root_dir%/PDCurses

    set LLVM_PROJ_BUILD=%root_dir%/llvm-project/build

    set LLVM_PROJ_SRC=%root_dir%/llvm-project

     

    md onnx-mliruild

    cd onnx-mliruild

    call cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 -DLLVM_EXTERNAL_LIT="%root_dir%llvm-projectuildReleaseinllvm-lit.py" -DCMAKE_BUILD_TYPE=Release ..

    call cmake --build . --config Release --target onnx-mlir -- /m

     

    REM Run FileCheck tests

    set LIT_OPTS=-v

    call cmake --build . --config Release --target check-onnx-lit

    上述命令成功onnx-mlir执行后,可执行文件应出现在bin目录中。

    使用ONNX-MLIR

    onnx-mlir用法如下:

     

     

    OVERVIEW: ONNX MLIR modular optimizer driver

     

    USAGE: onnx-mlir [options] <input file>

     

    OPTIONS:

     

    Generic Options:

     

      --help        - Display available options (--help-hidden for more)

      --help-list   - Display list of available options (--help-list-hidden for more)

      --version     - Display the version of this program

     

    ONNX MLIR Options:

    These are frontend options.

     

      Choose target to emit:

          --EmitONNXIR - Ingest ONNX and emit corresponding ONNX dialect.

          --EmitMLIR   - Lower model to MLIR built-in transformation dialect.

          --EmitLLVMIR - Lower model to LLVM IR (LLVM dialect).

          --EmitLLVMBC - Lower model to LLVM IR and emit (to file) LLVM bitcode for model.

    Example

    例如,要将ONNX模型(例如add.onnx)降低为ONNX方言,使用以下命令:

    ./onnx-mlir --EmitONNXIR add.onnx

    输出应如下所示:

    module {

      func @main_graph(%arg0: tensor<10x10x10xf32>, %arg1: tensor<10x10x10xf32>) -> tensor<10x10x10xf32> {

        %0 = "onnx.Add"(%arg0, %arg1) : (tensor<10x10x10xf32>, tensor<10x10x10xf32>) -> tensor<10x10x10xf32>

        return %0 : tensor<10x10x10xf32>

      }

    }

    人工智能芯片与自动驾驶
  • 相关阅读:
    vmware ubuntu 异常关机无法连接到网络
    Speed up GCC link
    常用的一些解压命令
    Log4j 漏洞复现
    Test Case Design method Boundary value analysis and Equivalence partitioning
    CCA (Citrix Certified Administrator) exam of “Implementing Citrix XenDesktop 4”
    What is Key Word driven Testing?
    SAP AGS面试小结
    腾讯2013终端实习生一面
    指针的引用
  • 原文地址:https://www.cnblogs.com/wujianming-110117/p/14683628.html
Copyright © 2011-2022 走看看