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

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

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