Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions onnxruntime/test/onnx/microbenchmark/tptest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BENCHMARK(BM_CreateThreadPool)
#pragma GCC optimize("O0")
#endif
void SimpleForLoop(ptrdiff_t first, ptrdiff_t last) {
size_t sum = 0;
[[maybe_unused]] size_t sum = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the compiler is warning about it, could it also be "smart" enough to optimize it away? should we also do something similar to the other change in the PR with benchmark::DoNotOptimize()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah possibly worth doing that, its unclear what the compiler will do. Its possible that its optimizing it away in older versions where this warning isn't being thrown. But I will check if benchmark::DoNotOptimize(sum) silences the warning and if so i'll make that change. (I assume it will)

for (; first != last; ++first) {
++sum;
}
Expand Down Expand Up @@ -102,7 +102,8 @@ static void BM_ThreadPoolSimpleParallelFor(benchmark::State& state) {
for (auto _ : state) {
for (int j = 0; j < 100; j++) {
ThreadPool::TrySimpleParallelFor(tp.get(), len, [&](size_t) {
for (volatile size_t x = 0; x < body; x++) {
for (size_t x = 0; x < body; x++) {
benchmark::DoNotOptimize(x);
}
});
}
Expand Down
Loading