From 51d9fe0b2d1ae5f620e2d803df309bc5a856e393 Mon Sep 17 00:00:00 2001 From: lind Date: Tue, 5 Nov 2024 22:56:25 -0800 Subject: [PATCH] fix seg fault --- .../executor_runner/executor_runner.cpp | 44 +++---------------- examples/portable/executor_runner/targets.bzl | 1 - 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/examples/portable/executor_runner/executor_runner.cpp b/examples/portable/executor_runner/executor_runner.cpp index 35e58fec035..93c150c0b90 100644 --- a/examples/portable/executor_runner/executor_runner.cpp +++ b/examples/portable/executor_runner/executor_runner.cpp @@ -22,11 +22,7 @@ #include -#include -#include - #include -#include #include #include #include @@ -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; @@ -58,33 +49,6 @@ using executorch::runtime::Program; using executorch::runtime::Result; using executorch::runtime::Span; -static Result 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 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 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(); @@ -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 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 = getProgram(is_fd_uri, model_path); + Result program = Program::load(&loader.get()); if (!program.ok()) { ET_LOG(Error, "Failed to parse model file %s", model_path); return 1; diff --git a/examples/portable/executor_runner/targets.bzl b/examples/portable/executor_runner/targets.bzl index 83c63d3a411..9cddaa4ed77 100644 --- a/examples/portable/executor_runner/targets.bzl +++ b/examples/portable/executor_runner/targets.bzl @@ -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", ],