Browse Source

feat(sdk/load_and_run): add flags --io-dump-stdout and --io-dump-stderr

GitOrigin-RevId: 64d572bdfc
release-1.2
Megvii Engine Team 4 years ago
parent
commit
ebe8689267
2 changed files with 38 additions and 0 deletions
  1. +20
    -0
      sdk/load-and-run/src/mgblar.cpp
  2. +18
    -0
      src/plugin/test/opr_io_dump.cpp

+ 20
- 0
sdk/load-and-run/src/mgblar.cpp View File

@@ -94,6 +94,8 @@ R"__usage__(
Dump input/output values of all internal variables to output file or
directory, in text or binary format. The binary file can be parsed by
`megbrain.plugin.load_tensor_binary`.
--io-dump-stdout | --io-dump-stderr
Dump input/output values of all internal variables to stdout or stderr in text format
--bin-out-dump <output dir>
Dump output tensor values in binary format to given directory.
--iter <num>
@@ -1200,6 +1202,24 @@ Args Args::from_argv(int argc, char **argv) {
ret.iodump = std::move(iodump);
continue;
}
if (!strcmp(argv[i], "--io-dump-stdout")) {
mgb_log_warn("enable opr io dump to stdout");
std::shared_ptr<FILE> sp(stdout, [](FILE*){});
auto iodump = std::make_unique<TextOprIODump>(
ret.load_config.comp_graph.get(), sp);
iodump->print_addr(false);
ret.iodump = std::move(iodump);
continue;
}
if (!strcmp(argv[i], "--io-dump-stderr")) {
mgb_log_warn("enable opr io dump to stderr");
std::shared_ptr<FILE> sp(stderr, [](FILE*){});
auto iodump = std::make_unique<TextOprIODump>(
ret.load_config.comp_graph.get(), sp);
iodump->print_addr(false);
ret.iodump = std::move(iodump);
continue;
}
if (!strcmp(argv[i], "--bin-io-dump")) {
mgb_log_warn("enable opr binary io dump");
++ i;


+ 18
- 0
src/plugin/test/opr_io_dump.cpp View File

@@ -181,6 +181,24 @@ TEST(TestOprIODump, Text) {
run_test(make_plugin, check_result);
}

TEST(TestOprIODump, StdErr) {
HostTensorGenerator<> gen;
auto host_x = gen({5});
auto host_y = gen({5});

auto graph = ComputingGraph::make();
std::shared_ptr<FILE> sp(stdout, [](FILE*){});
auto plugin = std::make_unique<TextOprIODump>(graph.get(), sp);

auto x = opr::Host2DeviceCopy::make(*graph, host_x);
auto y = opr::Host2DeviceCopy::make(*graph, host_y);
auto z = x + y;

HostTensorND host_z;
auto func = graph->compile({make_callback_copy(z, host_z)});
func->execute();
}

TEST(TestOprIODump, Binary) {
auto fname = output_file("");
auto make_plugin = [&](ComputingGraph* graph, int level) {


Loading…
Cancel
Save