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.

handle.cpp 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * \file dnn/src/cambricon/handle.cpp
  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. #include "src/common/handle_impl.h"
  12. #include "src/common/version_symbol.h"
  13. #include "src/cambricon/handle.h"
  14. #include "src/cambricon/utils.h"
  15. #include <cnrt.h>
  16. #include "src/cambricon/checksum/opr_impl.h"
  17. namespace megdnn {
  18. namespace cambricon {
  19. HandleImpl::HandleImpl(megcoreComputingHandle_t comp_handle)
  20. : HandleImplHelper(comp_handle, HandleType::CAMBRICON) {
  21. // Get megcore device handle
  22. megcoreDeviceHandle_t dev_handle;
  23. megcoreGetDeviceHandle(comp_handle, &dev_handle);
  24. int dev_id;
  25. megcoreGetDeviceID(dev_handle, &dev_id);
  26. unsigned int dev_num;
  27. cnrt_check(cnrtGetDeviceCount(&dev_num));
  28. MEGDNN_MARK_USED_VAR(dev_num);
  29. // check validity of device_id
  30. megdnn_assert(dev_id >= 0 && static_cast<unsigned int>(dev_id) < dev_num);
  31. m_device_id = dev_id;
  32. cnrt_check(cnrtGetDeviceInfo(&m_device_info, dev_id));
  33. megcore::getCambriconContext(comp_handle, &m_megcore_context);
  34. }
  35. HandleImpl::~HandleImpl() noexcept = default;
  36. template <typename Opr>
  37. std::unique_ptr<Opr> HandleImpl::create_operator() {
  38. megdnn_throw("unsupported cambricon opr");
  39. return nullptr;
  40. }
  41. size_t HandleImpl::alignment_requirement() const {
  42. return 1;
  43. }
  44. MEGDNN_SPECIALIZE_CREATE_OPERATOR(ChecksumForward);
  45. #pragma GCC diagnostic push
  46. #pragma GCC diagnostic ignored "-Wpragmas"
  47. #pragma GCC diagnostic ignored "-Winstantiation-after-specialization"
  48. MEGDNN_FOREACH_OPR_CLASS(MEGDNN_INST_CREATE_OPERATOR)
  49. #pragma GCC diagnostic pop
  50. } // namespace cambricon
  51. } // namespace megdnn
  52. MEGDNN_VERSION_SYMBOL3(
  53. CNRT, CNRT_MAJOR_VERSION, CNRT_MINOR_VERSION, CNRT_PATCH_VERSION);
  54. // vim: syntax=cpp.doxygen

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