Skip to content

Commit c81d8cf

Browse files
committed
[executorch][core] NamedDataMap interface
Add NamedDataMap interface to runtime. Differential Revision: [D66834552](https://our.internmc.facebook.com/intern/diff/D66834552/) [ghstack-poisoned]
1 parent 46ee760 commit c81d8cf

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

runtime/core/named_data_map.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
12+
#include <executorch/runtime/core/freeable_buffer.h>
13+
#include <executorch/runtime/core/result.h>
14+
#include <executorch/runtime/core/span.h>
15+
#include <executorch/runtime/core/tensor_layout.h>
16+
#include <executorch/runtime/platform/compiler.h>
17+
18+
namespace executorch {
19+
namespace runtime {
20+
21+
/**
22+
* Interface to access and retrieve data via name from a loaded data file.
23+
* See executorch/extension/flat_tensor/ for an example.
24+
*/
25+
class NamedDataMap {
26+
public:
27+
virtual ~NamedDataMap() = default;
28+
/**
29+
* Get tensor metadata by fully qualified name (FQN).
30+
*
31+
* @param fqn Fully qualified name of the tensor.
32+
* @return Result containing a pointer to the metadata.
33+
*/
34+
ET_NODISCARD virtual Result<const executorch::runtime::TensorLayout>
35+
get_metadata(const char* fqn) const = 0;
36+
/**
37+
* Get tensor data by fully qualified name (FQN).
38+
*
39+
* @param fqn Fully qualified name of the tensor.
40+
* @return Result containing a span of uint8_t representing the tensor data.
41+
*/
42+
ET_NODISCARD virtual Result<Span<const uint8_t>> get_data(
43+
const char* fqn) const = 0;
44+
};
45+
46+
} // namespace runtime
47+
} // namespace executorch

runtime/core/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def define_common_targets():
3232
"data_loader.h",
3333
"error.h",
3434
"freeable_buffer.h",
35+
"named_data_map.h",
3536
"result.h",
3637
"span.h",
3738
"tensor_layout.h",

0 commit comments

Comments
 (0)