Skip to content

Commit d2ce595

Browse files
authored
Fix weight cache bug (#18295)
Summary: XNNPACK sometimes calls weight cache look_up_or_insert with ptr==nullptr. This is a bit weird - maybe a bug on the XNNPACK side?, but it seems to do this when it's already hit the cache. Just return the cached value for the key without validating contents in this case, since we can't insert anything. Differential Revision: D97006279
1 parent d0705e1 commit d2ce595

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

backends/xnnpack/runtime/XNNWeightsCache.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,18 @@ size_t XNNWeightsCache::look_up_or_insert(
206206
size_t size) {
207207
size_t offset = context->look_up(context, cache_key);
208208

209+
// XNNPACK can call this with ptr==nullptr when it previously hit the cache
210+
// and skipped packing. We can't validate against the ptr contents in this
211+
// case, so just return the offset. This might actually be a bug in XNNPACK
212+
// since calling look_up_or_insert with ptr==nullptr doesn't really make
213+
// sense...
214+
if (ptr == nullptr) {
215+
return offset;
216+
}
217+
209218
if (offset != SIZE_MAX) {
210219
void* saved_ptr = context->offset_to_addr(context, offset);
211-
if (0 == memcmp(ptr, saved_ptr, size)) {
220+
if (saved_ptr != nullptr && 0 == memcmp(ptr, saved_ptr, size)) {
212221
return offset;
213222
}
214223
// Failure, cache is out of date

0 commit comments

Comments
 (0)