Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert D25199264: Enable callgrind collection for C++ snippet…
…s" (#48720) Summary: Pull Request resolved: #48720 This reverts commit 6646ff1. Test Plan: Imported from OSS Reviewed By: malfet Differential Revision: D25273994 Pulled By: malfet fbshipit-source-id: 61743176dc650136622e1b8f2384bbfbd7a46294
- Loading branch information
1 parent
b2ec21a
commit 022c929
Showing
6 changed files
with
133 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
torch/utils/benchmark/utils/valgrind_wrapper/timer_callgrind_template.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* C++ template for Timer.collect_callgrind | ||
This template will be consumed by `cpp_jit.py`, and will replace: | ||
`SETUP_TEMPLATE_LOCATION` | ||
and | ||
`STMT_TEMPLATE_LOCATION` | ||
sections with user provided statements. | ||
*/ | ||
|
||
#include <string> | ||
|
||
#include <callgrind.h> | ||
#include <torch/torch.h> | ||
|
||
#if defined(NVALGRIND) | ||
static_assert(false); | ||
#endif | ||
|
||
int main(int argc, char* argv[]) { | ||
// This file should only be called inside of `Timer`, so we can adopt a | ||
// very simple and rigid argument parsing scheme. | ||
TORCH_CHECK(argc == 7); | ||
TORCH_CHECK(std::string(argv[1]) == "--number"); | ||
auto number = std::stoi(argv[2]); | ||
|
||
TORCH_CHECK(std::string(argv[3]) == "--number_warmup"); | ||
auto number_warmup = std::stoi(argv[4]); | ||
|
||
TORCH_CHECK(std::string(argv[5]) == "--number_threads"); | ||
auto number_threads = std::stoi(argv[6]); | ||
torch::set_num_threads(number_threads); | ||
|
||
// Setup | ||
// SETUP_TEMPLATE_LOCATION | ||
|
||
// Warmup | ||
for (int i = 0; i < number_warmup; i++) { | ||
// STMT_TEMPLATE_LOCATION | ||
} | ||
|
||
// Main loop | ||
CALLGRIND_TOGGLE_COLLECT; | ||
for (int i = 0; i < number; i++) { | ||
// STMT_TEMPLATE_LOCATION | ||
} | ||
CALLGRIND_TOGGLE_COLLECT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters