Skip to content

Revert changes to executor_runner #6687

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 1 commit into from
Nov 7, 2024
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
44 changes: 6 additions & 38 deletions examples/portable/executor_runner/executor_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

#include <gflags/gflags.h>

#include <fcntl.h>
#include <unistd.h>

#include <executorch/extension/data_loader/file_data_loader.h>
#include <executorch/extension/data_loader/file_descriptor_data_loader.h>
#include <executorch/extension/evalue_util/print_evalue.h>
#include <executorch/extension/runner_util/inputs.h>
#include <executorch/runtime/executor/method.h>
Expand All @@ -40,13 +36,8 @@ DEFINE_string(
model_path,
"model.pte",
"Model serialized in flatbuffer format.");
DEFINE_bool(
is_fd_uri,
false,
"True if the model_path passed is a file descriptor with the prefix \"fd:///\".");

using executorch::extension::FileDataLoader;
using executorch::extension::FileDescriptorDataLoader;
using executorch::runtime::Error;
using executorch::runtime::EValue;
using executorch::runtime::HierarchicalAllocator;
Expand All @@ -58,33 +49,6 @@ using executorch::runtime::Program;
using executorch::runtime::Result;
using executorch::runtime::Span;

static Result<Program> getProgram(
const bool is_fd_uri,
const char* model_path) {
// Create a loader to get the data of the program file. This demonstrates both
// FileDataLoader and FileDescriptorDataLoader. There are other DataLoaders
// that use mmap() or point to data that's already in memory, and users can
// create their own DataLoaders to load from arbitrary sources.
if (!is_fd_uri) {
Result<FileDataLoader> loader = FileDataLoader::from(model_path);

ET_CHECK_MSG(
loader.ok(),
"FileDataLoader::from() failed: 0x%" PRIx32,
(uint32_t)loader.error());
return Program::load(&loader.get());
} else {
Result<FileDescriptorDataLoader> loader =
FileDescriptorDataLoader::fromFileDescriptorUri(model_path);

ET_CHECK_MSG(
loader.ok(),
"FileDescriptorDataLoader::fromFileDescriptorUri() failed: 0x%" PRIx32,
(uint32_t)loader.error());
return Program::load(&loader.get());
}
}

int main(int argc, char** argv) {
executorch::runtime::runtime_init();

Expand All @@ -102,11 +66,15 @@ int main(int argc, char** argv) {
// DataLoaders that use mmap() or point to data that's already in memory, and
// users can create their own DataLoaders to load from arbitrary sources.
const char* model_path = FLAGS_model_path.c_str();
const bool is_fd_uri = FLAGS_is_fd_uri;
Result<FileDataLoader> loader = FileDataLoader::from(model_path);
ET_CHECK_MSG(
loader.ok(),
"FileDataLoader::from() failed: 0x%" PRIx32,
(uint32_t)loader.error());

// Parse the program file. This is immutable, and can also be reused between
// multiple execution invocations across multiple threads.
Result<Program> program = getProgram(is_fd_uri, model_path);
Result<Program> program = Program::load(&loader.get());
if (!program.ok()) {
ET_LOG(Error, "Failed to parse model file %s", model_path);
return 1;
Expand Down
1 change: 0 additions & 1 deletion examples/portable/executor_runner/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def define_common_targets():
deps = [
"//executorch/runtime/executor:program",
"//executorch/extension/data_loader:file_data_loader",
"//executorch/extension/data_loader:file_descriptor_data_loader",
"//executorch/extension/evalue_util:print_evalue",
"//executorch/extension/runner_util:inputs",
],
Expand Down
Loading