构建编译TVM方法

本文提供如何在各种系统上构建和安装TVM包的说明。它包括两个步骤:

  1. 1.     首先从C代码构建共享库( libtvm.so for linux, libtvm.dylib for macOS and libtvm.dll for windows)。
  2. 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克隆源。克隆子模块很重要,--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构建,启用所有功能。

如果要使用CUDA,需要CUDA toolkit version >= 8.0。如果从老版本更新,确信删除了老版本,并且需要安装后reboot重启。

  • 在macOS上,可能需要安装Homebrew https://brew.sh管理依赖项。

使用cmake来构建库,TVM的配置可以通过以下config.cmake方式进行。

  • ·        检查系统中的cmake。如果没有cmake,可以从官方网站找最新版本
  • ·        创建一个构建目录,复制cmake/config.cmake到目录
  • mkdir build
  • cp cmake/config.cmake build
  • cd build
  • cmake ..
  • make -j4
  • 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
  • 编辑build/config.cmake自定义编译选项
    • 在macOS上,对于某些版本的Xcode,需要添加-lc++abi否则会出现链接错误
    • 改变set(USE_CUDA OFF)到 设置(使用_CUDA开)启用CUDA后端。对其它后端和库执行相同的操作(OpenCL、RCOM、METAL、VULKAN…)。
    • 若要帮助调试,确保使用启用了set(USE_GRAPH_EXECUTOR ON)和设置(使用_PROFILER开)嵌入式图形执行器和调试函数。
  • TVM需要LLVM用于CPU codegen。强烈建议构建LLVM支持。
    • 使用LLVM构建需要LLVM 4.0或更高版本。注意,默认apt的LLVM版本可能低于4.0。
    • 由于LLVM从源代码构建需要很长时间,所以可以从LLVM下载页面https://apt.llvm.org/ .
      • 解压缩到某个位置,修改build/config.cmake添加 set(USE_LLVM /path/to/your/llvm/bin/llvm-config)
      • 也可以直接设置set(USE_LLVM ON),让cmake搜索LLVM的可用版本。
    • 也可以使用LLVM预编译Ubuntu构建https://releases.llvm.org/download.html
      • 注意apt包appendllvm-config带版本编号。用于示例,集合 set(USE_LLVM llvm-config-10),如果安装了LLVM 10包。
  • 然后可以建立tvm和相关的库。

If everything goes well, we can go to Python Package Installation

Building with a Conda Environment

Conda是获取运行TVM所需依赖项的一种非常方便的方法。ollow the conda’s installation guide,如果系统中还没有conda,安装miniconda或anaconda。在conda环境中运行以下命令:

# 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

上面的命令将安装所有必要的构建依赖项,如cmake和LLVM。然后可以在最后一节中运行标准生成过程。

如果要在conda环境之外使用编译后的二进制文件,可以将LLVM设置为静态链接模式set(USE_LLVM "llvm-config --link-static")。这样,生成的库就不会依赖于conda环境中的动态LLVM库。

上面的说明展示了如何使用conda来提供构建所需的libtvm构建依赖关系。如果已经在使用conda作为软件包管理器,并且希望直接将tvm作为conda软件包进行构建和安装,可以按照以下说明进行操作:

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构建TVM支持。需要安装一个visualstudio编译器最低要求VS版本为Visual Studio Community 2015 Update 3。建议:Building with a Conda Environment以获得必要的依赖关系,获得激活的tvm构建环境。然后可以运行以下命令来构建:

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=$TVM_HOME/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

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.

构建编译TVM方法的更多相关文章

  1. Spring5源码阅读环境搭建-gradle构建编译

      前沿:Spring系列生态十分丰富,涉及到各个方面.但是作为Spring生态的核心基础Spring,是最重要的环节,需要理解Spring的设计原理,我们需要解读源码.   在构建Spring源码阅 ...

  2. 转 谈谈android反编译和防止反编译的方法

    谈谈android反编译和防止反编译的方法   android基于java的,而java反编译工具很强悍,所以对正常apk应用程序基本上可以做到100%反编译还原. 因此开发人员如果不准备开源自己的项 ...

  3. 谈谈android反编译和防止反编译的方法(转)

    谈谈android反编译和防止反编译的方法(转) android基于java的,而java反编译工具很强悍,所以对正常apk应用程序基本上可以做到100%反编译还原. 因此开发人员如果不准备开源自己的 ...

  4. 反编译class文件并重新编译的方法

    在没有.java源码的情况下,如果想修改一个.class文件.可以通过以下步骤实现: 修改前的class文件: 一.反编译.class文件成.java文件. 1.可以使用Java Decompiler ...

  5. LaTeX多文件编译的方法总结

    LaTeX多文件编译的方法总结 在编写LaTeX文档的时候,由于文档的section较多,或者section的编写时间各不相同,我们可能碰到如下问题: 1.由于想分开编写各个section 2.pre ...

  6. 简单的反编译class文件并重新编译的方法

    在没有.java源码的情况下,如果想修改一个.class文件.可以通过以下步骤实现: 修改前的class文件: 一.反编译.class文件成.java文件. 1.可以使用Java Decompiler ...

  7. VS2010 MFC中 静态编译设置方法

    问题:VS2010 c++编写的程序在别人的机子运行不了,缺少mfc100u.dll xxx100d.dll等 解决方法:1.将这些dll打包,和应用程序一起发布;2.采用MFC静态编译; 静态编译: ...

  8. Jenkins 通过 maven 构建编译 JAVA 项目环境

    Jenkins 通过maven 构建编译 JAVA 项目环境 官网下载合适Jenkins版本包: 1.jenkins http://mirrors.jenkins.io/war-stable/ 2.J ...

  9. apache-2.4.x 编译安装方法

    apache-2.4.x 编译安装方法 作者:朱 茂海 /分类:Apache 字号:L M S apache-.2与新出的apache-.4安装不同的地方在于,.4版的已经不自带apr库,所以在安装a ...

随机推荐

  1. SpringCloud(五)GateWay网关

    Config 分布式配置中心 概述 微服务意味着要将单体应用中的业务拆分成个个子服务,每个服务的粒度相对较小因此系统中会出现大量的服务 由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动态 ...

  2. vuex 引用方法

    引入Vuex(前提是已经用Vue脚手架工具构建好项目) 1.利用npm包管理工具,进行安装 vuex.在控制命令行中输入下边的命令就可以了. npm install vuex --save 要注意的是 ...

  3. 一个DDOS病毒的分析(二)

    一.基本信息 样本名称:hra33.dll或者lpk.dll 样本大小: 66560 字节 文件类型:Win32的dll文件 病毒名称:Dropped:Generic.ServStart.A3D47B ...

  4. POJ 2396 构造矩阵(上下流)

    题意:       要求构造一个矩阵,给你行和,列和,还有一些点的上下范围,输出一个满足题意的矩阵. 思路:       这个题目很经典,这是自己看上下流后接触的第一道题,感觉很基础的一道题目,现在我 ...

  5. Hbase问题小结(一)

    1. Hbase读写优化 写: 批量写.异步批量提交.多线程并发写.使用BulkLoad写入.表优化(压缩算法.预分区.合理的rowkey设计.合理关闭WAL或异步WAL) SKIP_WAL:只写缓存 ...

  6. Linux 内核调度器源码分析 - 初始化

    导语 上篇系列文 混部之殇-论云原生资源隔离技术之CPU隔离(一) 介绍了云原生混部场景中CPU资源隔离核心技术:内核调度器,本系列文章<Linux内核调度器源码分析>将从源码的角度剖析内 ...

  7. MFC对话框不能使用菜单更新宏ON_UPDATE_COMMAND_UI

    菜单更新宏的原理 更新处理宏的工作原理是基于框架窗口类的.MFC中对话框菜单更新宏的原理是:当我们使用从CFrameWnd框架窗口类中派生的类创建窗口时,当我们单击菜单且菜单还未弹出前会产生WM_IN ...

  8. 比物理线程都好用的C++20的协程,你会用吗?

    摘要:事件驱动(event driven)是一种常见的代码模型,其通常会有一个主循环(mainloop)不断的从队列中接收事件,然后分发给相应的函数/模块处理.常见使用事件驱动模型的软件包括图形用户界 ...

  9. (转)如何优雅的使用rabbit mq

    RabbitMQ无疑是目前最流行的消息队列之一,对各种语言环境的支持也很丰富,作为一个.NET developer有必要学习和了解这一工具.消息队列的使用场景大概有3种: 1.系统集成,分布式系统的设 ...

  10. 简单了解 MySQL 中相关的锁

    本文主要是带大家快速了解 InnoDB 中锁相关的知识 为什么需要加锁 首先,为什么要加锁?我想我不用多说了,想象接下来的场景你就能 GET 了. 你在商场的卫生间上厕所,此时你一定会做的操作是啥?锁 ...