-
Notifications
You must be signed in to change notification settings - Fork 349
[MicroBenchmarks/LoopVectorization] Add Microbenchmark for Epilogue Vectorization #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fhahn
merged 4 commits into
llvm:main
from
juliannagele:epilogue-vectorization-microbenchmarks
Oct 3, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
76ffb58
[MicroBenchmarks/LoopVectorization] Add Microbenchmarks for Epilogue …
juliannagele 2cf9bc5
fixup! [MicroBenchmarks/LoopVectorization] Add Microbenchmarks for Ep…
juliannagele 1c7c209
fixup! fixup! [MicroBenchmarks/LoopVectorization] Add Microbenchmarks…
juliannagele b070f2e
fixup! fixup! fixup! [MicroBenchmarks/LoopVectorization] Add Microben…
juliannagele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
88 changes: 88 additions & 0 deletions
88
MicroBenchmarks/LoopVectorization/EpilogueVectorization.cpp
This file contains hidden or 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,88 @@ | ||
// This program tests performance impact of Epilogue Vectorization | ||
// with varying epilogue lengths, and vector widths. | ||
#include <cstdint> | ||
#include <memory> | ||
#include <random> | ||
|
||
#include "benchmark/benchmark.h" | ||
|
||
static std::mt19937 rng; | ||
uint64_t g_sum = 0; | ||
|
||
// Initialize array A with random numbers. | ||
template <typename Ty> | ||
static void init_data(const std::unique_ptr<Ty[]> &A, unsigned N) { | ||
std::uniform_int_distribution<Ty> distrib(std::numeric_limits<Ty>::min(), | ||
std::numeric_limits<Ty>::max()); | ||
for (unsigned I = 0; I < N; I++) | ||
A[I] = distrib(rng); | ||
} | ||
|
||
// Helper to block optimizing \p F based on its arguments. | ||
template <typename F, typename... Args> | ||
__attribute__((optnone)) static uint64_t callThroughOptnone(F &&f, Args &&...args) { | ||
return f(std::forward<Args>(args)...); | ||
} | ||
|
||
template <typename Ty> | ||
static void __attribute__((always_inline)) | ||
runBenchForEpilogueVectorization(benchmark::State &state, | ||
uint64_t (*Fn)(Ty *, Ty *, Ty *, int)) { | ||
auto Iterations = state.range(0); | ||
std::unique_ptr<Ty[]> A(new Ty[Iterations]); | ||
std::unique_ptr<Ty[]> B(new Ty[Iterations]); | ||
std::unique_ptr<Ty[]> C(new Ty[Iterations]); | ||
init_data(A, Iterations); | ||
init_data(B, Iterations); | ||
init_data(C, Iterations); | ||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(A); | ||
benchmark::DoNotOptimize(B); | ||
benchmark::DoNotOptimize(C); | ||
benchmark::ClobberMemory(); | ||
g_sum += callThroughOptnone(Fn, &A[0], &B[0], &C[0], Iterations); | ||
} | ||
} | ||
|
||
template <typename Ty> | ||
static uint64_t __attribute__((noinline)) | ||
loopAutoVec(Ty *A, Ty *B, Ty *C, int Iterations) { | ||
for (int J = 0; J < Iterations; J++) { | ||
A[J] = B[J] + C[J]; | ||
} | ||
return 0; | ||
} | ||
|
||
template <typename Ty> | ||
static uint64_t __attribute__((noinline)) | ||
loopWithReductionAutoVec(Ty *A, Ty *B, Ty *C, int Iterations) { | ||
uint64_t sum = 0; | ||
for (int J = 0; J < Iterations; J++) { | ||
sum += A[J]; | ||
} | ||
return sum; | ||
} | ||
|
||
template <typename Ty> void benchAutoVec(benchmark::State &state) { | ||
runBenchForEpilogueVectorization<Ty>(state, &loopAutoVec<Ty>); | ||
} | ||
|
||
template <typename Ty> void benchReductionAutoVec(benchmark::State &state) { | ||
runBenchForEpilogueVectorization<Ty>(state, &loopWithReductionAutoVec<Ty>); | ||
} | ||
|
||
#ifdef ALL_LOOP_EPILOGUE_TESTS | ||
BENCHMARK_TEMPLATE(benchAutoVec, uint8_t)->DenseRange(65, 127, 1); | ||
BENCHMARK_TEMPLATE(benchReductionAutoVec, uint8_t)->DenseRange(65, 127, 1); | ||
BENCHMARK_TEMPLATE(benchAutoVec, uint16_t)->DenseRange(65, 127, 1); | ||
BENCHMARK_TEMPLATE(benchReductionAutoVec, uint16_t)->DenseRange(65, 127, 1); | ||
BENCHMARK_TEMPLATE(benchAutoVec, uint32_t)->DenseRange(65, 127, 1); | ||
BENCHMARK_TEMPLATE(benchReductionAutoVec, uint32_t)->DenseRange(65, 127, 1); | ||
#else | ||
BENCHMARK_TEMPLATE(benchAutoVec, uint8_t)->Arg(65)->Arg(127); | ||
BENCHMARK_TEMPLATE(benchReductionAutoVec, uint8_t)->Arg(65)->Arg(127); | ||
BENCHMARK_TEMPLATE(benchAutoVec, uint16_t)->Arg(65)->Arg(127); | ||
BENCHMARK_TEMPLATE(benchReductionAutoVec, uint16_t)->Arg(65)->Arg(127); | ||
BENCHMARK_TEMPLATE(benchAutoVec, uint32_t)->Arg(65)->Arg(127); | ||
BENCHMARK_TEMPLATE(benchReductionAutoVec, uint32_t)->Arg(65)->Arg(127); | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.