diff --git a/backends/xnnpack/runtime/XNNWeightsCache.cpp b/backends/xnnpack/runtime/XNNWeightsCache.cpp index 54191b72825..7767c65285a 100644 --- a/backends/xnnpack/runtime/XNNWeightsCache.cpp +++ b/backends/xnnpack/runtime/XNNWeightsCache.cpp @@ -206,9 +206,18 @@ size_t XNNWeightsCache::look_up_or_insert( size_t size) { size_t offset = context->look_up(context, cache_key); + // XNNPACK can call this with ptr==nullptr when it previously hit the cache + // and skipped packing. We can't validate against the ptr contents in this + // case, so just return the offset. This might actually be a bug in XNNPACK + // since calling look_up_or_insert with ptr==nullptr doesn't really make + // sense... + if (ptr == nullptr) { + return offset; + } + if (offset != SIZE_MAX) { 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