fixes and a rebase
This commit is contained in:
parent
0fb706866c
commit
e4a4a8d91a
@ -7,36 +7,23 @@
|
|||||||
#include "../../third_party/compute_detail/lru_cache.hpp"
|
#include "../../third_party/compute_detail/lru_cache.hpp"
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
// sizeof size_t: 8
|
||||||
|
// sizeof unsigned: 4
|
||||||
|
// sizeof unchar: 1
|
||||||
|
// sizeof uint32: 4
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
namespace engine
|
namespace engine
|
||||||
{
|
{
|
||||||
typedef unsigned char ExcludeIndex;
|
typedef unsigned char ExcludeIndex;
|
||||||
typedef unsigned Timestamp;
|
typedef unsigned Timestamp;
|
||||||
typedef std::tuple<NodeID, NodeID, ExcludeIndex> Key;
|
typedef std::tuple<NodeID, NodeID, unsigned char> Key;
|
||||||
typedef std::size_t HashedKey;
|
|
||||||
|
|
||||||
struct HashKey
|
|
||||||
{
|
|
||||||
std::size_t operator()(Key const &key) const noexcept
|
|
||||||
{
|
|
||||||
std::size_t h1 = std::hash<NodeID>{}(std::get<0>(key));
|
|
||||||
std::size_t h2 = std::hash<NodeID>{}(std::get<1>(key));
|
|
||||||
std::size_t h3 = std::hash<ExcludeIndex>{}(std::get<2>(key));
|
|
||||||
|
|
||||||
std::size_t seed = 0;
|
|
||||||
boost::hash_combine(seed, h1);
|
|
||||||
boost::hash_combine(seed, h2);
|
|
||||||
boost::hash_combine(seed, h3);
|
|
||||||
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class UnpackingCache
|
class UnpackingCache
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
boost::compute::detail::lru_cache<HashedKey, EdgeDuration> m_cache;
|
boost::compute::detail::lru_cache<std::tuple<NodeID, NodeID, unsigned char>, EdgeDuration> m_cache;
|
||||||
unsigned m_current_data_timestamp = 0;
|
unsigned m_current_data_timestamp = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -45,27 +32,28 @@ class UnpackingCache
|
|||||||
// https://github.com/Project-OSRM/osrm-backend/issues/4798#issue-288608332)
|
// https://github.com/Project-OSRM/osrm-backend/issues/4798#issue-288608332)
|
||||||
|
|
||||||
// LRU CACHE IMPLEMENTATION HAS THESE TWO STORAGE CONTAINERS
|
// LRU CACHE IMPLEMENTATION HAS THESE TWO STORAGE CONTAINERS
|
||||||
// map: n * tuple_hash + n * EdgeDuration
|
// Key is of size: std::uint32_t * 2 + (unsigned char) * 1 + unsigned * 1
|
||||||
// = n * std::size_t + n * std::int32_t
|
// = 4 * 2 + 1 * 1 + 4 * 1 = 21
|
||||||
// = n * 8 bytes + n * 4 bytes
|
// map: n * Key + n * EdgeDuration
|
||||||
// = n * 12 bytes
|
// = n * 21 bytes + n * std::int32_t
|
||||||
// list: n * HashedKey
|
// = n * 21 bytes + n * 4 bytes
|
||||||
// = n * std::size_t
|
// = n * 25 bytes
|
||||||
// = n * 8 bytes
|
// list: n * Key
|
||||||
// Total = n * 20 bytes
|
// = n * 21 bytes
|
||||||
|
// Total = n * (25 + 21) = n * 46 bytes
|
||||||
// Total cache size: 500 mb = 500 * 1024 *1024 bytes = 524288000 bytes
|
// Total cache size: 500 mb = 500 * 1024 *1024 bytes = 524288000 bytes
|
||||||
|
|
||||||
// THREAD LOCAL STORAGE
|
// THREAD LOCAL STORAGE
|
||||||
// Number of lines we need = 524288000 / 20 / number of threads = 26214400 / number of threads
|
// Number of lines we need = 524288000 / 46 / number of threads = 11397565 / number of threads
|
||||||
// 16 threads: 26214400 / 16 = 1638400
|
// 16 threads: 11397565 / 16 = 712347
|
||||||
// 8 threads: 26214400 / 8 = 3276800
|
// 8 threads: 11397565 / 8 = 1424695
|
||||||
// 4 threads: 26214400 / 4 = 6553600
|
// 4 threads: 11397565 / 4 = 2849391
|
||||||
// 2 threads: 26214400 / 2 = 13107200
|
// 2 threads: 11397565 / 2 = 5698782
|
||||||
|
|
||||||
// SHARED STORAGE CACHE
|
// SHARED STORAGE CACHE
|
||||||
// Number of lines we need for shared storage cache = 524288000 / 20 = 26214400
|
// Number of lines we need for shared storage cache = 524288000 / 20 = 26214400
|
||||||
|
|
||||||
UnpackingCache(unsigned timestamp) : m_cache(13107200), m_current_data_timestamp(timestamp){};
|
UnpackingCache(unsigned timestamp) : m_cache(712347), m_current_data_timestamp(timestamp){};
|
||||||
|
|
||||||
UnpackingCache(std::size_t cache_size, unsigned timestamp)
|
UnpackingCache(std::size_t cache_size, unsigned timestamp)
|
||||||
: m_cache(cache_size), m_current_data_timestamp(timestamp){};
|
: m_cache(cache_size), m_current_data_timestamp(timestamp){};
|
||||||
@ -79,22 +67,19 @@ class UnpackingCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsEdgeInCache(Key edge)
|
bool IsEdgeInCache(std::tuple<NodeID, NodeID, unsigned char> edge)
|
||||||
{
|
{
|
||||||
HashedKey hashed_edge = HashKey{}(edge);
|
return m_cache.contains(edge);
|
||||||
return m_cache.contains(hashed_edge);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddEdge(Key edge, EdgeDuration duration)
|
void AddEdge(std::tuple<NodeID, NodeID, unsigned char> edge, EdgeDuration duration)
|
||||||
{
|
{
|
||||||
HashedKey hashed_edge = HashKey{}(edge);
|
m_cache.insert(edge, duration);
|
||||||
m_cache.insert(hashed_edge, duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeDuration GetDuration(Key edge)
|
EdgeDuration GetDuration(std::tuple<NodeID, NodeID, unsigned char> edge)
|
||||||
{
|
{
|
||||||
HashedKey hashed_edge = HashKey{}(edge);
|
boost::optional<EdgeDuration> duration = m_cache.get(edge);
|
||||||
boost::optional<EdgeDuration> duration = m_cache.get(hashed_edge);
|
|
||||||
return duration ? *duration : MAXIMAL_EDGE_DURATION;
|
return duration ? *duration : MAXIMAL_EDGE_DURATION;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user