Skip to content

Commit c2700b8

Browse files
authored
GTBench as a Library + Python Bindings (GridTools#69)
- Reorganizes source and header tree. - Provides CMake install targets (and basic, untested export). - Provides Python bindings to core solver functionality.
1 parent 0ee360d commit c2700b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+768
-218
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.*
2+
build*

.github/workflows/python.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Python
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
env:
10+
DOCKER_BUILDKIT: 1
11+
OMP_NUM_THREADS: 1
12+
13+
jobs:
14+
main:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
name: checkout
19+
- name: build
20+
run: >
21+
docker build
22+
--cache-from fthaler/gtbench:python-test
23+
--progress=plain
24+
--build-arg BUILD_FROM=python:3.9.0
25+
--build-arg GTBENCH_BACKEND=cpu_ifirst
26+
--build-arg GTBENCH_RUNTIME=single_node
27+
--build-arg GTBENCH_PYTHON_BINDINGS=ON
28+
--build-arg BUILDKIT_INLINE_CACHE=1
29+
-t fthaler/gtbench:python-test
30+
.
31+
- name: test
32+
run: >
33+
docker run --rm fthaler/gtbench:python-test bash -c 'pip install numpy pytest && pytest /gtbench/python/test.py'
34+
- name: push
35+
if: ${{ github.event_name == 'push' && github.repository == 'GridTools/gtbench' }}
36+
run: >
37+
echo ${{ secrets.DOCKER_TOKEN }} | docker login -u fthaler --password-stdin &&
38+
docker push fthaler/gtbench:python-test &&
39+
docker logout
40+

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
- name: test
4444
if: ${{ matrix.backend != 'cuda' && matrix.backend != 'hip' }}
4545
run: >
46-
docker run --rm fthaler/gtbench:${{ matrix.backend }}-${{ matrix.runtime }} /usr/bin/benchmark --domain-size 11 13 17 --runs 1 &&
47-
docker run --rm fthaler/gtbench:${{ matrix.backend }}-${{ matrix.runtime }} /usr/bin/convergence_tests
46+
docker run --rm fthaler/gtbench:${{ matrix.backend }}-${{ matrix.runtime }} benchmark --domain-size 11 13 17 --runs 1 &&
47+
docker run --rm fthaler/gtbench:${{ matrix.backend }}-${{ matrix.runtime }} convergence_tests
4848
- name: push
4949
if: ${{ github.event_name == 'push' && github.repository == 'GridTools/gtbench' }}
5050
run: >

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.*
2+
!.gitignore
3+
!.github
4+
!.dockerignore
5+
build
6+
__pycache__

CMakeLists.txt

+42-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
cmake_minimum_required(VERSION 3.14.5)
2-
project(GTBench LANGUAGES CXX)
2+
3+
file(STRINGS "version.txt" _gtbench_version)
4+
project(GTBench VERSION ${_gtbench_version} LANGUAGES CXX)
5+
unset(_gtbench_version)
36

47
if(NOT CMAKE_BUILD_TYPE)
58
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
@@ -22,6 +25,9 @@ set(GTBENCH_BPARAMS_VDIFF "" CACHE STRING "Parameters for GridTools backend for
2225
set(GTBENCH_BPARAMS_HADV "" CACHE STRING "Parameters for GridTools backend for horizontal advection")
2326
set(GTBENCH_BPARAMS_VADV "" CACHE STRING "Parameters for GridTools backend for vertical advection")
2427

28+
option(GTBENCH_PYTHON_BINDINGS "Build Python bindings" OFF)
29+
30+
set(_gtbench_cuda_enabled OFF)
2531
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND GTBENCH_BACKEND STREQUAL "gpu")
2632
set(GT_CLANG_CUDA_MODE "Clang-CUDA" CACHE STRING "Clang-CUDA or NVCC-CUDA")
2733
set_property(CACHE GT_CLANG_CUDA_MODE PROPERTY STRINGS "Clang-CUDA" "NVCC-CUDA")
@@ -32,6 +38,7 @@ else()
3238
enable_language(CUDA)
3339
set(CMAKE_CUDA_STANDARD 14)
3440
set(CMAKE_CUDA_EXTENSIONS OFF)
41+
set(_gtbench_cuda_enabled ON)
3542
endif()
3643
endif()
3744

@@ -40,65 +47,56 @@ if(NOT _gridtools_already_fetched)
4047
find_package(GridTools "2" QUIET)
4148
endif()
4249
if(NOT GridTools_FOUND)
43-
set(_gridtools_repository "https://github.com/GridTools/gridtools.git")
44-
set(_gridtools_tag "release_v2.0")
45-
if(NOT _gridtools_already_fetched)
46-
message(STATUS "Fetching GridTools ${_gridtools_tag} from ${_gridtools_repository}")
47-
endif()
48-
include(FetchContent)
49-
FetchContent_Declare(
50-
gridtools
51-
GIT_REPOSITORY ${_gridtools_repository}
52-
GIT_TAG ${_gridtools_tag}
53-
)
54-
FetchContent_MakeAvailable(gridtools)
55-
set(_gridtools_already_fetched ON CACHE INTERNAL "")
50+
set(_gridtools_repository "https://github.com/GridTools/gridtools.git")
51+
set(_gridtools_tag "release_v2.0")
52+
if(NOT _gridtools_already_fetched)
53+
message(STATUS "Fetching GridTools ${_gridtools_tag} from ${_gridtools_repository}")
54+
endif()
55+
include(FetchContent)
56+
FetchContent_Declare(
57+
gridtools
58+
GIT_REPOSITORY ${_gridtools_repository}
59+
GIT_TAG ${_gridtools_tag}
60+
)
61+
FetchContent_MakeAvailable(gridtools)
62+
set(_gridtools_already_fetched ON CACHE INTERNAL "")
5663
endif()
5764

58-
set(CMAKE_CXX_STANDARD 14)
59-
set(CMAKE_CXX_EXTENSIONS OFF)
60-
6165
# Helper functions
6266
function(compile_as_cuda)
63-
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
64-
if("CUDA" IN_LIST languages)
67+
if(_gtbench_cuda_enabled)
6568
set_source_files_properties(${ARGN} PROPERTIES LANGUAGE CUDA)
6669
endif()
6770
endfunction()
6871

69-
add_library(common INTERFACE)
70-
target_compile_options(common INTERFACE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--default-stream per-thread>")
71-
72-
target_compile_definitions(common INTERFACE
72+
add_library(gtbench_common INTERFACE)
73+
target_include_directories(gtbench_common INTERFACE
74+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
75+
$<INSTALL_INTERFACE:include>
76+
)
77+
target_compile_definitions(gtbench_common INTERFACE
7378
GTBENCH_BACKEND=${GTBENCH_BACKEND}
7479
GTBENCH_BACKEND_$<UPPER_CASE:${GTBENCH_BACKEND}>
7580
GTBENCH_FLOAT=${GTBENCH_FLOAT}
7681
)
77-
target_link_libraries(common INTERFACE
82+
target_link_libraries(gtbench_common INTERFACE
7883
GridTools::gridtools
7984
GridTools::stencil_${GTBENCH_BACKEND}
8085
GridTools::storage_${GTBENCH_BACKEND}
81-
)
86+
)
87+
set_target_properties(
88+
gtbench_common
89+
PROPERTIES
90+
INTERFACE_POSITION_INDEPENDENT_CODE ON)
8291

83-
add_library(common_runtime INTERFACE)
84-
target_compile_definitions(common_runtime INTERFACE
85-
GTBENCH_RUNTIME=${GTBENCH_RUNTIME}
86-
)
87-
target_link_libraries(common_runtime INTERFACE
88-
common
89-
)
92+
add_library(gtbench)
93+
add_library(GTBench::gtbench ALIAS gtbench)
94+
target_link_libraries(gtbench PUBLIC gtbench_common)
9095

91-
# Subdirectories
92-
add_subdirectory(common)
93-
add_subdirectory(io)
94-
add_subdirectory(runtime)
95-
add_subdirectory(numerics)
96+
add_subdirectory(src)
9697

97-
# Current directory
98-
compile_as_cuda(convergence_tests.cpp benchmark.cpp)
98+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/export.cmake)
9999

100-
add_executable(convergence_tests convergence_tests.cpp)
101-
target_link_libraries(convergence_tests advection diffusion options runtime device io)
102-
103-
add_executable(benchmark benchmark.cpp)
104-
target_link_libraries(benchmark advection diffusion options runtime device io)
100+
if(GTBENCH_PYTHON_BINDINGS)
101+
add_subdirectory(python)
102+
endif()

Dockerfile

+9-8
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ RUN wget -q https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}
2020
rm -rf cmake-${CMAKE_VERSION}-Linux-x86_64*
2121

2222
ARG BOOST_VERSION=1.67.0
23-
RUN export BOOST_VERSION_UNERLINE=$(echo ${BOOST_VERSION} | sed 's/\./_/g') && \
24-
wget -q https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNERLINE}.tar.gz && \
25-
tar xzf boost_${BOOST_VERSION_UNERLINE}.tar.gz && \
26-
cp -r boost_${BOOST_VERSION_UNERLINE}/boost /usr/local/include/ && \
27-
rm -rf boost_${BOOST_VERSION_UNERLINE}*
23+
RUN export BOOST_VERSION_UNDERLINE=$(echo ${BOOST_VERSION} | sed 's/\./_/g') && \
24+
wget -q https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNDERLINE}.tar.gz && \
25+
tar xzf boost_${BOOST_VERSION_UNDERLINE}.tar.gz && \
26+
cp -r boost_${BOOST_VERSION_UNDERLINE}/boost /usr/local/include/ && \
27+
rm -rf boost_${BOOST_VERSION_UNDERLINE}*
2828

2929
FROM base
3030
ARG GTBENCH_BACKEND=cpu_ifirst
3131
ARG GTBENCH_RUNTIME=ghex_comm
32+
ARG GTBENCH_PYTHON_BINDINGS=OFF
3233
COPY . /gtbench
3334
RUN cd /gtbench && \
3435
mkdir -p build && \
@@ -38,9 +39,9 @@ RUN cd /gtbench && \
3839
-DCMAKE_BUILD_TYPE=Release \
3940
-DGTBENCH_BACKEND=${GTBENCH_BACKEND} \
4041
-DGTBENCH_RUNTIME=${GTBENCH_RUNTIME} \
42+
-DGTBENCH_PYTHON_BINDINGS=${GTBENCH_PYTHON_BINDINGS} \
4143
.. && \
42-
make -j $(nproc) && \
43-
cp benchmark convergence_tests /usr/bin/ && \
44+
make -j $(nproc) install && \
4445
rm -rf /gtbench/build
4546

46-
CMD ["/usr/bin/convergence_tests"]
47+
CMD ["convergence_tests"]

cmake/GTBenchConfig.cmake.in

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(GTBench_VERSION @GTBench_Version@)
2+
3+
@PACKAGE_INIT@
4+
5+
if(NOT @PROJECT_NAME@_BINARY_DIR AND NOT TARGET GTBench::gtbench)
6+
include("${GTBENCH_CONFIG_CMAKE_DIR}/GTBenchTargets.cmake")
7+
endif()
8+
9+
include(FindPackageHandleStandardArgs)
10+
find_package_handle_standard_args(GTBench REQUIRED_VARS GTBench_VERSION VERSION_VAR GTBench_VERSION)

cmake/export.cmake

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
set(GTBENCH_MODULE_PATH lib/cmake/GTBench)
2+
include(GNUInstallDirs)
3+
include(CMakePackageConfigHelpers)
4+
configure_package_config_file(
5+
cmake/GTBenchConfig.cmake.in
6+
"${CMAKE_CURRENT_BINARY_DIR}/install/GTBenchConfig.cmake"
7+
PATH_VARS GTBENCH_MODULE_PATH
8+
INSTALL_DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/GTBench"
9+
)
10+
write_basic_package_version_file(
11+
"${CMAKE_CURRENT_BINARY_DIR}/install/GTBenchConfigVersion.cmake"
12+
COMPATIBILITY SameMajorVersion
13+
)
14+
15+
install(
16+
TARGETS gtbench
17+
EXPORT GTBenchTargets
18+
INCLUDES DESTINATION include
19+
)
20+
install(TARGETS benchmark convergence_tests)
21+
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
22+
23+
# Workaround for GT export strategy
24+
install(
25+
TARGETS stencil_${GTBENCH_BACKEND} storage_${GTBENCH_BACKEND}
26+
EXPORT GTBenchTargets
27+
)
28+
29+
include(GNUInstallDirs)
30+
install(
31+
FILES
32+
"${CMAKE_CURRENT_BINARY_DIR}/install/GTBenchConfig.cmake"
33+
"${CMAKE_CURRENT_BINARY_DIR}/install/GTBenchConfigVersion.cmake"
34+
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}"
35+
)
36+
37+
# Currently disabled due to GT dependency issues
38+
# install(
39+
# EXPORT GTBenchTargets
40+
# FILE GTBenchTargets.cmake
41+
# NAMESPACE GTBench::
42+
# DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}"
43+
# )

common/CMakeLists.txt

-1
This file was deleted.

common/options.hpp include/gtbench/common/options.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string>
1818
#include <vector>
1919

20+
namespace gtbench {
2021
namespace options_impl {
2122

2223
void abort(std::string const &message);
@@ -124,3 +125,5 @@ class options {
124125

125126
std::vector<option> m_options;
126127
};
128+
129+
} // namespace gtbench

common/types.hpp include/gtbench/common/types.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <gridtools/storage/gpu.hpp>
2828
#endif
2929

30+
namespace gtbench {
31+
3032
namespace gt = gridtools;
3133

3234
using real_t = GTBENCH_FLOAT;
@@ -56,3 +58,5 @@ inline auto storage_builder(vec<std::size_t, 3> const &resolution) {
5658

5759
using storage_t =
5860
decltype(storage_builder(std::declval<vec<std::size_t, 3>>())());
61+
62+
} // namespace gtbench

io/base64.hpp include/gtbench/io/base64.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cstdint>
1313
#include <ostream>
1414

15+
namespace gtbench {
1516
namespace io {
1617
class base64_encoder {
1718
std::ostream &m_out;
@@ -47,3 +48,4 @@ class base64_encoder {
4748
}
4849
};
4950
} // namespace io
51+
} // namespace gtbench

io/io.hpp include/gtbench/io/io.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../common/types.hpp"
1616
#include "../numerics/solver.hpp"
1717

18+
namespace gtbench {
1819
namespace io {
1920

2021
std::function<void(real_t, numerics::solver_state const &state)>
@@ -24,3 +25,4 @@ write_time_series(std::string const &filename,
2425
vec<std::size_t, 3> const &local_offset);
2526

2627
} // namespace io
28+
} // namespace gtbench

io/numpy.hpp include/gtbench/io/numpy.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "./io.hpp"
1313

14+
namespace gtbench {
1415
namespace io {
1516
namespace numpy {
1617

@@ -22,3 +23,4 @@ write_time_series(std::string const &filename,
2223

2324
} // namespace numpy
2425
} // namespace io
26+
} // namespace gtbench

io/util.hpp include/gtbench/io/util.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
#include "../common/types.hpp"
1313

14+
namespace gtbench {
1415
namespace io {
1516
std::size_t rank(vec<std::size_t, 3> const &global_resolution,
1617
vec<std::size_t, 3> const &local_resolution,
1718
vec<std::size_t, 3> const &local_offset);
1819

1920
std::size_t ranks(vec<std::size_t, 3> const &global_resolution,
2021
vec<std::size_t, 3> const &local_resolution);
21-
} // namespace io
22+
} // namespace io
23+
} // namespace gtbench

io/vtk.hpp include/gtbench/io/vtk.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "./io.hpp"
1515

16+
namespace gtbench {
1617
namespace io {
1718
namespace vtk {
1819

@@ -25,3 +26,4 @@ write_time_series(std::string const &filename,
2526
} // namespace vtk
2627

2728
} // namespace io
29+
} // namespace gtbench

numerics/advection.hpp include/gtbench/numerics/advection.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "./computation.hpp"
1313

14+
namespace gtbench {
1415
namespace numerics {
1516
namespace advection {
1617

@@ -23,3 +24,4 @@ vertical(vec<std::size_t, 3> const &resolution, vec<real_t, 3> const &delta);
2324

2425
} // namespace advection
2526
} // namespace numerics
27+
} // namespace gtbench

0 commit comments

Comments
 (0)