Skip to content

[executorch][runtime] Add get_named_data_map to Program #8853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions runtime/executor/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ Result<const void*> Program::get_constant_buffer_data(
}
}

Result<const NamedDataMap*> Program::get_named_data_map() const {
if (pte_data_map_.has_value()) {
return &pte_data_map_.value();
}
return Error::NotFound;
}

Result<const char*> Program::get_output_flattening_encoding(
const char* method_name) const {
auto plan = get_execution_plan(internal_program_, method_name);
Expand Down
6 changes: 6 additions & 0 deletions runtime/executor/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ class Program final {
Result<const void*> get_constant_buffer_data(size_t buffer_idx, size_t nbytes)
const;

/**
* Get the named data map from the program.
* @return The named data map.
*/
Result<const NamedDataMap*> get_named_data_map() const;

/**
* Returns the number of methods in the program.
*/
Expand Down
12 changes: 12 additions & 0 deletions runtime/executor/test/program_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,18 @@ TEST_F(ProgramTest, getMethods) {
EXPECT_EQ(strcmp(res2.get(), "forward2"), 0);
}

TEST_F(ProgramTest, GetNamedDataMap_Fail) {
Result<Program> program =
Program::load(add_loader_.get(), kDefaultVerification);
ASSERT_EQ(program.error(), Error::Ok);

// Get the named data map. Expect to fail, as add.pte does not have any
// named data segments.
Result<const executorch::runtime::NamedDataMap*> named_data_map =
program->get_named_data_map();
EXPECT_EQ(named_data_map.error(), Error::NotFound);
}

// Test that the deprecated Load method (capital 'L') still works.
TEST_F(ProgramTest, DEPRECATEDLoad) {
// Parse the Program from the data.
Expand Down
Loading