Back out "Back out "[profiling] Adding targets file for test_mobile_profiler"" (#82243)

Summary:
Originally reverted this diff D37116110 (c9aa74a37f) 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: https://github.com/pytorch/pytorch/pull/82243
Approved by: https://github.com/salilsdesai
This commit is contained in:
Max Ren 2022-07-28 23:08:52 +00:00 committed by PyTorch MergeBot
parent 89c0123ba0
commit 727a327162
2 changed files with 45 additions and 1 deletions

View File

@ -145,6 +145,15 @@ class BackendWithCompiler : public PyTorchBackendInterface {
auto x_ptr = float_data_ptr(x); auto x_ptr = float_data_ptr(x);
auto h_ptr = float_data_ptr(h); auto h_ptr = float_data_ptr(h);
auto y_ptr = float_data_ptr(y); 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") { if (instruction == "aten::add") {
y_ptr[0] = x_ptr[0] + h_ptr[0]; y_ptr[0] = x_ptr[0] + h_ptr[0];
} else { } else {

View File

@ -25,7 +25,9 @@ bool checkMetaData(
if (line.find(op_name) != std::string::npos) { if (line.find(op_name) != std::string::npos) {
while (std::getline(trace_file, line)) { while (std::getline(trace_file, line)) {
if (line.find(metadata_name) != std::string::npos) { 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;
}
} }
} }
} }
@ -122,6 +124,39 @@ TEST(MobileProfiler, Backend) {
checkMetaData("aten::add", metadata_name, "test_backend", trace_file)); 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 mobile
} // namespace jit } // namespace jit
} // namespace torch } // namespace torch