Skip to content

Commit ebbec6d

Browse files
committed
updates (apache#25)
* [FIX] Remove extra move * [MEMORY] Add inplace index
1 parent be19963 commit ebbec6d

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

nnvm/src/c_api/c_api_symbolic.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int NNSymbolListAttrs(SymbolHandle symbol,
160160
NNAPIThreadLocalEntry *ret = NNAPIThreadLocalStore::Get();
161161
API_BEGIN();
162162
std::unordered_map<std::string, std::string> attr =
163-
std::move(s->ListAttrs(static_cast<Symbol::ListAttrOption>(option))); // NOLINT(*)
163+
s->ListAttrs(static_cast<Symbol::ListAttrOption>(option)); // NOLINT(*)
164164

165165
std::vector<std::string>& attr_list = ret->ret_vec_str;
166166
attr_list.clear();
@@ -184,8 +184,8 @@ int NNSymbolListInputNames(SymbolHandle symbol,
184184
Symbol *s = static_cast<Symbol*>(symbol);
185185
NNAPIThreadLocalEntry *ret = NNAPIThreadLocalStore::Get();
186186
API_BEGIN();
187-
ret->ret_vec_str = std::move(
188-
s->ListInputNames(Symbol::ListInputOption(option)));
187+
ret->ret_vec_str =
188+
s->ListInputNames(Symbol::ListInputOption(option));
189189
ret->ret_vec_charp.clear();
190190
for (size_t i = 0; i < ret->ret_vec_str.size(); ++i) {
191191
ret->ret_vec_charp.push_back(ret->ret_vec_str[i].c_str());
@@ -201,7 +201,7 @@ int NNSymbolListOutputNames(SymbolHandle symbol,
201201
Symbol *s = static_cast<Symbol*>(symbol);
202202
NNAPIThreadLocalEntry *ret = NNAPIThreadLocalStore::Get();
203203
API_BEGIN();
204-
ret->ret_vec_str = std::move(s->ListOutputNames());
204+
ret->ret_vec_str = s->ListOutputNames();
205205
ret->ret_vec_charp.clear();
206206
for (size_t i = 0; i < ret->ret_vec_str.size(); ++i) {
207207
ret->ret_vec_charp.push_back(ret->ret_vec_str[i].c_str());

nnvm/src/pass/order_mutation.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ inline T get_with_default(const std::unordered_map<Node*, T> &map,
2222
}
2323

2424
inline bool IsMutate(const std::vector<uint32_t>& mutate_inputs, uint32_t i) {
25-
if (mutate_inputs.size() == 0) return false;
26-
auto it = std::lower_bound(
27-
mutate_inputs.begin(), mutate_inputs.end(), i);
28-
return (it != mutate_inputs.end()) && (*it == i);
25+
return std::binary_search(mutate_inputs.begin(), mutate_inputs.end(), i);
2926
}
3027

3128
Graph OrderMutation(const Graph& src) {

nnvm/src/pass/plan_memory.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Graph PlanMemory(Graph ret) {
150150
}
151151
// step 2: allocate memory.
152152
StorageVector storage(idx.num_node_entries(), -1);
153+
std::vector<int> storage_inplace_index(idx.num_node_entries(), -1);
153154
const ShapeVector& shape_vec = ret.GetAttr<ShapeVector>("shape");
154155
const DTypeVector& dtype_vec = ret.GetAttr<DTypeVector>("dtype");
155156
const DeviceVector* device_vec = nullptr;
@@ -173,8 +174,10 @@ Graph PlanMemory(Graph ret) {
173174
uint32_t eid_out = idx.entry_id(nid, kv.second);
174175
uint32_t eid_in = idx.entry_id(inode.inputs[kv.first]);
175176
if (ref_count[eid_in] == 1 && storage[eid_in] != GraphAllocator::kBadStorageID) {
177+
// inplace optimization
176178
storage[eid_out] = storage[eid_in];
177179
ref_count[eid_in] = 0;
180+
storage_inplace_index[eid_out] = kv.first;
178181
}
179182
}
180183
}
@@ -209,8 +212,8 @@ Graph PlanMemory(Graph ret) {
209212
}
210213
}
211214
}
212-
213215
ret.attrs["storage_id"] = std::make_shared<any>(std::move(storage));
216+
ret.attrs["storage_inplace_index"] = std::make_shared<any>(std::move(storage_inplace_index));
214217
ret.attrs["storage_allocated_bytes"] = std::make_shared<any>(allocator.TotalAllocBytes());
215218
ret.attrs["storage_num_not_allocated"] = std::make_shared<any>(num_not_allocated);
216219
return ret;
@@ -222,7 +225,8 @@ NNVM_REGISTER_PASS(PlanMemory)
222225
.set_change_graph(false)
223226
.depend_graph_attr("dtype")
224227
.depend_graph_attr("shape")
225-
.provide_graph_attr("storage_id");
228+
.provide_graph_attr("storage_id")
229+
.provide_graph_attr("storage_inplace_index");
226230

227231
} // namespace
228232
} // namespace pass

nnvm/src/pass/saveload_json.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct JSONNode {
8989
}
9090

9191
void Load(dmlc::JSONReader *reader) {
92-
node = std::move(Node::Create());
92+
node = Node::Create();
9393
control_deps.clear();
9494
dmlc::JSONObjectReadHelper helper;
9595
std::string op_type_str;

0 commit comments

Comments
 (0)