Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port TVM to support GIGO hw #1

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

DemonGiggle
Copy link
Owner

@DemonGiggle DemonGiggle commented Sep 10, 2020

GIGO hw support

Well, I try to write a minimal implementation for a new (non-existed) hw porting.

List of supported operators for the GIGO hw:

  • nn.conv2d (software simulated)

Steps & example to use GIGO hw

  • Create build folder in the tvm root directory
  • Copy cmake/config.cmake to build
  • Change the setting USE_GIGO in build/config.cmake to "ON"
  • Make the whole project

Now, with this simple file, we can see what had been changed by GIGO relay backend, by comparing the relay IR output.

from __future__ import absolute_import, print_function

import tvm
from tvm import te
import numpy as np
from tvm import relay
import tflite

def output(filename, content):
    with open(filename, "w") as f:
        f.write(content)

model_buf = open("mobilenet.tflite", "rb").read()

tflite_model = tflite.Model.GetRootAsModel(model_buf, 0)

# TFLite input tensor name, shape and type
input_tensor = "input"
input_shape = (1, 224, 224, 3)
input_dtype = "float32"

# Parse TFLite model and convert it to a Relay module
mod, params = relay.frontend.from_tflite(tflite_model,
        shape_dict={input_tensor: input_shape},
        dtype_dict={input_tensor: input_dtype})
output("relay_ir.before.txt", str(mod))

# Partition with gigo
mod = relay.op.contrib.gigo.partition_for_gigo(mod)
output("relay_ir.after.txt", str(mod))

relay_ir.before.txt looks like:

def @main(...) {
  %0 = nn.conv2d(...)
  %1 = nn.bias_add(%0, ...)
  %2 = nn.conv2d(%1, ...)
  ...
}

relay_ir.after.txt looks like:

def @gigo_0(...) {
  nn.conv2d(...)
}

def @gigo_2(...) {
  nn.conv2d(...)
}

def @main(...) {
  %0 = @gigo_0(...)
  %1 = @nn.bias_add(%0, ...)
  %2 = @gigo_2(%1, ...)
}

By comparing the two files, we know that the operator GIGO supports will be replaced with another wrapper function.

gigo added 2 commits September 10, 2020 15:45
[WIP] In current implementation, you can check the relay IR before and
after the annotation transformation.

Currently, GIGO hw only supports `nn.conv2d' operator.
The concept here is to generate related c code wrapper which will call
gigo_xxx function (e.g. gigo_conv2d).

In the gigo_xxx function, it is expected to transfer buffer from host to
GIGO hw, and perform operations on it. After that, the result will be
copied back to host.

In this commit, only `conv2d` is wrapped.
@DemonGiggle DemonGiggle force-pushed the feature/customize-target branch from 93958c6 to ee720db Compare September 14, 2020 09:11
@DemonGiggle
Copy link
Owner Author

Attach file is the example to use GIGO hw

gigo_hw.zip

But it still has a lot to impl
@DemonGiggle
Copy link
Owner Author

Attach file is the example to use GIGO hw

gigo_hw.zip

This one miss the weight info when building device kernel code.
I upload the correct version.

gigo_hw_correct_weights_in.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant