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

[Golang][Doc] improve the samples and doc #4385

Merged
merged 4 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ To Demonstrates sample TVM module compilation using python and deploy via golang

To deploy a realtime module with lib, graph and param.
```bash
python3 gen_mobilenet_lib.py

./complex
```

Expand All @@ -80,13 +82,13 @@ To demonstrate go function closure conversion to packed function handle.
To demonstrate a packed function handle given as an argument.

```bash
pack_func_handle_arg
./pack_func_handle_arg
```

To register go function with runtime as a global function.

```bash
pack_func_register
./pack_func_register
```

To demonstrate function closure passed as argument to a function call.
Expand Down Expand Up @@ -120,5 +122,5 @@ Please refer ```docker/install/ubuntu_install_golang.sh``` for the packages depe
go compiler 1.10 on ubuntu doesn't install on standard path, hence an explicit export may be needed as shown below.

```bash
export PATH="/usr/lib/go-1.10/bin:$PATH"```
export PATH="/usr/lib/go-1.10/bin:$PATH"
```
2 changes: 1 addition & 1 deletion golang/sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ all: $(EXECUTABLE)
@go tool compile -pack -o $@ $<

clean:
@rm -f $(EXECUTABLE) *.so *.o *.a
@rm -f $(EXECUTABLE) *.so *.o *.a *.json *.params
4 changes: 2 additions & 2 deletions golang/sample/complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func main() {
fmt.Printf("Graph runtime Created\n")

// Array allocation attributes
tshapeIn := []int64{1, 224, 224, 3}
tshapeOut := []int64{1, 1001}
tshapeIn := []int64{1, 3, 224, 224}
tshapeOut := []int64{1, 1000}

// Allocate input Array
inX, err := gotvm.Empty(tshapeIn, "float32", gotvm.CPU(0))
Expand Down
55 changes: 55 additions & 0 deletions golang/sample/gen_mobilenet_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import tvm
from tvm import relay
import tvm.relay.testing

######################################################################
# Load Neural Network in Relay
####################################################
cchung100m marked this conversation as resolved.
Show resolved Hide resolved

mod, params = relay.testing.mobilenet.get_workload(batch_size=1)
cchung100m marked this conversation as resolved.
Show resolved Hide resolved

# set show_meta_data=True if you want to show meta data
print(mod.astext(show_meta_data=False))

######################################################################
# Compilation
####################################################

target = 'llvm'

# Build with Relay
with relay.build_config(opt_level=0):
graph, lib, params = relay.build_module.build(
mod, target, params=params)

######################################################################
# Save and Load Compiled Module
# -----------------------------
# We can also save the graph, lib and parameters into files
####################################################

lib.export_library("./mobilenet.so")
print('lib export succeefully')

with open("./mobilenet.json", "w") as fo:
fo.write(graph)

with open("./mobilenet.params", "wb") as fo:
fo.write(relay.save_param_dict(params))