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.

query_blocksize.cpp 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * \file dnn/src/cuda/query_blocksize.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 "./query_blocksize.cuh"
  12. #include "src/cuda/utils.h"
  13. #include <mutex>
  14. #include <unordered_map>
  15. using namespace megdnn;
  16. using namespace cuda;
  17. namespace {
  18. size_t hash_pair_combine(size_t x, size_t y) {
  19. return y + 0x9e3779b9 + (x << 6) + (x >> 2);
  20. }
  21. //! stupid committee has no pair hash. Let's do it for them
  22. struct pairhash {
  23. public:
  24. template <typename T, typename U>
  25. size_t operator()(const std::pair<T, U>& x) const {
  26. return hash_pair_combine(std::hash<T>{}(x.first), std::hash<U>{}(x.second));
  27. }
  28. };
  29. } // anonymous namespace
  30. LaunchConfig cuda::query_launch_config_for_kernel(
  31. const void* kern, const SmemGetter& smem) {
  32. static std::mutex mtx;
  33. static std::unordered_map<std::pair<int, const void*>, LaunchConfig, pairhash>
  34. cache;
  35. std::lock_guard<std::mutex> _lock{mtx};
  36. int device = -1;
  37. cuda_check(cudaGetDevice(&device));
  38. auto ins = cache.insert({{device, kern}, LaunchConfig{}});
  39. if (ins.second) {
  40. ins.first->second = detail::query_launch_config_for_kernel_uncached(kern, smem);
  41. }
  42. return ins.first->second;
  43. }
  44. // vim: ft=cpp syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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