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
43126602
Commit
43126602
authored
6 years ago
by
Zhennan Qin
Committed by
Tianqi Chen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow inplace memory optimization for different data type (#1696)
parent
10ae8ee1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nnvm/src/pass/plan_memory.cc
+27
-1
27 additions, 1 deletion
nnvm/src/pass/plan_memory.cc
with
27 additions
and
1 deletion
nnvm/src/pass/plan_memory.cc
+
27
−
1
View file @
43126602
...
...
@@ -7,12 +7,37 @@
#include
<nnvm/pass.h>
#include
<nnvm/graph_attr_types.h>
#include
<nnvm/op_attr_types.h>
#include
<nnvm/top/tensor.h>
#include
<memory>
#include
"graph_algorithm.h"
namespace
nnvm
{
namespace
pass
{
namespace
{
using
namespace
nnvm
::
top
;
// Return bytes of data flag.
static
int
GetDTypeSize
(
int
type_flag
)
{
switch
(
type_flag
)
{
case
kUint8
:
case
kInt8
:
return
1
;
case
kFloat16
:
case
kInt16
:
case
kUint16
:
return
2
;
case
kFloat32
:
case
kInt32
:
case
kUint32
:
return
4
;
case
kFloat64
:
case
kInt64
:
case
kUint64
:
return
8
;
default:
LOG
(
FATAL
)
<<
"unknown type_flag="
<<
type_flag
;
return
-
1
;
}
}
// simple graph based allocator.
class
GraphAllocator
{
...
...
@@ -199,7 +224,8 @@ size_t AllocMemory(const Graph& ret, const IndexedGraph& idx,
((
storage_ref_count
[
sid_in
]
==
1
&&
!
ignore_all_inputs
)
||
identity
[
ipair
])
&&
entry_ref_count
[
eid_out
]
>
0
&&
shape_vec
[
eid_out
].
Size
()
==
shape_vec
[
eid_in
].
Size
()
&&
dtype_vec
[
eid_out
]
==
dtype_vec
[
eid_in
])
{
(
dtype_vec
[
eid_out
]
==
dtype_vec
[
eid_in
]
||
GetDTypeSize
(
dtype_vec
[
eid_out
])
==
GetDTypeSize
(
dtype_vec
[
eid_in
])))
{
// inplace optimization
taken
[
kv
.
first
]
=
true
;
storage
[
eid_out
]
=
sid_in
;
...
...
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