README.md 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--- 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. -->

tqchen committed
18
# NNVM Compiler Module of TVM Stack
19 20 21 22 23 24 25

```python
import tvm
from tvm.contrib import graph_runtime, rpc
import nnvm.frontend
import nnvm.compiler

26
# GET model from frameworks
27 28 29
# change xyz to supported framework name.
graph, params = nnvm.frontend.from_xyz(...)

30
# OPTIMIZE and COMPILE the graph to get a deployable module
31 32
# target can be "opencl", "llvm", "metal" or any target supported by tvm
target = "cuda"
33
graph, lib, params = nnvm.compiler.build(graph, target, {"data", data_shape}, params=params)
34

35
# DEPLOY and run on gpu(0)
36 37
module = graph_runtime.create(graph, lib, tvm.gpu(0))
module.set_input(**params)
38
module.run(data=data_array)
39
output = tvm.nd.empty(out_shape, ctx=tvm.gpu(0))
40
module.get_output(0, output)
41

42
# DEPLOY to REMOTE mobile/rasp/browser with minimum tvm rpc runtime
43 44 45 46 47 48 49 50 51 52
# useful for quick experiments on mobile devices
remote = rpc.connect(remote_host, remote_port)
lib.export_library("mylib.so")
remote.upload("mylib.so")
rlib = rpc.load_module("mylib.so")
# run on remote device
rmodule = graph_runtime.create(graph, rlib, remote.gpu(0))
rmodule.set_input(**params)
rmodule.run()
```