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

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

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