GithubHelp home page GithubHelp logo

isabella232 / halideir Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dmlc/halideir

0.0 0.0 0.0 251 KB

Symbolic Expression and Statement Module for new DSLs

License: Other

Makefile 0.16% C++ 99.84%

halideir's Introduction

HalideIR: Symbolic Arithmetic IR Module

HalideIR is a base module for building symbolic expression and arithmetic simplification for building new DSLs. It is isolated and refactored from part of Halide project (credit should go to the original authors). It was used in earlier versions of the tvm project.

Note that some portions of the TVM compiler outside of this folder are also adapted from Halide codebase, where we needed similar logic (e.g loop vectorization). These are commented where they occur.

Motivation

We build this component during the development of TVM project. Symbolic expression data structure and simplification libary is essential to for such compiler stack project.

Unfortunately there is no standalone module that fits our need at the moment. We find that the IR and simplification module of Halide project fits such purposes nicely. So we isolated and refactor the coresponding module into this repo.

The major goal is minimum and interpolatable with more front-end languages. HalideIR is used in TVM project. Here are the few major improvements.

  • An isolated dependency free symbolic IR and simplification (no LLVM dependency).
  • The project modularized into logical components.
  • All IR structure are serializable and publically accessible from front-end language(e.g. python)
    • This supports ease of development and proptyping in python
  • Think of re-usablity when adding new DSL structure.
    • A runtime dispatching mechanism is introduced to allow ease of add new IR node.
  • Simplified variable defintiion rule: change from match by string to match by pointer
    • This ensures each variable to have single define location (like SSA)

Besides these changes, we also re-factored the code to resolve some of the issues in the codebase. Some of these changes addresses the pain point raised in Halide project. The detailed change are listed in the later part of the project.

Project Structure

Based on code from Halide(release_2017_05_03). The code is componetized into four logical components

  • tvm: TVM container code for interpolation, basic data structures.
  • base: base utilities and type.
  • ir: The IR data structure
  • arithmetic: Arithemetic simplification.

Code Style

We keep old files in old code style, but use Google C style in the newly added files.

List of Changes

  • Replace implmentation of Float16.cpp with a simpler version that does not depend on LLVM
  • IntrusivePtr
    • Remove IntrusivePtr, change everything to base on std::shared_ptr
    • See tvm/node.h
    • Add support for IR reflection via NodeRef.VisitAttrs
    • All the IR is constructable from python via TVM
      • This enables quick proptyping and debuging from python
  • Call
    • Remove Parameter, BufferPtr from Variable, Call, Load
    • This simplifies dependency, we also find it is cleaner to simply use Variable for Parameter.
  • AssertStmt
    • Add body field to AssertStmt, which represents the scope where the assert condition holds
    • This makes it easier to do Visitor pattern that take benefit of the scope assert information.
  • AttrStmt
    • This is a new Stmt that can be used to annotate attribute of certain things (e.g. content type of buffer). This removes the need of string matching for properties and hacks around string matching in Let.
    • We use this extensively to add new hints in the environment scope.
  • FunctionContent
    • Make FunctionBaseNode abstract, to replace FunctionContent
  • Provide, Realize, Prefetch, ProducerConsumer, Call
    • Remove use of string name matching of function
    • When place where function is needed, use FunctionRef
    • FunctionRef is uniqued matched by internal pointer.
  • Variable, Store, Allocate, Free, For, Load, Let, LetStmt
    • Remove use of string name matching of Variable
    • When place where variable is needed, use VarExpr
    • VarExpr is uniqued matched by internal pointer.
  • Variable
    • Rename Variable.name -> Variable.name_hint, to avoid confusion.
    • Variable.name_hint is not used to uniquely identify the variable.
    • By default, each Variable should be only defined once
      • This is in analog to SSA, and can make ir pass simplier(remove need of scoping)
  • Provide, Realize, Prefetch
    • Change Provide and Realize to associate with value_index.
    • Original Provide/Realize with multiple values can be represented by several Provide and Realize chained together
    • This allows outputs of a Function to have different shapes.
  • Make every field the IR reflectable and accessible from python
    • std::vector<> - > Array<>(tvm/container.h)
    • struct Range -> Range(Range.h)
  • Range
    • Remove constructor Range(min, extent) to Range::make_with_min_extent(min, extent)
    • The original constructor could make new user confuse since a typical way is range(begin, end) in both c++ and python
  • Simplify Visitor
    • Remove use of string name mapping in the Scope
    • Remove Scope in Substitute to check name conflicts because we use variable pointer matching
    • Add Expr&/Stmt& to visit interface in the IRVisitor and IRMutator
  • Add a more flexible RTTI and dynamic dispatch support, see src/tvm/node.h
    • IRFunctor allows plugin of new IR Node more easily, without chaning interface

halideir's People

Contributors

abadams avatar ajtulloch avatar alex-weaver avatar anthony-mai avatar antinucleon avatar derisavi avatar derisavi-huawei avatar doctaweeks avatar ezyang avatar gussmith23 avatar hlu1 avatar icemelon avatar jroesch avatar junrushao avatar liangdzou avatar marcelotrevisani avatar merrymercy avatar newproggie avatar tqchen avatar wweic avatar xqdan avatar yangchen-ms avatar zihengjiang 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.