@@ -174,22 +174,42 @@ inline std::unique_ptr<Module> load_module_from_buffer(
174
174
}
175
175
176
176
inline std::unique_ptr<Module> load_module_from_file (
177
- const std::string& path,
177
+ const std::string& program_path,
178
+ std::optional<const std::string>& data_map_path,
178
179
std::unique_ptr<runtime::EventTracer> event_tracer,
179
180
Program::Verification program_verification) {
180
181
EXECUTORCH_SCOPE_PROF (" load_module_from_file" );
181
182
182
- Result<MmapDataLoader> res = MmapDataLoader::from (
183
- path .c_str (), MmapDataLoader::MlockConfig::UseMlockIgnoreErrors);
183
+ Result<MmapDataLoader> program_loader_res = MmapDataLoader::from (
184
+ program_path .c_str (), MmapDataLoader::MlockConfig::UseMlockIgnoreErrors);
184
185
THROW_IF_ERROR (
185
- res .error (),
186
+ program_loader_res .error (),
186
187
" Failed to create MmapDataLoader from file %s, error: 0x:%" PRIx32,
187
- path.c_str (),
188
- static_cast <uint32_t >(res.error ()));
189
-
190
- auto loader = std::make_unique<MmapDataLoader>(std::move (res.get ()));
188
+ program_path.c_str (),
189
+ static_cast <uint32_t >(program_loader_res.error ()));
190
+ auto program_loader =
191
+ std::make_unique<MmapDataLoader>(std::move (program_loader_res.get ()));
192
+
193
+ if (data_map_path.has_value ()) {
194
+ Result<MmapDataLoader> data_map_loader_res = MmapDataLoader::from (
195
+ data_map_path->c_str (),
196
+ MmapDataLoader::MlockConfig::UseMlockIgnoreErrors);
197
+ THROW_IF_ERROR (
198
+ data_map_loader_res.error (),
199
+ " Failed to create MmapDataLoader from file %s, error: 0x:%" PRIx32,
200
+ data_map_path->c_str (),
201
+ static_cast <uint32_t >(data_map_loader_res.error ()));
202
+ auto data_map_loader =
203
+ std::make_unique<MmapDataLoader>(std::move (data_map_loader_res.get ()));
204
+ return std::make_unique<Module>(
205
+ std::move (program_loader),
206
+ nullptr , // memory_allocator
207
+ nullptr , // temp_allocator
208
+ std::move (event_tracer), // event_tracer
209
+ std::move (data_map_loader)); // data_map_loader
210
+ }
191
211
return std::make_unique<Module>(
192
- std::move (loader ),
212
+ std::move (program_loader ),
193
213
nullptr , // memory_allocator
194
214
nullptr , // temp_allocator
195
215
std::move (event_tracer), // event_tracer
@@ -510,14 +530,16 @@ struct PyModule final {
510
530
program_verification)) {}
511
531
512
532
explicit PyModule (
513
- const std::string& path,
533
+ const std::string& program_path,
534
+ std::optional<const std::string>& data_path,
514
535
bool enable_etdump,
515
536
size_t debug_buffer_size = 0 ,
516
537
Program::Verification program_verification =
517
538
Program::Verification::InternalConsistency)
518
539
: debug_buffer_size_(debug_buffer_size),
519
540
module_(load_module_from_file(
520
- path,
541
+ program_path,
542
+ data_path,
521
543
setup_event_tracer (enable_etdump, debug_buffer_size),
522
544
program_verification)) {}
523
545
@@ -536,14 +558,20 @@ struct PyModule final {
536
558
return std::make_unique<PyModule>(
537
559
buffer, enable_etdump, debug_buffer_size, program_verification);
538
560
}
561
+
539
562
static std::unique_ptr<PyModule> load_from_file (
540
- const std::string& path,
563
+ const std::string& program_path,
564
+ std::optional<const std::string>& data_path,
541
565
bool enable_etdump,
542
566
size_t debug_buffer_size = 0 ,
543
567
Program::Verification program_verification =
544
568
Program::Verification::InternalConsistency) {
545
569
return std::make_unique<PyModule>(
546
- path, enable_etdump, debug_buffer_size, program_verification);
570
+ program_path,
571
+ data_path,
572
+ enable_etdump,
573
+ debug_buffer_size,
574
+ program_verification);
547
575
}
548
576
549
577
static std::unique_ptr<PyModule> load_from_bundled_program (
@@ -1351,7 +1379,8 @@ PYBIND11_MODULE(EXECUTORCH_PYTHON_MODULE_NAME, m) {
1351
1379
m.def (
1352
1380
" _load_for_executorch" ,
1353
1381
PyModule::load_from_file,
1354
- py::arg (" path" ),
1382
+ py::arg (" program_path" ),
1383
+ py::arg (" data_path" ) = std::nullopt ,
1355
1384
py::arg (" enable_etdump" ) = false ,
1356
1385
py::arg (" debug_buffer_size" ) = 0 ,
1357
1386
py::arg (" program_verification" ) =
0 commit comments