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 970 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "test/common/fast_run_cache.h"
  2. #include "src/common/utils.h"
  3. using namespace megdnn;
  4. using namespace test;
  5. FastRunCache::SearchItemStorage::SearchItemStorage(const Algorithm::SearchItem& item) {
  6. Algorithm::serialize_write_pod(item.opr_type, data_hold);
  7. for (auto&& layout : item.layouts) {
  8. data_hold += layout.serialize();
  9. }
  10. data_hold += item.param;
  11. }
  12. Algorithm::Info::Desc FastRunCache::get(const Algorithm::SearchItem& key) {
  13. SearchItemStorage key_storage(key);
  14. key_storage.init_hash();
  15. auto iter = m_cache.find(key_storage);
  16. if (iter == m_cache.end()) {
  17. return {};
  18. }
  19. return iter->second;
  20. }
  21. void FastRunCache::put(
  22. const Algorithm::SearchItem& key, const Algorithm::Info::Desc& val) {
  23. SearchItemStorage key_storage(key);
  24. key_storage.init_hash();
  25. megdnn_assert(m_cache.find(key_storage) == m_cache.end());
  26. m_cache[std::move(key_storage)] = val;
  27. }
  28. // vim: syntax=cpp.doxygen