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.

libacl_cblas-wrap.cpp 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * \file dnn/atlas-stub/src/libacl_cblas-wrap.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
  10. * implied.
  11. */
  12. #pragma GCC visibility push(default)
  13. #include <cstdio>
  14. #define LOGE(fmt, v...) fprintf(stderr, "err: " fmt "\n", ##v)
  15. #include "acl/acl.h"
  16. #include "acl/ops/acl_cblas.h"
  17. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  18. #if defined(_WIN32)
  19. #include <windows.h>
  20. #define RTLD_LAZY 0
  21. static void* dlopen(const char* file, int) {
  22. return static_cast<void*>(LoadLibraryA(file));
  23. }
  24. static void* dlerror() {
  25. const char* errmsg = "dlerror not aviable in windows";
  26. return const_cast<char*>(errmsg);
  27. }
  28. static void* dlsym(void* handle, const char* name) {
  29. FARPROC symbol = GetProcAddress((HMODULE)handle, name);
  30. return reinterpret_cast<void*>(symbol);
  31. }
  32. #else
  33. #include <dlfcn.h>
  34. #include <unistd.h>
  35. #endif
  36. static void log_failed_load(int func_idx);
  37. namespace {
  38. template <typename T>
  39. T on_init_failed(int func_idx);
  40. template <>
  41. aclError on_init_failed(int func_idx) {
  42. log_failed_load(func_idx);
  43. return ACL_ERROR_INTERNAL_ERROR;
  44. }
  45. } // namespace
  46. #include "./libacl_cblas-wrap.h"
  47. static const char* default_so_paths[] = {
  48. "/usr/local/Ascend/acllib/lib64/libacl_cblas.so",
  49. "libacl_cblas.so",
  50. };
  51. static void* get_library_handle() {
  52. void* handle = nullptr;
  53. for (size_t i = 0; i < (sizeof(default_so_paths) / sizeof(char*)); i++) {
  54. handle = dlopen(default_so_paths[i], RTLD_LAZY);
  55. if (handle) {
  56. break;
  57. }
  58. }
  59. if (!handle) {
  60. LOGE("Failed to load atlas library");
  61. return nullptr;
  62. }
  63. return handle;
  64. }
  65. static void log_failed_load(int func_idx) {
  66. LOGE("failed to load atlas func: %s", g_func_name[func_idx]);
  67. }
  68. static void* resolve_library_func(void* handle, const char* func) {
  69. if (!handle) {
  70. LOGE("handle should not be nullptr!");
  71. return nullptr;
  72. }
  73. auto ret = dlsym(handle, func);
  74. if (!ret) {
  75. LOGE("failed to load atlas func: %s", func);
  76. }
  77. return ret;
  78. }

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