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.h 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include "megdnn/oprs.h"
  3. #include "src/common/hash_ct.h"
  4. #include <unordered_map>
  5. namespace megdnn {
  6. namespace test {
  7. class FastRunCache {
  8. struct SearchItemStorage {
  9. std::string data_hold;
  10. size_t hash = 0;
  11. SearchItemStorage(const Algorithm::SearchItem& item);
  12. SearchItemStorage& init_hash() {
  13. hash = XXHash64CT::hash(data_hold.data(), data_hold.size(), 20201225);
  14. return *this;
  15. }
  16. bool operator==(const SearchItemStorage& rhs) const {
  17. return data_hold == rhs.data_hold;
  18. }
  19. struct Hash {
  20. size_t operator()(const SearchItemStorage& s) const { return s.hash; }
  21. };
  22. };
  23. std::unordered_map<
  24. SearchItemStorage, Algorithm::Info::Desc, SearchItemStorage::Hash>
  25. m_cache;
  26. public:
  27. Algorithm::Info::Desc get(const Algorithm::SearchItem& key);
  28. void put(const Algorithm::SearchItem& key, const Algorithm::Info::Desc& val);
  29. };
  30. } // namespace test
  31. } // namespace megdnn
  32. // vim: syntax=cpp.doxygen