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

Add benchmark #41

Merged
merged 15 commits into from
Feb 8, 2024
12 changes: 8 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ jobs:
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_OPENMP \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_OPENMP=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_OPENMP=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON \
-DKokkosFFT_ENABLE_BENCHMARK=ON

- name: Configure CMake for CUDA backend
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_CUDA \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON \
-DKokkosFFT_ENABLE_BENCHMARK=ON

- name: Configure CMake for CUDA backend with HOST and DEVICE option
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand All @@ -71,7 +73,7 @@ jobs:
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_CUDA_HOST_DEVICE \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON \
-DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON -DKokkosFFT_INTERNAL_Kokkos=ON
-DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON -DKokkosFFT_INTERNAL_Kokkos=ON -DKokkosFFT_ENABLE_BENCHMARK=ON

- name: Build
# Build your program with the given configuration
Expand Down Expand Up @@ -135,7 +137,8 @@ jobs:
run: |
docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_${{matrix.backend.name}} \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_HIP=ON -DKokkosFFT_INTERNAL_Kokkos=ON -DKokkos_ARCH_${{env.architecture}}=ON -DBUILD_TESTING=ON ${{matrix.backend.option}}
-DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_HIP=ON -DKokkosFFT_INTERNAL_Kokkos=ON -DKokkos_ARCH_${{env.architecture}}=ON -DBUILD_TESTING=ON \
-DKokkosFFT_ENABLE_BENCHMARK=ON -DCMAKE_CXX_FLAGS="-pthread" ${{matrix.backend.option}}

- name: Build
# Build your program with the given configuration
Expand Down Expand Up @@ -189,6 +192,7 @@ jobs:
-DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \
-DCMAKE_CXX_STANDARD=17 \
-DKokkosFFT_INTERNAL_Kokkos=ON \
-DKokkosFFT_ENABLE_BENCHMARK=ON \
-DKOKKOS_IMPL_SYCL_DEVICE_GLOBAL_SUPPORTED=0 \
-DKokkos_ARCH_NATIVE=ON \
-DCMAKE_CXX_FLAGS="-fsycl-device-code-split=per_kernel -Wno-deprecated-declarations -Werror -Wno-gnu-zero-variadic-macro-arguments -Wno-unknown-cuda-version -Wno-sycl-target" \
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "tpls/googletest"]
path = tpls/googletest
url = https://github.com/google/googletest.git
[submodule "tpls/benchmark"]
path = tpls/benchmark
url = https://github.com/google/benchmark.git
48 changes: 44 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Options
option(BUILD_EXAMPLES "Build KokkosFFT examples" ON)
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable FFT on both host and device")
option(KokkosFFT_INTERNAL_Kokkos "Build internal Kokkos instead of relying on external one")
option(KokkosFFT_ENABLE_HOST_AND_DEVICE "Enable FFT on both host and device" OFF)
option(KokkosFFT_INTERNAL_Kokkos "Build internal Kokkos instead of relying on external one" OFF)
option(KokkosFFT_ENABLE_BENCHMARK "Build benchmarks for KokkosFFT" OFF)

# Version information
set(KokkosFFT_VERSION_MAJOR 0)
set(KokkosFFT_VERSION_MINOR 0)
set(KokkosFFT_VERSION_PATCH 00)
Comment on lines +14 to +16
Copy link

Choose a reason for hiding this comment

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

If you're set to release a beta, you should probably put a 0.1.0 or something I suppose.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure. As well as DDC, I am planning to begin with 0.0.00.

set(KokkosFFT_VERSION "${KokkosFFT_VERSION_MAJOR}.${KokkosFFT_VERSION_MINOR}.${KokkosFFT_VERSION_PATCH}")

#Set variables for config file
math(EXPR KOKKOSFFT_VERSION "${KokkosFFT_VERSION_MAJOR} * 10000 + ${KokkosFFT_VERSION_MINOR} * 100 + ${KokkosFFT_VERSION_PATCH}")
math(EXPR KOKKOSFFT_VERSION_MAJOR "${KOKKOSFFT_VERSION} / 10000")
math(EXPR KOKKOSFFT_VERSION_MINOR "${KOKKOSFFT_VERSION} / 100 % 100")
math(EXPR KOKKOSFFT_VERSION_PATCH "${KOKKOSFFT_VERSION} % 100")
Comment on lines +20 to +23
Copy link

Choose a reason for hiding this comment

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

I don't understand the use of the KOKKOSFFT_VERSION variable. Could you be a little more explicit please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

KOKKOSFFT_VERSION is a temporary variable to convert version variables into integers. What we would really like to have in integers are KOKKOSFFT_VERSION_MAJOR, KOKKOSFFT_VERSION_MINOR and KOKKOSFFT_VERSION_PATCH. These are used to replace the placeholders in c++ codes that are used to show version info in benchmark.

Is it OK for you?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As commented, this will be done in the fix of #32
For the moment, need to focus on docs and thread capability.


if (NOT KokkosFFT_INTERNAL_Kokkos)
# First check, Kokkos is added as subdirectory or not
Expand All @@ -27,6 +40,33 @@ if(BUILD_TESTING)
endif()
endif()

# Benchmark
if(KokkosFFT_ENABLE_BENCHMARK)
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
add_subdirectory(tpls/benchmark)

# [TO DO] Fix this, it detects benchmark not a googlebench
#find_package(benchmark QUIET)
#if(NOT benchmark_FOUND)
# add_subdirectory(tpls/benchmark)
#endif()
endif()

# Configure files to display configuration
# Configure the library
set(
PACKAGE_NAME_CONFIG_FILES
KokkosFFT_config.h
KokkosFFT_Version_Info.hpp
)

foreach(CONFIG_FILE ${PACKAGE_NAME_CONFIG_FILES})
configure_file(
cmake/${CONFIG_FILE}.in
${CMAKE_BINARY_DIR}/${CONFIG_FILE}
)
endforeach()

# Set directories used for install
include(GNUInstallDirs)
set(LIBDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
Expand Down Expand Up @@ -71,12 +111,12 @@ configure_package_config_file(cmake/KokkosFFTConfig.cmake.in

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
VERSION 0.0.0
VERSION ${KokkosFFT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/KokkosFFTConfigVersion.cmake
DESTINATION ${INSTALL_LIBDIR}
)
)
36 changes: 36 additions & 0 deletions cmake/KokkosFFT_Version_Info.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#ifndef KOKKOSFFT_VERSION_INFO_HPP
#define KOKKOSFFT_VERSION_INFO_HPP

#include <string_view>

namespace KokkosFFT {
namespace Impl {

constexpr std::string_view GIT_BRANCH = R"branch(@GIT_BRANCH@)branch";
constexpr std::string_view GIT_COMMIT_HASH = "@GIT_COMMIT_HASH@";
constexpr std::string_view GIT_CLEAN_STATUS = "@GIT_CLEAN_STATUS@";
constexpr std::string_view GIT_COMMIT_DESCRIPTION =
R"message(@GIT_COMMIT_DESCRIPTION@)message";
constexpr std::string_view GIT_COMMIT_DATE = "@GIT_COMMIT_DATE@";
constexpr std::string_view BENCHMARK_VERSION = "@BENCHMARK_VERSION@";

} // namespace Impl
} // namespace KokkosFFT

#endif
30 changes: 30 additions & 0 deletions cmake/KokkosFFT_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef KOKKOSFFT_CONFIG_H
#define KOKKOSFFT_CONFIG_H

/* Define the current version of Kokkos Kernels */
#define KOKKOSFFT_VERSION @KOKKOSFFT_VERSION@
#define KOKKOSFFT_VERSION_MAJOR @KOKKOSFFT_VERSION_MAJOR@
#define KOKKOSFFT_VERSION_MINOR @KOKKOSFFT_VERSION_MINOR@
#define KOKKOSFFT_VERSION_PATCH @KOKKOSFFT_VERSION_PATCH@

/* Define if building in debug mode */
#cmakedefine HAVE_KOKKOSFFT_DEBUG

#cmakedefine KOKKOSFFT_ENABLE_BENCHMARK

/* Define this macro if experimental features of KokkosFFT are enabled */
#cmakedefine HAVE_KOKKOSFFT_EXPERIMENTAL

/* FFTW */
#cmakedefine KOKKOSFFT_ENABLE_TPL_FFTW

/* CUFFT */
#cmakedefine KOKKOSFFT_ENABLE_TPL_CUFFT

/* HIPFFT */
#cmakedefine KOKKOSFFT_ENABLE_TPL_HIPFFT

/* ONEMKL */
#cmakedefine KOKKOSFFT_ENABLE_TPL_ONEMKL

#endif
11 changes: 8 additions & 3 deletions common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,38 @@ target_link_libraries(common
if(Kokkos_ENABLE_CUDA)
find_package(CUDAToolkit REQUIRED COMPONENTS cufft)
target_link_libraries(common INTERFACE CUDA::cufft)
target_compile_definitions(common INTERFACE KOKKOSFFT_ENABLE_TPL_CUFFT)
if(KokkosFFT_ENABLE_HOST_AND_DEVICE)
find_package(FFTW MODULE REQUIRED)
target_link_libraries(common INTERFACE FFTW::Float FFTW::Double FFTW::FloatOpenMP FFTW::DoubleOpenMP)
target_compile_definitions(common INTERFACE ENABLE_HOST_AND_DEVICE)
target_compile_definitions(common INTERFACE ENABLE_HOST_AND_DEVICE KOKKOSFFT_ENABLE_TPL_FFTW)
endif()
elseif(Kokkos_ENABLE_HIP)
find_package(hipfft REQUIRED)
target_link_libraries(common INTERFACE hip::hipfft)
target_compile_definitions(common INTERFACE KOKKOSFFT_ENABLE_TPL_HIPFFT)
if(KokkosFFT_ENABLE_HOST_AND_DEVICE)
find_package(FFTW MODULE REQUIRED)
target_link_libraries(common INTERFACE FFTW::Float FFTW::Double FFTW::FloatOpenMP FFTW::DoubleOpenMP)
target_compile_definitions(common INTERFACE ENABLE_HOST_AND_DEVICE)
target_compile_definitions(common INTERFACE ENABLE_HOST_AND_DEVICE KOKKOSFFT_ENABLE_TPL_FFTW)
endif()
elseif(Kokkos_ENABLE_SYCL)
find_package(MKL REQUIRED COMPONENTS SYCL)
target_link_libraries(common INTERFACE MKL::MKL_SYCL)
target_compile_definitions(common INTERFACE KOKKOSFFT_ENABLE_TPL_ONEMKL)
if(KokkosFFT_ENABLE_HOST_AND_DEVICE)
find_package(FFTW MODULE REQUIRED)
target_link_libraries(common INTERFACE FFTW::Float FFTW::Double FFTW::FloatOpenMP FFTW::DoubleOpenMP)
target_compile_definitions(common INTERFACE ENABLE_HOST_AND_DEVICE)
target_compile_definitions(common INTERFACE ENABLE_HOST_AND_DEVICE KOKKOSFFT_ENABLE_TPL_FFTW)
endif()
elseif(Kokkos_ENABLE_OPENMP)
find_package(FFTW MODULE REQUIRED)
target_link_libraries(common INTERFACE FFTW::Float FFTW::Double FFTW::FloatOpenMP FFTW::DoubleOpenMP)
target_compile_definitions(common INTERFACE KOKKOSFFT_ENABLE_TPL_FFTW)
elseif(Kokkos_ENABLE_SERIAL)
find_package(FFTW MODULE REQUIRED)
target_link_libraries(common INTERFACE FFTW::Float FFTW::Double)
target_compile_definitions(common INTERFACE KOKKOSFFT_ENABLE_TPL_FFTW)
endif()

target_compile_features(common INTERFACE cxx_std_17)
Expand Down
2 changes: 1 addition & 1 deletion common/src/KokkosFFT_normalization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void normalize(const ExecutionSpace& exec_space, ViewType& inout,
if (to_normalize) _normalize(exec_space, inout, coef);
}

auto swap_direction(Normalization normalization) {
inline auto swap_direction(Normalization normalization) {
Normalization new_direction = Normalization::FORWARD;
switch (normalization) {
case Normalization::FORWARD: new_direction = Normalization::BACKWARD; break;
Expand Down
4 changes: 4 additions & 0 deletions fft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
add_subdirectory(src)
if(BUILD_TESTING)
add_subdirectory(unit_test)
endif()

if(KokkosFFT_ENABLE_BENCHMARK)
add_subdirectory(perf_test)
endif()
37 changes: 37 additions & 0 deletions fft/perf_test/BenchmarkMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
*/

#include <benchmark/benchmark.h>

#include "Benchmark_Context.hpp"
#include <Kokkos_Core.hpp>

int main(int argc, char** argv) {
Kokkos::initialize(argc, argv);
{
benchmark::Initialize(&argc, argv);
benchmark::SetDefaultTimeUnit(benchmark::kSecond);
KokkosFFTBenchmark::add_benchmark_context(true);

benchmark::RunSpecifiedBenchmarks();

benchmark::Shutdown();
}
Kokkos::finalize();
return 0;
}
Loading
Loading