Browse Source

!15242 fix: random_device() failed in some situation

From: @jonyguo
Reviewed-by: @heleiwang,@liucunwei
Signed-off-by: @liucunwei
pull/15242/MERGE
mindspore-ci-bot Gitee 4 years ago
parent
commit
09a57fc33b
3 changed files with 8 additions and 4 deletions
  1. +3
    -0
      mindspore/ccsrc/minddata/dataset/util/random.h
  2. +3
    -2
      mindspore/ccsrc/minddata/mindrecord/io/shard_writer.cc
  3. +2
    -2
      mindspore/ccsrc/minddata/mindrecord/meta/shard_task.cc

+ 3
- 0
mindspore/ccsrc/minddata/dataset/util/random.h View File

@@ -17,6 +17,9 @@
#define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_RANDOM_H_

#if defined(_WIN32) || defined(_WIN64)
#ifndef _CRT_RAND_S
#define _CRT_RAND_S
#endif
#include <stdlib.h>
#endif
#include <chrono>


+ 3
- 2
mindspore/ccsrc/minddata/mindrecord/io/shard_writer.cc View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "minddata/dataset/util/random.h"
#include "minddata/mindrecord/include/shard_writer.h"
#include "utils/ms_utils.h"
#include "minddata/mindrecord/include/common/shard_utils.h"
@@ -1156,8 +1157,8 @@ std::vector<std::pair<int, int>> ShardWriter::BreakIntoShards() {

std::vector<int> v_list(shard_count_);
std::iota(v_list.begin(), v_list.end(), 0);
std::random_device rd;
std::mt19937 g(rd());
std::mt19937 g = mindspore::dataset::GetRandomDevice();
std::shuffle(v_list.begin(), v_list.end(), g);
std::unordered_set<int> set(v_list.begin(), v_list.begin() + remains);



+ 2
- 2
mindspore/ccsrc/minddata/mindrecord/meta/shard_task.cc View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "minddata/dataset/util/random.h"
#include "minddata/mindrecord/include/shard_task.h"
#include "utils/ms_utils.h"
#include "minddata/mindrecord/include/common/shard_utils.h"
@@ -65,8 +66,7 @@ std::tuple<TaskType, std::tuple<int, int>, std::vector<uint64_t>, json> &ShardTa
}

std::tuple<TaskType, std::tuple<int, int>, std::vector<uint64_t>, json> &ShardTask::GetRandomTask() {
std::random_device rd;
std::mt19937 gen(rd());
std::mt19937 gen = mindspore::dataset::GetRandomDevice();
std::uniform_int_distribution<> dis(0, task_list_.size() - 1);
return task_list_[dis(gen)];
}


Loading…
Cancel
Save