Skip to content

Commit 1c8ce55

Browse files
committed
Update on "[ExecuTorch][Weight Sharing][XNNPACK] load named data map data for xnnpack"
If data is serialized into the NamedDataMap, then we overload getConstantDataPtr to retrieve the data from the named data map. This should be done in a Backwards Compatible way. Meaning if no data is serialized into the named data map, then we are still loading the data from the flatbuffer payload. Since the runtime change here is being made before the AoT changes, All CI on this diff by itself should test that the changes made here are backwards compatitble. Note: We do not resolve Runtime Memory usage at this point. WeightCache will be implemented in the next diff. Meaning If we load via the same key across different methods, we still pack twice and allocate two instances for the packed weights. Differential Revision: [D70315209](https://our.internmc.facebook.com/intern/diff/D70315209/) [ghstack-poisoned]
1 parent c5cfe62 commit 1c8ce55

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backends/xnnpack/runtime/XNNCompiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ const uint8_t* getConstantDataPtr(
179179
ConstantDataOffsetPtr constant_data_offset = flatbuffer_graph->constant_data()->Get(buffer_idx);
180180
uint64_t offset = constant_data_offset->offset();
181181

182-
const std::string &data_name = constant_data_offset->named_key()->str();
182+
bool has_named_key = flatbuffers::IsFieldPresent(constant_data_offset, fb_xnnpack::ConstantDataOffset::VT_NAMED_KEY);
183183
// If there is no tensor name
184-
if (data_name.length() == 0) {
184+
if (!has_named_key) {
185185
return constant_data_ptr + offset;
186186
} else {
187+
const std::string &data_name = constant_data_offset->named_key()->str();
187188
Result<FreeableBuffer> buffer = named_data_map->get_data(data_name.c_str());
188189
if (!buffer.ok()) {
189190
ET_LOG(Error, "Failed to get constant data for key %s", data_name.c_str());

0 commit comments

Comments
 (0)