GithubHelp home page GithubHelp logo

erroroverflow / toy Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 3.53 MB

Base on MLIR & https://github.com/MingliSun/MLIR-TVM

License: Apache License 2.0

CMake 0.76% C 0.32% C++ 67.36% MLIR 23.75% LLVM 0.14% Python 7.52% Emacs Lisp 0.03% Shell 0.04% Vim Script 0.07%

toy's Introduction

TOY2Relay 文档

1.如何构建项目

首先需要在Linux下构建LLVM,我参考的是https://github.com/llvm/llvm-project 的代码和 https://mlir.llvm.org/getting_started/ 的构建方法。当然还要感谢孙明利学长的前期工作 https://github.com/MingliSun/MLIR-TVM

如果你已经完成了LLVM的构建并且已经完成了官方文档对toy语言的教学,接着把本项目的项目名“toy”重命名为“mlir”,覆盖复制进LLVM的一级目录,这是因为mlir是一个开发活跃的项目,新老版本大概率不兼容。接着可以把本项目中的tvm文件夹剪切出去,它是用来做tvm下的网络测试,和mlir部分无关。

下一步是编译我们自己修改的mlir,mlir/example下面包含toy的所有源代码文件。如果你之前自己亲手编译了LLVM项目,那么应该指导LLVM项目编译的build文件夹,去那里在终端中输入

cmake --build . --target check-mlir

即可只编译mlir项目来节约编译时间,toy编译器的生成文件会在build/bin内,你可以在这里执行toy编译。

2.如何执行toy编译

在1.中提到的build/bin内,终端输入

./toyc-ch8 /path to LLVM/mlir/inception.toy -emit=relay

可以完成对一个toy语言源文件inception.toy编译,记得替换成自己的LLVM项目绝对路径名,最后一个emit是编译选项,支持多种编译输出:

-emit=ast //输出AST 
-emit=mlir //输出toy dialect 
-emit=mlir-relay //输出relay dialect 
-emit=relay //输出python-relay代码   

输出文件会在/path to LLVM/mlir/examples/toy/out.py,写毕业设计的时候没有用相对路径,这个部分需要你自己去translateModuleToRelayIR.cpp中修改(ε=ε=ε=┏(゜ロ゜;)┛。当然out.py里面应该是有一个我生成的inception_v3网络的代码可以先将就着用。

3.如何在TVM中运行编译器的生成代码

在1.我们提到的那个和mlir无关的文件夹这就派上用场了,里面一级目录有tutorial和python.tvm.relay.testing两个文件夹,如果你对TVM项目足够熟悉的话应知道前者是TVM的教程文件,后者是TVM的测试文件(包括了用relay层编写的不同深度学习网络的样例),我在前者中的relay_test_net.py中会调用后者对应的网络文件(比如inception_v3_2.py)来执行网络。

考虑到TVM也是一个开发活跃的项目,我也建议把我的tutorial和python.tvm.relay.testing文件夹覆盖复制进你clone下来的TVM项目中。如果你觉得python.tvm.relay.testing中的代码和史老师那边开发文档中不一致的话,还是以python.tvm.relay.testing为准。

4.开发中的一些坑

4.1 SSA问题我处理得比较武断,这在我的论文中有描述,显然用phi指令的话代码会更优美。

4.2 有一个重载函数runOnFunction,你得注意它是并行执行的,这是mlir本身设计的,一个module中的多个function不会从上到下的一个一个编译,它们会同时执行,这在输出relay代码的时候影响很大,我的解决办法是每个function生成一个文件,再将这些文件合并为一个out.py。

toy's People

Contributors

erroroverflow avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.