-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from lanl/benchmark
Add google benchmark
- Loading branch information
Showing
8 changed files
with
325 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
install-* | ||
benchmark/benchmark* | ||
build-matar-* | ||
install/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
cmake_minimum_required(VERSION 3.1.3) | ||
|
||
project (matarbenchmark) | ||
|
||
set(benchmark_DIR "benchmark/build") | ||
|
||
find_package(benchmark REQUIRED) | ||
find_package(Matar REQUIRED) | ||
|
||
|
||
|
||
|
||
|
||
if (NOT KOKKOS) | ||
add_executable(BM_Carray src/CArray_benchmark.cpp) | ||
target_link_libraries(BM_Carray matar benchmark::benchmark) | ||
endif() | ||
|
||
if (KOKKOS) | ||
find_package(Kokkos REQUIRED) #new | ||
|
||
add_definitions(-DHAVE_KOKKOS=1) | ||
|
||
add_executable(BM_CArray src/CArray_benchmark.cpp) | ||
target_link_libraries(BM_CArray matar Kokkos::kokkos benchmark::benchmark) | ||
|
||
add_executable(BM_CArrayDevice src/CArrayDevice_benchmark.cpp) | ||
target_link_libraries(BM_CArrayDevice matar Kokkos::kokkos benchmark::benchmark) | ||
|
||
if (CUDA) | ||
add_definitions(-DHAVE_CUDA=1) | ||
elseif (HIP) | ||
add_definitions(-DHAVE_HIP=1) | ||
elseif (OPENMP) | ||
add_definitions(-DHAVE_OPENMP=1) | ||
elseif (THREADS) | ||
add_definitions(-DHAVE_THREADS=1) | ||
endif() | ||
endif() | ||
|
||
# find_package(Kokkos REQUIRED) #new | ||
|
||
# set(This matar_benchmark) | ||
|
||
# set(Sources | ||
# src/serial_types_benchmark.cpp | ||
# ) | ||
|
||
|
||
|
||
|
||
# if (KOKKOKS) | ||
# target_link_libraries(${This} matar Kokkos::kokkos benchmark::benchmark) | ||
# endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string> | ||
#include <assert.h> | ||
#include <memory> // for shared_ptr | ||
#include <benchmark/benchmark.h> | ||
#include "matar.h" | ||
|
||
using namespace mtr; // matar namespace | ||
|
||
// ------- vector vector multiply ------------- // | ||
static void BM_CArrayDevice_1d_multiply(benchmark::State& state) | ||
{ | ||
|
||
int size = state.range(0); | ||
|
||
CArrayDevice<double> A(size); | ||
CArrayDevice<double> B(size); | ||
CArrayDevice<double> C(size); | ||
|
||
FOR_ALL(i, 0, size, { | ||
A(i) = (double)i+1.0; | ||
B(i) = (double)i+2.0; | ||
}); | ||
// Begin benchmarked section | ||
for (auto _ : state){ | ||
FOR_ALL(i, 0, size, { | ||
C(i) = A(i)*B(i); | ||
}); | ||
} // end benchmarked section | ||
|
||
// Kokkos::finalize(); | ||
|
||
} | ||
BENCHMARK(BM_CArrayDevice_1d_multiply) | ||
->Unit(benchmark::kMillisecond) | ||
->Name("Benchmark Multiplying 2 1D CArrayDevice of size ") | ||
->RangeMultiplier(2)->Range(1<<12, 1<<20); | ||
|
||
// ------- vector vector dot product ------------- // | ||
static void BM_CArrayDevice_vec_vec_dot(benchmark::State& state) | ||
{ | ||
int size = state.range(0); | ||
|
||
CArrayDevice<double> A(size); | ||
CArrayDevice<double> B(size); | ||
double C = 0.0; | ||
|
||
FOR_ALL(i, 0, size, { | ||
A(i) = (double)i+1.0; | ||
B(i) = (double)i+2.0; | ||
}); | ||
|
||
|
||
// Begin benchmarked section | ||
for (auto _ : state){ | ||
|
||
double loc_sum = 0; | ||
double C = 0; | ||
REDUCE_SUM(i, 0, size, | ||
loc_sum, { | ||
loc_sum += A(i)*B(i); | ||
}, C); | ||
} // end benchmarked section | ||
} | ||
BENCHMARK(BM_CArrayDevice_vec_vec_dot) | ||
->Unit(benchmark::kMillisecond) | ||
->Name("Benchmark dot product of 2 1D CArrayDevice of size ") | ||
->RangeMultiplier(2)->Range(1<<12, 1<<20); | ||
|
||
|
||
// ------- matrix matrix multiply ------------- // | ||
static void BM_CArrayDevice_mat_mat_multiply(benchmark::State& state) | ||
{ | ||
int size = state.range(0); | ||
|
||
CArrayDevice<double> A(size, size); | ||
CArrayDevice<double> B(size, size); | ||
CArrayDevice<double> C(size, size); | ||
|
||
FOR_ALL(i, 0, size, | ||
j, 0, size, { | ||
A(i,j) = (double)i+(double)j+1.0; | ||
B(i,j) = (double)i+(double)j+2.0; | ||
C(i,j) = 0.0; | ||
}); | ||
|
||
// Begin benchmarked section | ||
for (auto _ : state){ | ||
|
||
FOR_ALL(i, 0, size, | ||
j, 0, size, { | ||
for(int k = 0; k < size; k++){ | ||
C(i,k) += A(i,j)*B(j,k); | ||
} | ||
}); | ||
} // end benchmarked section | ||
} | ||
BENCHMARK(BM_CArrayDevice_mat_mat_multiply) | ||
->Unit(benchmark::kMillisecond) | ||
->Name("Benchmark matrix-matrix multiply of CArrayDevice of size ") | ||
->RangeMultiplier(2)->Range(1<<3, 1<<10); | ||
|
||
|
||
// Run Benchmarks | ||
int main(int argc, char** argv) | ||
{ | ||
Kokkos::initialize(); | ||
::benchmark::Initialize(&argc, argv); | ||
::benchmark::RunSpecifiedBenchmarks(); | ||
Kokkos::finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string> | ||
#include <assert.h> | ||
#include <memory> // for shared_ptr | ||
#include <benchmark/benchmark.h> | ||
#include "matar.h" | ||
|
||
using namespace mtr; // matar namespace | ||
|
||
// ------- vector vector multiply ------------- // | ||
static void BM_CArray_1d_multiply(benchmark::State& state) | ||
{ | ||
// const int size = 4000; | ||
|
||
int size = state.range(0); | ||
|
||
CArray<double> A(size); | ||
CArray<double> B(size); | ||
CArray<double> C(size); | ||
|
||
for(int i=0; i<size; i++){ | ||
A(i) = (double)i+1.0; | ||
B(i) = (double)i+2.0; | ||
} | ||
|
||
// Begin benchmarked section | ||
for (auto _ : state){ | ||
for(int i=0; i<size; i++){ | ||
C(i) = A(i)*B(i); | ||
} | ||
} // end benchmarked section | ||
} | ||
BENCHMARK(BM_CArray_1d_multiply) | ||
->Unit(benchmark::kMillisecond) | ||
->Name("Benchmark Multiplying 2 1D CArrays of size ") | ||
->RangeMultiplier(2)->Range(1<<12, 1<<20); | ||
|
||
|
||
// ------- vector vector dot product ------------- // | ||
static void BM_Carray_vec_vec_dot(benchmark::State& state) | ||
{ | ||
int size = state.range(0); | ||
|
||
// Begin benchmarked section | ||
for (auto _ : state){ | ||
CArray<double> A(size); | ||
CArray<double> B(size); | ||
double C = 0.0; | ||
|
||
for(int i = 0; i < size; i++){ | ||
A(i) = (double)i+1.0; | ||
B(i) = (double)i+2.0; | ||
} | ||
|
||
for(int i = 0; i < size; i++){ | ||
C += A(i)*B(i); | ||
} | ||
} // end benchmarked section | ||
} | ||
BENCHMARK(BM_CArray_1d_multiply) | ||
->Unit(benchmark::kMillisecond) | ||
->Name("Benchmark dot product of 2 1D CArrays of size ") | ||
->RangeMultiplier(2)->Range(1<<12, 1<<20); | ||
|
||
// ------- matrix matrix multiply ------------- // | ||
static void BM_CArray_mat_mat_multiply(benchmark::State& state) | ||
{ | ||
int size = state.range(0); | ||
|
||
// Begin benchmarked section | ||
for (auto _ : state){ | ||
CArray<double> A(size, size); | ||
CArray<double> B(size, size); | ||
CArray<double> C(size, size); | ||
|
||
for(int i = 0; i < size; i++){ | ||
for(int j = 0; j < size; j++){ | ||
A(i,j) = (double)i+(double)j+1.0; | ||
B(i,j) = (double)i+(double)j+2.0; | ||
C(i,j) = 0.0; | ||
} | ||
} | ||
|
||
for(int i = 0; i < size; i++){ | ||
for(int j = 0; j < size; j++){ | ||
for(int k = 0; k < size; k++){ | ||
C(i,k) += A(i,j)*B(j,k); | ||
} | ||
} | ||
} | ||
} // end benchmarked section | ||
} | ||
BENCHMARK(BM_CArray_mat_mat_multiply) | ||
->Unit(benchmark::kMillisecond) | ||
->Name("Benchmark matrix-matrix multiply of CArrays of size ") | ||
->RangeMultiplier(2)->Range(1<<3, 1<<10); | ||
|
||
// Run benchmarks | ||
int main(int argc, char** argv) | ||
{ | ||
Kokkos::initialize(); | ||
::benchmark::Initialize(&argc, argv); | ||
::benchmark::RunSpecifiedBenchmarks(); | ||
Kokkos::finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash -e | ||
|
||
kokkos_build_type="${1}" | ||
|
||
if [ ! -d "${BENCHMARK_SOURCE_DIR}/benchmark" ] | ||
then | ||
echo "Missing googlebenchmark for benchmarking, downloading and installing...." | ||
git clone https://github.com/google/benchmark.git ${BENCHMARK_SOURCE_DIR}/benchmark | ||
cd ${BENCHMARK_SOURCE_DIR}/benchmark | ||
cmake -E make_directory "build" | ||
cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../ | ||
cmake --build "build" --config Release -j${MATAR_BUILD_CORES} | ||
# Test install | ||
cmake -E chdir "build" ctest --build-config Release | ||
fi | ||
|
||
cmake_options=( | ||
-D CMAKE_PREFIX_PATH="${MATAR_INSTALL_DIR};${KOKKOS_INSTALL_DIR};${BENCHMARK_INSTALL_DIR}" | ||
-D BENCHMARK_DOWNLOAD_DEPENDENCIES=on | ||
-DCMAKE_BUILD_TYPE=Release | ||
) | ||
|
||
|
||
|
||
if [ "$kokkos_build_type" = "none" ]; then | ||
cmake_options+=( | ||
-D KOKKOS=OFF | ||
) | ||
else | ||
cmake_options+=( | ||
-D KOKKOS=ON | ||
) | ||
fi | ||
# Print CMake options for reference | ||
echo "CMake Options: ${cmake_options[@]}" | ||
|
||
cmake "${cmake_options[@]}" -B "${BENCHMARK_BUILD_DIR}" -S "${BENCHMARK_SOURCE_DIR}" | ||
|
||
# Build benchmark | ||
make -C "${BENCHMARK_BUILD_DIR}" -j${MATAR_BUILD_CORES} | ||
|
||
cd $basedir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters