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.

profiling_based_solver.cpp 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * \file src/gopt/impl/profiling_based_solver.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. #include "megbrain/gopt/global_layout_transform.h"
  13. #include "megbrain/opr/dnn/pooling.h"
  14. #include "megbrain/opr/imgproc.h"
  15. using namespace mgb;
  16. using namespace gopt;
  17. using namespace opr;
  18. /* =================== ProfilingBasedSolverSolver ======================*/
  19. ProfilingBasedSolver::ProfilingBasedSolver(
  20. std::unique_ptr<ProfilerBase> profiler)
  21. : m_profiler{std::move(profiler)} {
  22. static const ThinHashSet<Typeinfo*> format_aware_oprs = {
  23. #define cb(_Opr) _Opr::typeinfo()
  24. cb(Convolution),
  25. cb(ConvBiasForward),
  26. cb(ConvolutionBackwardData),
  27. cb(PoolingForward),
  28. cb(WarpPerspective),
  29. cb(Resize),
  30. };
  31. m_graph_partition_filter = [](const GraphPartition& partition) {
  32. bool has_format_aware_opr = false;
  33. for (auto&& opr : partition.all_oprs()) {
  34. if (!has_format_aware_opr &&
  35. format_aware_oprs.count(opr->dyn_typeinfo())) {
  36. has_format_aware_opr = true;
  37. break;
  38. }
  39. }
  40. return has_format_aware_opr;
  41. };
  42. }
  43. ProfilingBasedSolver::Solution ProfilingBasedSolver::solve(
  44. const Problem& problem) const {
  45. const auto& partition = problem.graph_partition();
  46. if (!m_graph_partition_filter(partition))
  47. return Solution{};
  48. return do_solve(problem);
  49. }
  50. // vim: syntax=cpp.doxygen

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