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.

fast_run_cache.cpp 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * \file dnn/test/common/fast_run_cache.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 "test/common/fast_run_cache.h"
  13. #include "src/common/utils.h"
  14. using namespace megdnn;
  15. using namespace test;
  16. FastRunCache::SearchItemStorage::SearchItemStorage(const Algorithm::SearchItem& item) {
  17. Algorithm::serialize_write_pod(item.opr_type, data_hold);
  18. for (auto&& layout : item.layouts) {
  19. data_hold += layout.serialize();
  20. }
  21. data_hold += item.param;
  22. }
  23. Algorithm::Info::Desc FastRunCache::get(const Algorithm::SearchItem& key) {
  24. SearchItemStorage key_storage(key);
  25. key_storage.init_hash();
  26. auto iter = m_cache.find(key_storage);
  27. if (iter == m_cache.end()) {
  28. return {};
  29. }
  30. return iter->second;
  31. }
  32. void FastRunCache::put(
  33. const Algorithm::SearchItem& key, const Algorithm::Info::Desc& val) {
  34. SearchItemStorage key_storage(key);
  35. key_storage.init_hash();
  36. megdnn_assert(m_cache.find(key_storage) == m_cache.end());
  37. m_cache[std::move(key_storage)] = val;
  38. }
  39. // vim: syntax=cpp.doxygen