Skip to content

Commit a3e1d71

Browse files
committed
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]
2 parents 44ade12 + 6f73f21 commit a3e1d71

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

backends/xnnpack/test/runtime/test_xnn_weights_cache.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ TEST_F(XNNWeightsCacheTest, ReusePackedWeights) {
278278
weight_cache.delete_packed_data(weight_cache.get_packed_data_names());
279279
std::vector<std::string> packed_data_names =
280280
weight_cache.get_packed_data_names();
281-
// check packed data names have been deleted
281+
// Packed Data Still exists because it has a ref count of 2
282+
ASSERT_EQ(packed_data_names.size(), 1);
283+
weight_cache.delete_packed_data(weight_cache.get_packed_data_names());
284+
packed_data_names =
285+
weight_cache.get_packed_data_names();
282286
ASSERT_EQ(packed_data_names.size(), 0);
283287
}

schema/targets.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def define_common_targets():
7878
# //executorch/runtime/executor/...
7979
"//executorch/codegen/tools/...",
8080
"//executorch/runtime/executor/...",
81+
# Tests have a set up which uses raw flatbuffer.
82+
# TODO will refactor these setup steps into
83+
# testing utils in runtime/executor/... path
84+
"//executorch/backends/xnnpack/test/...",
8185
],
8286
exported_headers = {
8387
OUTPUT_PROGRAM_HEADER: ":{}[{}]".format(PROGRAM_GEN_RULE_NAME, OUTPUT_PROGRAM_HEADER),

0 commit comments

Comments
 (0)