Ruy: Profile cache ejection.
PiperOrigin-RevId: 283795957 Change-Id: I139678b43340a134e74d30704d3a07f73c7ca8c2
This commit is contained in:
parent
71421f37a8
commit
5cb564092f
@ -118,6 +118,7 @@ cc_library(
|
||||
":opt_set",
|
||||
":platform",
|
||||
":time",
|
||||
"@gemmlowp//:profiler",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/lite/experimental/ruy/prepacked_cache.h"
|
||||
|
||||
#include "profiling/instrumentation.h"
|
||||
#include "tensorflow/lite/experimental/ruy/matrix.h"
|
||||
|
||||
namespace ruy {
|
||||
@ -26,7 +27,7 @@ CacheIterator PrepackedCache::FindAndUpdate(const CacheKey &key) {
|
||||
auto itr = cache_.find(key);
|
||||
// If found, update with new access time for this entry.
|
||||
if (itr != cache_.end()) {
|
||||
const TimePoint time = CoarseNow();
|
||||
const TimePoint time = CacheNow();
|
||||
itr->second.second = time;
|
||||
}
|
||||
return itr;
|
||||
@ -47,12 +48,15 @@ void PrepackedCache::Insert(const CacheKey &key,
|
||||
}
|
||||
|
||||
void PrepackedCache::EjectOne() {
|
||||
TimePoint oldest_time = CoarseNow();
|
||||
TimePoint oldest_time = CacheNow();
|
||||
auto oldest = cache_.begin();
|
||||
for (auto itr = cache_.begin(); itr != cache_.end(); ++itr) {
|
||||
if (itr->second.second < oldest_time) {
|
||||
oldest_time = itr->second.second;
|
||||
oldest = itr;
|
||||
{
|
||||
gemmlowp::ScopedProfilingLabel label("PepackedCacheEjection");
|
||||
for (auto itr = cache_.begin(); itr != cache_.end(); ++itr) {
|
||||
if (itr->second.second < oldest_time) {
|
||||
oldest_time = itr->second.second;
|
||||
oldest = itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
PrepackedMatrix &pmatrix = oldest->second.first;
|
||||
@ -70,10 +74,7 @@ void PrepackedCache::AllocatePrepackedMatrix(PrepackedMatrix *pmatrix) {
|
||||
|
||||
void PrepackedCache::DoInsert(const CacheKey &key,
|
||||
const PrepackedMatrix &matrix) {
|
||||
// TODO(talumbau) Profile timestamps on relevant models to see if
|
||||
// this level of granularity is sufficient. CoarseNow is cheap so
|
||||
// it would be nice to keep it.
|
||||
const TimePoint t = CoarseNow();
|
||||
const TimePoint t = CacheNow();
|
||||
const MatrixWithTimeStamp mts({matrix, t});
|
||||
cache_.insert({key, mts});
|
||||
}
|
||||
|
||||
@ -106,6 +106,12 @@ class PrepackedCache {
|
||||
// Returns the total size (in bytes) of data held in this cache.
|
||||
int TotalSize() const { return cache_size_; }
|
||||
|
||||
// All calls to get current TimePoints go through here.
|
||||
// TODO(b/145625614) Profile timestamps on relevant models to see if
|
||||
// this level of granularity is sufficient. CoarseNow is cheap so
|
||||
// it would be nice to keep it.
|
||||
TimePoint CacheNow() const { return CoarseNow(); }
|
||||
|
||||
// Performs the memory allocation for the `data` and `sums` members of a
|
||||
// PrepackedMatrix.
|
||||
void AllocatePrepackedMatrix(PrepackedMatrix *pmatrix);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user