2222
2323#include < gflags/gflags.h>
2424
25- #include < fcntl.h>
26- #include < unistd.h>
27-
2825#include < executorch/extension/data_loader/file_data_loader.h>
29- #include < executorch/extension/data_loader/file_descriptor_data_loader.h>
3026#include < executorch/extension/evalue_util/print_evalue.h>
3127#include < executorch/extension/runner_util/inputs.h>
3228#include < executorch/runtime/executor/method.h>
@@ -40,13 +36,8 @@ DEFINE_string(
4036 model_path,
4137 " model.pte" ,
4238 " Model serialized in flatbuffer format." );
43- DEFINE_bool (
44- is_fd_uri,
45- false ,
46- " True if the model_path passed is a file descriptor with the prefix \" fd:///\" ." );
4739
4840using executorch::extension::FileDataLoader;
49- using executorch::extension::FileDescriptorDataLoader;
5041using executorch::runtime::Error;
5142using executorch::runtime::EValue;
5243using executorch::runtime::HierarchicalAllocator;
@@ -58,33 +49,6 @@ using executorch::runtime::Program;
5849using executorch::runtime::Result;
5950using executorch::runtime::Span;
6051
61- static Result<Program> getProgram (
62- const bool is_fd_uri,
63- const char * model_path) {
64- // Create a loader to get the data of the program file. This demonstrates both
65- // FileDataLoader and FileDescriptorDataLoader. There are other DataLoaders
66- // that use mmap() or point to data that's already in memory, and users can
67- // create their own DataLoaders to load from arbitrary sources.
68- if (!is_fd_uri) {
69- Result<FileDataLoader> loader = FileDataLoader::from (model_path);
70-
71- ET_CHECK_MSG (
72- loader.ok (),
73- " FileDataLoader::from() failed: 0x%" PRIx32,
74- (uint32_t )loader.error ());
75- return Program::load (&loader.get ());
76- } else {
77- Result<FileDescriptorDataLoader> loader =
78- FileDescriptorDataLoader::fromFileDescriptorUri (model_path);
79-
80- ET_CHECK_MSG (
81- loader.ok (),
82- " FileDescriptorDataLoader::fromFileDescriptorUri() failed: 0x%" PRIx32,
83- (uint32_t )loader.error ());
84- return Program::load (&loader.get ());
85- }
86- }
87-
8852int main (int argc, char ** argv) {
8953 executorch::runtime::runtime_init ();
9054
@@ -102,11 +66,15 @@ int main(int argc, char** argv) {
10266 // DataLoaders that use mmap() or point to data that's already in memory, and
10367 // users can create their own DataLoaders to load from arbitrary sources.
10468 const char * model_path = FLAGS_model_path.c_str ();
105- const bool is_fd_uri = FLAGS_is_fd_uri;
69+ Result<FileDataLoader> loader = FileDataLoader::from (model_path);
70+ ET_CHECK_MSG (
71+ loader.ok (),
72+ " FileDataLoader::from() failed: 0x%" PRIx32,
73+ (uint32_t )loader.error ());
10674
10775 // Parse the program file. This is immutable, and can also be reused between
10876 // multiple execution invocations across multiple threads.
109- Result<Program> program = getProgram (is_fd_uri, model_path );
77+ Result<Program> program = Program::load (&loader. get () );
11078 if (!program.ok ()) {
11179 ET_LOG (Error, " Failed to parse model file %s" , model_path);
11280 return 1 ;
0 commit comments