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.

option_manager.h 2.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * \file imperative/src/impl/interpreter/option_manager.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #pragma once
  12. #include <string>
  13. #include <unordered_map>
  14. #include "megbrain/common.h"
  15. namespace mgb::imperative::interpreter::intl {
  16. struct OptionManager {
  17. private:
  18. std::unordered_map<std::string, size_t*> m_option_map = {};
  19. public:
  20. #define DEF_OPTION(name, env_key, default_value, desc) \
  21. size_t name = (m_option_map[#name]=&name, get_option_from_env(env_key, default_value));
  22. DEF_OPTION(async_level, "MEGENGINE_INTERP_ASYNC_LEVEL", 2,
  23. "config whether raise error exactly when invoking op.\n"
  24. "level 2: both device and user side errors are async;\n"
  25. "level 1: user side errors are sync;\n"
  26. "level 0: both sync.");
  27. DEF_OPTION(enable_swap, "MEGENGINE_ENABLE_SWAP", 0, "");
  28. DEF_OPTION(enable_drop, "MEGENGINE_ENABLE_DROP", 0, "");
  29. DEF_OPTION(max_recompute_time, "MEGENGINE_MAX_RECOMP_TIME", 1, "");
  30. DEF_OPTION(catch_worker_execption, "MEGENGINE_CATCH_WORKER_EXEC", 1,
  31. "catch worker exception if enabled, close it when debugging");
  32. DEF_OPTION(buffer_length, "MEGENGINE_COMMAND_BUFFER_LENGTH", 3,
  33. "set command buffer length.");
  34. DEF_OPTION(enable_host_compute, "MEGENGINE_HOST_COMPUTE", 1,
  35. "enable host compute, thus computation may be done in host event if it's device is gpu.");
  36. DEF_OPTION(enable_auto_drop, "MEGENGINE_AUTO_DROP", 0, "");
  37. DEF_OPTION(memory_budget, "MEGENGINE_MEMORY_BUDGET", 0,
  38. "auto drop will start whenever gpu memory usage exceeds this value.");
  39. DEF_OPTION(tensor_lowerbound, "MEGENGINE_TENSOR_LOWERBOUND", 1048576,
  40. "the minimum memory value of a tensor added to the candidate set");
  41. DEF_OPTION(record_computing_path, "MEGENGINE_RECORD_COMPUTING_PATH", 0, "");
  42. #undef DEF_OPTION
  43. void set_option(const std::string& name, size_t value) {
  44. *m_option_map[name] = value;
  45. }
  46. size_t get_option(const std::string& name) const {
  47. return *m_option_map.at(name);
  48. }
  49. static size_t get_option_from_env(const std::string& name, size_t default_value) {
  50. if (const char* env_val = MGB_GETENV(name.c_str())) {
  51. sscanf(env_val, "%zu", &default_value);
  52. }
  53. return default_value;
  54. }
  55. };
  56. }

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