@@ -34,57 +34,37 @@ static uint8_t runtime_pool[kRuntimeMemorySize];
34
34
DEFINE_string (model_path, " model.ff" , " Model serialized in flatbuffer format." );
35
35
36
36
using namespace torch ::executor;
37
+ using torch::executor::util::FileDataLoader;
37
38
38
39
int main (int argc, char ** argv) {
39
40
runtime_init ();
40
41
41
42
gflags::ParseCommandLineFlags (&argc, &argv, true );
42
43
if (argc != 1 ) {
43
- std::string msg = " Extra commandline args: " ;
44
+ std::string msg = " Extra commandline args:" ;
44
45
for (int i = 1 /* skip argv[0] (program name) */ ; i < argc; i++) {
45
- msg += argv[i];
46
+ msg += std::string ( " " ) + argv[i];
46
47
}
47
48
ET_LOG (Error, " %s" , msg.c_str ());
48
49
return 1 ;
49
50
}
50
51
51
- // Create a DataLoader that wraps the input file. It may be a plain Program,
52
- // or it may be a BundledProgram that contains a Program.
53
- Result<util::FileDataLoader> loader =
54
- util::FileDataLoader::From (FLAGS_model_path.c_str ());
52
+ // Create a loader to get the data of the program file. There are other
53
+ // DataLoaders that use mmap() or point to data that's already in memory, and
54
+ // users can create their own DataLoaders to load from arbitrary sources.
55
+ const char * model_path = FLAGS_model_path.c_str ();
56
+ Result<FileDataLoader> loader = FileDataLoader::From (model_path);
55
57
ET_CHECK_MSG (
56
- loader.ok (),
57
- " Could not create loader for file '%s': 0x%x" ,
58
- FLAGS_model_path.c_str (),
59
- (unsigned int )loader.error ());
60
-
61
- Result<FreeableBuffer> header =
62
- loader->Load (/* offset=*/ 0 , Program::kMinHeadBytes );
63
- ET_CHECK_MSG (
64
- header.ok (),
65
- " Could not load header of file '%s': 0x%x" ,
66
- FLAGS_model_path.c_str (),
67
- (unsigned int )loader.error ());
68
- Program::HeaderStatus hs =
69
- Program::check_header (header->data (), header->size ());
70
- if (hs != Program::HeaderStatus::CompatibleVersion) {
71
- ET_CHECK_MSG (
72
- false ,
73
- " Failed to load contents of file '%s' "
74
- " Expected header status 0x%x but got 0x%x" ,
75
- FLAGS_model_path.c_str (),
76
- Program::HeaderStatus::CompatibleVersion,
77
- hs);
78
- }
58
+ loader.ok (), " FileDataLoader::From() failed: 0x%" PRIx32, loader.error ());
79
59
80
60
// Parse the program file. This is immutable, and can also be reused between
81
61
// multiple execution invocations across multiple threads.
82
62
Result<Program> program = Program::Load (&loader.get ());
83
63
if (!program.ok ()) {
84
- ET_LOG (Error, " Failed to parse model file %s" , FLAGS_model_path. c_str () );
64
+ ET_LOG (Error, " Failed to parse model file %s" , model_path );
85
65
return 1 ;
86
66
}
87
- ET_LOG (Info, " Model file %s is loaded." , FLAGS_model_path. c_str () );
67
+ ET_LOG (Info, " Model file %s is loaded." , model_path );
88
68
89
69
// Use the first method in the program.
90
70
const size_t plan_index = 0 ;
0 commit comments