From: @laiyongqiang Reviewed-by: @jjfeing,@kisnwang Signed-off-by: @jjfeingtags/v1.1.0
| @@ -33,6 +33,7 @@ | |||
| #endif | |||
| #include "backend/optimizer/common/helper.h" | |||
| #include "utils/ms_context.h" | |||
| #include "debug/common.h" | |||
| namespace mindspore { | |||
| namespace somas { | |||
| @@ -364,6 +365,7 @@ void Somas::RefNodeProcess(const session::KernelGraph *graph) { | |||
| auto kernel_mod = AnfAlgo::GetKernelMod(kernel); | |||
| if (kernel_mod == nullptr) { | |||
| MS_LOG(WARNING) << "Kernel mode is NULL Of " << kernel->fullname_with_scope(); | |||
| continue; | |||
| } | |||
| auto output_sizes = kernel_mod->GetOutputSizeList(); | |||
| size_t output_index = 0; | |||
| @@ -602,7 +604,7 @@ static bool ValidSubset(std::set<SomasStreamPtr> destStreams, std::set<SomasStre | |||
| tensor->GetSourceNode()->anc_stream_max_order_[stream->GetId()]) { | |||
| return false; | |||
| } | |||
| } else { // stream == tensor->GetSourceStream() | |||
| } else { | |||
| if (ancestorTensor->max_destination_id_[stream] >= tensor->lifetime_.start_) { | |||
| return false; | |||
| } | |||
| @@ -1054,23 +1056,17 @@ void Somas::DumpSomasBasicIR(const string filename) { | |||
| MS_LOG(ERROR) << "File path " << filename << " is too long."; | |||
| return; | |||
| } | |||
| char real_path[PATH_MAX] = {0}; | |||
| #if defined(_WIN32) || defined(_WIN64) | |||
| if (_fullpath(real_path, filename.c_str(), PATH_MAX) == nullptr) { | |||
| MS_LOG(DEBUG) << "dir " << filename << " does not exit."; | |||
| } | |||
| #else | |||
| if (realpath(filename.c_str(), real_path) == nullptr) { | |||
| MS_LOG(DEBUG) << "Dir " << filename << " does not exit."; | |||
| auto real_path = Common::GetRealPath(filename); | |||
| if (!real_path.has_value()) { | |||
| MS_LOG(ERROR) << "Get real path failed. path=" << filename; | |||
| return; | |||
| } | |||
| #endif | |||
| std::string path_string = real_path; | |||
| ChangeFileMode(path_string, S_IRWXU); | |||
| std::ofstream ofs(real_path); | |||
| ChangeFileMode(real_path.value(), S_IRWXU); | |||
| std::ofstream ofs(real_path.value()); | |||
| if (!ofs.is_open()) { | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path << "' failed!"; | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!"; | |||
| return; | |||
| } | |||
| ofs << "All Tensors:\n\n"; | |||
| @@ -1146,23 +1142,18 @@ void Somas::DumpOfflineIR(const string filename) { | |||
| MS_LOG(ERROR) << "File path " << filename << " is too long."; | |||
| return; | |||
| } | |||
| char real_path[PATH_MAX] = {0}; | |||
| #if defined(_WIN32) || defined(_WIN64) | |||
| if (_fullpath(real_path, filename.c_str(), PATH_MAX) == nullptr) { | |||
| MS_LOG(DEBUG) << "dir " << filename << " does not exit."; | |||
| } | |||
| #else | |||
| if (realpath(filename.c_str(), real_path) == nullptr) { | |||
| MS_LOG(DEBUG) << "Dir " << filename << " does not exit."; | |||
| auto real_path = Common::GetRealPath(filename); | |||
| if (!real_path.has_value()) { | |||
| MS_LOG(ERROR) << "Get real path failed. path=" << filename; | |||
| return; | |||
| } | |||
| #endif | |||
| std::string path_string = real_path; | |||
| ChangeFileMode(path_string, S_IRWXU); | |||
| std::ofstream ofs(real_path); | |||
| ChangeFileMode(real_path.value(), S_IRWXU); | |||
| std::ofstream ofs(real_path.value()); | |||
| if (!ofs.is_open()) { | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path << "' failed!"; | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!"; | |||
| return; | |||
| } | |||
| @@ -1222,23 +1213,18 @@ void Somas::DumpSomasMemoryIR(const string filename) { | |||
| MS_LOG(ERROR) << "File path " << filename << " is too long."; | |||
| return; | |||
| } | |||
| char real_path[PATH_MAX] = {0}; | |||
| #if defined(_WIN32) || defined(_WIN64) | |||
| if (_fullpath(real_path, filename.c_str(), PATH_MAX) == nullptr) { | |||
| MS_LOG(DEBUG) << "dir " << filename << " does not exit."; | |||
| } | |||
| #else | |||
| if (realpath(filename.c_str(), real_path) == nullptr) { | |||
| MS_LOG(DEBUG) << "Dir " << filename << " does not exit."; | |||
| auto real_path = Common::GetRealPath(filename); | |||
| if (!real_path.has_value()) { | |||
| MS_LOG(ERROR) << "Get real path failed. path=" << filename; | |||
| return; | |||
| } | |||
| #endif | |||
| std::string path_string = real_path; | |||
| ChangeFileMode(path_string, S_IRWXU); | |||
| std::ofstream ofs(real_path); | |||
| ChangeFileMode(real_path.value(), S_IRWXU); | |||
| std::ofstream ofs(real_path.value()); | |||
| if (!ofs.is_open()) { | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path << "' failed!"; | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!"; | |||
| return; | |||
| } | |||
| @@ -1344,23 +1330,18 @@ void Somas::DumpSomasMemoryPoolInfoIR(const string filename) { | |||
| MS_LOG(ERROR) << "File path " << filename << " is too long."; | |||
| return; | |||
| } | |||
| char real_path[PATH_MAX] = {0}; | |||
| #if defined(_WIN32) || defined(_WIN64) | |||
| if (_fullpath(real_path, filename.c_str(), PATH_MAX) == nullptr) { | |||
| MS_LOG(DEBUG) << "dir " << filename << " does not exit."; | |||
| } | |||
| #else | |||
| if (realpath(filename.c_str(), real_path) == nullptr) { | |||
| MS_LOG(DEBUG) << "Dir " << filename << " does not exit."; | |||
| auto real_path = Common::GetRealPath(filename); | |||
| if (!real_path.has_value()) { | |||
| MS_LOG(ERROR) << "Get real path failed. path=" << filename; | |||
| return; | |||
| } | |||
| #endif | |||
| std::string path_string = real_path; | |||
| ChangeFileMode(path_string, S_IRWXU); | |||
| std::ofstream ofs(real_path); | |||
| ChangeFileMode(real_path.value(), S_IRWXU); | |||
| std::ofstream ofs(real_path.value()); | |||
| if (!ofs.is_open()) { | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path << "' failed!"; | |||
| MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!"; | |||
| return; | |||
| } | |||
| @@ -1514,6 +1495,5 @@ uint8_t *Somas::GetNodeWorkSpacePtr(const AnfNodePtr &node, size_t index) const | |||
| } | |||
| return ptr; | |||
| } | |||
| } // namespace somas | |||
| } // namespace mindspore | |||
| @@ -79,7 +79,7 @@ class Somas { | |||
| std::vector<vector<size_t>> ref_overlap_constraints_; | |||
| // total Offset | |||
| size_t mem_offset_; | |||
| size_t mem_offset_{0}; | |||
| // Memory base addr | |||
| uint8_t *mem_base_addr_{nullptr}; | |||
| @@ -30,9 +30,8 @@ void SomasNode::ComputeAncestorNodes() { | |||
| this->anc_stream_max_order_[ancestorId] = std::max(this->anc_stream_max_order_[ancestorId], node->GetId()); | |||
| } | |||
| for (SomasStreamPtr stream : node->GetStream()->ancestor_streams_) { | |||
| int64_t streamId = stream->GetId(); | |||
| this->anc_stream_max_order_[streamId] = | |||
| std::max(this->anc_stream_max_order_[streamId], node->anc_stream_max_order_[streamId]); | |||
| this->anc_stream_max_order_[stream->GetId()] = | |||
| std::max(this->anc_stream_max_order_[stream->GetId()], node->anc_stream_max_order_[stream->GetId()]); | |||
| } | |||
| } | |||
| } | |||
| @@ -100,6 +100,7 @@ bool FootPrint::findFirst(stack<Interval> *merged, const BlockTensor &block, siz | |||
| } | |||
| void FootPrint::Merge(vector<Interval> *interval_v, stack<Interval> *s) { | |||
| MS_EXCEPTION_IF_NULL(s); | |||
| MS_EXCEPTION_IF_NULL(interval_v); | |||
| sort((*interval_v).begin(), (*interval_v).end(), | |||
| [](Interval &i1, Interval &i2) { return (i1.lb() < i2.lb()) || (i1.lb() == i2.lb() && i1.ub() < i2.ub()); }); | |||
| (*s).push((*interval_v)[0]); | |||
| @@ -199,9 +200,8 @@ void FootPrint::addElem(BlockTensor *block, const size_t &offset) { | |||
| void FootPrint::printStats() { | |||
| MS_LOG(DEBUG) << "Footprint blocks: " << m_starts_.size() << " \toffset: " << m_offset_; | |||
| } | |||
| bool FastHeuristic::Eval( // unordered_map<size_t, SomasSolverTensorDescPtr> &tensors_m, | |||
| vector<BlockTensor> *block_tensors_v, std::shared_ptr<FootPrint> foot_print, | |||
| const std::shared_ptr<Array> &pConstraints) { | |||
| bool FastHeuristic::Eval(vector<BlockTensor> *block_tensors_v, std::shared_ptr<FootPrint> foot_print, | |||
| const std::shared_ptr<Array> &pConstraints) { | |||
| MS_EXCEPTION_IF_NULL(foot_print); | |||
| auto start = std::chrono::system_clock::now(); | |||
| @@ -53,6 +53,10 @@ class Interval { | |||
| m_a_ = a; | |||
| m_b_ = b; | |||
| } | |||
| ~Interval() = default; | |||
| size_t m_a_; | |||
| size_t m_b_; | |||
| bool intersect(const Interval &i) { return (in(i.m_a_) || in(i.m_b_)); } | |||
| bool in(const size_t &a) { return ((a > m_a_) && (a < m_b_)); } | |||
| Interval intersection(const Interval &i) { | |||
| @@ -74,10 +78,6 @@ class Interval { | |||
| m_b_ = in.m_b_; | |||
| return *this; | |||
| } | |||
| private: | |||
| size_t m_a_; | |||
| size_t m_b_; | |||
| }; | |||
| class BlockTensor { | |||
| @@ -97,6 +97,7 @@ class BlockTensor { | |||
| m_bre_allocate_(true), | |||
| offsets_(), | |||
| m_size_(0) {} | |||
| ~BlockTensor() = default; | |||
| BlockTensor &operator=(const BlockTensor &bt) { | |||
| m_bre_allocate_ = bt.m_bre_allocate_; | |||
| @@ -121,14 +122,16 @@ class BlockTensor { | |||
| class FootPrint : public std::enable_shared_from_this<FootPrint> { | |||
| public: | |||
| uint32_t m_solId_; | |||
| std::shared_ptr<FootPrint> m_foot_print_next_; | |||
| FootPrint() | |||
| : m_offset_(0), | |||
| m_starts_(), | |||
| m_foot_print_next_(NULL), | |||
| : m_foot_print_next_(NULL), | |||
| m_offset_(0), | |||
| m_starts_({}), | |||
| m_alignment_(0), | |||
| m_branching_strategy_(0), | |||
| m_algorithm_(0) {} | |||
| ~FootPrint() = default; | |||
| void setAlignment(const size_t a) { m_alignment_ = a; } | |||
| void setBranchingStrategy(uint32_t bs) { m_branching_strategy_ = bs; } | |||
| void setCurrentSol(uint32_t solId) { m_solId_ = solId; } | |||
| @@ -151,7 +154,6 @@ class FootPrint : public std::enable_shared_from_this<FootPrint> { | |||
| private: | |||
| size_t m_offset_; | |||
| vector<BlockTensor *> m_starts_; | |||
| std::shared_ptr<FootPrint> m_foot_print_next_; | |||
| size_t m_alignment_; | |||
| uint32_t m_branching_strategy_; | |||
| uint32_t m_algorithm_; | |||
| @@ -160,12 +162,12 @@ class FootPrint : public std::enable_shared_from_this<FootPrint> { | |||
| class FastHeuristic { | |||
| public: | |||
| FastHeuristic() : m_alignment_(512), m_tensors_allocated_(0) {} | |||
| ~FastHeuristic() = default; | |||
| void setAlignment(const size_t &a) { m_alignment_ = a; } | |||
| void Destroy(); | |||
| bool Eval( // unordered_map<size_t, SomasSolverTensorDescPtr> &tensors_m, | |||
| vector<BlockTensor> *block_tensors_v, std::shared_ptr<FootPrint> foot_print, | |||
| const std::shared_ptr<Array> &pConstraints); | |||
| bool Eval(vector<BlockTensor> *block_tensors_v, std::shared_ptr<FootPrint> foot_print, | |||
| const std::shared_ptr<Array> &pConstraints); | |||
| private: | |||
| size_t m_alignment_; | |||
| @@ -42,6 +42,8 @@ class SomasSolverCore { | |||
| verify_(false), | |||
| all_(true), | |||
| best_sol_(0), | |||
| best_sort_(kGreaterSizeSmallerIndex), | |||
| best_branching_(kBest), | |||
| sort_strategy_(kGreaterSizeSmallerIndex), | |||
| branching_strategy_(kBest), | |||
| sol_count_(0), | |||
| @@ -33,13 +33,12 @@ Status SomasSolverPre::Solving(const session::KernelGraph *graph, | |||
| Status retval = SUCCESS; | |||
| try { | |||
| size_t maxIndex = 0; | |||
| std::unordered_map<size_t, SomasSolverTensorDescPtr> &tensors = *ptensors; | |||
| std::unordered_map<size_t, SomasSolverTensorDescPtr>::iterator max = | |||
| std::max_element(tensors.begin(), tensors.end(), | |||
| [](const std::pair<size_t, SomasSolverTensorDescPtr> &a, | |||
| const std::pair<size_t, SomasSolverTensorDescPtr> &b) { return a.first < b.first; }); | |||
| maxIndex = max->first; | |||
| size_t maxIndex = max->first; | |||
| if (maxIndex > pConstraints->Rows() - 1) { | |||
| MS_LOG(WARNING) << "ERROR: MaxIndex invalid, MaxIndex " << maxIndex << ", Rows " << pConstraints->Rows(); | |||
| return FAILED; | |||
| @@ -475,7 +475,7 @@ DeviceAddressPtr KernelRuntime::PreAssignCNodeMemory(const AnfNodePtr &anf_node, | |||
| } | |||
| auto cnode = anf_node->cast<CNodePtr>(); | |||
| if (opt::IsNopNode(cnode)) { | |||
| size_t kNopNodeInputSize = 2; | |||
| const size_t kNopNodeInputSize = 2; | |||
| if (cnode->size() != kNopNodeInputSize) { | |||
| MS_LOG(EXCEPTION) << cnode->fullname_with_scope() << " has invalid input size: " << cnode->size(); | |||
| } | |||