Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
8902ae7b
Commit
8902ae7b
authored
7 years ago
by
Mu Li
Committed by
Tianqi Chen
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update cross_compilation_and_rpc.py (#816)
parent
37734045
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tutorials/deployment/cross_compilation_and_rpc.py
+31
-9
31 additions, 9 deletions
tutorials/deployment/cross_compilation_and_rpc.py
with
31 additions
and
9 deletions
tutorials/deployment/cross_compilation_and_rpc.py
+
31
−
9
View file @
8902ae7b
...
...
@@ -14,11 +14,6 @@ the device in order to save time and space.
In this tutorial, I will take Raspberry Pi as our target platform
for example.
"""
from
__future__
import
absolute_import
,
print_function
import
tvm
import
numpy
as
np
from
tvm.contrib
import
rpc
,
util
######################################################################
# Build TVM Runtime on Device
...
...
@@ -27,6 +22,12 @@ from tvm.contrib import rpc, util
# There're some prerequisites: similar as compiling TVM on your
# local machine, we need build runtime on remote device.
#
# .. note::
#
# All instructions in both this section and next section should be
# executed on the target device, e.g. Raspberry Pi. And we assume it
# has Linux running.
#
# To get started, clone tvm repo from github. It is important to clone
# the submodules along, with --recursive option (Assuming you are in
# your home directory):
...
...
@@ -106,8 +107,19 @@ server = rpc.Server(host='0.0.0.0', port=9090, use_popen=True)
######################################################################
# Declare and Cross Compile Kernel on Local Machine
# -------------------------------------------------
# Here we will declare a simple kernel with TVM on the local machine:
#
# .. note::
#
# Now we back to the local machine, which has a full TVM installed.
#
# Here we will declare a simple kernel with TVM on the local machine:
from
__future__
import
absolute_import
,
print_function
import
tvm
import
numpy
as
np
from
tvm.contrib
import
rpc
,
util
n
=
tvm
.
convert
(
1024
)
A
=
tvm
.
placeholder
((
n
,),
name
=
'
A
'
)
B
=
tvm
.
compute
(
A
.
shape
,
lambda
*
i
:
A
(
*
i
)
+
1.0
,
name
=
'
B
'
)
...
...
@@ -136,7 +148,8 @@ f.save(path)
# Pi. Here we use :code:`'llvm'` directly to make the tutorial runable.
#
# Usually, you can query the target by execute :code:`gcc -v` on your
# device, although it may be still a loose configuration.
# device, and look for the line starting with :code:`Target:`
# (Though it may be still a loose configuration.)
#
# Besides :code:`-target`, you can also set other compilation options
# like:
...
...
@@ -171,9 +184,15 @@ f.save(path)
# Run CPU Kernel Remotely by RPC
# ------------------------------
# Here we will show you how to run the kernel on the remote device:
#
# .. note::
# In order to have this tutorial runs locally to build the nice HTML, we
# start a RPC server on the local machine. You can ignore it if you already
# started the server on the target device. And then change host IP properly.
# replace host with the ip address of your device
host
=
'
0.0.0.0
'
# Can be ignored if you already started the RPC server
server
=
rpc
.
Server
(
host
=
'
0.0.0.0
'
,
port
=
9090
,
use_popen
=
True
)
host
=
'
0.0.0.0
'
# Change to your target device IP
port
=
9090
# connect the remote device
remote
=
rpc
.
connect
(
host
,
port
)
...
...
@@ -213,9 +232,12 @@ print('%g secs/op' % cost)
# on remote compiler to re-link them.
#
# .. note::
#
# Raspberry Pi does not support OpenCL, the following code is tested on
# Firefly-RK3399. The target_host should be 'llvm -target=aarch64-linux-gnu'.
# But here we set 'llvm' to enable this tutorial to run locally.
#
# Also we need to build the runtime with the flag `USE_OPENCL=1`.
# build kernel (different from cpu, we need bind axis for OpenCL)
s
=
tvm
.
create_schedule
(
B
.
op
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment