[PATCH] D53030: [MicroBenchmark] Add initial LoopInterchange test/benchmark.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 28 02:48:16 PST 2018
fhahn updated this revision to Diff 175643.
fhahn marked an inline comment as done.
fhahn added a comment.
Use DoNotOptimize
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D53030/new/
https://reviews.llvm.org/D53030
Files:
MicroBenchmarks/CMakeLists.txt
MicroBenchmarks/LoopInterchange/CMakeLists.txt
MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
MicroBenchmarks/LoopInterchange/main.cpp
Index: MicroBenchmarks/LoopInterchange/main.cpp
===================================================================
--- /dev/null
+++ MicroBenchmarks/LoopInterchange/main.cpp
@@ -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);
Index: MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
===================================================================
--- /dev/null
+++ MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
@@ -0,0 +1 @@
+test1: 1572352
Index: MicroBenchmarks/LoopInterchange/CMakeLists.txt
===================================================================
--- /dev/null
+++ MicroBenchmarks/LoopInterchange/CMakeLists.txt
@@ -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)
Index: MicroBenchmarks/CMakeLists.txt
===================================================================
--- MicroBenchmarks/CMakeLists.txt
+++ MicroBenchmarks/CMakeLists.txt
@@ -5,4 +5,4 @@
add_subdirectory(LCALS)
add_subdirectory(harris)
add_subdirectory(ImageProcessing)
-
+add_subdirectory(LoopInterchange)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53030.175643.patch
Type: text/x-patch
Size: 2378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181128/f944ff8e/attachment.bin>
More information about the llvm-commits
mailing list