Skip to content

Commit 1ae93b4

Browse files
authored
[executorch][runtime] Add get_named_data_map to Program (#8853)
Add to the program interface, to allow users to retrieve the NDM. Differential Revision: [D70276106](https://our.internmc.facebook.com/intern/diff/D70276106/) [ghstack-poisoned]
1 parent 94be000 commit 1ae93b4

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

runtime/executor/program.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ Result<const void*> Program::get_constant_buffer_data(
373373
}
374374
}
375375

376+
Result<const NamedDataMap*> Program::get_named_data_map() const {
377+
if (pte_data_map_.has_value()) {
378+
return &pte_data_map_.value();
379+
}
380+
return Error::NotFound;
381+
}
382+
376383
Result<const char*> Program::get_output_flattening_encoding(
377384
const char* method_name) const {
378385
auto plan = get_execution_plan(internal_program_, method_name);

runtime/executor/program.h

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class Program final {
107107
Result<const void*> get_constant_buffer_data(size_t buffer_idx, size_t nbytes)
108108
const;
109109

110+
/**
111+
* Get the named data map from the program.
112+
* @return The named data map.
113+
*/
114+
Result<const NamedDataMap*> get_named_data_map() const;
115+
110116
/**
111117
* Returns the number of methods in the program.
112118
*/

runtime/executor/test/program_test.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,18 @@ TEST_F(ProgramTest, getMethods) {
371371
EXPECT_EQ(strcmp(res2.get(), "forward2"), 0);
372372
}
373373

374+
TEST_F(ProgramTest, GetNamedDataMap_Fail) {
375+
Result<Program> program =
376+
Program::load(add_loader_.get(), kDefaultVerification);
377+
ASSERT_EQ(program.error(), Error::Ok);
378+
379+
// Get the named data map. Expect to fail, as add.pte does not have any
380+
// named data segments.
381+
Result<const executorch::runtime::NamedDataMap*> named_data_map =
382+
program->get_named_data_map();
383+
EXPECT_EQ(named_data_map.error(), Error::NotFound);
384+
}
385+
374386
// Test that the deprecated Load method (capital 'L') still works.
375387
TEST_F(ProgramTest, DEPRECATEDLoad) {
376388
// Parse the Program from the data.

0 commit comments

Comments
 (0)