You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rng_seed.cpp 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * \file test/src/rng_seed.cpp
  3. *
  4. * This file is part of MegBrain, a deep learning framework developed by Megvii.
  5. *
  6. * \copyright Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
  7. *
  8. */
  9. #include "./rng_seed.h"
  10. #include "megbrain/common.h"
  11. #include "megbrain/utils/hash.h"
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <ctime>
  15. using namespace mgb;
  16. RNGSeedManager& RNGSeedManager::inst() {
  17. static RNGSeedManager inst;
  18. return inst;
  19. }
  20. RNGSeedManager::RNGSeedManager() {
  21. if (getenv("MGB_STABLE_RNG")) {
  22. mgb_log_warn("use stable rand seed");
  23. m_stable = true;
  24. m_next_seed = 0;
  25. } else {
  26. m_stable = false;
  27. m_next_seed = time(nullptr);
  28. }
  29. }
  30. void RNGSeedManager::OnTestStart(const ::testing::TestInfo& test_info) {
  31. if (m_stable) {
  32. auto cname = test_info.test_case_name(), tname = test_info.name();
  33. m_next_seed = mgb::XXHash{}
  34. .update(cname, strlen(cname))
  35. .update(".", 1)
  36. .update(tname, strlen(tname))
  37. .digest();
  38. }
  39. }
  40. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台