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.

profiler.cpp 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * \file imperative/src/impl/profiler.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 "megbrain/imperative/profiler.h"
  12. #include <chrono>
  13. #include "megbrain/imperative/ops/opr_attr.h"
  14. #include "megbrain/imperative/physical_tensor.h"
  15. #include "megbrain/plugin/opr_footprint.h"
  16. #include "./function_hook.h"
  17. #include "./event_pool.h"
  18. #include "./op_trait.h"
  19. namespace mgb {
  20. namespace imperative {
  21. namespace {
  22. DeviceTimer::SharedEvent alloc_recorded_event(CompNode device) {
  23. auto event = EventPool::with_timer().alloc_shared(device);
  24. event->record();
  25. return event;
  26. }
  27. } // namespace
  28. DeviceTimer::SharedEvent DeviceTimer::get_device_time(CompNode device) {
  29. return alloc_recorded_event(device);
  30. }
  31. SmallVector<DeviceTimer::SharedEvent> DeviceTimer::get_all(SmallVector<CompNode> device_list) {
  32. SmallVector<DeviceTimer::SharedEvent> results;
  33. for (auto&& device: device_list) {
  34. results.push_back(alloc_recorded_event(device));
  35. }
  36. return results;
  37. }
  38. double HostTimer::get_msecs() {
  39. using namespace std::chrono;
  40. auto finish = steady_clock::now();
  41. auto duration = duration_cast<microseconds>(finish - m_start);
  42. return (double)duration.count() / 1e3;
  43. }
  44. double HostTimer::get_started_at() {
  45. return m_started_at;
  46. }
  47. void HostTimer::reset() {
  48. using namespace std::chrono;
  49. m_start = steady_clock::now();
  50. auto now_us = duration_cast<microseconds>(std::chrono::system_clock::now().time_since_epoch());
  51. m_started_at = (double)(now_us.count()) / 1e3;
  52. }
  53. } // namespace imperative
  54. } // namespace mgb

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