Skip to content

Commit a25d855

Browse files
committed
Update on "[executorch][runtime] Introduce PteDataMap for weight sharing"
PteDataMap is the NamedDataMap that will live in the runtime. It is used to give delegates access to opaque named data stored in the PTE file. Open to alternative naming suggestions, maybe 'PTEDataMap' or 'ProgramDataMap'? **Usage** The PteDataMap is owned by the program, and instantiated at program load time if named_data exists in the PTE file. We introduce usage of 'std::optional' here. I think we can also use executorch::aten::optional to avoid adding standard lib ? When initializing delegates, the PteDataMap is given to delegate_init. Delegates can retrieve opaque delegate data by key using 'get_data'. This gives them a FreeableBuffer that they can free later. **Testing** This test uses the C++ flatbuffer API to build a fake program containing named data. We also creates a temp file with sample data that the data loader can wrap around. TODO: e2e test once delegate aot is ready and we can generate a file with named data. **Note** As the PteDataMap wraps around flatbuffer constructs, the Program must outlive the PteDataMap. PteDataMap does not implement - get_metadata; currently, all data stored is opaque. Later, we can implement get_metadata if a backend stores plain tensor data. - load_into; this is mostly used for the training case, and isn't used by delegates, at least not at the moment Differential Revision: [D70213646](https://our.internmc.facebook.com/intern/diff/D70213646/) [ghstack-poisoned]
2 parents 43484a2 + 6ad37bb commit a25d855

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

runtime/executor/program.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include <cinttypes>
1515
#include <cstdint>
16-
#include <optional>
1716

1817
#include <executorch/runtime/core/data_loader.h>
1918
#include <executorch/runtime/core/error.h>

runtime/executor/pte_data_map.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,30 @@ struct DataSegment;
1919
} // namespace executorch_flatbuffer
2020

2121
namespace flatbuffers {
22-
// TODO(T216992074): update internal flatbuffers (v1.12) to match OSS (v24.3.5).
2322
template <typename T>
2423
struct Offset;
25-
#if EXECUTORCH_INTERNAL == 1
24+
} // namespace flatbuffers
25+
26+
#if EXECUTORCH_INTERNAL_FLATBUFFERS == 1
27+
// TODO(T216992074): update internal flatbuffers (v1.12) to match OSS (v24.3.5).
28+
namespace flatbuffers {
2629
template <typename T>
2730
class Vector;
2831
using FlatbufferNamedData =
2932
flatbuffers::Vector<flatbuffers::Offset<executorch_flatbuffer::NamedData>>;
3033
using FlatbufferDataSegment = flatbuffers::Vector<
3134
flatbuffers::Offset<executorch_flatbuffer::DataSegment>>;
35+
} // namespace flatbuffers
3236
#else
37+
namespace flatbuffers {
3338
template <typename T, typename SizeT>
3439
class Vector;
3540
using FlatbufferNamedData = flatbuffers::
3641
Vector<flatbuffers::Offset<executorch_flatbuffer::NamedData>, uint32_t>;
3742
using FlatbufferDataSegment = flatbuffers::
3843
Vector<flatbuffers::Offset<executorch_flatbuffer::DataSegment>, uint32_t>;
39-
#endif
4044
} // namespace flatbuffers
45+
#endif
4146

4247
namespace executorch {
4348
namespace runtime {

runtime/executor/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def define_common_targets():
5959
"//executorch/runtime/core:named_data_map",
6060
"//executorch/schema:program",
6161
],
62-
exported_preprocessor_flags = [] if runtime.is_oss else ["-DEXECUTORCH_INTERNAL=1"],
62+
exported_preprocessor_flags = [] if runtime.is_oss else ["-DEXECUTORCH_INTERNAL_FLATBUFFERS=1"],
6363
)
6464

6565
for aten_mode in get_aten_mode_options():

runtime/executor/test/pte_data_map_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ class PteDataMapTest : public ::testing::Test {
5555
// Create segments.
5656
const flatbuffers::Offset<executorch_flatbuffer::DataSegment>
5757
segment_arr[2] = {
58+
// NOLINT facebook-hte-BadArgumentComment
5859
executorch_flatbuffer::CreateDataSegment(
5960
builder_, /*offset=*/0, /*size=*/kSegmentSizes[0]),
61+
// NOLINT facebook-hte-BadArgumentComment
6062
executorch_flatbuffer::CreateDataSegment(
6163
builder_,
6264
/*offset=*/kSegmentAlignment * 2,

0 commit comments

Comments
 (0)