Coder Social home page Coder Social logo

mlir-hello's Introduction

MLIR Hello Dialect nightly build status

This is the minimal example to look into the way to implement the hello-world kind of program with MLIR. The basic code structure is borrowed from standalone and Toy language in LLVM project.

We constantly check the compatibility with the latest LLVM/MLIR in the nightly build. The status of the build is shown in the badge above.

Prerequisites

We need to build our own MLIR in the local machine in advance. Please follow the build instruction for MLIR here.

Building

Please make sure to build LLVM project first according to the instruction.

mkdir build && cd build
cmake -G Ninja .. -DLLVM_DIR=/path/to/llvm-project/build/lib/cmake/llvm \
  -DMLIR_DIR=/path/to/llvm-project/build/lib/cmake/mlir

cmake --build . --target hello-opt

To run the test, check-hello target will be usable.

To build the documentation from the TableGen description of the dialect operations, run

cmake --build . --target mlir-doc

Execution

hello-opt will lower the MLIR into the bytecode of LLVM.

# Lower MLIR to LLVM IR
$ ./build/bin/hello-opt ./test/Hello/print.mlir > /path/to/print.ll

# Execute the code with LLVM interpreter
$ lli /path/to/print.ll 

1.000000 2.000000 3.000000
4.000000 5.000000 6.000000

Operations

hello.constant (::hello::ConstantOp)

constant

Constant operation turns a literal into an SSA value. The data is attached to the operation as an attribute. For example:

  %0 = "hello.constant"()
  { value = dense<[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]> : tensor<2x3xf64> }
  : () -> tensor<2x3xf64>

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Attributes:

Attribute MLIR Type Description
value ::mlir::DenseElementsAttr 64-bit float elements attribute

Results:

Result Description
«unnamed» tensor of 64-bit float values

hello.print (::hello::PrintOp)

print operation

Syntax:

operation ::= `hello.print` $input attr-dict `:` type($input)

The "print" builtin operation prints a given input tensor, and produces no results.

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

Operand Description
input tensor of 64-bit float values or memref of 64-bit float values

hello.world (::hello::WorldOp)

print Hello, World

The "world" operation prints "Hello, World", and produces no results.

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

mlir-hello's People

Contributors

lewuathe avatar xgupta avatar renxida 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.