forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for timing C++ snippets. (pytorch#47864)
Summary: Pull Request resolved: pytorch#47864 Test Plan: Imported from OSS Reviewed By: ngimel Differential Revision: D25199262 Pulled By: robieta fbshipit-source-id: 1c2114628ed543fba4f403bf49c065f4d71388e2
- Loading branch information
1 parent
17ea112
commit 0225d3d
Showing
7 changed files
with
224 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* C++ template for Timer.timeit | ||
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 <chrono> | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <torch/extension.h> | ||
|
||
|
||
double timeit(int n) { | ||
// Setup | ||
// SETUP_TEMPLATE_LOCATION | ||
|
||
{ | ||
// Warmup | ||
// STMT_TEMPLATE_LOCATION | ||
} | ||
|
||
// Main loop | ||
auto start_time = std::chrono::high_resolution_clock::now(); | ||
for (int loop_idx = 0; loop_idx < n; loop_idx++) { | ||
// STMT_TEMPLATE_LOCATION | ||
} | ||
auto end_time = std::chrono::high_resolution_clock::now(); | ||
return std::chrono::duration<double>(end_time - start_time).count(); | ||
} | ||
|
||
|
||
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { | ||
m.def("timeit", &timeit); | ||
} |
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