Always write a valid initial cache file when starting a cache build.

Before this change, if the XNNPack delegate is used but no operation is
delegated, then an invalid cache file is created.

PiperOrigin-RevId: 845763378
This commit is contained in:
Quentin Khan
2025-12-17 07:40:18 -08:00
committed by TensorFlower Gardener
parent b295c98d0a
commit 3b2c89f5ed

View File

@@ -120,12 +120,17 @@ bool WeightCacheBuilder::Start(const char* path, const FileDescriptor& fd) {
XNNPackCacheHeader header{XNNPackCacheHeader::kInvalidHeader};
header.buffer_list_offset = sizeof(header);
XNNPACK_RETURN_CHECK(fd_.Truncate(0), "could not truncate weight cache");
XNNPACK_RETURN_CHECK(fd_.Truncate(0), "could not truncate weight cache.");
XNNPACK_RETURN_CHECK(fd_.SetPos(0) == 0, "couldn't move to file start.");
XNNPACK_RETURN_CHECK(fd_.Write(&header, sizeof(header)),
"could not write initial cache header in %s: %s.",
file_path_.c_str(), strerror(errno));
schema_.base_offset = Align(sizeof(header), kMinAlignment);
XNNPACK_RETURN_CHECK(StartBuildStep(), "failed to start initial write step.");
XNNPACK_RETURN_CHECK(StopBuildStep(), "failed to write initial step.");
return true;
}