You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FastBroadcast.jl exports @.. that compiles broadcast expressions into loops
that are easier for the compiler to optimize.
julia>using FastBroadcast
julia>functionfast_foo9(a, b, c, d, e, f, g, h, i)
@.. a = b +0.1* (0.2c +0.3d +0.4e +0.5f +0.6g +0.6h +0.6i)
nothingend
fast_foo9 (generic function with 1 method)
julia>functionfoo9(a, b, c, d, e, f, g, h, i)
@. a = b +0.1* (0.2c +0.3d +0.4e +0.5f +0.6g +0.6h +0.6i)
nothingend
foo9 (generic function with 1 method)
julia> a, b, c, d, e, f, g, h, i = [rand(100, 100, 2) for i in1:9];
julia>using BenchmarkTools
julia>@btimefast_foo9($a, $b, $c, $d, $e, $f, $g, $h, $i);
19.902 μs (0 allocations:0 bytes)
julia>@btimefoo9($a, $b, $c, $d, $e, $f, $g, $h, $i);
81.457 μs (0 allocations:0 bytes)
It's important to note that FastBroadcast doesn't speed up "dynamic broadcast",
i.e. when the arguments are not equal-axised or scalars. For example, dynamic
broadcast happens when the expansion of singleton dimensions occurs:
The macro @.. of FastBroadcast.jl accepts a keyword argument thread
determining whether the broadcast call should use threading (disabled
by default). You can use it as follows (starting Julia with multiple
threads).
julia>using FastBroadcast
julia>functionfoo_serial!(dest, src)
@.. thread=false dest =log(src)
end
foo_serial! (generic function with 1 method)
julia>functionfoo_parallel!(dest, src)
@.. thread=true dest =log(src)
end
foo_parallel! (generic function with 1 method)
julia>functionfoo_maybe_parallel!(dest, src, thread)
@.. thread=thread dest =log(src)
end
foo_maybe_parallel! (generic function with 1 method)
julia> src =rand(10^4); dest =similar(src);
julia>@btimefoo_serial!($dest, $src);
50.860 μs (0 allocations:0 bytes)
julia>@btimefoo_parallel!($dest, $src);
17.245 μs (1 allocation:48 bytes)
julia>@btimefoo_maybe_parallel!($dest, $src, $FastBroadcast.False());
51.682 μs (0 allocations:0 bytes)
julia>@btimefoo_maybe_parallel!($dest, $src, $FastBroadcast.True());
17.360 μs (1 allocation:48 bytes)