22
22
23
23
#include < gflags/gflags.h>
24
24
25
- #include < fcntl.h>
26
- #include < unistd.h>
27
-
28
25
#include < executorch/extension/data_loader/file_data_loader.h>
29
- #include < executorch/extension/data_loader/file_descriptor_data_loader.h>
30
26
#include < executorch/extension/evalue_util/print_evalue.h>
31
27
#include < executorch/extension/runner_util/inputs.h>
32
28
#include < executorch/runtime/executor/method.h>
@@ -40,13 +36,8 @@ DEFINE_string(
40
36
model_path,
41
37
" model.pte" ,
42
38
" 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:///\" ." );
47
39
48
40
using executorch::extension::FileDataLoader;
49
- using executorch::extension::FileDescriptorDataLoader;
50
41
using executorch::runtime::Error;
51
42
using executorch::runtime::EValue;
52
43
using executorch::runtime::HierarchicalAllocator;
@@ -58,33 +49,6 @@ using executorch::runtime::Program;
58
49
using executorch::runtime::Result;
59
50
using executorch::runtime::Span;
60
51
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
-
88
52
int main (int argc, char ** argv) {
89
53
executorch::runtime::runtime_init ();
90
54
@@ -102,11 +66,15 @@ int main(int argc, char** argv) {
102
66
// DataLoaders that use mmap() or point to data that's already in memory, and
103
67
// users can create their own DataLoaders to load from arbitrary sources.
104
68
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 ());
106
74
107
75
// Parse the program file. This is immutable, and can also be reused between
108
76
// multiple execution invocations across multiple threads.
109
- Result<Program> program = getProgram (is_fd_uri, model_path );
77
+ Result<Program> program = Program::load (&loader. get () );
110
78
if (!program.ok ()) {
111
79
ET_LOG (Error, " Failed to parse model file %s" , model_path);
112
80
return 1 ;
0 commit comments