From c34108225a907f438f2061e210b1712a00ea3529 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 24 Jun 2024 14:26:34 +0200 Subject: [PATCH 1/2] [INFRA] Update CI --- .github/workflows/ci_asan.yml | 61 +++++++++----------- .github/workflows/ci_header.yml | 75 +++++++++---------------- .github/workflows/ci_linux.yml | 98 +++++++++------------------------ .github/workflows/ci_macos.yml | 64 ++++++--------------- 4 files changed, 98 insertions(+), 200 deletions(-) diff --git a/.github/workflows/ci_asan.yml b/.github/workflows/ci_asan.yml index e47ae697..a03b56a8 100644 --- a/.github/workflows/ci_asan.yml +++ b/.github/workflows/ci_asan.yml @@ -3,15 +3,13 @@ name: ASAN on: push: branches: - # Push events to branches matching refs/heads/master - 'master' pull_request: - # Enables a manual trigger, may run on any branch workflow_dispatch: concurrency: group: asan-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + cancel-in-progress: ${{ github.event_name != 'push' }} env: TZ: Europe/Berlin @@ -22,58 +20,51 @@ defaults: jobs: build: - name: ${{ matrix.name }} - runs-on: ubuntu-22.04 - timeout-minutes: 120 + runs-on: ubuntu-latest + name: ${{ matrix.compiler }} ${{ matrix.cereal == '1' && 'cereal' || '' }} if: github.repository_owner == 'xxsds' || github.event_name == 'workflow_dispatch' strategy: fail-fast: false matrix: - include: - - name: "gcc13" - compiler: "gcc-13" - cxx_flags: "-std=c++23" - - - name: "clang17" - compiler: "clang-17" - cxx_flags: "-std=c++23 -stdlib=libc++" - + compiler: ["clang-18", "gcc-14"] + cereal: ["0", "1"] + container: + image: ghcr.io/seqan/${{ matrix.compiler }} + volumes: + - /home/runner:/home/runner steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 1 submodules: true - - name: Setup toolchain - uses: seqan/actions/setup-toolchain@main - with: - compiler: ${{ matrix.compiler }} - ccache_size: 125M + - name: Get number of processors + run: echo "NUM_THREADS=$(getconf _NPROCESSORS_ONLN)" >> "$GITHUB_ENV" - - name: Install CMake - uses: seqan/actions/setup-cmake@main + - name: Load ccache + uses: actions/cache@v4 with: - cmake: 3.13.5 + path: /home/runner/.ccache + save-always: true + key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }} - name: Configure tests run: | - mkdir ci-build - cd ci-build + mkdir bbuild && cd bbuild cmake .. -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror -fsanitize=address ${{ matrix.cxx_flags }}" - make -j2 gtest_build + -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror -std=c++23 -fsanitize=address" \ + -DSDSL_CEREAL=${{ matrix.cereal }} + make -j${NUM_THREADS} gtest_build - name: Build tests + working-directory: bbuild run: | - ccache -p - cd ci-build - make sdsl_test_targets sdsl_examples sdsl_tutorials -k -j2 - ccache -s + ccache -z + make -k -j${NUM_THREADS} sdsl_test_targets sdsl_examples sdsl_tutorials + ccache -sv - name: Run tests - run: | - cd ci-build - ctest . -j2 -E 'faust|moby' -R '-im' + working-directory: bbuild + run: ctest . -j${NUM_THREADS} --output-on-failure -E 'faust|moby' -R '-im' diff --git a/.github/workflows/ci_header.yml b/.github/workflows/ci_header.yml index f6e37786..feeb834e 100644 --- a/.github/workflows/ci_header.yml +++ b/.github/workflows/ci_header.yml @@ -3,15 +3,13 @@ name: Header on: push: branches: - # Push events to branches matching refs/heads/master - 'master' pull_request: - # Enables a manual trigger, may run on any branch workflow_dispatch: concurrency: group: header-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + cancel-in-progress: ${{ github.event_name != 'push' }} env: TZ: Europe/Berlin @@ -22,72 +20,53 @@ defaults: jobs: build: - name: ${{ matrix.name }} - runs-on: ubuntu-22.04 - timeout-minutes: 120 + runs-on: ubuntu-latest + name: ${{ matrix.compiler }} ${{ matrix.type }} if: github.repository_owner == 'xxsds' || github.event_name == 'workflow_dispatch' strategy: fail-fast: false matrix: - include: - - name: "gcc13" - compiler: "gcc-13" - build_type: Release - cxx_flags: "-std=c++23" - - - name: "gcc11" - compiler: "gcc-13" - build_type: Debug - cxx_flags: "-std=c++23" - - - name: "clang17" - compiler: "clang-17" - build_type: Release - cxx_flags: "-std=c++23 -stdlib=libc++" - - - name: "clang16" - compiler: "clang-16" - build_type: Debug - cxx_flags: "-std=c++20 -stdlib=libc++" - + compiler: ["clang-18", "gcc-14", "gcc-11"] + type: ["Release", "Debug"] + container: + image: ghcr.io/seqan/${{ matrix.compiler }} + volumes: + - /home/runner:/home/runner steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 1 submodules: true - - name: Setup toolchain - uses: seqan/actions/setup-toolchain@main - with: - compiler: ${{ matrix.compiler }} - ccache_size: 75M + - name: Get number of processors + run: echo "NUM_THREADS=$(getconf _NPROCESSORS_ONLN)" >> "$GITHUB_ENV" - - name: Install CMake - uses: seqan/actions/setup-cmake@main + - name: Load ccache + uses: actions/cache@v4 with: - cmake: 3.13.5 + path: /home/runner/.ccache + save-always: true + key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }} - name: Configure tests run: | - mkdir ci-build - cd ci-build - cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + mkdir bbuild && cd bbuild + cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.type }} \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror ${{ matrix.cxx_flags }}" \ + -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror -std=c++23" \ -DSDSL_CEREAL=1 \ -DSDSL_HEADER_TEST=ON - make -j2 gtest_build + make -j${NUM_THREADS} gtest_build - name: Build tests + working-directory: bbuild run: | - ccache -p - cd ci-build - make sdsl_header_test -k -j2 - ccache -s + ccache -z + make -k -j${NUM_THREADS} sdsl_header_test + ccache -sv - name: Run tests - run: | - cd ci-build - ctest . -j2 + working-directory: bbuild + run: ctest . -j${NUM_THREADS} --output-on-failure + diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml index 321bc8c7..c7b1900d 100644 --- a/.github/workflows/ci_linux.yml +++ b/.github/workflows/ci_linux.yml @@ -3,15 +3,13 @@ name: Linux on: push: branches: - # Push events to branches matching refs/heads/master - 'master' pull_request: - # Enables a manual trigger, may run on any branch workflow_dispatch: concurrency: group: linux-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + cancel-in-progress: ${{ github.event_name != 'push' }} env: TZ: Europe/Berlin @@ -22,93 +20,51 @@ defaults: jobs: build: - name: ${{ matrix.name }} - runs-on: ubuntu-22.04 - timeout-minutes: 120 + runs-on: ubuntu-latest + name: ${{ matrix.compiler }} ${{ matrix.cereal == '1' && 'cereal' || '' }} if: github.repository_owner == 'xxsds' || github.event_name == 'workflow_dispatch' strategy: fail-fast: false matrix: - include: - - name: "gcc13" - compiler: "gcc-13" - build_type: Release - cxx_flags: "-std=c++23" - - - name: "cereal gcc13" - compiler: "gcc-13" - build_type: Release - cxx_flags: "-std=c++23" - has_cereal: "1" - - - name: "gcc12" - compiler: "gcc-12" - build_type: Release - cxx_flags: "-std=c++23" - - - name: "gcc11" - compiler: "gcc-11" - build_type: Release - cxx_flags: "-std=c++23" - - - name: "clang17" - compiler: "clang-17" - build_type: Release - cxx_flags: "-std=c++23 -stdlib=libc++" - - - name: "cereal clang17" - compiler: "clang-17" - build_type: Release - cxx_flags: "-std=c++23 -stdlib=libc++" - has_cereal: "1" - - - name: "clang16" - compiler: "clang-16" - build_type: Release - cxx_flags: "-std=c++20 -stdlib=libc++" - - - name: "clang15" - compiler: "clang-15" - build_type: Release - cxx_flags: "-std=c++20 -stdlib=libc++" - + compiler: ["clang-18", "clang-17", "gcc-14", "gcc-13", "gcc-12", "gcc-11", "intel"] + cereal: ["0", "1"] + container: + image: ghcr.io/seqan/${{ matrix.compiler }} + volumes: + - /home/runner:/home/runner steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 1 submodules: true - - name: Setup toolchain - uses: seqan/actions/setup-toolchain@main - with: - compiler: ${{ matrix.compiler }} - ccache_size: 75M + - name: Get number of processors + run: echo "NUM_THREADS=$(getconf _NPROCESSORS_ONLN)" >> "$GITHUB_ENV" - - name: Install CMake - uses: seqan/actions/setup-cmake@main + - name: Load ccache + uses: actions/cache@v4 with: - cmake: 3.13.5 + path: /home/runner/.ccache + save-always: true + key: ccache-${{ runner.os }}-${{ github.workflow }}-${{ matrix.compiler }}-${{ github.ref }} - name: Configure tests run: | - mkdir ci-build - cd ci-build - cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + mkdir bbuild && cd bbuild + cmake .. -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror ${{ matrix.cxx_flags }}" \ - -DSDSL_CEREAL=${{ matrix.has_cereal }} - make -j2 gtest_build + -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror -std=c++23" \ + -DSDSL_CEREAL=${{ matrix.cereal }} + make -j${NUM_THREADS} gtest_build - name: Build tests + working-directory: bbuild run: | - ccache -p - cd ci-build - make sdsl_test_targets sdsl_examples sdsl_tutorials -k -j2 - ccache -s + ccache -z + make -k -j${NUM_THREADS} sdsl_test_targets sdsl_examples sdsl_tutorials + ccache -sv - name: Run tests - run: | - cd ci-build - ctest . -j2 + working-directory: bbuild + run: ctest . -j${NUM_THREADS} --output-on-failure diff --git a/.github/workflows/ci_macos.yml b/.github/workflows/ci_macos.yml index ff6f52d7..269fe2ed 100644 --- a/.github/workflows/ci_macos.yml +++ b/.github/workflows/ci_macos.yml @@ -3,15 +3,13 @@ name: macOS on: push: branches: - # Push events to branches matching refs/heads/master - 'master' pull_request: - # Enables a manual trigger, may run on any branch workflow_dispatch: concurrency: group: macos-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + cancel-in-progress: ${{ github.event_name != 'push' }} env: TZ: Europe/Berlin @@ -22,72 +20,46 @@ defaults: jobs: build: - name: ${{ matrix.name }} runs-on: macos-12 - timeout-minutes: 120 + name: ${{ matrix.compiler }} ${{ matrix.cereal == '1' && 'cereal' || '' }} if: github.repository_owner == 'xxsds' || github.event_name == 'workflow_dispatch' strategy: fail-fast: false matrix: - include: - - name: "clang17" - compiler: "clang-17" - build_type: Release - cxx_flags: "-std=c++23" - - - name: "cereal clang17" - compiler: "clang-17" - build_type: Release - cxx_flags: "-std=c++23" - has_cereal: "1" - - - name: "clang16" - compiler: "clang-16" - build_type: Release - cxx_flags: "-std=c++20" - - - name: "clang15" - compiler: "clang-15" - build_type: Release - cxx_flags: "-std=c++20" - + compiler: ["clang-18", "clang-17", "gcc-14", "gcc-13", "gcc-12", "gcc-11"] + cereal: ["0", "1"] steps: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 1 submodules: true + - name: Get number of processors + run: echo "NUM_THREADS=$(getconf _NPROCESSORS_ONLN)" >> "$GITHUB_ENV" + - name: Setup toolchain uses: seqan/actions/setup-toolchain@main with: compiler: ${{ matrix.compiler }} ccache_size: 75M - - name: Install CMake - uses: seqan/actions/setup-cmake@main - with: - cmake: 3.13.5 - - name: Configure tests run: | - mkdir ci-build - cd ci-build - cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + mkdir bbuild && cd bbuild + cmake .. -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror ${{ matrix.cxx_flags }}" \ - -DSDSL_CEREAL=${{ matrix.has_cereal }} - make -j3 gtest_build + -DCMAKE_CXX_FLAGS="-pedantic -Wall -Wextra -Werror -std=c++23" \ + -DSDSL_CEREAL=${{ matrix.cereal }} + make -j${NUM_THREADS} gtest_build - name: Build tests + working-directory: bbuild run: | - ccache -p - cd ci-build - make sdsl_test_targets sdsl_examples sdsl_tutorials -k -j3 - ccache -s + ccache -z + make -k -j${NUM_THREADS} sdsl_test_targets sdsl_examples sdsl_tutorials + ccache -sv - name: Run tests - run: | - cd ci-build - ctest . -j3 + working-directory: bbuild + run: ctest . -j${NUM_THREADS} --output-on-failure From 508528f550a98a3c0ee08cb5aaff9f280d0c23c8 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Tue, 25 Jun 2024 16:15:00 +0200 Subject: [PATCH 2/2] [FIX] Do not use std::pow for integers --- include/sdsl/k2_tree.hpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/include/sdsl/k2_tree.hpp b/include/sdsl/k2_tree.hpp index 278558d1..6a4593f9 100644 --- a/include/sdsl/k2_tree.hpp +++ b/include/sdsl/k2_tree.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -64,11 +65,21 @@ class k2_tree uint8_t k_k; uint16_t k_height; + template + return_t integral_pow(uint64_t base, uint64_t exponent) const noexcept + { + uint64_t result = 1u; + for (; exponent; exponent >>= 1, base *= base) + result *= (exponent & 1) ? base : 1; + assert(result <= std::numeric_limits::max()); + return static_cast(result); + } + protected: void build_from_matrix(std::vector> const & matrix) { // Makes the size a power of k. - int simulated_size = std::pow(k, k_height); + int const simulated_size = integral_pow(k, k_height); std::vector> acc(k_height + 1); k2_tree_ns::_build_from_matrix(matrix, k, simulated_size, k_height, 1, 0, 0, acc); @@ -128,7 +139,7 @@ class k2_tree if (k_t[level] == 1) { - idx_type y = k_t_rank(level + 1) * std::pow(k_k, 2) + k_k * std::floor(row / static_cast(n)); + idx_type y = k_t_rank(level + 1) * k_k * k_k + k_k * std::floor(row / static_cast(n)); for (unsigned j = 0; j < k_k; j++) _neigh(n / k_k, row % n, col + n * j, y + j, acc); } @@ -158,7 +169,7 @@ class k2_tree if (k_t[level] == 1) { - idx_type y = k_t_rank(level + 1) * std::pow(k_k, 2) + std::floor(col / static_cast(n)); + idx_type y = k_t_rank(level + 1) * k_k * k_k + std::floor(col / static_cast(n)); for (unsigned j = 0; j < k_k; j++) _reverse_neigh(n / k_k, row + n * j, col % n, y + j * k_k, acc); } @@ -181,14 +192,14 @@ class k2_tree k_k = k; k_height = std::ceil(std::log(size) / std::log(k_k)); k_height = k_height > 1 ? k_height : 1; // If size == 0 - size_type k_2 = std::pow(k_k, 2); + size_type k_2 = k_k * k_k; bit_vector k_t_ = bit_vector(k_2 * k_height * edges.size(), 0); bit_vector k_l_; std::queue q; idx_type t = 0, last_level = 0; idx_type i, j, r_0, c_0, it, c, r; - size_type l = std::pow(k_k, k_height - 1); + size_type l = integral_pow(k_k, k_height - 1); std::vector pos_by_chunk(k_2 + 1, 0); q.push(t_part_tuple(0, edges.size(), l, 0, 0)); @@ -420,8 +431,8 @@ class k2_tree { if (k_t.size() == 0 && k_l.size() == 0) return false; - size_type n = std::pow(k_k, k_height - 1); - size_type k_2 = std::pow(k_k, 2); + size_type n = integral_pow(k_k, k_height - 1); + size_type k_2 = k_k * k_k; idx_type col, row; // This is duplicated to avoid an extra if at the loop. As idx_type @@ -459,7 +470,7 @@ class k2_tree std::vector acc{}; if (k_l.size() == 0 && k_t.size() == 0) return acc; - size_type n = static_cast(std::pow(k_k, k_height)) / k_k; + size_type n = integral_pow(k_k, k_height) / k_k; idx_type y = k_k * std::floor(i / static_cast(n)); for (unsigned j = 0; j < k_k; j++) _neigh(n / k_k, i % n, n * j, y + j, acc); @@ -477,7 +488,7 @@ class k2_tree if (k_l.size() == 0 && k_t.size() == 0) return acc; // Size of the first square division - size_type n = static_cast(std::pow(k_k, k_height)) / k_k; + size_type n = integral_pow(k_k, k_height) / k_k; idx_type y = std::floor(i / static_cast(n)); for (unsigned j = 0; j < k_k; j++) _reverse_neigh(n / k_k, n * j, i % n, y + j * k_k, acc);