Skip to content

Commit 6cef6c7

Browse files
dbortfacebook-github-bot
authored andcommitted
Simplify executor_runner
Summary: Remove some leftover pieces that were only necessary to handle the bundled program path. Also fix the error message printed when there are extra args. And fix `get_oss_build_kwargs` so that `linker_flags` is a list of strings instead of just a string. Reviewed By: JacobSzwejbka Differential Revision: D47885731 fbshipit-source-id: a48e484d3a79ecc7fdf767da5170d0ba96793f2a
1 parent 2d70a98 commit 6cef6c7

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

examples/executor_runner/executor_runner.cpp

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,57 +34,37 @@ static uint8_t runtime_pool[kRuntimeMemorySize];
3434
DEFINE_string(model_path, "model.ff", "Model serialized in flatbuffer format.");
3535

3636
using namespace torch::executor;
37+
using torch::executor::util::FileDataLoader;
3738

3839
int main(int argc, char** argv) {
3940
runtime_init();
4041

4142
gflags::ParseCommandLineFlags(&argc, &argv, true);
4243
if (argc != 1) {
43-
std::string msg = "Extra commandline args: ";
44+
std::string msg = "Extra commandline args:";
4445
for (int i = 1 /* skip argv[0] (program name) */; i < argc; i++) {
45-
msg += argv[i];
46+
msg += std::string(" ") + argv[i];
4647
}
4748
ET_LOG(Error, "%s", msg.c_str());
4849
return 1;
4950
}
5051

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);
5557
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());
7959

8060
// Parse the program file. This is immutable, and can also be reused between
8161
// multiple execution invocations across multiple threads.
8262
Result<Program> program = Program::Load(&loader.get());
8363
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);
8565
return 1;
8666
}
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);
8868

8969
// Use the first method in the program.
9070
const size_t plan_index = 0;

examples/executor_runner/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def define_common_targets():
1313
srcs = ["executor_runner.cpp"],
1414
deps = [
1515
"//executorch/runtime/executor/test:test_backend_compiler_lib",
16-
"//executorch/runtime/executor:executor",
16+
"//executorch/runtime/executor:program",
1717
"//executorch/extension/data_loader:file_data_loader",
1818
"//executorch/util:util",
1919
"//executorch/kernels/portable:generated_lib_all_ops",

shim/xplat/executorch/build/runtime_wrapper.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,13 @@ def _python_test(*args, **kwargs):
309309

310310
def get_oss_build_kwargs():
311311
if env.is_oss:
312-
return {"link_style": "static", "linker_flags": "-ldl"}
312+
return {
313+
"link_style": "static",
314+
"linker_flags": [
315+
# platform/system.h uses dladdr() on mac and linux
316+
"-ldl",
317+
],
318+
}
313319
return {}
314320

315321
# Names in this struct should match the standard Buck rule names if possible:

0 commit comments

Comments
 (0)