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
cc7cbbe7
Commit
cc7cbbe7
authored
7 years ago
by
Lianmin Zheng
Committed by
Tianqi Chen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[BUILD] add target_host to compiler.build (#240)
parent
2b15684f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
nnvm/include/nnvm/graph.h
+11
-0
11 additions, 0 deletions
nnvm/include/nnvm/graph.h
nnvm/python/nnvm/compiler/build_module.py
+16
-3
16 additions, 3 deletions
nnvm/python/nnvm/compiler/build_module.py
nnvm/src/compiler/graph_fuse.cc
+5
-1
5 additions, 1 deletion
nnvm/src/compiler/graph_fuse.cc
with
32 additions
and
4 deletions
nnvm/include/nnvm/graph.h
+
11
−
0
View file @
cc7cbbe7
...
...
@@ -47,6 +47,12 @@ class Graph {
*/
template
<
typename
T
>
inline
const
T
&
GetAttr
(
const
std
::
string
&
attr_name
)
const
;
/*!
* \brief Check whether has a specific attribute.
* \param attr_name the name of the attribute
* \return a boolean result
*/
inline
bool
HasAttr
(
const
std
::
string
&
attr_name
)
const
;
/*!
* \brief Get a move copy of the attribute, implement copy on write semantics.
* The content is moved if the reference counter of shared_ptr is 1.
...
...
@@ -226,6 +232,11 @@ inline const T& Graph::GetAttr(const std::string& attr_name) const {
return
nnvm
::
get
<
T
>
(
*
it
->
second
);
}
inline
bool
Graph
::
HasAttr
(
const
std
::
string
&
attr_name
)
const
{
auto
it
=
attrs
.
find
(
attr_name
);
return
it
!=
attrs
.
end
();
}
template
<
typename
T
>
inline
T
Graph
::
MoveCopyAttr
(
const
std
::
string
&
attr_name
)
{
auto
it
=
attrs
.
find
(
attr_name
);
...
...
This diff is collapsed.
Click to expand it.
nnvm/python/nnvm/compiler/build_module.py
+
16
−
3
View file @
cc7cbbe7
...
...
@@ -112,8 +112,10 @@ def _lower(sch, inputs, func_name, graph):
@tvm.register_func
(
"
nnvm.compiler.build_target
"
)
def
_build
(
funcs
,
target
):
return
tvm
.
build
(
funcs
,
target
=
target
)
def
_build
(
funcs
,
target
,
target_host
):
if
target_host
==
""
:
target_host
=
None
return
tvm
.
build
(
funcs
,
target
=
target
,
target_host
=
target_host
)
def
_update_shape_dtype
(
shape
,
dtype
,
params
):
...
...
@@ -161,7 +163,7 @@ def optimize(graph, shape, dtype="float32"):
return
graph
def
build
(
graph
,
target
=
None
,
shape
=
None
,
dtype
=
"
float32
"
,
params
=
None
):
def
build
(
graph
,
target
=
None
,
shape
=
None
,
dtype
=
"
float32
"
,
params
=
None
,
target_host
=
None
):
"""
Build graph into runtime library.
The build function will optimize the graph and do the compilation.
...
...
@@ -189,6 +191,15 @@ def build(graph, target=None, shape=None, dtype="float32", params=None):
during inference time. Used for pre-compute
folding optimization.
target_host : str or :any:`tvm.target.Target` optional
Host compilation target, if target is device.
When TVM compiles device specific program such as CUDA,
we also need host(CPU) side code to interact with the driver
setup the dimensions and parameters correctly.
target_host is used to specify the host side codegen target.
By default, llvm is used if it is enabled,
otherwise a stackvm intepreter is used.
Returns
-------
graph : Graph
...
...
@@ -228,6 +239,8 @@ def build(graph, target=None, shape=None, dtype="float32", params=None):
graph
=
graph_attr
.
set_shape_inputs
(
graph
,
shape
)
graph
=
graph_attr
.
set_dtype_inputs
(
graph
,
dtype
)
graph
.
_set_json_attr
(
"
target
"
,
str
(
target
),
"
str
"
)
if
target_host
is
not
None
:
graph
.
_set_json_attr
(
"
target_host
"
,
str
(
target_host
),
"
str
"
)
if
cfg
.
pass_enabled
(
"
OpFusion
"
):
graph
.
_set_json_attr
(
"
opt_level
"
,
1
,
"
int
"
)
else
:
...
...
This diff is collapsed.
Click to expand it.
nnvm/src/compiler/graph_fuse.cc
+
5
−
1
View file @
cc7cbbe7
...
...
@@ -219,6 +219,10 @@ nnvm::Graph GraphFuseCompile(nnvm::Graph g) {
const
std
::
vector
<
TOpPattern
>&
pattern_vec
=
g
.
GetAttr
<
std
::
vector
<
TOpPattern
>
>
(
"pattern"
);
std
::
string
target
=
g
.
GetAttr
<
std
::
string
>
(
"target"
);
std
::
string
target_host
;
if
(
g
.
HasAttr
(
"target_host"
))
target_host
=
g
.
GetAttr
<
std
::
string
>
(
"target_host"
);
std
::
vector
<
FuseEntry
>
fuse_vec
(
idx
.
num_nodes
());
// setup inputs and placeholder.
for
(
uint32_t
nid
=
0
;
nid
<
idx
.
num_nodes
();
++
nid
)
{
...
...
@@ -398,7 +402,7 @@ nnvm::Graph GraphFuseCompile(nnvm::Graph g) {
ret
.
attrs
[
"dltype"
]
=
std
::
make_shared
<
any
>
(
std
::
move
(
new_dltype_vec
));
// Setup module
static
const
PackedFunc
&
fbuild
=
GetPackedFunc
(
"nnvm.compiler.build_target"
);
tvm
::
runtime
::
Module
module
=
fbuild
(
func_list
,
target
);
tvm
::
runtime
::
Module
module
=
fbuild
(
func_list
,
target
,
target_host
);
ret
.
attrs
[
"module"
]
=
std
::
make_shared
<
any
>
(
std
::
move
(
module
));
ret
=
nnvm
::
ApplyPass
(
ret
,
"PlanMemory"
);
return
ret
;
...
...
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