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.

cpuinfo_help.h 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * \file dnn/test/arm_common/cpuinfo_help.h
  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 once
  13. #include <mutex>
  14. #include <vector>
  15. #include "src/common/utils.h"
  16. #if MGB_ENABLE_CPUINFO
  17. #include "cpuinfo.h"
  18. extern const struct cpuinfo_core** cpuinfo_linux_cpu_to_core_map;
  19. class CpuInfoTmpReplace {
  20. public:
  21. CpuInfoTmpReplace(enum cpuinfo_uarch arch) {
  22. m_cpuinfo_lock.lock();
  23. for (uint32_t i = 0; i < cpuinfo_get_cores_count(); ++i) {
  24. m_arch_bak_vec.push_back(cpuinfo_linux_cpu_to_core_map[i]->uarch);
  25. ((struct cpuinfo_core**)cpuinfo_linux_cpu_to_core_map)[i]->uarch = arch;
  26. }
  27. }
  28. ~CpuInfoTmpReplace() {
  29. if (m_arch_bak_vec.size() > 0) {
  30. for (uint32_t i = 0; i < cpuinfo_get_cores_count(); ++i) {
  31. ((struct cpuinfo_core**)cpuinfo_linux_cpu_to_core_map)[i]->uarch =
  32. m_arch_bak_vec[i];
  33. }
  34. }
  35. m_cpuinfo_lock.unlock();
  36. }
  37. private:
  38. static std::mutex m_cpuinfo_lock;
  39. std::vector<cpuinfo_uarch> m_arch_bak_vec;
  40. };
  41. #endif
  42. // vim: syntax=cpp.doxygen