Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MicroBenchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ add_subdirectory(harris)
add_subdirectory(ImageProcessing)
add_subdirectory(LoopInterchange)
add_subdirectory(LoopVectorization)
add_subdirectory(LoopSplit)
add_subdirectory(MemFunctions)
add_subdirectory(SLPVectorization)
14 changes: 14 additions & 0 deletions MicroBenchmarks/LoopSplit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# LoopSplit microbenchmark for #pragma omp split counts(...).
# Copy this directory to llvm-test-suite/MicroBenchmarks/LoopSplit/
# and add: add_subdirectory(LoopSplit) to MicroBenchmarks/CMakeLists.txt.
#
# Configure test-suite with a Clang that supports -fopenmp and -fopenmp-version=60.
Comment on lines +2 to +5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copy this directory to llvm-test-suite/MicroBenchmarks/LoopSplit/
# and add: add_subdirectory(LoopSplit) to MicroBenchmarks/CMakeLists.txt.
#
# Configure test-suite with a Clang that supports -fopenmp and -fopenmp-version=60.

remove instructions from AI that you obviously applied.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that one out, will keep a note for future references.


llvm_test_run(WORKDIR %S)
llvm_test_verify(%b/${FPCMP} %S/LoopSplit.reference_output %S/LoopSplit.txt)

llvm_test_executable(LoopSplit main.cpp)
llvm_test_data(LoopSplit LoopSplit.reference_output)

target_compile_options(LoopSplit PRIVATE -fopenmp -fopenmp-version=60)
target_link_libraries(LoopSplit benchmark)
1 change: 1 addition & 0 deletions MicroBenchmarks/LoopSplit/LoopSplit.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test1: 19999999900000000
57 changes: 57 additions & 0 deletions MicroBenchmarks/LoopSplit/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Microbenchmark for #pragma omp split counts(...).
#include <cstdlib>
#include <fstream>
#include <iostream>

#include "benchmark/benchmark.h"

// Large N for measurable runs; lit verification uses same kernel once.
#define N 200000000

// Kernel: sum 0..(N-1) with split into four segments.
static long run_split() {
long sum = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long is 32 bits on 32 bit platforms and Windows 64. It will overflow on 19999999900000000

#pragma omp split counts(50000000, 50000000, 50000000, omp_fill)
for (int i = 0; i < N; ++i)
sum += i;
return sum;
}

// Baseline: same loop without split (for comparison).
static long run_baseline() {
long sum = 0;
for (int i = 0; i < N; ++i)
sum += i;
return sum;
}

int main(int argc, char *argv[]) {
benchmark::Initialize(&argc, argv);

// Run kernel once and write result for lit verification.
std::ofstream myfile("LoopSplit.txt");
if (myfile.is_open()) {
long y = run_split();
myfile << "test1: " << y << "\n";
myfile.close();
} else {
return EXIT_FAILURE;
}

benchmark::RunSpecifiedBenchmarks();
return EXIT_SUCCESS;
}

static void BM_Split(benchmark::State &state) {
long x = 0;
for (auto _ : state)
benchmark::DoNotOptimize(x += run_split());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
benchmark::DoNotOptimize(x += run_split());
auto x = run_split();
benchmark::DoNotOptimize(x);

}
BENCHMARK(BM_Split)->Unit(benchmark::kMicrosecond)->MinTime(2.0);

static void BM_Baseline(benchmark::State &state) {
long x = 0;
for (auto _ : state)
benchmark::DoNotOptimize(x += run_baseline());
}
BENCHMARK(BM_Baseline)->Unit(benchmark::kMicrosecond)->MinTime(2.0);