Skip to content

Commit

Permalink
Back out "Back out "[profiling] Adding targets file for test_mobile_p…
Browse files Browse the repository at this point in the history
…rofiler"" (pytorch#82243)

Summary:
Originally reverted this diff D37116110 (pytorch@c9aa74a) because

```
> /usr/local/bin/buck build //caffe2/test/cpp/lite_interpreter_runtime/...

BUILD FAILED
The rule //caffe2:backend_interface_libAndroid could not be found.
Please check the spelling and whether it is one of the 1866 targets in /data/users/batanasov/fbsource/fbcode/caffe2/TARGETS. (52107 bytes)
1 similar targets in /data/users/batanasov/fbsource/fbcode/caffe2/TARGETS are:
  //caffe2:backend_interface_lib

This error happened while trying to get dependency '//caffe2:backend_interface_libAndroid' of target '//caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profilerAndroid'
    At //caffe2:backend_interface_libAndroid (ovr_config//platform/linux:x86_64-fbcode)
    At //caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profilerAndroid (ovr_config//platform/linux:x86_64-fbcode)
```

The add test_mobile_profiler was not meant to be built with Android or other mobile platforms, so we are changing the test to a cpp_unittest

Test Plan:
```
buck test //caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profiler
Parsing buck files: finished in 0.9 sec
Creating action graph: finished in 26.5 sec
Downloaded 2/2 artifacts, 1.30 Mbytes, 0.0% cache miss (for updated rules)
Building: finished in 16.5 sec (100%) 18451/18451 jobs, 3/18451 updated
  Total time: 44.0 sec
More details at https://www.internalfb.com/intern/buck/build/8bee82c1-66a9-4fae-805f-e4ef5505d25d
BUILD SUCCEEDED
Tpx test run coordinator for Facebook. See https://fburl.com/tpx for details.
Running with tpx session id: 6904f989-5c17-4c5b-9a4f-ffb643dfcc43
Trace available for this run at /tmp/tpx-20220726-114727.001729-6904f989-5c17-4c5b-9a4f-ffb643dfcc43/trace.log
RemoteExecution session id: reSessionID-6904f989-5c17-4c5b-9a4f-ffb643dfcc43-tpx
Started reporting to test run: https://www.internalfb.com/intern/testinfra/testrun/844425183404951
    ✓ ListingSuccess: caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profiler : 3 tests discovered (17.640)
    ✓ Pass: caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profiler - MobileProfiler.Backend (0.206)
    ✓ Pass: caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profiler - MobileProfiler.BackendMemoryEvents (0.271)
    ✓ Pass: caffe2/test/cpp/lite_interpreter_runtime:test_mobile_profiler - MobileProfiler.ModuleHierarchy (0.268)
Summary
  Pass: 3
  ListingSuccess: 1
Finished test run: https://www.internalfb.com/intern/testinfra/testrun/844425183404951
```

Differential Revision: D38166171

Pull Request resolved: pytorch#82243
Approved by: https://github.com/salilsdesai
  • Loading branch information
mcr229 authored and pytorchmergebot committed Jul 28, 2022
1 parent 89c0123 commit 727a327
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/cpp/jit/test_backend_compiler_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ class BackendWithCompiler : public PyTorchBackendInterface {
auto x_ptr = float_data_ptr(x);
auto h_ptr = float_data_ptr(h);
auto y_ptr = float_data_ptr(y);
#ifndef NO_PROFILING
RECORD_BACKEND_MEMORY_EVENT_TO_EDGE_PROFILER(
x_ptr,
x.numel() * sizeof(float),
x.numel() * sizeof(float),
x.numel() * sizeof(float) + y.numel() * sizeof(float) +
h.numel() * sizeof(float),
c10::Device(c10::kCPU));
#endif
if (instruction == "aten::add") {
y_ptr[0] = x_ptr[0] + h_ptr[0];
} else {
Expand Down
37 changes: 36 additions & 1 deletion test/cpp/lite_interpreter_runtime/test_mobile_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ bool checkMetaData(
if (line.find(op_name) != std::string::npos) {
while (std::getline(trace_file, line)) {
if (line.find(metadata_name) != std::string::npos) {
return (line.find(metadata_val) != std::string::npos);
if (line.find(metadata_val) != std::string::npos) {
return true;
}
}
}
}
Expand Down Expand Up @@ -122,6 +124,39 @@ TEST(MobileProfiler, Backend) {
checkMetaData("aten::add", metadata_name, "test_backend", trace_file));
}

TEST(MobileProfiler, BackendMemoryEvents) {
std::string filePath(__FILE__);
auto testModelFile = filePath.substr(0, filePath.find_last_of("/\\") + 1);
testModelFile.append("test_backend_for_profiling.ptl");

std::vector<IValue> inputs;
inputs.emplace_back(at::rand({64, 64}));
inputs.emplace_back(at::rand({64, 64}));
std::string trace_file_name("/tmp/test_trace_backend_memory.trace");

mobile::Module bc = _load_for_mobile(testModelFile);
{
mobile::KinetoEdgeCPUProfiler profiler(
bc,
trace_file_name,
false, // record input_shapes
true, // profile memory
true, // record callstack
false, // record flops
true); // record module hierarchy
bc.forward(inputs);
}
std::ifstream trace_file(trace_file_name);
std::string line;
ASSERT_TRUE(trace_file.is_open());
trace_file.seekg(0, std::ios_base::beg);
std::string metadata_name("Bytes");
ASSERT_TRUE(checkMetaData("[memory]", metadata_name, "16384", trace_file));
trace_file.seekg(0, std::ios_base::beg);
metadata_name = "Total Reserved";
ASSERT_TRUE(checkMetaData("[memory]", metadata_name, "49152", trace_file));
}

} // namespace mobile
} // namespace jit
} // namespace torch
Expand Down

0 comments on commit 727a327

Please sign in to comment.