Skip to content

Commit a4755f4

Browse files
committed
[MicroBenchmark] Add initial LoopInterchange test/benchmark.
This patch adds a first test case specifically for LoopInterchange. I am not sure if MicroBenchmarks is the best place for this, but it seems like a good way to benchmark/tests a set of loops targeted at loop interchange. Reviewers: Meinersbur, homerdin, proton0001, proton, MatzeB Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D53030 llvm-svn: 347740
1 parent 0fe899a commit a4755f4

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

MicroBenchmarks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ add_subdirectory(XRay)
55
add_subdirectory(LCALS)
66
add_subdirectory(harris)
77
add_subdirectory(ImageProcessing)
8-
8+
add_subdirectory(LoopInterchange)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
llvm_test_run(WORKDIR ${CMAKE_CURRENT_BINARY_DIR})
2+
3+
llvm_test_verify(WORKDIR ${CMAKE_CURRENT_BINARY_DIR}
4+
${FPCMP} LoopInterchange.reference_output LoopInterchange.txt
5+
)
6+
llvm_test_executable(LoopInterchange main.cpp)
7+
llvm_test_data(LoopInterchange LoopInterchange.reference_output)
8+
9+
target_link_libraries(LoopInterchange benchmark)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test1: 1572352
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <fstream>
4+
5+
#include "benchmark/benchmark.h"
6+
7+
8+
#define N 1024
9+
unsigned A[N][N];
10+
11+
void init() {
12+
for (unsigned i = 0; i < N; i++)
13+
for (unsigned j = 0; j < N; j++)
14+
A[i][j] = i + j;
15+
}
16+
17+
unsigned y = 0;
18+
19+
static unsigned test1() {
20+
for (unsigned i = 0; i < N; i++) {
21+
y = 0;
22+
for (unsigned j = 0; j < N; j++) {
23+
A[i][j] += 1;
24+
y += A[i][j];
25+
}
26+
}
27+
return y;
28+
}
29+
30+
int main(int argc, char *argv[]) {
31+
benchmark::Initialize(&argc, argv);
32+
33+
init();
34+
35+
// Run kernels once, to test functionality.
36+
std::ofstream myfile ("LoopInterchange.txt");
37+
if (myfile.is_open()) {
38+
unsigned y = test1();
39+
myfile << "test1: " << y << "\n";
40+
myfile.close();
41+
} else
42+
return EXIT_FAILURE;
43+
44+
benchmark::RunSpecifiedBenchmarks();
45+
return EXIT_SUCCESS;
46+
}
47+
48+
void BENCHMARK_LI1(benchmark::State &state) {
49+
unsigned x = 0;
50+
for (auto _ : state)
51+
benchmark::DoNotOptimize(x += test1());
52+
}
53+
54+
BENCHMARK(BENCHMARK_LI1)->Unit(benchmark::kMicrosecond);

0 commit comments

Comments
 (0)