Skip to content
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

build benchmarks and cbench in ci #292

Merged
merged 12 commits into from
Nov 17, 2023
Merged
18 changes: 10 additions & 8 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,33 @@ jobs:
curl --url ${{ matrix.compiler_url }} --output download.sh
sudo sh -x download.sh -s -a -s --action install --eula accept
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
run: |
sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
sudo apt install libbenchmark1 libbenchmark-dev

- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/mdspan-build

- name: Check Out
uses: actions/checkout@v2
with:
path: ${{github.workspace}}/mdspan-src

- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/mdspan-build
run: CXX=${{ matrix.compiler_prefix}}/${{ matrix.compiler_driver }} cmake $GITHUB_WORKSPACE/mdspan-src -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON -DCMAKE_CXX_FLAGS=${{matrix.cxx_flags_extra}}
run: CXX=${{ matrix.compiler_prefix}}/${{ matrix.compiler_driver }} cmake $GITHUB_WORKSPACE/mdspan-src -DMDSPAN_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON -DMDSPAN_ENABLE_BENCHMARKS=ON -DMDSPAN_ENABLE_COMP_BENCH=ON -DCMAKE_CXX_FLAGS=${{matrix.cxx_flags_extra}}

- name: Build
shell: bash
working-directory: ${{github.workspace}}/mdspan-build
run: make -j

- name: Test
working-directory: ${{github.workspace}}/mdspan-build
shell: bash
run: ctest
run: ctest --output-on-failure

- name: Install
shell: bash
working-directory: ${{github.workspace}}/mdspan-build
Expand Down
4 changes: 4 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ function(mdspan_add_benchmark EXENAME)
target_include_directories(${EXENAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/benchmarks>
)
# Set flag to build with parenthesis enabled
target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
endfunction()

find_package(benchmark REQUIRED)
Expand Down Expand Up @@ -42,6 +44,7 @@ function(mdspan_add_cuda_benchmark EXENAME)
string(REPLACE "-pthread" "" _benchmark_libs "${_benchmark_libs_old}")
target_include_directories(${EXENAME} PUBLIC "${_benchmark_include}")
target_link_libraries(${EXENAME} PUBLIC "${_benchmark_libs};${_benchmark_libs_imported}")
target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
if(_benchmark_libs_old MATCHES "-pthread")
target_compile_options(${EXENAME} PUBLIC "-Xcompiler=-pthread")
endif()
Expand All @@ -59,6 +62,7 @@ function(mdspan_add_openmp_benchmark EXENAME)
target_include_directories(${EXENAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/benchmarks>
)
target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
else()
message(WARNING "Not adding target ${EXENAME} because OpenMP was not found")
endif()
Expand Down
18 changes: 17 additions & 1 deletion comp_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@

include(metabench)

# C++ standards that our benchmark will actually support
set(_cbench_supported_standards 17 20 23)

# Obtain the subset that are actually supported by the compiler
set(_cbench_standards "")
foreach(_std IN LISTS _cbench_supported_standards)
if ("cxx_std_${_std}" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
list(APPEND _cbench_standards "${_std}")
endif()
endforeach()

message(STATUS "Using the following C++ standards for compiler benchmarking: ${_cbench_standards}")

function(add_cxx_comparison name template range)

set(all_datasets)
foreach(std IN ITEMS 11 14 17)
foreach(std IN LISTS _cbench_standards)
metabench_add_dataset(
${name}_${std}
${template}
${range}
MEDIAN_OF 3
)
target_link_libraries(${name}_${std} mdspan)
# Set parenthesis operator regardless of which standard we are using
# so we don't have to ifdef
target_compile_definitions(${name}_${std} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
set_property(TARGET ${name}_${std} PROPERTY CXX_STANDARD ${std})
set(all_datasets ${all_datasets} ${name}_${std})
endforeach()
Expand Down
4 changes: 2 additions & 2 deletions comp_bench/cbench_submdspan.cpp.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
int test(int* data) {
#if defined(METABENCH)
auto sub0 = Kokkos::mdspan<int,
Kokkos::extents<
Kokkos::extents<size_t,
<%= (["2"] * n).join(", ") %>
>
>(data);
<% (32/n).times do |k| %>
auto <%= "sub0_#{k}" %> = Kokkos::mdspan<int,
Kokkos::extents<
Kokkos::extents<size_t,
<%= (["#{k+2}"] * n).join(", ") %>
>
>(data);
Expand Down
Loading