[test-suite] r347740 - [MicroBenchmark] Add initial LoopInterchange test/benchmark.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 28 02:46:17 PST 2018
Author: fhahn
Date: Wed Nov 28 02:46:17 2018
New Revision: 347740
URL: http://llvm.org/viewvc/llvm-project?rev=347740&view=rev
Log:
[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
Added:
test-suite/trunk/MicroBenchmarks/LoopInterchange/
test-suite/trunk/MicroBenchmarks/LoopInterchange/CMakeLists.txt
test-suite/trunk/MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
test-suite/trunk/MicroBenchmarks/LoopInterchange/main.cpp
Modified:
test-suite/trunk/MicroBenchmarks/CMakeLists.txt
Modified: test-suite/trunk/MicroBenchmarks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/CMakeLists.txt?rev=347740&r1=347739&r2=347740&view=diff
==============================================================================
--- test-suite/trunk/MicroBenchmarks/CMakeLists.txt (original)
+++ test-suite/trunk/MicroBenchmarks/CMakeLists.txt Wed Nov 28 02:46:17 2018
@@ -5,4 +5,4 @@ add_subdirectory(XRay)
add_subdirectory(LCALS)
add_subdirectory(harris)
add_subdirectory(ImageProcessing)
-
+add_subdirectory(LoopInterchange)
Added: test-suite/trunk/MicroBenchmarks/LoopInterchange/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/LoopInterchange/CMakeLists.txt?rev=347740&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/LoopInterchange/CMakeLists.txt (added)
+++ test-suite/trunk/MicroBenchmarks/LoopInterchange/CMakeLists.txt Wed Nov 28 02:46:17 2018
@@ -0,0 +1,9 @@
+llvm_test_run(WORKDIR ${CMAKE_CURRENT_BINARY_DIR})
+
+llvm_test_verify(WORKDIR ${CMAKE_CURRENT_BINARY_DIR}
+ ${FPCMP} LoopInterchange.reference_output LoopInterchange.txt
+)
+llvm_test_executable(LoopInterchange main.cpp)
+llvm_test_data(LoopInterchange LoopInterchange.reference_output)
+
+target_link_libraries(LoopInterchange benchmark)
Added: test-suite/trunk/MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output?rev=347740&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output (added)
+++ test-suite/trunk/MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output Wed Nov 28 02:46:17 2018
@@ -0,0 +1 @@
+test1: 1572352
Added: test-suite/trunk/MicroBenchmarks/LoopInterchange/main.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/LoopInterchange/main.cpp?rev=347740&view=auto
==============================================================================
--- test-suite/trunk/MicroBenchmarks/LoopInterchange/main.cpp (added)
+++ test-suite/trunk/MicroBenchmarks/LoopInterchange/main.cpp Wed Nov 28 02:46:17 2018
@@ -0,0 +1,54 @@
+#include <iostream>
+#include <cstdlib>
+#include <fstream>
+
+#include "benchmark/benchmark.h"
+
+
+#define N 1024
+unsigned A[N][N];
+
+void init() {
+ for (unsigned i = 0; i < N; i++)
+ for (unsigned j = 0; j < N; j++)
+ A[i][j] = i + j;
+}
+
+unsigned y = 0;
+
+static unsigned test1() {
+ for (unsigned i = 0; i < N; i++) {
+ y = 0;
+ for (unsigned j = 0; j < N; j++) {
+ A[i][j] += 1;
+ y += A[i][j];
+ }
+ }
+ return y;
+}
+
+int main(int argc, char *argv[]) {
+ benchmark::Initialize(&argc, argv);
+
+ init();
+
+ // Run kernels once, to test functionality.
+ std::ofstream myfile ("LoopInterchange.txt");
+ if (myfile.is_open()) {
+ unsigned y = test1();
+ myfile << "test1: " << y << "\n";
+ myfile.close();
+ } else
+ return EXIT_FAILURE;
+
+ benchmark::RunSpecifiedBenchmarks();
+ return EXIT_SUCCESS;
+}
+
+void BENCHMARK_LI1(benchmark::State &state) {
+ unsigned x = 0;
+ for (auto _ : state)
+ benchmark::DoNotOptimize(x += test1());
+}
+
+BENCHMARK(BENCHMARK_LI1)->Unit(benchmark::kMicrosecond);
More information about the llvm-commits
mailing list