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
6196cd50
Commit
6196cd50
authored
Jul 18, 2017
by
ziheng
Committed by
Tianqi Chen
Jul 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EXECUTOR] Move tvm_op and Handler<DLTensor> to graph_executor.cc (#259)
parent
eaea99c5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
72 deletions
+73
-72
apps/graph_executor/src/graph_executor.cc
+73
-0
apps/graph_executor/src/graph_pass.cc
+0
-72
No files found.
apps/graph_executor/src/graph_executor.cc
View file @
6196cd50
...
...
@@ -399,6 +399,55 @@ FOpExec GraphExecutor::CreateTVMOp(const nnvm::NodeAttrs& attrs,
return
fexec
;
}
struct
TVMOpParam
:
public
dmlc
::
Parameter
<
TVMOpParam
>
{
std
::
string
func_name
;
uint32_t
num_inputs
;
uint32_t
num_outputs
;
bool
flatten_data
;
DMLC_DECLARE_PARAMETER
(
TVMOpParam
)
{
DMLC_DECLARE_FIELD
(
func_name
);
DMLC_DECLARE_FIELD
(
num_inputs
)
.
set_default
(
1
);
DMLC_DECLARE_FIELD
(
num_outputs
)
.
set_default
(
1
);
DMLC_DECLARE_FIELD
(
flatten_data
)
.
set_default
(
false
);
}
};
DMLC_REGISTER_PARAMETER
(
TVMOpParam
);
/*! \brief Parse keyword arguments as PType arguments and save to parsed */
template
<
typename
PType
>
inline
void
ParamParser
(
nnvm
::
NodeAttrs
*
attrs
)
{
PType
param
;
try
{
param
.
Init
(
attrs
->
dict
);
}
catch
(
const
dmlc
::
ParamError
&
e
)
{
std
::
ostringstream
os
;
os
<<
e
.
what
();
os
<<
", in operator "
<<
attrs
->
op
->
name
<<
"("
<<
"name=
\"
"
<<
attrs
->
name
<<
"
\"
"
;
for
(
const
auto
&
k
:
attrs
->
dict
)
{
os
<<
", "
<<
k
.
first
<<
"=
\"
"
<<
k
.
second
<<
"
\"
"
;
}
os
<<
")"
;
throw
dmlc
::
ParamError
(
os
.
str
());
}
attrs
->
parsed
=
std
::
move
(
param
);
}
// ewise tvm op
NNVM_REGISTER_OP
(
tvm_op
)
.
set_attr_parser
(
ParamParser
<
TVMOpParam
>
)
.
set_num_inputs
([](
const
NodeAttrs
&
attrs
)
{
const
TVMOpParam
&
param
=
nnvm
::
get
<
TVMOpParam
>
(
attrs
.
parsed
);
return
param
.
num_inputs
;
})
.
set_num_outputs
([](
const
NodeAttrs
&
attrs
)
{
const
TVMOpParam
&
param
=
nnvm
::
get
<
TVMOpParam
>
(
attrs
.
parsed
);
return
param
.
num_outputs
;
});
// Create executor
tvm
::
runtime
::
Module
CreateExecutor
(
nnvm
::
Graph
g
,
TVMContext
ctx
)
{
std
::
shared_ptr
<
GraphExecutor
>
exec
=
...
...
@@ -460,3 +509,27 @@ TVM_REGISTER_GLOBAL("tvm_graph._load_executor")
});
}
// namespace contrib
}
// namespace tvm
namespace
dmlc
{
namespace
json
{
template
<>
struct
Handler
<
DLDataType
>
{
static
void
Write
(
JSONWriter
*
writer
,
const
DLDataType
&
data
)
{
std
::
vector
<
int
>
tmp
({
data
.
code
,
data
.
bits
,
data
.
lanes
});
writer
->
Write
(
tmp
);
}
static
void
Read
(
JSONReader
*
reader
,
DLDataType
*
data
)
{
std
::
vector
<
int
>
tmp
;
reader
->
Read
(
&
tmp
);
data
->
code
=
tmp
[
0
];
data
->
bits
=
tmp
[
1
];
data
->
lanes
=
tmp
[
2
];
}
};
DMLC_JSON_ENABLE_ANY
(
std
::
vector
<
DLDataType
>
,
list_dltype
);
}
// namespace dmlc
}
// namespace json
apps/graph_executor/src/graph_pass.cc
View file @
6196cd50
...
...
@@ -340,54 +340,6 @@ nnvm::Graph GraphFuse(nnvm::Graph g) {
NNVM_REGISTER_PASS
(
GraphFuse
)
.
set_body
(
GraphFuse
);
struct
TVMOpParam
:
public
dmlc
::
Parameter
<
TVMOpParam
>
{
std
::
string
func_name
;
uint32_t
num_inputs
;
uint32_t
num_outputs
;
bool
flatten_data
;
DMLC_DECLARE_PARAMETER
(
TVMOpParam
)
{
DMLC_DECLARE_FIELD
(
func_name
);
DMLC_DECLARE_FIELD
(
num_inputs
)
.
set_default
(
1
);
DMLC_DECLARE_FIELD
(
num_outputs
)
.
set_default
(
1
);
DMLC_DECLARE_FIELD
(
flatten_data
)
.
set_default
(
false
);
}
};
DMLC_REGISTER_PARAMETER
(
TVMOpParam
);
/*! \brief Parse keyword arguments as PType arguments and save to parsed */
template
<
typename
PType
>
inline
void
ParamParser
(
nnvm
::
NodeAttrs
*
attrs
)
{
PType
param
;
try
{
param
.
Init
(
attrs
->
dict
);
}
catch
(
const
dmlc
::
ParamError
&
e
)
{
std
::
ostringstream
os
;
os
<<
e
.
what
();
os
<<
", in operator "
<<
attrs
->
op
->
name
<<
"("
<<
"name=
\"
"
<<
attrs
->
name
<<
"
\"
"
;
for
(
const
auto
&
k
:
attrs
->
dict
)
{
os
<<
", "
<<
k
.
first
<<
"=
\"
"
<<
k
.
second
<<
"
\"
"
;
}
os
<<
")"
;
throw
dmlc
::
ParamError
(
os
.
str
());
}
attrs
->
parsed
=
std
::
move
(
param
);
}
// ewise tvm op
NNVM_REGISTER_OP
(
tvm_op
)
.
set_attr_parser
(
ParamParser
<
TVMOpParam
>
)
.
set_num_inputs
([](
const
NodeAttrs
&
attrs
)
{
const
TVMOpParam
&
param
=
nnvm
::
get
<
TVMOpParam
>
(
attrs
.
parsed
);
return
param
.
num_inputs
;
})
.
set_num_outputs
([](
const
NodeAttrs
&
attrs
)
{
const
TVMOpParam
&
param
=
nnvm
::
get
<
TVMOpParam
>
(
attrs
.
parsed
);
return
param
.
num_outputs
;
});
inline
bool
IsIdentityLayout
(
const
LayoutInfo
&
layout
)
{
if
(
layout
.
src
==
""
&&
layout
.
dst
==
""
)
return
true
;
...
...
@@ -515,27 +467,3 @@ NNVM_REGISTER_OP(layout_transform)
.
set_num_outputs
(
1
);
}
// namespace contrib
}
// namespace tvm
namespace
dmlc
{
namespace
json
{
template
<>
struct
Handler
<
DLDataType
>
{
static
void
Write
(
JSONWriter
*
writer
,
const
DLDataType
&
data
)
{
std
::
vector
<
int
>
tmp
({
data
.
code
,
data
.
bits
,
data
.
lanes
});
writer
->
Write
(
tmp
);
}
static
void
Read
(
JSONReader
*
reader
,
DLDataType
*
data
)
{
std
::
vector
<
int
>
tmp
;
reader
->
Read
(
&
tmp
);
data
->
code
=
tmp
[
0
];
data
->
bits
=
tmp
[
1
];
data
->
lanes
=
tmp
[
2
];
}
};
DMLC_JSON_ENABLE_ANY
(
std
::
vector
<
DLDataType
>
,
list_dltype
);
}
// namespace dmlc
}
// namespace json
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