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 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2020 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. _conv_execution_strategy = os.getenv("MEGENGINE_CONV_EXECUTION_STRATEGY", "HEURISTIC")
  11. def get_conv_execution_strategy() -> str:
  12. """
  13. Returns the execuation strategy of :class:`~.Conv2d`.
  14. See :func:`~.set_conv_execution_strategy` for possible return values
  15. """
  16. return _conv_execution_strategy
  17. def set_conv_execution_strategy(option: str):
  18. """
  19. Sets the execuation strategy of :class:`~.Conv2d`.
  20. :param option: Decides how :class:`~.Conv2d` algorithm is chosen.
  21. Available values:
  22. * 'HEURISTIC' uses heuristic to choose the fastest algorithm.
  23. * 'PROFILE' runs possible algorithms on real device to find the best one.
  24. * 'PROFILE_HEURISTIC' uses profiling result and heuristic to choose the fastest algorithm.
  25. * 'PROFILE_REPRODUCIBLE' uses the fastest of profiling result that is also reproducible.
  26. * 'HEURISTIC_REPRODUCIBLE' uses heuristic to choose the fastest algorithm that is also reproducible.
  27. The default strategy is 'HEURISTIC'.
  28. It can also be set through the environment variable 'MEGENGINE_CONV_EXECUTION_STRATEGY'.
  29. """
  30. valid_option = (
  31. "HEURISTIC",
  32. "PROFILE",
  33. "PROFILE_HEURISTIC",
  34. "PROFILE_REPRODUCIBLE",
  35. "HEURISTIC_REPRODUCIBLE",
  36. )
  37. if not option in valid_option:
  38. raise ValueError("Valid option can only be one of {}".format(valid_option))
  39. global _conv_execution_strategy # pylint: disable=global-statement
  40. _conv_execution_strategy = option

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