Browse Source

repair code check problem

tags/v1.3.0
ms_yan 4 years ago
parent
commit
ee88785b9e
5 changed files with 38 additions and 70 deletions
  1. +31
    -55
      mindspore/ccsrc/minddata/dataset/engine/perf/cpu_sampling.cc
  2. +2
    -6
      mindspore/ccsrc/minddata/dataset/engine/perf/cpu_sampling.h
  3. +2
    -3
      mindspore/dataset/engine/datasets.py
  4. +3
    -4
      mindspore/dataset/engine/validators.py
  5. +0
    -2
      mindspore/mindrecord/tools/tfrecord_to_mr.py

+ 31
- 55
mindspore/ccsrc/minddata/dataset/engine/perf/cpu_sampling.cc View File

@@ -17,8 +17,8 @@
#if !defined(_WIN32) && !defined(_WIN64) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__)
#include <sys/syscall.h>
#endif
#include <math.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <memory>
@@ -49,6 +49,26 @@ BaseCpu::BaseCpu() {
cpu_processor_num_ = 0;
}

Status BaseCpu::GetTotalCpuTime(uint64_t *total_stat) {
std::ifstream file("/proc/stat");
if (!file.is_open()) {
MS_LOG(INFO) << "Open CPU file failed when collect CPU information";
return Status::OK();
}
std::string str;
getline(file, str);
uint64_t user = 0, sys = 0, idle = 0, iowait = 0, nice = 0, irq = 0, softirq = 0;
if (sscanf_s(str.c_str(), "%*s %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &sys, &idle, &iowait, &irq, &softirq) ==
EOF) {
file.close();
return Status(StatusCode::kMDUnexpectedError, "Get device CPU failed.");
}
file.close();
*total_stat = user + nice + sys + idle + iowait + irq + softirq;

return Status::OK();
}

Status DeviceCpu::ParseCpuInfo(const std::string &str) {
CpuStat cpu_stat;
uint64_t nice = 0;
@@ -64,18 +84,14 @@ Status DeviceCpu::ParseCpuInfo(const std::string &str) {
// Calculate the utilization from the second sampling
if (!first_collect_) {
CpuUtil info;
info.user_utilization_ = floor((cpu_stat.user_stat_ - pre_cpu_stat_.user_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100 +
0.5);
info.sys_utilization_ = floor((cpu_stat.sys_stat_ - pre_cpu_stat_.sys_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100 +
0.5);
info.io_utilization_ = floor((cpu_stat.io_stat_ - pre_cpu_stat_.io_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100 +
0.5);
info.idle_utilization_ = floor((cpu_stat.idle_stat_ - pre_cpu_stat_.idle_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100 +
0.5);
info.user_utilization_ = round((cpu_stat.user_stat_ - pre_cpu_stat_.user_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100);
info.sys_utilization_ = round((cpu_stat.sys_stat_ - pre_cpu_stat_.sys_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100);
info.io_utilization_ = round((cpu_stat.io_stat_ - pre_cpu_stat_.io_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100);
info.idle_utilization_ = round((cpu_stat.idle_stat_ - pre_cpu_stat_.idle_stat_) * 1.0 /
(cpu_stat.total_stat_ - pre_cpu_stat_.total_stat_) * 100);
cpu_util_.emplace_back(info);
}
pre_cpu_stat_.user_stat_ = cpu_stat.user_stat_;
@@ -237,26 +253,6 @@ Status OperatorCpu::ParseCpuInfo(int32_t op_id, int64_t thread_id,
return Status::OK();
}

Status OperatorCpu::GetTotalCpuTime(uint64_t *total_stat) {
std::ifstream file("/proc/stat");
if (!file.is_open()) {
MS_LOG(INFO) << "Open CPU file failed when collect CPU information";
return Status::OK();
}
std::string str;
getline(file, str);
uint64_t user = 0, sys = 0, idle = 0, iowait = 0, nice = 0, irq = 0, softirq = 0;
if (sscanf_s(str.c_str(), "%*s %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &sys, &idle, &iowait, &irq, &softirq) ==
EOF) {
file.close();
return Status(StatusCode::kMDUnexpectedError, "Get device CPU failed.");
}
file.close();
*total_stat = user + nice + sys + idle + iowait + irq + softirq;

return Status::OK();
}

Status OperatorCpu::Collect(const ExecutionTree *tree) {
if (first_collect_) {
for (auto iter = tree->begin(); iter != tree->end(); ++iter) {
@@ -340,9 +336,9 @@ Status OperatorCpu::Collect(const ExecutionTree *tree) {
// mainly obtain the init CPU execute time in first collect
for (auto iter = op_thread.begin(); iter != op_thread.end(); iter++) {
int32_t op_id = iter->first;
for (auto thread_id : iter->second) {
for (auto thread_id_ : iter->second) {
// ignore errors in the first collect
(void)ParseCpuInfo(op_id, thread_id, &op_stat_);
(void)ParseCpuInfo(op_id, thread_id_, &op_stat_);
}
}
}
@@ -483,26 +479,6 @@ Status ProcessCpu::ParseCpuInfo() {
return Status::OK();
}

Status ProcessCpu::GetTotalCpuTime(uint64_t *total_stat) {
std::ifstream file("/proc/stat");
if (!file.is_open()) {
MS_LOG(INFO) << "Open CPU file failed when collect CPU information";
return Status::OK();
}
std::string str;
getline(file, str);
uint64_t user = 0, sys = 0, idle = 0, iowait = 0, nice = 0, irq = 0, softirq = 0;
if (sscanf_s(str.c_str(), "%*s %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &sys, &idle, &iowait, &irq, &softirq) ==
EOF) {
file.close();
return Status(StatusCode::kMDUnexpectedError, "Get device CPU failed.");
}
file.close();
*total_stat = user + nice + sys + idle + iowait + irq + softirq;

return Status::OK();
}

Status ProcessCpu::Collect(const ExecutionTree *tree) {
if (first_collect_) {
#if defined(USING_LINUX)


+ 2
- 6
mindspore/ccsrc/minddata/dataset/engine/perf/cpu_sampling.h View File

@@ -72,6 +72,8 @@ class BaseCpu {
virtual Status Collect(const ExecutionTree *tree) = 0;
virtual Status SaveToFile(const std::string &file_path) = 0;
virtual Status Analyze(std::string *name, double *utilization, std::string *extra_message) = 0;
// Get the total CPU time of device
Status GetTotalCpuTime(uint64_t *total_stat);

protected:
std::vector<CpuUtil> cpu_util_;
@@ -128,9 +130,6 @@ class OperatorCpu : public BaseCpu {
Status ParseCpuInfo(int32_t op_id, int64_t thread_id,
std::unordered_map<int32_t, std::unordered_map<int64_t, CpuOpStat>> *op_stat);

// Get the total CPU time of device
Status GetTotalCpuTime(uint64_t *total_stat);

// Store the CPU utilization of each operator
std::vector<std::vector<CpuOpUtil>> cpu_op_util_;

@@ -158,9 +157,6 @@ class ProcessCpu : public BaseCpu {
// Get CPU information, include use/sys/idle/io utilization
Status ParseCpuInfo();

// Get the total CPU time of device
Status GetTotalCpuTime(uint64_t *total_stat);

bool first_collect_;
std::vector<CpuProcessUtil> process_util_;
uint64_t pre_total_stat_;


+ 2
- 3
mindspore/dataset/engine/datasets.py View File

@@ -266,9 +266,8 @@ class Dataset:
for d in item.children:
temp.append(d)
op_name[str(d)] = operator_id
if isinstance(d, GeneratorDataset) and d.sample_fn:
if d.sample_fn.pid:
generator_process[operator_id] = [d.num_parallel_workers, set(d.sample_fn.pid)]
if isinstance(d, GeneratorDataset) and d.sample_fn and d.sample_fn.pid:
generator_process[operator_id] = [d.num_parallel_workers, set(d.sample_fn.pid)]

operator_id = operator_id + 1
return process_name(temp, operator_id)


+ 3
- 4
mindspore/dataset/engine/validators.py View File

@@ -456,7 +456,8 @@ def check_pad_info(key, val):
type_check(key, (str,), "key in pad_info")

if val is not None:
assert len(val) == 2, "value of pad_info should be a tuple of size 2."
if len(val) != 2:
raise ValueError("value of pad_info should be a tuple of size 2.")
type_check(val, (tuple,), "value in pad_info")

if val[0] is not None:
@@ -464,9 +465,7 @@ def check_pad_info(key, val):

for dim in val[0]:
if dim is not None:
type_check(dim, (int,), "dim in pad_shape")
if dim <= 0:
raise ValueError("pad shape should be positive integers")
check_pos_int32(dim, "dim in pad_shape")
if val[1] is not None:
type_check(val[1], (int, float, str, bytes), "pad_value")



+ 0
- 2
mindspore/mindrecord/tools/tfrecord_to_mr.py View File

@@ -342,8 +342,6 @@ class TFRecordToMR:
self.tf.float64: "float64",
self.tf.double: "float64",
self.tf.bool: "int32"}
unsupport_tf_type_to_mr_type = {self.tf.complex64: "None",
self.tf.complex128: "None"}

if value in tf_type_to_mr_type:
return tf_type_to_mr_type[value]


Loading…
Cancel
Save