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.

megcore_rocm.h 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * \file dnn/include/megcore_rocm.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 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 "./megcore.h"
  13. #include "hip_header.h"
  14. #include "megdnn/internal/visibility_prologue.h"
  15. #include <atomic>
  16. namespace megcore {
  17. struct ROCMContext {
  18. hipStream_t stream = nullptr;
  19. static std::atomic_bool sm_miopen_algo_search;
  20. static inline bool enable_miopen_algo_search() {
  21. return sm_miopen_algo_search.load();
  22. }
  23. static inline void enable_miopen_algo_search(bool enable_algo_search) {
  24. sm_miopen_algo_search.store(enable_algo_search);
  25. }
  26. //! device pointer to buffer for error reporting from kernels
  27. AsyncErrorInfo* error_info = nullptr;
  28. ROCMContext() = default;
  29. ROCMContext(hipStream_t s, AsyncErrorInfo* e) : stream{s}, error_info{e} {}
  30. };
  31. megcoreStatus_t createComputingHandleWithROCMContext(
  32. megcoreComputingHandle_t* compHandle, megcoreDeviceHandle_t devHandle,
  33. unsigned int flags, const ROCMContext& ctx);
  34. megcoreStatus_t getROCMContext(megcoreComputingHandle_t handle, ROCMContext* ctx);
  35. // Set MIOpen algo search enabled or disabled
  36. megcoreStatus_t enableMIOpenAlgoSearch(bool enable_algo_search = true);
  37. // Find out whether MIOpen algo search is enabled or disabled
  38. megcoreStatus_t getMIOpenAlgoSearchStatus(bool* algo_search_enabled);
  39. } // namespace megcore
  40. static inline megcoreStatus_t megcoreCreateComputingHandleWithROCMStream(
  41. megcoreComputingHandle_t* compHandle, megcoreDeviceHandle_t devHandle,
  42. unsigned int flags, hipStream_t stream) {
  43. megcore::ROCMContext ctx;
  44. ctx.stream = stream;
  45. return megcore::createComputingHandleWithROCMContext(
  46. compHandle, devHandle, flags, ctx);
  47. }
  48. static inline megcoreStatus_t megcoreGetROCMStream(
  49. megcoreComputingHandle_t handle, hipStream_t* stream) {
  50. megcore::ROCMContext ctx;
  51. auto ret = megcore::getROCMContext(handle, &ctx);
  52. *stream = ctx.stream;
  53. return ret;
  54. }
  55. #include "megdnn/internal/visibility_epilogue.h"
  56. // vim: syntax=cpp.doxygen

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