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.

debug_param.py 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  5. #
  6. # Unless required by applicable law or agreed to in writing,
  7. # software distributed under the License is distributed on an
  8. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. import os
  10. from ..logger import get_logger
  11. from ..utils.deprecation import deprecated
  12. _execution_strategy = os.getenv("MEGENGINE_EXECUTION_STRATEGY", "HEURISTIC")
  13. if os.getenv("MEGENGINE_CONV_EXECUTION_STRATEGY") != None:
  14. get_logger().warning(
  15. "Environment variable `MEGENGINE_CONV_EXECUTION_STRATEGY` is deprecated, please use `MEGENGINE_EXECUTION_STRATEGY`"
  16. )
  17. def get_execution_strategy() -> str:
  18. """
  19. Returns the execution strategy of :class:`~.Conv2d` and :func:'~.matmul'
  20. See :func:`~.set_execution_strategy` for possible return values
  21. """
  22. return _execution_strategy
  23. def set_execution_strategy(option: str):
  24. """
  25. Sets the execution strategy of :class:`~.Conv2d` and :func:'~.matmul'
  26. :param option: Decides how :class:`~.Conv2d` and :func:'~.matmul' algorithms are chosen.
  27. Available values:
  28. * 'HEURISTIC' uses heuristic to choose the fastest algorithm.
  29. * 'PROFILE' runs possible algorithms on real device to find the best one.
  30. * 'PROFILE_HEURISTIC' uses profiling result and heuristic to choose the fastest algorithm.
  31. * 'PROFILE_REPRODUCIBLE' uses the fastest of profiling result that is also reproducible.
  32. * 'HEURISTIC_REPRODUCIBLE' uses heuristic to choose the fastest algorithm that is also reproducible.
  33. The default strategy is 'HEURISTIC'.
  34. It can also be set through the environment variable 'MEGENGINE_EXECUTION_STRATEGY'.
  35. """
  36. valid_option = (
  37. "HEURISTIC",
  38. "PROFILE",
  39. "PROFILE_HEURISTIC",
  40. "PROFILE_REPRODUCIBLE",
  41. "HEURISTIC_REPRODUCIBLE",
  42. )
  43. if not option in valid_option:
  44. raise ValueError("Valid option can only be one of {}".format(valid_option))
  45. global _execution_strategy # pylint: disable=global-statement
  46. _execution_strategy = option
  47. @deprecated(version="1.3", reason="use get_execution_strategy() instead")
  48. def get_conv_execution_strategy() -> str:
  49. return get_execution_strategy()
  50. @deprecated(version="1.3", reason="use set_execution_strategy() instead")
  51. def set_conv_execution_strategy(option: str):
  52. return set_execution_strategy(option)

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