Skip to content

Commit

Permalink
Add lint and unit test CI (#13)
Browse files Browse the repository at this point in the history
- increase tolerance to work on gcc
- bench job comparison to main
- clean up build and tests
  • Loading branch information
ProExpertProg authored Oct 18, 2024
1 parent e4a69fe commit 07088e2
Show file tree
Hide file tree
Showing 20 changed files with 842 additions and 740 deletions.
20 changes: 20 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
BasedOnStyle: LLVM
IndentWidth: 2
UseTab: Never
AllowShortBlocksOnASingleLine: Always
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
BreakBeforeBraces: Attach
InsertBraces: true
ColumnLimit: 100

IncludeCategories:
- Regex: '^<'
Priority: 4
- Regex: '^<(gmock|gtest)/'
Priority: 3
- Regex: '^"fftw-cpp/'
Priority: 1
- Regex: '.*'
Priority: 2
48 changes: 31 additions & 17 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ on:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build:
bench:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
Expand All @@ -32,20 +35,31 @@ jobs:
cmake ../cpp -G Ninja -D CMAKE_BUILD_TYPE=Release -D ENABLE_CILK=OFF
ninja
- name: benchmark
run: ./cmake-build-release/bench/bench-naive --benchmark_format=json --benchmark_out=bench-naive.json
run: ./cmake-build-release/bench/bench-naive --benchmark_out_format=json --benchmark_out=../bench-naive.json

# # TODO main for comparison
# - uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
# with:
# ref: main
# - name: build-main
# run: |
# mkdir cmake-build-release-main
# cd cmake-build-release-main
# cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -D ENABLE_CILK=OFF
# ninja
# - name: benchmark-main
# run: ./cmake-build-release-main/bench/bench-naive --benchmark_format=json --benchmark_out=bench-naive-main.json
#
# - name: compare
# run: python3 cmake-build-release/_deps/google-benchmark-src/tools/compare.py bench-naive-main.json bench-naive.json
# Compare to baseline (main)
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
with:
ref: main
- name: build-main
run: |
mkdir cmake-build-release-main
cd cmake-build-release-main
cmake ../cpp -G Ninja -D CMAKE_BUILD_TYPE=Release -D ENABLE_CILK=OFF
ninja
- name: benchmark-main
run: ./cmake-build-release-main/bench/bench-naive --benchmark_out_format=json --benchmark_out=../bench-naive-main.json
- name: compare-install
run: |
# Use cmake-build-release-main because cmake-build-release is gone after checkout
pip3 install -r cmake-build-release-main/_deps/google-benchmark-src/tools/requirements.txt
- name: compare
run: |
echo "Times in milliseconds"
python3 cmake-build-release-main/_deps/google-benchmark-src/tools/compare.py -d bench-naive-compared.json benchmarks ../bench-naive-main.json ../bench-naive.json
- uses: actions/upload-artifact@v4
with:
name: bench-naive-comparison
path: bench-naive-compared.json
compression-level: '0' # Short file, no need to compress
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI Lint
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: install
run: sudo apt update && sudo apt install clang-format-15
- name: lint
run: |
./format.sh 1
39 changes: 39 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI Unit tests
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: install
run: |
sudo apt update
sudo apt install build-essential ninja-build cmake
- name: fftw-download # TODO use fftw-cpp for download
run: |
wget https://www.fftw.org/fftw-3.3.10.tar.gz
tar -xf fftw-3.3.10.tar.gz
- name: configure-fftw
working-directory: ./fftw-3.3.10
run: |
./configure --enable-threads --enable-avx2 --enable-avx512
make
sudo make install
- name: build
run: |
mkdir cmake-build-relwithdebinfo
cd cmake-build-relwithdebinfo
cmake ../cpp -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo -D ENABLE_CILK=OFF
ninja
- name: test
run: ctest --verbose
working-directory: ./cmake-build-relwithdebinfo
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/*.log
*.jld2
build
cmake-build-*
.vscode
.DS_Store
cachegrind.out.*
Expand Down
4 changes: 3 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ if (ENABLE_CILK)
add_compile_definitions(CILK_ENABLED)
endif ()

add_executable(adaptive_hermite_refinement test-triangle.cpp)
# TODO: cleanup (currently just to test formatting)
add_executable(adaptive_hermite_refinement lib/test-triangle.cpp)
target_include_directories(adaptive_hermite_refinement PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(adaptive_hermite_refinement argparse mdspan)

add_library(src-lib OBJECT Naive.cpp Naive.h HermiteRunner.cpp HermiteRunner.h)
Expand Down
4 changes: 2 additions & 2 deletions cpp/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target_link_libraries(bench-fft-multi argparse fftw-cpp)
add_executable(bench-fft-fusion fftw/bench-fft-fusion.cpp)
target_link_libraries(bench-fft-fusion argparse fftw-cpp)

option(BENCHMARK_ENABLE_GTEST_TESTS "Enable Google Test tests for Google Benchmark." OFF)
option(BENCHMARK_ENABLE_TESTING "Enable testing for Google Benchmark." OFF)

include(FetchContent)
FetchContent_Declare(
Expand All @@ -22,7 +22,7 @@ FetchContent_MakeAvailable(google-benchmark)
add_executable(bench-naive naive.cpp)
target_link_libraries(bench-naive src-lib benchmark::benchmark_main)

if (CILK_ENABLED)
if (ENABLE_CILK)
add_executable(bench-fftw-cilk fftw-cilk.cpp)
target_link_libraries(bench-fftw-cilk fftw-cpp benchmark::benchmark fftw3_threads)

Expand Down
20 changes: 5 additions & 15 deletions cpp/bench/fftw-cilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <thread>

static void copy(fftw::buffer const &in, fftw::buffer &out) {
std::memcpy(out.data(), in.data(),
in.size() * sizeof(fftw::buffer::element_type));
std::memcpy(out.data(), in.data(), in.size() * sizeof(fftw::buffer::element_type));
}

static void BM_copy_1D(benchmark::State &state) {
Expand Down Expand Up @@ -77,15 +76,9 @@ static void BM_FFTW_2D(benchmark::State &state) {
auto constexpr K = 1024;
auto constexpr M = K * K;

BENCHMARK(BM_copy_1D)
->RangeMultiplier(2)
->Range(16 * M, 64 * M)
->Unit(benchmark::kMillisecond);
BENCHMARK(BM_copy_1D)->RangeMultiplier(2)->Range(16 * M, 64 * M)->Unit(benchmark::kMillisecond);

BENCHMARK(BM_FFTW_1D)
->RangeMultiplier(2)
->Range(16 * M, 64 * M)
->Unit(benchmark::kMillisecond);
BENCHMARK(BM_FFTW_1D)->RangeMultiplier(2)->Range(16 * M, 64 * M)->Unit(benchmark::kMillisecond);

BENCHMARK(BM_copy_2D)
->ArgsProduct({{4 * K, 8 * K, 16 * K}, {4 * K, 8 * K, 16 * K}})
Expand All @@ -97,8 +90,7 @@ BENCHMARK(BM_FFTW_2D)

// TODO pthreads, openmp, cilk -> compare all
#ifndef FFTW_PTHREADS
void parallel_for(void *(*work)(char *), char *jobdata, size_t elsize,
int njobs, void *data) {
void parallel_for(void *(*work)(char *), char *jobdata, size_t elsize, int njobs, void *data) {
// std::cout << "parallel_for: " << njobs << std::endl;
cilk_for(int i = 0; i < njobs; ++i) { work(jobdata + i * elsize); }
}
Expand All @@ -115,9 +107,7 @@ int main(int argc, char **argv) {
fftw_threads_set_callback(parallel_for, nullptr);
#endif

if (auto const n = std::getenv("BENCH_NJOBS"); n) {
njobs = std::stoi(n);
}
if (auto const n = std::getenv("BENCH_NJOBS"); n) { njobs = std::stoi(n); }

std::cout << "Using " << njobs << " jobs for FFTW" << std::endl;
fftw_plan_with_nthreads(njobs);
Expand Down
Loading

0 comments on commit 07088e2

Please sign in to comment.