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

Update github workflows #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/conan-ci-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pip3 install conan

conan profile detect -f

std=20
std=23
profile="$(conan profile path default)"

mv "$profile" "${profile}.bak"
Expand Down
147 changes: 119 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,56 +36,72 @@ jobs:
if: always()
run: cmake -P cmake/spell.cmake

sanitize:
test-avx512:
needs: [lint]

runs-on: ubuntu-22.04
strategy:
matrix:
os: [ubuntu-22.04]

runs-on: ${{ matrix.os }}

env: { CXX: clang++-18 }
env:
CC: clang-18
CXX: clang++-18
CLANG_DIR: '/usr/lib/llvm-18/lib/cmake/clang'
LLVM_DIR: '/usr/lib/llvm-18/lib/cmake/llvm'

steps:
- uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with: { python-version: "3.12" }

- name: Install LLVM 18
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
sudo apt update
sudo apt install llvm-18 llvm-18-dev llvm-18-tools clang-18 clang-tidy-18 clang-format-18 clang-tools-18 libclang-18-dev -y

- name: Install static analyzers
if: matrix.os == 'ubuntu-22.04'
run: >-
sudo apt-get install clang-tidy-18 cppcheck -y -q

sudo update-alternatives --install
/usr/bin/clang-tidy clang-tidy
/usr/bin/clang-tidy-18 140

- name: Conan cache
uses: actions/cache@v4
with:
path: conan_cache_save.tgz
key: conan-sanitize-${{ hashFiles('conan*.[pl][yo]*') }}
path: conan_cache_save-${{ matrix.os}}.tgz
key: conan-${{ matrix.os }}-${{ hashFiles('conan*.[pl][yo]*') }}

- name: Install dependencies
shell: bash
run: bash < .github/scripts/conan-ci-setup.sh

- name: Configure
run: cmake --preset=ci-sanitize
shell: pwsh
run: |
$output = cmake -DENABLE_SIMD=ON "--preset=ci-$("${{ matrix.os }}".split("-")[0])"
Write-Output $output
if ($output -match "AVX-512 is supported") {
Write-Output "AVX512 is enabled"
} else {
throw "AVX512 is not available"
}

- name: Build
run: cmake --build build/sanitize -j 2
run: cmake --build build --config Release -j 4

- name: Install
run: cmake --install build --config Release --prefix prefix

- name: Test
working-directory: build/sanitize
env:
ASAN_OPTIONS: "strict_string_checks=1:\
detect_stack_use_after_return=1:\
check_initialization_order=1:\
strict_init_order=1:\
detect_leaks=1:\
halt_on_error=1"
UBSAN_OPTIONS: "print_stacktrace=1:\
halt_on_error=1"
run: ctest --output-on-failure --no-tests=error -j 2

test:
working-directory: build
run: ctest --output-on-failure --no-tests=error -C Release -j 2

test-nosimd:
needs: [lint]

strategy:
Expand All @@ -94,6 +110,12 @@ jobs:

runs-on: ${{ matrix.os }}

env:
CC: clang-18
CXX: clang++-18
CLANG_DIR: '/usr/lib/llvm-18/lib/cmake/clang'
LLVM_DIR: '/usr/lib/llvm-18/lib/cmake/llvm'

steps:
- uses: actions/checkout@v4

Expand All @@ -113,14 +135,77 @@ jobs:
/usr/bin/clang-tidy clang-tidy
/usr/bin/clang-tidy-18 140

- name: Conan cache
uses: actions/cache@v4
with:
path: conan_cache_save-${{ matrix.os}}.tgz
key: conan-${{ matrix.os }}-${{ hashFiles('conan*.[pl][yo]*') }}

- name: Install dependencies
shell: bash
run: bash < .github/scripts/conan-ci-setup.sh

- name: Configure
shell: pwsh
run: |
$output = cmake -DENABLE_SIMD=OFF "--preset=ci-$("${{ matrix.os }}".split("-")[0])"
Write-Output $output
if ($output -match "SIMD is not supported by the compiler") {
Write-Output "SIMD is disabled"
} else {
throw "SIMD is enabled when it should not be"
}

- name: Build
run: cmake --build build --config Release -j 4

- name: Install
run: cmake --install build --config Release --prefix prefix

- name: Test
working-directory: build
run: ctest --output-on-failure --no-tests=error -C Release -j 2

test-neon:
needs: [lint]

strategy:
matrix:
os: [macos-14]

runs-on: ${{ matrix.os }}

env:
CC: /opt/homebrew/opt/llvm@18/bin/clang
CXX: /opt/homebrew/opt/llvm@18/bin/clang++
CLANG_DIR: '/opt/homebrew/opt/llvm@18/bin/clang'
LLVM_DIR: '/opt/homebrew/opt/llvm@18'

steps:
- uses: actions/checkout@v4

- name: Install LLVM 18
run: |
brew install llvm@18

- name: Verify Installation
run: |
${{ env.CC }} --version
${{ env.CXX }} --version

- name: Install static analyzers
if: matrix.os == 'macos-14'
run: >-
brew install cppcheck

- name: Install Python
uses: actions/setup-python@v5
with: { python-version: "3.12" }

- name: Conan cache
uses: actions/cache@v4
with:
path: conan_cache_save.tgz
path: conan_cache_save-${{ matrix.os}}.tgz
key: conan-${{ matrix.os }}-${{ hashFiles('conan*.[pl][yo]*') }}

- name: Install dependencies
Expand All @@ -129,15 +214,21 @@ jobs:

- name: Configure
shell: pwsh
run: cmake "--preset=ci-$("${{ matrix.os }}".split("-")[0])"
run: |
$output = cmake -DENABLE_SIMD=OFF "--preset=ci-$("${{ matrix.os }}".split("-")[0])"
Write-Output $output
if ($output -match "ARM NEON is supported by the compiler") {
Write-Output "ARM NEON is enabled"
} else {
throw "ARM NEON is not available"
}

- name: Build
run: cmake --build build --config Release -j 2
run: cmake --build build --config Release -j 4

- name: Install
run: cmake --install build --config Release --prefix prefix

- name: Test
working-directory: build
run: ctest --output-on-failure --no-tests=error -C Release -j 2

19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ project(
include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake)

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
# add_compile_options(-fno-inline -fno-omit-frame-pointer)
add_compile_options(-fno-inline -fno-omit-frame-pointer)


# ---- Declare library ----
Expand All @@ -30,24 +30,31 @@ add_library(
source/units/coordinates.cpp
)

option(ENABLE_SIMD "Enable SIMD instructions if available" ON)

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-mavx512f -mavx512dq -mavx512vl -mavx512bf16" HAS_AVX512)
check_cxx_source_compiles("
#include <immintrin.h>
int main() {
__m512i t = _mm512_set1_epi64(0);
return 0;
}" HAS_AVX512)
check_cxx_source_compiles("
#include <arm_neon.h>
int main() {
float32x4_t vec = vdupq_n_f32(0.0f);
return 0;
}" HAS_NEON)

if (HAS_ALL_AVX512)
if (HAS_AVX512 AND ENABLE_SIMD)
message(STATUS "AVX-512 is supported by the compiler.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mavx512dq -mavx512vl -mavx512bf16")
target_sources(fractal-generator_lib PRIVATE source/mandelbrot/equations_simd.cpp)
elseif(HAS_NEON)
elseif(HAS_NEON AND ENABLE_SIMD)
message(STATUS "ARM NEON is supported by the compiler.")
target_sources(fractal-generator_lib PRIVATE source/mandelbrot/equations_neon.cpp)
else()
message(STATUS "SIMD is not fully supported by the compiler. SIMD will not be enabled.")
message(STATUS "SIMD is not supported by the compiler. SIMD will not be enabled.")
target_sources(fractal-generator_lib PRIVATE source/mandelbrot/equations_compat.cpp)
endif()

Expand Down
4 changes: 2 additions & 2 deletions source/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ constexpr std::size_t WINDOW_HEIGHT = 600UZ * 2;
constexpr std::size_t FRAME_RATE = 60UZ;

constexpr complex_domain START_COMPLEX_DOMAIN{
{complex_underlying{-1.402}, complex_underlying{-.001}},
{complex_underlying{-1.400}, complex_underlying{.001} }
complex_coordinate{-2, -1 },
complex_coordinate{1, 1.25}
};

const complex_underlying MANDELBROT_DIVERGENCE_NORM = 4;
Expand Down
2 changes: 1 addition & 1 deletion source/mandelbrot/mandelbrot_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace fractal {

std::unique_ptr<MandelbrotWindow::pixel_iteration_counts> MandelbrotWindow::calculate_(
std::unique_ptr<MandelbrotWindow::pixel_iteration_counts> MandelbrotWindow::calculate(
const DisplayDomain& full_display_domain, const DisplayDomain& new_domain_selection
)
{
Expand Down
2 changes: 1 addition & 1 deletion source/mandelbrot/mandelbrot_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MandelbrotWindow {

using pixel_iteration_counts =
std::array<iteration_count, WINDOW_HEIGHT * WINDOW_WIDTH>;
std::unique_ptr<pixel_iteration_counts> calculate_(
std::unique_ptr<pixel_iteration_counts> calculate(
const DisplayDomain& full_display_domain,
const DisplayDomain& new_domain_selection
);
Expand Down
4 changes: 2 additions & 2 deletions source/mandelbrot/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Window : public DisplayEventObserver {
display_domain.get_end_coordinate().y + 1u
);

set_pixel_colors(mandelbrot_.calculate_(DISPLAY_DOMAIN, DISPLAY_DOMAIN));
set_pixel_colors(mandelbrot_.calculate(DISPLAY_DOMAIN, DISPLAY_DOMAIN));
}

void on_mouse_button_pressed(const sf::Event::MouseButtonEvent& event) override
Expand All @@ -70,7 +70,7 @@ class Window : public DisplayEventObserver {
DisplayDomain ends = calculate_rectangle_end_points(
{selection_start_x_, selection_start_y_}, {event.x, event.y}
);
set_pixel_colors(mandelbrot_.calculate_(DISPLAY_DOMAIN, ends));
set_pixel_colors(mandelbrot_.calculate(DISPLAY_DOMAIN, ends));
}

std::optional<std::unique_ptr<sf::Drawable>> get_drawable() override
Expand Down