Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions backends/xnnpack/runtime/XNNWeightsCache.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
Expand Down Expand Up @@ -27,18 +27,18 @@

XNNWeightsCache::XNNWeightsCache() {
weights_cache_.context = this;
weights_cache_.look_up = (size_t(*)(
weights_cache_.look_up = (size_t (*)(
void*, const xnn_weights_cache_look_up_key*))XNNWeightsCache::look_up;
weights_cache_.reserve_space =
(void* (*)(void*, size_t))XNNWeightsCache::reserve_space;
weights_cache_.look_up_or_insert =
(size_t(*)(void*, const xnn_weights_cache_look_up_key*, void*, size_t))
(size_t (*)(void*, const xnn_weights_cache_look_up_key*, void*, size_t))
XNNWeightsCache::look_up_or_insert;
weights_cache_.is_finalized = (bool (*)(void*))XNNWeightsCache::is_finalized;
weights_cache_.offset_to_addr =
(void* (*)(void*, size_t))XNNWeightsCache::offset_to_addr;
weights_cache_.delete_cache =
(enum xnn_status(*)(void*))XNNWeightsCache::delete_cache;
(enum xnn_status (*)(void*))XNNWeightsCache::delete_cache;
}

Error XNNWeightsCache::initialize_for_runtime(
Expand Down Expand Up @@ -207,8 +207,14 @@
size_t offset = context->look_up(context, cache_key);

if (offset != SIZE_MAX) {
// When XNNPACK's look_up already returned a cache hit, it skips packing
// and calls look_up_or_insert with ptr = NULL. In this case, trust the
// cache and return the existing offset without comparing.
if (ptr == nullptr) {
return offset;
}
void* saved_ptr = context->offset_to_addr(context, offset);
if (0 == memcmp(ptr, saved_ptr, size)) {
if (saved_ptr != nullptr && 0 == memcmp(ptr, saved_ptr, size)) {
return offset;
}
// Failure, cache is out of date
Expand Down
Loading