File tree Expand file tree Collapse file tree 10 files changed +58
-81
lines changed Expand file tree Collapse file tree 10 files changed +58
-81
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ include(cmake/project-is-top-level.cmake)
14
14
include (cmake/variables.cmake )
15
15
16
16
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" )
18
18
# add_compile_options(-fno-inline -fno-omit-frame-pointer)
19
19
20
20
@@ -27,11 +27,21 @@ add_library(
27
27
source /mandelbrot/mandelbrot_window.cpp
28
28
source /graphics/color_conversions/color_conversions.cpp
29
29
source /graphics/aspect_ratio/aspect_ratio.cpp
30
- source /mandelbrot/equations_simd.cpp
31
- source /mandelbrot/equations.cpp
32
30
source /units/coordinates.cpp
33
31
)
34
32
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
+
35
45
target_include_directories (
36
46
fractal-generator_lib ${warning_guard}
37
47
PUBLIC
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ version: '3'
2
2
3
3
vars :
4
4
NAME : fractal-generator
5
- RELEASE_BUILD : " false "
6
- RELEASE_PRESET : " ci-ubuntu "
5
+ RELEASE_BUILD : " true "
6
+ RELEASE_PRESET : " ci-macos "
7
7
8
8
tasks :
9
9
deps :
18
18
- test -f CMakeUserPresets.json
19
19
cmds :
20
20
- cmake --preset=dev
21
- - cmake --preset={{.RELEASE_PRESET}}
21
+ - cmake --preset={{.RELEASE_PRESET}} -DCMAKE_BUILD_TYPE=Release
22
22
23
23
24
24
build :
Original file line number Diff line number Diff line change 2
2
#include " units/coordinates.hpp"
3
3
#include " graphics/display_to_complex.hpp"
4
4
#include " mandelbrot/equations.hpp"
5
- #include " mandelbrot/equations_simd .hpp"
5
+ #include " mandelbrot/equations .hpp"
6
6
#include " units/units.hpp"
7
7
8
8
#include < benchmark/benchmark.h>
9
9
10
10
using namespace fractal ;
11
11
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
-
33
12
static void BM_GenerateMandelbrotSimd (benchmark::State& state)
34
13
{
35
14
DisplayDomain display = {
@@ -52,6 +31,5 @@ static void BM_GenerateMandelbrotSimd(benchmark::State& state)
52
31
state.SetItemsProcessed (prox);
53
32
}
54
33
55
- BENCHMARK (BM_GenerateMandelbrot)->Arg(0 );
56
34
BENCHMARK (BM_GenerateMandelbrotSimd)->Arg(0 );
57
35
// BENCHMARK(BM_GenerateMandelbrotSimd)->Arg(100000);
Original file line number Diff line number Diff line change 7
7
8
8
namespace fractal {
9
9
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;
12
12
constexpr std::size_t FRAME_RATE = 60UZ;
13
13
14
14
constexpr complex_domain START_COMPLEX_DOMAIN{
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
3
- #include " units/units.hpp"
4
-
5
- #include < complex>
3
+ #include " units/units_avx.hpp"
6
4
7
5
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);
11
6
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
15
9
);
16
10
} // namespace fractal
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
#include " config.hpp"
2
+ #include " equations.hpp"
2
3
#include " units/units.hpp"
3
4
#include " units/units_avx.hpp"
4
5
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
#include " mandelbrot_window.hpp"
2
2
3
3
#include " config.hpp"
4
- #include " equations_simd .hpp"
4
+ #include " equations .hpp"
5
5
#include " graphics/display_to_complex.hpp"
6
6
#include " units/coordinates.hpp"
7
7
#include " units/units.hpp"
8
8
9
9
#include < fmt/format.h>
10
- #include < immintrin.h>
11
10
#include < SFML/Graphics/Drawable.hpp>
12
11
#include < SFML/Graphics/Image.hpp>
13
12
#include < SFML/Graphics/Sprite.hpp>
@@ -90,7 +89,8 @@ MandelbrotWindow::arr MandelbrotWindow::calculate_(
90
89
91
90
MandelbrotWindow::MandelbrotWindow (
92
91
const DisplayDomain& display_domain, const complex_domain& complex_domain
93
- ) : to_complex_{display_domain, complex_domain}
92
+ ) :
93
+ to_complex_{display_domain, complex_domain}
94
94
{}
95
95
96
96
} // namespace fractal
You can’t perform that action at this time.
0 commit comments