Skip to content

Commit 21ce1a4

Browse files
committed
Added compatibility
1 parent 77724df commit 21ce1a4

File tree

10 files changed

+58
-81
lines changed

10 files changed

+58
-81
lines changed

CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ include(cmake/project-is-top-level.cmake)
1414
include(cmake/variables.cmake)
1515

1616
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
17-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mavx512f -mavx512dq -mavx512vl -mavx512bf16")
17+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
1818
# add_compile_options(-fno-inline -fno-omit-frame-pointer)
1919

2020

@@ -27,11 +27,21 @@ add_library(
2727
source/mandelbrot/mandelbrot_window.cpp
2828
source/graphics/color_conversions/color_conversions.cpp
2929
source/graphics/aspect_ratio/aspect_ratio.cpp
30-
source/mandelbrot/equations_simd.cpp
31-
source/mandelbrot/equations.cpp
3230
source/units/coordinates.cpp
3331
)
3432

33+
include(CheckCXXCompilerFlag)
34+
check_cxx_compiler_flag("-mavx512f -mavx512dq -mavx512vl -mavx512bf16" HAS_AVX512)
35+
36+
if (HAS_ALL_AVX512)
37+
message(STATUS "AVX-512 is supported by the compiler.")
38+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mavx512dq -mavx512vl -mavx512bf16")
39+
target_sources(fractal-generator_lib PRIVATE source/mandelbrot/equations_simd.cpp)
40+
else()
41+
message(STATUS "AVX-512 is not fully supported by the compiler. AVX-512 will not be enabled.")
42+
target_sources(fractal-generator_lib PRIVATE source/mandelbrot/equations_compat.cpp)
43+
endif()
44+
3545
target_include_directories(
3646
fractal-generator_lib ${warning_guard}
3747
PUBLIC

Taskfile.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: '3'
22

33
vars:
44
NAME: fractal-generator
5-
RELEASE_BUILD: "false"
6-
RELEASE_PRESET: "ci-ubuntu"
5+
RELEASE_BUILD: "true"
6+
RELEASE_PRESET: "ci-macos"
77

88
tasks:
99
deps:
@@ -18,7 +18,7 @@ tasks:
1818
- test -f CMakeUserPresets.json
1919
cmds:
2020
- cmake --preset=dev
21-
- cmake --preset={{.RELEASE_PRESET}}
21+
- cmake --preset={{.RELEASE_PRESET}} -DCMAKE_BUILD_TYPE=Release
2222

2323

2424
build:

benchmark/source/bench.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,13 @@
22
#include "units/coordinates.hpp"
33
#include "graphics/display_to_complex.hpp"
44
#include "mandelbrot/equations.hpp"
5-
#include "mandelbrot/equations_simd.hpp"
5+
#include "mandelbrot/equations.hpp"
66
#include "units/units.hpp"
77

88
#include <benchmark/benchmark.h>
99

1010
using namespace fractal;
1111

12-
static void BM_GenerateMandelbrot(benchmark::State& state)
13-
{
14-
DisplayDomain display = {
15-
{0, 0 },
16-
{800, 800}
17-
};
18-
complex_domain complex = START_COMPLEX_DOMAIN;
19-
DisplayToComplexCoordinates t{display, complex};
20-
21-
std::int64_t prox = 0;
22-
for (auto _ : state) {
23-
for (auto it = display.begin(); it != display.end(); it += 1) {
24-
benchmark::DoNotOptimize(
25-
compute_iterations({}, t.to_complex_projection(*it), 100)
26-
);
27-
}
28-
prox += display.size();
29-
}
30-
state.SetItemsProcessed(prox);
31-
}
32-
3312
static void BM_GenerateMandelbrotSimd(benchmark::State& state)
3413
{
3514
DisplayDomain display = {
@@ -52,6 +31,5 @@ static void BM_GenerateMandelbrotSimd(benchmark::State& state)
5231
state.SetItemsProcessed(prox);
5332
}
5433

55-
BENCHMARK(BM_GenerateMandelbrot)->Arg(0);
5634
BENCHMARK(BM_GenerateMandelbrotSimd)->Arg(0);
5735
// BENCHMARK(BM_GenerateMandelbrotSimd)->Arg(100000);

source/config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace fractal {
99

10-
constexpr std::size_t WINDOW_WIDTH = 800UZ * 2;
11-
constexpr std::size_t WINDOW_HEIGHT = 600UZ * 2;
10+
constexpr std::size_t WINDOW_WIDTH = 800UZ;
11+
constexpr std::size_t WINDOW_HEIGHT = 600UZ;
1212
constexpr std::size_t FRAME_RATE = 60UZ;
1313

1414
constexpr complex_domain START_COMPLEX_DOMAIN{

source/mandelbrot/equations.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

source/mandelbrot/equations.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
#pragma once
22

3-
#include "units/units.hpp"
4-
5-
#include <complex>
3+
#include "units/units_avx.hpp"
64

75
namespace fractal {
8-
// https://en.wikipedia.org/wiki/Mandelbrot_set#Formal_definition
9-
std::complex<complex_underlying>
10-
step(std::complex<complex_underlying> z_n, std::complex<complex_underlying> constant);
116

12-
iteration_count compute_iterations(
13-
std::complex<complex_underlying> z_0, std::complex<complex_underlying> constant,
14-
iteration_count max_iters
7+
std::array<iteration_count, 8> compute_iterations(
8+
const avx512_complex& z_0, const avx512_complex& constant, iteration_count max_iters
159
);
1610
} // namespace fractal
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "config.hpp"
2+
#include "equations.hpp"
3+
4+
namespace fractal {
5+
std::complex<complex_underlying>
6+
step(std::complex<complex_underlying> z_n, std::complex<complex_underlying> constant)
7+
{
8+
return z_n * z_n + constant;
9+
}
10+
11+
std::array<iteration_count, 8> compute_iterations(
12+
const avx512_complex& z_0, const avx512_complex& constant, iteration_count max_iters
13+
)
14+
{
15+
std::array<iteration_count, 8> ret{};
16+
17+
for (uint8_t i = 0; i < 8; i++) {
18+
iteration_count iterations = 0;
19+
std::complex<complex_underlying> z_n = {z_0.real[i], z_0.imaginary[i]};
20+
std::complex<complex_underlying> constant_n = {
21+
constant.real[i], constant.imaginary[i]
22+
};
23+
while (iterations < max_iters && std::norm(z_n) < MANDELBROT_DIVERGENCE_NORM) {
24+
z_n = step(z_n, constant_n);
25+
++iterations;
26+
}
27+
ret[i] = iterations;
28+
}
29+
30+
return ret;
31+
}
32+
} // namespace fractal

source/mandelbrot/equations_simd.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "config.hpp"
2+
#include "equations.hpp"
23
#include "units/units.hpp"
34
#include "units/units_avx.hpp"
45

source/mandelbrot/equations_simd.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

source/mandelbrot/mandelbrot_window.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "mandelbrot_window.hpp"
22

33
#include "config.hpp"
4-
#include "equations_simd.hpp"
4+
#include "equations.hpp"
55
#include "graphics/display_to_complex.hpp"
66
#include "units/coordinates.hpp"
77
#include "units/units.hpp"
88

99
#include <fmt/format.h>
10-
#include <immintrin.h>
1110
#include <SFML/Graphics/Drawable.hpp>
1211
#include <SFML/Graphics/Image.hpp>
1312
#include <SFML/Graphics/Sprite.hpp>
@@ -90,7 +89,8 @@ MandelbrotWindow::arr MandelbrotWindow::calculate_(
9089

9190
MandelbrotWindow::MandelbrotWindow(
9291
const DisplayDomain& display_domain, const complex_domain& complex_domain
93-
) : to_complex_{display_domain, complex_domain}
92+
) :
93+
to_complex_{display_domain, complex_domain}
9494
{}
9595

9696
} // namespace fractal

0 commit comments

Comments
 (0)