[PATCH] D53030: [MicroBenchmark] Add initial LoopInterchange test/benchmark.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 16 18:09:32 PDT 2018


fhahn updated this revision to Diff 169932.
fhahn marked 2 inline comments as done.
fhahn added a comment.

Thanks. I've dropped the range.  On a cortex-a72, it takes around 1 second.


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,58 @@
+#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) {
+  for (auto _ : state) {
+    unsigned y = test1();
+    // We do not run the benchmark with state.range(0) == 20, but this should
+    // ensure we do not optimize the call to test1 away.
+    if (state.range(0) == 20)
+      printf("%d\n", y);
+  }
+}
+
+BENCHMARK(BENCHMARK_LI1)->Arg(0)->Unit(benchmark::kMicrosecond);
Index: MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
===================================================================
--- /dev/null
+++ MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output
@@ -0,0 +1 @@
+test1: 392960
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.169932.patch
Type: text/x-patch
Size: 2553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181017/0cc283e4/attachment.bin>


More information about the llvm-commits mailing list