日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

构建编译TVM方法

發(fā)布時間:2023/11/28 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 构建编译TVM方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

構(gòu)建編譯TVM方法
本文提供如何在各種系統(tǒng)上構(gòu)建和安裝TVM包的說明。它包括兩個步驟:

  1. 首先從C代碼構(gòu)建共享庫( libtvm.so for linux, libtvm.dylib for macOS and libtvm.dll for windows)。
  2. 語言包的設置(例如Python包)。
    TVM源碼下載鏈接
    https://github.com/apache/tvm/

Developers: Get Source from Github
You can also choose to clone the source repo from github. It is important to clone the submodules along, with --recursive option.
可以選擇從github中repo克隆源??寺∽幽K很重要,–recursive選項
git clone --recursive https://github.com/apache/tvm tvm
For windows users who use github tools, you can open the git shell, and type the following command.
對于使用github工具的windows用戶,可以打開git shell,然后鍵入以下命令。
git submodule init
git submodule update
Build the Shared Library
目標是建立共享庫:
? On Linux the target library are libtvm.so
? On macOS the target library are libtvm.dylib
? On Windows the target library are libtvm.dll
sudo apt-get update
sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
最低building要求是
? 支持c14(g-5或更高版本)的最新c++編譯器
? CMake 3.5或更高
? 強烈建議使用LLVM構(gòu)建,啟用所有功能。
如果要使用CUDA,需要CUDA toolkit version >= 8.0。如果從老版本更新,確信刪除了老版本,并且需要安裝后reboot重啟。
? 在macOS上,可能需要安裝Homebrew https://brew.sh,管理依賴項。
使用cmake來構(gòu)建庫,TVM的配置可以通過以下config.cmake方式進行。
? 檢查系統(tǒng)中的cmake。如果沒有cmake,可以從官方網(wǎng)站找最新版本
? 創(chuàng)建一個構(gòu)建目錄,復制cmake/config.cmake到目錄
? mkdir build
? cp cmake/config.cmake build
? 編輯build/config.cmake自定義編譯選項
o 在macOS上,對于某些版本的Xcode,需要添加-lc++abi否則會出現(xiàn)鏈接錯誤
o 改變set(USE_CUDA OFF)到 設置(使用_CUDA開)啟用CUDA后端。對其它后端和庫執(zhí)行相同的操作(OpenCL、RCOM、METAL、VULKAN…)。
o 若要幫助調(diào)試,確保使用啟用了set(USE_GRAPH_EXECUTOR ON)和設置(使用_PROFILER開)嵌入式圖形執(zhí)行器和調(diào)試函數(shù)。
? TVM需要LLVM用于CPU codegen。強烈建議構(gòu)建LLVM支持。
o 使用LLVM構(gòu)建需要LLVM 4.0或更高版本。注意,默認apt的LLVM版本可能低于4.0。
o 由于LLVM從源代碼構(gòu)建需要很長時間,所以可以從LLVM下載頁面https://apt.llvm.org/ .
? 解壓縮到某個位置,修改build/config.cmake添加 set(USE_LLVM /path/to/your/llvm/bin/llvm-config)
? 也可以直接設置set(USE_LLVM ON),讓cmake搜索LLVM的可用版本。
o 也可以使用LLVM預編譯Ubuntu構(gòu)建https://releases.llvm.org/download.html
? 注意apt包appendllvm-config帶版本編號。用于示例,集合 set(USE_LLVM llvm-config-10),如果安裝了LLVM 10包。
? 然后可以建立tvm和相關(guān)的庫。
? cd build
? cmake …
? make -j4
o You can also use Ninja build system instead of Unix Makefiles. It can be faster to build than using Makefiles.
? cd build
? cmake … -G Ninja
? ninja
If everything goes well, we can go to Python Package Installation
Building with a Conda Environment
Conda是獲取運行TVM所需依賴項的一種非常方便的方法。ollow the conda’s installation guide,如果系統(tǒng)中還沒有conda,安裝miniconda或anaconda。在conda環(huán)境中運行以下命令:

Create a conda environment with the dependencies specified by the yaml

conda env create --file conda/build-environment.yaml

Activate the created environment

conda activate tvm-build
上面的命令將安裝所有必要的構(gòu)建依賴項,如cmake和LLVM。然后可以在最后一節(jié)中運行標準生成過程。
如果要在conda環(huán)境之外使用編譯后的二進制文件,可以將LLVM設置為靜態(tài)鏈接模式set(USE_LLVM “l(fā)lvm-config --link-static”)。這樣,生成的庫就不會依賴于conda環(huán)境中的動態(tài)LLVM庫。
上面的說明展示了如何使用conda來提供構(gòu)建所需的libtvm構(gòu)建依賴關(guān)系。如果已經(jīng)在使用conda作為軟件包管理器,并且希望直接將tvm作為conda軟件包進行構(gòu)建和安裝,可以按照以下說明進行操作:
conda build --output-folder=conda/pkg conda/recipe

Run conda/build_cuda.sh to build with cuda enabled

conda install tvm -c ./conda/pkg
Building on Windows
使用cmake通過MSVC構(gòu)建TVM支持。需要安裝一個visualstudio編譯器最低要求VS版本為Visual Studio Community 2015 Update 3。建議:Building with a Conda Environment以獲得必要的依賴關(guān)系,獲得激活的tvm構(gòu)建環(huán)境。然后可以運行以下命令來構(gòu)建:
mkdir build
cd build
cmake -A x64 -Thost=x64 …
cd …
The above command generates the solution file under the build directory. You can then run the following command to build
cmake --build build --config Release – /m
Building ROCm support
Currently, ROCm is supported only on linux, so all the instructions are written with linux in mind.
? Set set(USE_ROCM ON), set ROCM_PATH to the correct path.
? You need to first install HIP runtime from ROCm. Make sure the installation system has ROCm installed in it.
? Install latest stable version of LLVM (v6.0.1), and LLD, make sure ld.lld is available via command line.
Python Package Installation
TVM package
Depending on your development environment, you may want to use a virtual environment and package manager, such as virtualenv or conda, to manage your python packages and dependencies.
to install and maintain your python development environment.
The python package is located at tvm/python There are two ways to install the package:
Method 1
This method is recommended for developers who may change the codes.
Set the environment variable PYTHONPATH to tell python where to find the library. For example, assume we cloned tvm on the directory /path/to/tvm then we can add the following line in ~/.bashrc. The changes will be immediately reflected once you pull the code and rebuild the project (no need to call setup again)
export TVM_HOME=/path/to/tvm
export PYTHONPATH=TVMHOME/python:TVM_HOME/python:TVMH?OME/python:{PYTHONPATH}
Method 2
Install TVM python bindings by setup.py:

install tvm package for the current user

NOTE: if you installed python via homebrew, --user is not needed during installaiton

it will be automatically installed to your user directory.

providing --user flag may trigger error during installation in such case.

export MACOSX_DEPLOYMENT_TARGET=10.9 # This is required for mac to avoid symbol conflicts with libstdc++
cd python; python setup.py install --user; cd …
Python dependencies
Note that the --user flag is not necessary if you’re installing to a managed local environment, like virtualenv.
? Necessary dependencies:
pip3 install --user numpy decorator attrs
? If you want to use RPC Tracker
pip3 install --user tornado
? If you want to use auto-tuning module
pip3 install --user tornado psutil xgboost cloudpickle
Install Contrib Libraries
? NNPACK Contrib Installation
Enable C++ Tests
We use Google Test to drive the C++ tests in TVM. The easiest way to install GTest is from source.
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake …
make
sudo make install
After installing GTest, the C++ tests can be built and started with ./tests/scripts/task_cpp_unittest.sh or just built with make cpptest.

總結(jié)

以上是生活随笔為你收集整理的构建编译TVM方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。