diff --git a/src/imperative/cached_op.cc b/src/imperative/cached_op.cc index 24270f210888..ec5a79a2e675 100644 --- a/src/imperative/cached_op.cc +++ b/src/imperative/cached_op.cc @@ -473,7 +473,7 @@ bool CachedOp::SetForwardGraph( storage[idx.entry_id(idx.outputs()[i])] = exec::kExternalStorageID; } - auto mem_plan = PlanMemory( + auto mem_plan = MXPlanMemory( &g, std::move(storage), g.GetAttr >(AddPrefix(prefix, REF_COUNT)), AddPrefix(prefix, STORAGE_PLAN)); g.attrs[AddPrefix(prefix, MEM_PLAN)] = @@ -601,7 +601,7 @@ bool CachedOp::SetBackwardGraph( for (const auto i : idx.input_nodes()) storage[idx.entry_id(i, 0)] = exec::kExternalStorageID; for (const auto i : idx.outputs()) storage[idx.entry_id(i)] = exec::kExternalStorageID; - auto mem_plan = PlanMemory( + auto mem_plan = MXPlanMemory( &g, std::move(storage), g.GetAttr >(AddPrefix(BACKWARD, REF_COUNT)), AddPrefix(BACKWARD, STORAGE_PLAN), diff --git a/src/imperative/imperative_utils.h b/src/imperative/imperative_utils.h index b609c54b50f3..edc2f2adf4c2 100644 --- a/src/imperative/imperative_utils.h +++ b/src/imperative/imperative_utils.h @@ -830,7 +830,7 @@ inline std::vector PlaceDevice(const nnvm::IndexedGraph& idx) { } -inline MemoryPlanVector PlanMemory( +inline MemoryPlanVector MXPlanMemory( nnvm::Graph* p_g, nnvm::StorageVector&& storage, const std::vector& ref_count, diff --git a/src/nnvm/graph_algorithm.h b/src/nnvm/graph_algorithm.h index d1590c3b9846..031e62254db7 100644 --- a/src/nnvm/graph_algorithm.h +++ b/src/nnvm/graph_algorithm.h @@ -42,7 +42,7 @@ namespace pass { * \param path the output path of nodes. * \return the total reward of best path. */ -inline uint32_t FindBestPath( +inline uint32_t MXFindBestPath( const IndexedGraph& graph, const std::vector& node_reward, std::vector* path) { @@ -89,7 +89,7 @@ inline uint32_t FindBestPath( * \param color the color index of each of the node. * \return the total number of colors. */ -inline uint32_t ColorNodeGroup( +inline uint32_t MXColorNodeGroup( const IndexedGraph &graph, std::vector node_importance, uint32_t max_ncolor, @@ -105,7 +105,7 @@ inline uint32_t ColorNodeGroup( // All the nodes in the path cannot run in parallel. for (cindex = 0; cindex < max_ncolor - 1; ++cindex) { std::vector path; - uint32_t reward = FindBestPath(graph, node_importance, &path); + uint32_t reward = MXFindBestPath(graph, node_importance, &path); if (reward == 0) break; for (uint32_t nid : path) { if (node_importance[nid] != 0) { diff --git a/src/nnvm/plan_memory.cc b/src/nnvm/plan_memory.cc index 427d1c751cba..c89eefc6d1ac 100644 --- a/src/nnvm/plan_memory.cc +++ b/src/nnvm/plan_memory.cc @@ -38,7 +38,7 @@ namespace pass { namespace { using namespace nnvm::top; // Return bytes of data flag. -static int GetDTypeSize(int type_flag) { +static int MXGetDTypeSize(int type_flag) { switch (type_flag) { case kUint8: case kInt8: @@ -62,7 +62,7 @@ static int GetDTypeSize(int type_flag) { } // simple graph based allocator. -class GraphAllocator { +class MXGraphAllocator { public: // storage id equals integer. using StorageID = int; @@ -131,7 +131,7 @@ class GraphAllocator { } // constructor - explicit GraphAllocator(const IndexedGraph* idx, const size_t match_range) : idx_(idx) { + explicit MXGraphAllocator(const IndexedGraph* idx, const size_t match_range) : idx_(idx) { this->Init(match_range, dmlc::GetEnv("NNVM_EXEC_NUM_TEMP", 1)); } @@ -146,7 +146,7 @@ class GraphAllocator { if ((*idx_)[nid].source->is_variable()) continue; importance[nid] = 1; } - num_match_color_ = pass::ColorNodeGroup( + num_match_color_ = pass::MXColorNodeGroup( *idx_, importance, num_match_color_, &node_color_); } } @@ -190,12 +190,12 @@ class GraphAllocator { /* * Internal method to perform the memory allocation for a graph * */ -size_t AllocMemory(const Graph& ret, const IndexedGraph& idx, +size_t MXAllocMemory(const Graph& ret, const IndexedGraph& idx, const std::pair& node_range, StorageVector* storage_ptr, std::vector* storage_inplace_index_ptr, const std::vector& entry_ref_count, - GraphAllocator* allocator) { + MXGraphAllocator* allocator) { static auto& finplace_option = Op::GetAttr("FInplaceOption"); static auto& finplace_identity = Op::GetAttr("FInplaceIdentity"); static auto& fignore_inputs = Op::GetAttr("FIgnoreInputs"); @@ -213,7 +213,7 @@ size_t AllocMemory(const Graph& ret, const IndexedGraph& idx, device_vec = &(ret.GetAttr("device")); } size_t num_not_allocated = 0; - std::vector storage_ref_count(idx.num_node_entries(), 0); + std::vector storage_ref_count(idx.num_node_entries(), 0); for (uint32_t nid = node_range.first; nid < node_range.second; ++nid) { const auto& inode = idx[nid]; @@ -247,13 +247,13 @@ size_t AllocMemory(const Graph& ret, const IndexedGraph& idx, shape_vec[eid_out].Size() == shape_vec[eid_in].Size() && dtype_vec[eid_out] == dtype_vec[eid_in]; if (taken[kv.first] == false && - sid_out == GraphAllocator::kBadStorageID && + sid_out == MXGraphAllocator::kBadStorageID && sid_in >= 0 && ((storage_ref_count[sid_in] == 1 && !ignore_all_inputs) || real_identity) && entry_ref_count[eid_out] > 0 && shape_vec[eid_out].Size() == shape_vec[eid_in].Size() && (dtype_vec[eid_out] == dtype_vec[eid_in] || - GetDTypeSize(dtype_vec[eid_out]) == GetDTypeSize(dtype_vec[eid_in]))) { + MXGetDTypeSize(dtype_vec[eid_out]) == MXGetDTypeSize(dtype_vec[eid_in]))) { // inplace optimization taken[kv.first] = true; storage[eid_out] = sid_in; @@ -272,7 +272,7 @@ size_t AllocMemory(const Graph& ret, const IndexedGraph& idx, for (uint32_t index = 0; index < inode.source->num_outputs(); ++index) { uint32_t eid = idx.entry_id(nid, index); // only request memory for kBadStorageID - if (storage[eid] == GraphAllocator::kBadStorageID) { + if (storage[eid] == MXGraphAllocator::kBadStorageID) { auto &eshape = shape_vec[eid]; size_t esize = ndim_is_known(shape_vec[eid]) ? eshape.Size() : 0; eids.insert(std::make_pair(esize, eid)); @@ -317,7 +317,7 @@ size_t AllocMemory(const Graph& ret, const IndexedGraph& idx, // use -2 to indicate that the node was never touched. storage_inplace_index[eid] = -2; } - if (storage[eid] == GraphAllocator::kBadStorageID) { + if (storage[eid] == MXGraphAllocator::kBadStorageID) { ++num_not_allocated; } } @@ -327,7 +327,7 @@ size_t AllocMemory(const Graph& ret, const IndexedGraph& idx, // function to plan memory -Graph PlanMemory(Graph ret) { +Graph MXPlanMemory(Graph ret) { // setup ref counter const IndexedGraph& idx = ret.indexed_graph(); static auto& fignore_inputs = Op::GetAttr("FIgnoreInputs"); @@ -380,11 +380,11 @@ Graph PlanMemory(Graph ret) { std::vector storage_inplace_index(idx.num_node_entries(), -1); // the allocator - GraphAllocator allocator(&idx, match_range); + MXGraphAllocator allocator(&idx, match_range); // number of entries that are not statically allocated. size_t storage_num_not_allocated = - AllocMemory(ret, idx, node_range, &storage_vec, &storage_inplace_index, + MXAllocMemory(ret, idx, node_range, &storage_vec, &storage_inplace_index, ref_count, &allocator); size_t storage_allocated_bytes = allocator.TotalAllocBytes(); @@ -406,7 +406,7 @@ Graph PlanMemory(Graph ret) { NNVM_REGISTER_PASS(MXPlanMemory) .describe("Plan the memory allocation of each node entries.") -.set_body(PlanMemory) +.set_body(MXPlanMemory) .set_change_graph(false) .depend_graph_attr("dtype") .depend_graph_attr("shape")