Skip to content

Commit ac12caa

Browse files
committed
Update base for Update on "[XNNPACK][Weights Cache] Initial Weights Cache Design with NamedDataMap"
XNNWeightsCache Design with NamedDataMap. The intent of the weights cache is for tensors to be loaded (via name) through the named data map. APIs to be used by XNNCompiler: - load_unpacked_data - Takes in a string name (tensor name). The weights cache loads the data for this string from the named data map and returns the pointer. It also creates a mapping of this pointer to the name which is later used by the XNNPACK's internal weight cache implementation - free_unpacked_data - Frees all the unpacked data loaded from NamedDataMap. This is only safe to call after xnn_create_runtime has been called. This is because create_runtime takes unpacked data pointers and packs them into a separate buffer. - a couple getter methods - get_packed_data_names - get_unpacked_data_names - get_num_packed_data - get() (get's the xnn_weights_cache object) Internal APIs used by XNNPACK Library - look_up - takes a cache key (weight and bias pointers) and looks up the offset to the packed weight if it exists - look_up_or_insert - takes a cache key and pointer to packed weights and looks_up the offset if it exists, or inserts a new packed weight into the cache and returns that offset - offset_to_addr - gets offset and returns address to packed pointer - reserve_space - returns memory address with appropriate sie for XNNPACK to populate with packed weights ( I want to use the runtime_allocator for this but i don't think we have the right sizes, so for now we are just using a string buffer and resizing it) - is_finalized - since this cache doesn't necessarily need to care about a finalized state we always return true. - delete_cache - deletes cache Differential Revision: [D70885917](https://our.internmc.facebook.com/intern/diff/D70885917/) [ghstack-poisoned]
1 parent e8db57d commit ac12caa

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)