Skip to content

Commit 6ef3058

Browse files
authored
[EXEC] Specify external memory directly in memory planning (apache#4558)
* [EXEC] Specify external memory directly in memory planning * Fix warnig
1 parent 803ba5b commit 6ef3058

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

NEWS.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ MXNet Change Log
1111
- New operators are encouraged to register their property to NNVM op registry attribute
1212
- Known features removed limitations to be fixed
1313
- Bulk segment execution not yet added.
14-
- The gradient aggregation optimization hack by switching to addto is not yet added,
15-
can harm LSTM if it is constructed by unrolling the graph
1614

1715
## v0.8
1816
This is the last release before the NNVM refactor.

example/memcost/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
no_optimization:
55
@echo "Estimating the cost with no optimization..."
6-
@MXNET_EXEC_ENABLE_INPLACE=false MXNET_EXEC_MATCH_RANGE=0 python inception_memcost.py
6+
@NNVM_EXEC_ENABLE_INPLACE=false NNVM_EXEC_MATCH_RANGE=0 python inception_memcost.py
77

88
with_inplace:
99
@echo "Estimating the cost with inplace optimization..."
10-
@MXNET_EXEC_ENABLE_INPLACE=true MXNET_EXEC_MATCH_RANGE=0 python inception_memcost.py
10+
@NNVM_EXEC_ENABLE_INPLACE=true MXNET_EXEC_MATCH_RANGE=0 python inception_memcost.py
1111

1212
with_sharing:
1313
@echo "Estimating the cost with memory sharing ..."
14-
@MXNET_EXEC_ENABLE_INPLACE=false python inception_memcost.py
14+
@NNVM_EXEC_ENABLE_INPLACE=false python inception_memcost.py
1515

1616
with_both:
1717
@echo "Estimating the cost with all optimizations ..."

example/memcost/inception_memcost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def InceptionFactoryB(data, num_3x3red, num_3x3, num_d3x3red, num_d3x3, name):
3636
cd3x3 = ConvFactory(data=cd3x3r, num_filter=num_d3x3, kernel=(3, 3), pad=(1, 1), stride=(1, 1), name=('%s_double_3x3_0' % name))
3737
cd3x3 = ConvFactory(data=cd3x3, num_filter=num_d3x3, kernel=(3, 3), pad=(1, 1), stride=(2, 2), name=('%s_double_3x3_1' % name))
3838
# pool + proj
39-
pooling = mx.symbol.Pooling(data=data, kernel=(3, 3), stride=(2, 2), pool_type="max", name=('max_pool_%s_pool' % name))
39+
pooling = mx.symbol.Pooling(data=data, kernel=(3, 3), stride=(2, 2), pad=(1, 1), pool_type="max", name=('max_pool_%s_pool' % name))
4040
# concat
4141
concat = mx.symbol.Concat(*[c3x3, cd3x3, pooling], name='ch_concat_%s_chconcat' % name)
4242
return concat

src/executor/graph_executor.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,18 @@ Graph GraphExecutor::InitGraph(nnvm::Symbol symbol,
399399
// other initializations
400400
g = nnvm::pass::InferShape(g, arg_shapes, "__shape__");
401401
g = nnvm::pass::InferType(g, arg_types, "__dtype__");
402-
g = nnvm::ApplyPass(g, "PlanMemory");
402+
403+
{
404+
// memory allocator
405+
const int kBadStorageID = -1;
406+
const int kExternalStorageID = -2;
407+
nnvm::StorageVector arg_storage_id(idx.num_node_entries(), kBadStorageID);
408+
for (size_t j = num_forward_outputs_; j < idx.outputs().size(); ++j) {
409+
arg_storage_id[idx.entry_id(idx.outputs()[j])] = kExternalStorageID;
410+
}
411+
g.attrs["storage"] = std::make_shared<dmlc::any>(std::move(arg_storage_id));
412+
g = nnvm::ApplyPass(g, "PlanMemory");
413+
}
403414
g = DetectInplaceAddTo(g);
404415
return g;
405416
}

0 commit comments

Comments
 (0)