diff --git a/sdk/load-and-run/src/mgblar.cpp b/sdk/load-and-run/src/mgblar.cpp index 506998ae6c7916ca8c36ae5e603550cdc1c30f75..b7888bc577f2ea899dc179e509097e4596855894 100644 --- a/sdk/load-and-run/src/mgblar.cpp +++ b/sdk/load-and-run/src/mgblar.cpp @@ -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 Dump output tensor values in binary format to given directory. --iter @@ -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 sp(stdout, [](FILE*){}); + auto iodump = std::make_unique( + 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 sp(stderr, [](FILE*){}); + auto iodump = std::make_unique( + 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; diff --git a/src/plugin/test/opr_io_dump.cpp b/src/plugin/test/opr_io_dump.cpp index 4907940f089a89bd1fba90868084c42d30db19db..3b88a2cca96da922743090463cad7b6d32fb3cbd 100644 --- a/src/plugin/test/opr_io_dump.cpp +++ b/src/plugin/test/opr_io_dump.cpp @@ -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 sp(stdout, [](FILE*){}); + auto plugin = std::make_unique(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) {