Forked from jpivarski/mandelbrot-on-all-accelerators.ipynb
Last active
June 14, 2022 14:36
-
-
Save Moelf/5aff79748afc6ff380f392fdf9445d19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= one can use these to test fastmath-like path in controlled way | |
@inline mul_fast(x::T, y::T) where {T<:Complex} = | |
T(complex(muladd(-imag(x), imag(y), real(x)*real(y)), | |
muladd( real(x), imag(y), imag(x)*real(y)))) | |
@inline abs2_fast(z::Complex) = muladd(real(z), real(z), imag(z)*imag(z)) | |
=# | |
function run_julia(height, width) | |
y = range(-1.0f0, 0.0f0; length = height) | |
x = range(-1.5f0, 0.0f0; length = width) | |
c = x' .+ y*im | |
fractal = fill(Int32(20), height, width) | |
@inbounds for w in 1:width | |
for h in 1:height | |
_c = c[h, w] | |
z = _c | |
for i in 1:20 | |
z = z^2 + _c | |
if abs2(z) > 4 | |
fractal[h, w] = i | |
break | |
end | |
end | |
end | |
end | |
return fractal | |
end | |
julia> @benchmark run_julia(2000, 3000) | |
BenchmarkTools.Trial: 27 samples with 1 evaluation. | |
Range (min … max): 181.366 ms … 222.897 ms ┊ GC (min … max): 0.20% … 17.82% | |
Time (median): 182.620 ms ┊ GC (median): 0.23% | |
Time (mean ± σ): 185.657 ms ± 9.775 ms ┊ GC (mean ± σ): 1.78% ± 4.44% | |
█▆ | |
██▇▇▄▆▁▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▄ ▁ | |
181 ms Histogram: frequency by time 223 ms < | |
Memory estimate: 68.66 MiB, allocs estimate: 4. | |
julia> @benchmark run_julia(4000, 6000) | |
BenchmarkTools.Trial: 7 samples with 1 evaluation. | |
Range (min … max): 728.765 ms … 773.615 ms ┊ GC (min … max): 0.06% … 5.51% | |
Time (median): 731.186 ms ┊ GC (median): 0.17% | |
Time (mean ± σ): 742.578 ms ± 18.685 ms ┊ GC (mean ± σ): 1.73% ± 2.37% | |
█▁ ▁ ▁ ▁ ▁ | |
██▁█▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁█ ▁ | |
729 ms Histogram: frequency by time 774 ms < | |
Memory estimate: 274.66 MiB, allocs estimate: 4. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment