-
Notifications
You must be signed in to change notification settings - Fork 4
Implement benchmarks for vector operations #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbaldu
wants to merge
9
commits into
root-project:main
Choose a base branch
from
sbaldu:feature-benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+580
−2
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2b1566d
Preparing first benchmarks
sbaldu 4422781
Add google benchmarks as external
sbaldu e0d460a
Add first working benchmark of serial Boost
sbaldu 33745f1
Add test for serial invariant mass
sbaldu 3523f26
Add first cuda benchmark
sbaldu 5b0be5e
Add sycl benchmarks and rename file
sbaldu 3bf980c
Finish implementing benchmarks for SYCL backend
sbaldu 760106a
Add benchmarks for cuda streamed functions
sbaldu 0347b22
Add benchmarks with single precision scalars
sbaldu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "external/benchmark"] | ||
path = external/benchmark | ||
url = https://github.com/google/benchmark.git |
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,45 @@ | ||
|
||
#include "SYCLMath/Boost.h" | ||
#include "SYCLMath/VecOps.h" | ||
#include "SYCLMath/Vector4D.h" | ||
#include <benchmark/benchmark.h> | ||
#include <chrono> | ||
#include <memory> | ||
|
||
#ifdef SINGLE_PRECISION | ||
using Scalar = float; | ||
#else | ||
using Scalar = double; | ||
#endif | ||
|
||
using LVector = | ||
ROOT::Experimental::LorentzVector<ROOT::Experimental::PtEtaPhiM4D<Scalar>>; | ||
using Boost = ROOT::Experimental::Boost; | ||
|
||
auto GenVectors(int n) { | ||
auto vectors = std::make_unique<LVector[]>(n); | ||
|
||
// generate n -4 momentum quantities | ||
std::for_each(vectors.get(), vectors.get() + n, [](auto &vec) -> void { | ||
vec = {1., 1., 1., 1.}; | ||
}); | ||
|
||
return std::move(vectors); | ||
} | ||
|
||
static void BM_ApplyBoost(benchmark::State &state) { | ||
for (auto _ : state) { | ||
const auto N = state.range(0); | ||
auto lvectors = GenVectors(N); | ||
auto* lvectorsboosted = new LVector[N]; | ||
|
||
Boost bst(0.3, 0.4, 0.5); | ||
lvectorsboosted = ROOT::Experimental::ApplyBoost(lvectors.get(), bst, N); | ||
|
||
delete[] lvectorsboosted; | ||
} | ||
} | ||
|
||
BENCHMARK(BM_ApplyBoost)->RangeMultiplier(2)->Range(1 << 10, 1 << 20); | ||
|
||
BENCHMARK_MAIN(); |
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,55 @@ | ||
#include "SYCLMath/Boost.h" | ||
#include "SYCLMath/GenVector/MathUtil.h" | ||
#include "SYCLMath/VecOps.h" | ||
#include "SYCLMath/Vector4D.h" | ||
#include <benchmark/benchmark.h> | ||
#include <cuda_runtime.h> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#ifdef SINGLE_PRECISION | ||
using Scalar = float; | ||
#else | ||
using Scalar = double; | ||
#endif | ||
|
||
using LVector = | ||
ROOT::Experimental::LorentzVector<ROOT::Experimental::PxPyPzE4D<Scalar>>; | ||
using Boost = ROOT::Experimental::Boost; | ||
|
||
template <class T> using Vector = std::vector<T>; // ROOT::RVec<T>; | ||
|
||
auto GenVectors(int n) { | ||
auto vectors = std::make_unique<LVector[]>(n); | ||
|
||
// generate n -4 momentum quantities | ||
std::for_each(vectors.get(), vectors.get() + n, | ||
[](auto &vec) -> void { vec = {1., 1., 1., 1.}; }); | ||
|
||
return std::move(vectors); | ||
} | ||
|
||
static void BM_ApplyBoost(benchmark::State &state) { | ||
int count; | ||
cudaGetDeviceCount(&count); | ||
cudaSetDevice(count - 1); | ||
for (auto _ : state) { | ||
const auto N = state.range(0); | ||
size_t local_size = 128; | ||
|
||
|
||
auto lvectors = GenVectors(N); | ||
LVector *lvectorsboosted = new LVector[N]; | ||
|
||
Boost bst(0.3, 0.4, 0.5); | ||
|
||
lvectorsboosted = ROOT::Experimental::ApplyBoost<Boost, LVector>( | ||
lvectors.get(), bst, N, local_size); | ||
|
||
delete[] lvectorsboosted; | ||
} | ||
} | ||
|
||
BENCHMARK(BM_ApplyBoost)->RangeMultiplier(2)->Range(1 << 10, 1 << 20)->UseRealTime(); | ||
|
||
BENCHMARK_MAIN(); |
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,58 @@ | ||
#include "SYCLMath/Boost.h" | ||
#include "SYCLMath/GenVector/MathUtil.h" | ||
#include "SYCLMath/VecOps.h" | ||
#include "SYCLMath/Vector4D.h" | ||
#include <benchmark/benchmark.h> | ||
#include <cuda_runtime.h> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#ifdef SINGLE_PRECISION | ||
using Scalar = float; | ||
#else | ||
using Scalar = double; | ||
#endif | ||
|
||
using LVector = | ||
ROOT::Experimental::LorentzVector<ROOT::Experimental::PxPyPzE4D<Scalar>>; | ||
using Boost = ROOT::Experimental::Boost; | ||
|
||
template <class T> using Vector = std::vector<T>; // ROOT::RVec<T>; | ||
|
||
auto GenVectors(int n) { | ||
auto vectors = std::make_unique<LVector[]>(n); | ||
|
||
// generate n -4 momentum quantities | ||
std::for_each(vectors.get(), vectors.get() + n, | ||
[](auto &vec) -> void { vec = {1., 1., 1., 1.}; }); | ||
|
||
return std::move(vectors); | ||
} | ||
|
||
static void BM_ApplyBoost(benchmark::State &state) { | ||
int count; | ||
cudaGetDeviceCount(&count); | ||
cudaSetDevice(count - 1); | ||
cudaStream_t stream; | ||
cudaStreamCreate(&stream); | ||
|
||
for (auto _ : state) { | ||
const auto N = state.range(0); | ||
size_t local_size = 128; | ||
|
||
auto lvectors = GenVectors(N); | ||
LVector *lvectorsboosted = new LVector[N]; | ||
|
||
Boost bst(0.3, 0.4, 0.5); | ||
|
||
lvectorsboosted = ROOT::Experimental::ApplyBoost<Boost, LVector>( | ||
lvectors.get(), bst, N, local_size, stream); | ||
|
||
delete[] lvectorsboosted; | ||
} | ||
cudaStreamDestroy(stream); | ||
} | ||
|
||
BENCHMARK(BM_ApplyBoost)->RangeMultiplier(2)->Range(1 << 10, 1 << 20)->UseRealTime(); | ||
|
||
BENCHMARK_MAIN(); |
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,49 @@ | ||
|
||
#include "SYCLMath/Boost.h" | ||
#include "SYCLMath/VecOps.h" | ||
#include "SYCLMath/Vector4D.h" | ||
#include <benchmark/benchmark.h> | ||
#include <chrono> | ||
#include <memory> | ||
#include <sycl/sycl.hpp> | ||
|
||
#ifdef SINGLE_PRECISION | ||
using Scalar = float; | ||
#else | ||
using Scalar = double; | ||
#endif | ||
|
||
using LVector = | ||
ROOT::Experimental::LorentzVector<ROOT::Experimental::PtEtaPhiM4D<Scalar>>; | ||
using Boost = ROOT::Experimental::Boost; | ||
|
||
auto GenVectors(int n) { | ||
auto vectors = std::make_unique<LVector[]>(n); | ||
|
||
// generate n -4 momentum quantities | ||
std::for_each(vectors.get(), vectors.get() + n, [](auto &vec) -> void { | ||
vec = {1., 1., 1., 1.}; | ||
}); | ||
|
||
return std::move(vectors); | ||
} | ||
|
||
static void BM_ApplyBoost(benchmark::State &state) { | ||
for (auto _ : state) { | ||
const auto N = state.range(0); | ||
const auto local_size = 128; | ||
auto lvectors = GenVectors(N); | ||
auto* lvectorsboosted = new LVector[N]; | ||
|
||
static sycl::queue queue{sycl::default_selector_v}; | ||
|
||
Boost bst(0.3, 0.4, 0.5); | ||
lvectorsboosted = ROOT::Experimental::ApplyBoost(lvectors.get(), bst, queue, N, local_size); | ||
|
||
delete[] lvectorsboosted; | ||
} | ||
} | ||
|
||
BENCHMARK(BM_ApplyBoost)->RangeMultiplier(2)->Range(1 << 10, 1 << 20); | ||
|
||
BENCHMARK_MAIN(); |
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,158 @@ | ||
|
||
add_executable(Boost_bench Boost.cpp) | ||
target_link_libraries(Boost_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(Boost_bench PRIVATE ${compile_list}) | ||
|
||
add_executable(InvariantMasses_bench InvariantMasses.cpp) | ||
target_link_libraries(InvariantMasses_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(InvariantMasses_bench PRIVATE ${compile_list}) | ||
|
||
if (single_precision) | ||
add_executable(SBoost_bench Boost.cpp) | ||
target_link_libraries(SBoost_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(SBoost_bench PRIVATE ${compile_list_single}) | ||
|
||
add_executable(SInvariantMasses_bench InvariantMasses.cpp) | ||
target_link_libraries(SInvariantMasses_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(SInvariantMasses_bench PRIVATE ${compile_list_single}) | ||
endif() | ||
|
||
if (oneapi) | ||
|
||
add_executable(InvariantMassesSYCL_bench InvariantMassesSYCL.cpp) | ||
target_link_options(InvariantMassesSYCL_bench PUBLIC -E) | ||
add_sycl_to_root_target_exe(TARGET InvariantMassesSYCL_bench SOURCES InvariantMassesSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list}) | ||
|
||
add_executable(BoostSYCL_bench BoostSYCL.cpp) | ||
target_link_options(BoostSYCL_bench PUBLIC -E) | ||
add_sycl_to_root_target_exe(TARGET BoostSYCL_bench SOURCES BoostSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list}) | ||
|
||
if (single_precision) | ||
add_executable(SInvariantMassesSYCL_bench InvariantMassesSYCL.cpp) | ||
target_link_options(SInvariantMassesSYCL_bench PUBLIC -E) | ||
add_sycl_to_root_target_exe(TARGET SInvariantMassesSYCL_bench SOURCES InvariantMassesSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list_single}) | ||
|
||
|
||
add_executable(SBoostSYCL_bench BoostSYCL.cpp) | ||
target_link_options(SBoostSYCL_bench PUBLIC -E) | ||
add_sycl_to_root_target_exe(TARGET SBoostSYCL_bench SOURCES BoostSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list_single}) | ||
|
||
endif() | ||
|
||
endif() | ||
|
||
if (adaptivecpp) | ||
add_executable(InvariantMassesSYCL_bench InvariantMassesSYCL.cpp) | ||
add_sycl_to_root_target(TARGET InvariantMassesSYCL_bench SOURCES InvariantMassesSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list}) | ||
|
||
|
||
add_executable(BoostSYCL_bench BoostSYCL.cpp) | ||
add_sycl_to_root_target(TARGET BoostSYCL_bench SOURCES BoostSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list}) | ||
|
||
|
||
if (single_precision) | ||
add_executable(SInvariantMassesSYCL_bench InvariantMassesSYCL.cpp) | ||
add_sycl_to_root_target(TARGET SInvariantMassesSYCL_bench SOURCES InvariantMassesSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list_single}) | ||
|
||
|
||
add_executable(SBoostSYCL_bench BoostSYCL.cpp) | ||
add_sycl_to_root_target(TARGET SBoostSYCL_bench SOURCES BoostSYCL.cpp | ||
DEPENDENCIES GenVectorX SYCLMath VecOps benchmark | ||
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/inc | ||
COMPILE_DEFINITIONS ${sycl_compile_list_single}) | ||
|
||
endif() | ||
|
||
endif() | ||
|
||
|
||
if (cuda) | ||
add_executable(BoostCUDA_bench BoostCUDA.cu) | ||
set_target_properties(BoostCUDA_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(BoostCUDA_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(BoostCUDA_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(BoostCUDA_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(BoostCUDA_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(BoostCUDA_bench PRIVATE ${cuda_compile_list}) | ||
|
||
add_executable(BoostCUDAStreamed_bench BoostCUDAStreamed.cu) | ||
set_target_properties(BoostCUDAStreamed_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(BoostCUDAStreamed_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(BoostCUDAStreamed_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(BoostCUDAStreamed_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(BoostCUDAStreamed_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(BoostCUDAStreamed_bench PRIVATE ${cuda_compile_list}) | ||
|
||
add_executable(InvariantMassesCUDA_bench InvariantMassesCUDA.cu) | ||
set_target_properties(InvariantMassesCUDA_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(InvariantMassesCUDA_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(InvariantMassesCUDA_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(InvariantMassesCUDA_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(InvariantMassesCUDA_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(InvariantMassesCUDA_bench PRIVATE ${cuda_compile_list}) | ||
|
||
add_executable(InvariantMassesCUDAStreamed_bench InvariantMassesCUDAStreamed.cu) | ||
set_target_properties(InvariantMassesCUDAStreamed_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(InvariantMassesCUDAStreamed_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(InvariantMassesCUDAStreamed_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(InvariantMassesCUDAStreamed_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(InvariantMassesCUDAStreamed_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(InvariantMassesCUDAStreamed_bench PRIVATE ${cuda_compile_list}) | ||
|
||
if (single_precision) | ||
add_executable(SBoostCUDA_bench BoostCUDA.cu) | ||
set_target_properties(SBoostCUDA_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(SBoostCUDA_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(SBoostCUDA_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(SBoostCUDA_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(SBoostCUDA_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(SBoostCUDA_bench PRIVATE ${cuda_compile_list_single}) | ||
|
||
add_executable(SBoostCUDAStreamed_bench BoostCUDAStreamed.cu) | ||
set_target_properties(SBoostCUDAStreamed_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(SBoostCUDAStreamed_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(SBoostCUDAStreamed_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(SBoostCUDAStreamed_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(SBoostCUDAStreamed_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(SBoostCUDAStreamed_bench PRIVATE ${cuda_compile_list_single}) | ||
|
||
add_executable(SInvariantMassesCUDA_bench InvariantMassesCUDA.cu) | ||
set_target_properties(SInvariantMassesCUDA_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(SInvariantMassesCUDA_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(SInvariantMassesCUDA_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(SInvariantMassesCUDA_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(SInvariantMassesCUDA_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(SInvariantMassesCUDA_bench PRIVATE ${cuda_compile_list_single}) | ||
|
||
add_executable(SInvariantMassesCUDAStreamed_bench InvariantMassesCUDAStreamed.cu) | ||
set_target_properties(SInvariantMassesCUDAStreamed_bench PROPERTIES LINKER_LANGUAGE CUDA) | ||
target_link_libraries(SInvariantMassesCUDAStreamed_bench PUBLIC GenVectorX SYCLMath VecOps) | ||
target_compile_options(SInvariantMassesCUDAStreamed_bench PRIVATE -rdc=true -lineinfo --expt-relaxed-constexpr) | ||
set_target_properties(SInvariantMassesCUDAStreamed_bench PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
target_link_libraries(SInvariantMassesCUDAStreamed_bench PRIVATE benchmark::benchmark) | ||
target_compile_definitions(SInvariantMassesCUDAStreamed_bench PRIVATE ${cuda_compile_list_single}) | ||
endif() | ||
|
||
endif() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I would require google benchmark here instead of relying on git modules
find_package(benchmark REQUIRED)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now I am using it as a submodule because I thought that it would make it easier to use on remote machine where maybe it isn't installed, but if you think it's better I can remove the submodule and just use the find package.