From c81d8cfd2419a3ab972354129d0d90fb7fee2669 Mon Sep 17 00:00:00 2001 From: lucylq Date: Fri, 17 Jan 2025 16:45:48 -0800 Subject: [PATCH] [executorch][core] NamedDataMap interface Add NamedDataMap interface to runtime. Differential Revision: [D66834552](https://our.internmc.facebook.com/intern/diff/D66834552/) [ghstack-poisoned] --- runtime/core/named_data_map.h | 47 +++++++++++++++++++++++++++++++++++ runtime/core/targets.bzl | 1 + 2 files changed, 48 insertions(+) create mode 100644 runtime/core/named_data_map.h diff --git a/runtime/core/named_data_map.h b/runtime/core/named_data_map.h new file mode 100644 index 0000000000..7f0ddbafa8 --- /dev/null +++ b/runtime/core/named_data_map.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace executorch { +namespace runtime { + +/** + * Interface to access and retrieve data via name from a loaded data file. + * See executorch/extension/flat_tensor/ for an example. + */ +class NamedDataMap { + public: + virtual ~NamedDataMap() = default; + /** + * Get tensor metadata by fully qualified name (FQN). + * + * @param fqn Fully qualified name of the tensor. + * @return Result containing a pointer to the metadata. + */ + ET_NODISCARD virtual Result + get_metadata(const char* fqn) const = 0; + /** + * Get tensor data by fully qualified name (FQN). + * + * @param fqn Fully qualified name of the tensor. + * @return Result containing a span of uint8_t representing the tensor data. + */ + ET_NODISCARD virtual Result> get_data( + const char* fqn) const = 0; +}; + +} // namespace runtime +} // namespace executorch diff --git a/runtime/core/targets.bzl b/runtime/core/targets.bzl index 4b8a7869af..15c1c65494 100644 --- a/runtime/core/targets.bzl +++ b/runtime/core/targets.bzl @@ -32,6 +32,7 @@ def define_common_targets(): "data_loader.h", "error.h", "freeable_buffer.h", + "named_data_map.h", "result.h", "span.h", "tensor_layout.h",