Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
aad48ff1
Commit
aad48ff1
authored
Oct 11, 2019
by
LiangHao
Committed by
Tianqi Chen
Oct 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a python tutorial of deploying tvm module with tvm runtime only (#4094)
parent
f3122887
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletions
+52
-1
apps/howto_deploy/python_deploy.py
+48
-0
apps/howto_deploy/run_example.sh
+4
-1
No files found.
apps/howto_deploy/python_deploy.py
0 → 100644
View file @
aad48ff1
# 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.
# Copyright (c) 2017 by Contributors
# brief Example code on load and run TVM module.s
# file python_deploy.py
import
tvm
import
numpy
as
np
def
verify
(
mod
,
fname
):
# Get the function from the module
f
=
mod
.
get_function
(
fname
)
# Use tvm.nd.array to convert numpy ndarray to tvm
# NDArray type, so that function can be invoked normally
N
=
10
x
=
tvm
.
nd
.
array
(
np
.
arange
(
N
,
dtype
=
np
.
float32
))
y
=
tvm
.
nd
.
array
(
np
.
zeros
(
N
,
dtype
=
np
.
float32
))
# Invoke the function
f
(
x
,
y
)
np_x
=
x
.
asnumpy
()
np_y
=
y
.
asnumpy
()
# Verify correctness of function
assert
(
np
.
all
([
xi
+
1
==
yi
for
xi
,
yi
in
zip
(
np_x
,
np_y
)]))
print
(
"Finish verification..."
)
if
__name__
==
"__main__"
:
# The normal dynamic loading method for deployment
mod_dylib
=
tvm
.
module
.
load
(
"lib/test_addone_dll.so"
)
print
(
"Verify dynamic loading from test_addone_dll.so"
)
verify
(
mod_dylib
,
"addone"
)
# There might be methods to use the system lib way in
# python, but dynamic loading is good enough for now.
apps/howto_deploy/run_example.sh
View file @
aad48ff1
...
@@ -25,5 +25,8 @@ export DYLD_LIBRARY_PATH=../../build:${DYLD_LIBRARY_PATH}
...
@@ -25,5 +25,8 @@ export DYLD_LIBRARY_PATH=../../build:${DYLD_LIBRARY_PATH}
echo
"Run the deployment with all in one packed library..."
echo
"Run the deployment with all in one packed library..."
lib/cpp_deploy_pack
lib/cpp_deploy_pack
echo
"Run the deployment with all in normal library..."
echo
"Run the
cpp
deployment with all in normal library..."
lib/cpp_deploy_normal
lib/cpp_deploy_normal
echo
"Run the python deployment with all in normal library..."
python python_deploy.py
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment