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
ff5dffa4
Unverified
Commit
ff5dffa4
authored
6 years ago
by
Tianqi Chen
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[APPS] add an external dll call example (#2156)
parent
2bd02e4e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/extension/python/tvm_ext/__init__.py
+3
-1
3 additions, 1 deletion
apps/extension/python/tvm_ext/__init__.py
apps/extension/src/tvm_ext.cc
+5
-0
5 additions, 0 deletions
apps/extension/src/tvm_ext.cc
apps/extension/tests/test_ext.py
+20
-0
20 additions, 0 deletions
apps/extension/tests/test_ext.py
with
28 additions
and
1 deletion
apps/extension/python/tvm_ext/__init__.py
+
3
−
1
View file @
ff5dffa4
...
@@ -8,7 +8,9 @@ import tvm
...
@@ -8,7 +8,9 @@ import tvm
def
load_lib
():
def
load_lib
():
"""
Load library, the functions will be registered into TVM
"""
"""
Load library, the functions will be registered into TVM
"""
curr_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
__file__
)))
curr_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
__file__
)))
lib
=
ctypes
.
CDLL
(
os
.
path
.
join
(
curr_path
,
"
../../lib/libtvm_ext.so
"
))
# load in as global so the global extern symbol is visible to other dll.
lib
=
ctypes
.
CDLL
(
os
.
path
.
join
(
curr_path
,
"
../../lib/libtvm_ext.so
"
),
ctypes
.
RTLD_GLOBAL
)
return
lib
return
lib
_LIB
=
load_lib
()
_LIB
=
load_lib
()
...
...
This diff is collapsed.
Click to expand it.
apps/extension/src/tvm_ext.cc
+
5
−
0
View file @
ff5dffa4
...
@@ -66,6 +66,11 @@ TVM_REGISTER_GLOBAL("device_api.ext_dev")
...
@@ -66,6 +66,11 @@ TVM_REGISTER_GLOBAL("device_api.ext_dev")
});
});
}
// namespace tvm_ext
}
// namespace tvm_ext
// External function exposed to runtime.
extern
"C"
float
TVMTestAddOne
(
float
y
)
{
return
y
+
1
;
}
// This callback approach allows extension allows tvm to extract
// This callback approach allows extension allows tvm to extract
// This way can be helpful when we want to use a header only
// This way can be helpful when we want to use a header only
// minimum version of TVM Runtime.
// minimum version of TVM Runtime.
...
...
This diff is collapsed.
Click to expand it.
apps/extension/tests/test_ext.py
+
20
−
0
View file @
ff5dffa4
...
@@ -49,7 +49,27 @@ def test_extract_ext():
...
@@ -49,7 +49,27 @@ def test_extract_ext():
assert
fdict
[
"
mul
"
](
3
,
4
)
==
12
assert
fdict
[
"
mul
"
](
3
,
4
)
==
12
def
test_extern_call
():
n
=
10
A
=
tvm
.
placeholder
((
n
,),
name
=
'
A
'
)
B
=
tvm
.
compute
((
n
,),
lambda
*
i
:
tvm
.
call_extern
(
"
float32
"
,
"
TVMTestAddOne
"
,
A
(
*
i
)),
name
=
'
B
'
)
s
=
tvm
.
create_schedule
(
B
.
op
)
def
check_llvm
():
if
not
tvm
.
module
.
enabled
(
"
llvm
"
):
return
f
=
tvm
.
build
(
s
,
[
A
,
B
],
"
llvm
"
)
ctx
=
tvm
.
cpu
(
0
)
# launch the kernel.
a
=
tvm
.
nd
.
array
(
np
.
random
.
uniform
(
size
=
n
).
astype
(
A
.
dtype
),
ctx
)
b
=
tvm
.
nd
.
array
(
np
.
zeros
(
n
,
dtype
=
B
.
dtype
),
ctx
)
f
(
a
,
b
)
tvm
.
testing
.
assert_allclose
(
b
.
asnumpy
(),
a
.
asnumpy
()
+
1
)
check_llvm
()
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
test_extern_call
()
test_ext_dev
()
test_ext_dev
()
test_ext_vec
()
test_ext_vec
()
test_bind_add
()
test_bind_add
()
...
...
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