forked from mindspore-Ecosystem/mindspore
!17919 change somas log file mode to 400
From: @laiyongqiang Reviewed-by: @yuchaojie,@zhoufeng54 Signed-off-by: @zhoufeng54
This commit is contained in:
commit
32afa49ed8
|
@ -131,12 +131,7 @@ bool Somas::CalcSomasModelHash(const session::KernelGraph *graph) {
|
|||
MS_LOG(INFO) << "Graph " << graph->graph_id() << "'s SOMAS Model hash id is " << hash_id_;
|
||||
std::string filename =
|
||||
save_graphs_path_ + "/somas_meta/" + "somas_graph" + std::to_string(graph->graph_id()) + "_" + hash_id_ + ".info";
|
||||
std::ofstream ofs;
|
||||
if (Common::OpenFile(filename, ofs)) {
|
||||
ofs << model_str << std::endl;
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
Common::SaveStringToFile(filename, model_str);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -167,11 +162,7 @@ bool Somas::SaveSomasResult(const session::KernelGraph *graph) {
|
|||
|
||||
std::string filename =
|
||||
save_graphs_path_ + "/somas_meta/" + "somas_graph" + std::to_string(graph->graph_id()) + "_" + hash_id_ + ".json";
|
||||
std::ofstream ofs;
|
||||
if (Common::OpenFile(filename, ofs)) {
|
||||
ofs << somas_json.dump() << std::endl;
|
||||
ofs.close();
|
||||
}
|
||||
Common::SaveStringToFile(filename, somas_json.dump());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1483,13 +1474,7 @@ void Somas::DumpParameters(std::ostringstream &oss) const {
|
|||
}
|
||||
}
|
||||
|
||||
void Somas::DumpSomasInfoIR(const string filename) const {
|
||||
std::ofstream ofs;
|
||||
if (Common::OpenFile(filename, ofs)) {
|
||||
ofs << SomasInfo();
|
||||
ofs.close();
|
||||
}
|
||||
}
|
||||
void Somas::DumpSomasInfoIR(const string filename) const { Common::SaveStringToFile(filename, SomasInfo()); }
|
||||
|
||||
std::string Somas::Offline() const {
|
||||
std::ostringstream oss;
|
||||
|
@ -1537,11 +1522,7 @@ std::string Somas::Offline() const {
|
|||
|
||||
void Somas::DumpOfflineIR(const string filename) const {
|
||||
MS_LOG(INFO) << "Printing somas-log-from-graph log: " << filename;
|
||||
std::ofstream ofs;
|
||||
if (Common::OpenFile(filename, ofs)) {
|
||||
ofs << Offline();
|
||||
ofs.close();
|
||||
}
|
||||
Common::SaveStringToFile(filename, Offline());
|
||||
}
|
||||
|
||||
std::string Somas::SomasMemory() const {
|
||||
|
@ -1611,13 +1592,7 @@ std::string Somas::SomasMemory() const {
|
|||
return oss.str();
|
||||
}
|
||||
|
||||
void Somas::DumpSomasMemoryIR(const string filename) const {
|
||||
std::ofstream ofs;
|
||||
if (Common::OpenFile(filename, ofs)) {
|
||||
ofs << SomasMemory();
|
||||
ofs.close();
|
||||
}
|
||||
}
|
||||
void Somas::DumpSomasMemoryIR(const string filename) const { Common::SaveStringToFile(filename, SomasMemory()); }
|
||||
|
||||
size_t Somas::CalcLowerBound() const {
|
||||
size_t max_node_id = std::accumulate(tensors_list_.begin(), tensors_list_.end(), 0, [](size_t max_id, auto tensor) {
|
||||
|
|
|
@ -51,7 +51,7 @@ size_t FootPrint::Result() {
|
|||
std::shared_ptr<FootPrint> foot_print = shared_from_this();
|
||||
size_t upperbound = 0;
|
||||
uint32_t total_footprints = 0;
|
||||
while (foot_print != NULL) {
|
||||
while (foot_print != nullptr) {
|
||||
foot_print->printStats();
|
||||
|
||||
upperbound = foot_print->getOffset();
|
||||
|
@ -136,7 +136,7 @@ bool FootPrint::findOffset(const std::vector<DynamicBitSet> *constraints, const
|
|||
}
|
||||
for (size_t i = 0; i < m_starts_.size(); i++) {
|
||||
auto allocated_tensor = m_starts_[i]->m_start_tensor_;
|
||||
while (allocated_tensor != NULL) {
|
||||
while (allocated_tensor != nullptr) {
|
||||
if ((*constraints)[block.m_start_tensor_->index_].IsBitTrue(allocated_tensor->index_) == false) {
|
||||
l_interval.emplace_back(Interval(allocated_tensor));
|
||||
}
|
||||
|
@ -147,11 +147,11 @@ bool FootPrint::findOffset(const std::vector<DynamicBitSet> *constraints, const
|
|||
int64_t start_offset = static_cast<int64_t>(m_offset_);
|
||||
for (size_t i = 0; i < m_starts_.size(); i++) {
|
||||
auto allocated_tensor = m_starts_[i]->m_start_tensor_;
|
||||
while (allocated_tensor != NULL) {
|
||||
while (allocated_tensor != nullptr) {
|
||||
int64_t allocated_offset = static_cast<int64_t>(allocated_tensor->offset_);
|
||||
int64_t allocated_size = static_cast<int64_t>(allocated_tensor->size_);
|
||||
int64_t accumulator = 0;
|
||||
for (auto block_tensor = block.m_start_tensor_; block_tensor != NULL; block_tensor = block_tensor->right_) {
|
||||
for (auto block_tensor = block.m_start_tensor_; block_tensor != nullptr; block_tensor = block_tensor->right_) {
|
||||
int64_t end_placement = allocated_offset + allocated_size - accumulator;
|
||||
if ((*constraints)[block_tensor->index_].IsBitTrue(allocated_tensor->index_) == false &&
|
||||
end_placement > start_offset) {
|
||||
|
@ -175,7 +175,7 @@ bool FootPrint::findOffset(const std::vector<DynamicBitSet> *constraints, const
|
|||
return bretval;
|
||||
}
|
||||
void FootPrint::addElem(BlockTensor *block, const size_t &offset) {
|
||||
if (m_foot_print_next_ == NULL) {
|
||||
if (m_foot_print_next_ == nullptr) {
|
||||
m_foot_print_next_ = std::make_shared<FootPrint>();
|
||||
size_t newoffset = m_offset_ + block->m_size_;
|
||||
m_foot_print_next_->setOffset(newoffset);
|
||||
|
@ -217,7 +217,7 @@ bool FastHeuristic::Eval(vector<BlockTensor> *block_tensors_v, std::shared_ptr<F
|
|||
uint32_t startscount = 0;
|
||||
size_t offset = foot_print->getOffset();
|
||||
m_tensors_allocated_ = 0;
|
||||
SomasSolverTensorDescPtr tensor = NULL;
|
||||
SomasSolverTensorDescPtr tensor = nullptr;
|
||||
|
||||
for (size_t i = 0; i < (*block_tensors_v).size(); i++) {
|
||||
BlockTensor &block = (*block_tensors_v)[i];
|
||||
|
@ -249,7 +249,7 @@ bool FastHeuristic::Eval(vector<BlockTensor> *block_tensors_v, std::shared_ptr<F
|
|||
break;
|
||||
}
|
||||
// go to the next footprint slot
|
||||
if (p->Next() != NULL) {
|
||||
if (p->Next() != nullptr) {
|
||||
p = p->Next();
|
||||
} else if (bpushed == false) { // something went wrong
|
||||
MS_LOG(WARNING) << "Could not allocate memory for tensor: " << tensor->index_;
|
||||
|
|
|
@ -91,7 +91,7 @@ class BlockTensor {
|
|||
unordered_map<uint32_t, size_t> offsets_;
|
||||
size_t m_size_;
|
||||
BlockTensor()
|
||||
: m_start_tensor_(NULL),
|
||||
: m_start_tensor_(nullptr),
|
||||
offsets_candidates_(),
|
||||
m_current_sol_(0),
|
||||
m_bre_allocate_(true),
|
||||
|
@ -108,7 +108,7 @@ class BlockTensor {
|
|||
m_size_ = bt.m_size_;
|
||||
return *this;
|
||||
}
|
||||
bool Alone() const { return ((NULL == m_start_tensor_->right_) && (NULL == m_start_tensor_->left_)); }
|
||||
bool Alone() const { return ((nullptr == m_start_tensor_->right_) && (nullptr == m_start_tensor_->left_)); }
|
||||
};
|
||||
|
||||
class FootPrint : public std::enable_shared_from_this<FootPrint> {
|
||||
|
@ -118,7 +118,7 @@ class FootPrint : public std::enable_shared_from_this<FootPrint> {
|
|||
|
||||
FootPrint()
|
||||
: m_solId_(0),
|
||||
m_foot_print_next_(NULL),
|
||||
m_foot_print_next_(nullptr),
|
||||
m_offset_(0),
|
||||
m_starts_({}),
|
||||
m_alignment_(0),
|
||||
|
|
|
@ -206,7 +206,7 @@ void SomasSolverCore::BuildBlocks() {
|
|||
pTensor->blocked_ = true;
|
||||
pTensor = pTensor->right_;
|
||||
tensors_block_count++;
|
||||
} while (pTensor != NULL);
|
||||
} while (pTensor != nullptr);
|
||||
|
||||
// add to the list
|
||||
this->block_tensors_.emplace_back(bTensor);
|
||||
|
@ -355,13 +355,13 @@ size_t SomasSolverCore::FindSolutions() {
|
|||
}
|
||||
|
||||
void SomasSolverCore::Destroy(std::shared_ptr<FootPrint> &pFootprint) {
|
||||
while (pFootprint != NULL) {
|
||||
if (pFootprint->Next() != NULL) {
|
||||
while (pFootprint != nullptr) {
|
||||
if (pFootprint->Next() != nullptr) {
|
||||
std::shared_ptr<FootPrint> &p = pFootprint;
|
||||
pFootprint = pFootprint->Next();
|
||||
p = NULL;
|
||||
p = nullptr;
|
||||
} else {
|
||||
pFootprint = NULL;
|
||||
pFootprint = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,30 +250,28 @@ void SomasSolverPre::SolverInputLog(const session::KernelGraph *graph, const Ten
|
|||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
auto save_graphs_path = context_ptr->get_param<std::string>(MS_CTX_SAVE_GRAPHS_PATH);
|
||||
std::string filename = save_graphs_path + "/" + "somas_solver_input_" + std::to_string(graph->graph_id()) + ".ir";
|
||||
std::ofstream ofs;
|
||||
if (Common::OpenFile(filename, ofs)) {
|
||||
for (auto &t : tensors) {
|
||||
ofs << "T " << t.second->index_ << " " << t.second->size_ << " " << t.second->lifelong_ << std::endl;
|
||||
}
|
||||
|
||||
for (auto &t1 : tensors) {
|
||||
for (auto &t2 : tensors) {
|
||||
size_t idx1 = t1.first;
|
||||
size_t idx2 = t2.first;
|
||||
if ((idx1 != idx2) && (*pConstraints)[idx1].IsBitTrue(idx2) == false) {
|
||||
ofs << "C " << idx1 << " " << idx2 << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &s : continuous_v) {
|
||||
ofs << "S";
|
||||
for (auto idx : s) {
|
||||
ofs << " " << idx;
|
||||
}
|
||||
ofs << std::endl;
|
||||
}
|
||||
ofs.close();
|
||||
std::ostringstream oss;
|
||||
for (auto &t : tensors) {
|
||||
oss << "T " << t.second->index_ << " " << t.second->size_ << " " << t.second->lifelong_ << std::endl;
|
||||
}
|
||||
|
||||
for (auto &t1 : tensors) {
|
||||
for (auto &t2 : tensors) {
|
||||
size_t idx1 = t1.first;
|
||||
size_t idx2 = t2.first;
|
||||
if ((idx1 != idx2) && (*pConstraints)[idx1].IsBitTrue(idx2) == false) {
|
||||
oss << "C " << idx1 << " " << idx2 << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &s : continuous_v) {
|
||||
oss << "S";
|
||||
for (auto idx : s) {
|
||||
oss << " " << idx;
|
||||
}
|
||||
oss << std::endl;
|
||||
}
|
||||
Common::SaveStringToFile(filename, oss.str());
|
||||
MS_LOG(INFO) << "SomasSolver input Log done";
|
||||
}
|
||||
|
||||
|
|
|
@ -152,8 +152,8 @@ struct SomasSolverTensorDesc {
|
|||
SomasSolverTensorDesc(size_t index, size_t size, size_t offset, bool blifelong)
|
||||
: index_(index), size_(size), offset_(offset), lifelong_(blifelong) {
|
||||
constraints_ = 0;
|
||||
right_ = NULL;
|
||||
left_ = NULL;
|
||||
right_ = nullptr;
|
||||
left_ = nullptr;
|
||||
blocked_ = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ std::string Common::AddId(const std::string &filename, const std::string &suffix
|
|||
return s.str();
|
||||
}
|
||||
|
||||
bool Common::OpenFile(const std::string filename, std::ofstream &ofs) {
|
||||
bool Common::SaveStringToFile(const std::string filename, const std::string string_info) {
|
||||
if (filename.size() > PATH_MAX) {
|
||||
MS_LOG(ERROR) << "File path " << filename << " is too long.";
|
||||
return false;
|
||||
|
@ -301,13 +301,18 @@ bool Common::OpenFile(const std::string filename, std::ofstream &ofs) {
|
|||
return false;
|
||||
}
|
||||
|
||||
ChangeFileMode(real_path.value(), S_IRUSR | S_IWUSR);
|
||||
ChangeFileMode(real_path.value(), S_IRWXU);
|
||||
std::ofstream ofs;
|
||||
ofs.open(real_path.value());
|
||||
|
||||
if (!ofs.is_open()) {
|
||||
MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!";
|
||||
return false;
|
||||
}
|
||||
ofs << string_info << std::endl;
|
||||
ofs.close();
|
||||
// set file mode to read only by user
|
||||
ChangeFileMode(real_path.value(), S_IRUSR);
|
||||
return true;
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -38,7 +38,7 @@ class Common {
|
|||
static bool CreateNotExistDirs(const std::string &path);
|
||||
|
||||
static std::string AddId(const std::string &filename, const std::string &suffix);
|
||||
static bool OpenFile(const std::string filename, std::ofstream &ofs);
|
||||
static bool SaveStringToFile(const std::string filename, const std::string string_info);
|
||||
|
||||
private:
|
||||
static bool IsEveryFilenameValid(const std::string &path, size_t length_limit, const std::string &error_message);
|
||||
|
|
Loading…
Reference in New Issue