| #pragma once |
| |
| #include <memory> |
| #include <mutex> |
| |
| namespace at { namespace native { |
| |
| // Hashing machinery for Params |
| // Fowler–Noll–Vo hash function |
| // see https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function |
| template <typename Params> |
| struct ParamsHash { |
| // Params must be a POD because we read out its memory |
| // contenst as char* when hashing |
| static_assert(std::is_pod<Params>::value, "Params is not POD"); |
| |
| size_t operator()(const Params& params) const { |
| auto ptr = reinterpret_cast<const uint8_t*>(¶ms); |
| uint32_t value = 0x811C9DC5; |
| for (const auto i : c10::irange((int)sizeof(Params))) { |
| value ^= ptr[i]; |
| value *= 0x01000193; |
| } |
| return (size_t)value; |
| } |
| }; |
| |
| template <typename Params> |
| struct ParamsEqual { |
| // Params must be a POD because we read out its memory |
| // contenst as char* when comparing |
| static_assert(std::is_pod<Params>::value, "Params is not POD"); |
| |
| bool operator()(const Params& a, const Params& b) const { |
| auto ptr1 = reinterpret_cast<const uint8_t*>(&a); |
| auto ptr2 = reinterpret_cast<const uint8_t*>(&b); |
| return memcmp(ptr1, ptr2, sizeof(Params)) == 0; |
| } |
| }; |
| |
| |
| }} // at::native |