Skip to content

Instantly share code, notes, and snippets.

@giordano
Created February 19, 2023 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giordano/d99aaff66c33880a19ce0e34b0ec6ee3 to your computer and use it in GitHub Desktop.
Save giordano/d99aaff66c33880a19ce0e34b0ec6ee3 to your computer and use it in GitHub Desktop.
A64FX vs Apple M1
julia> versioninfo()
Julia Version 1.10.0-DEV.635
Commit 12d329b6e3d (2023-02-17 20:01 UTC)
Platform Info:
OS: Linux (aarch64-linux-gnu)
CPU: 50 × unknown
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, a64fx)
Threads: 1 on 50 virtual cores
julia> using BenchmarkTools
julia> v = randn(Float64, 2 ^ 20);
julia> function sum_no_simd(v)
sum = zero(eltype(v))
for x in v
sum += x
end
return sum
end;
julia> function sum_simd(v)
sum = zero(eltype(v))
@simd for x in v
sum += x
end
return sum
end;
julia> run(`fcc -shared -fPIC -O3 -o libsum_no_simd.so sum.c`);
julia> run(`fcc -shared -fPIC -O3 -Keval,fp_contract -KSVE -o libsum_simd.so sum.c`);
julia> sum_no_simd_c(v::Vector{Float64}) = @ccall "./libsum_no_simd.so".sum(v::Ptr{Cdouble}, length(v)::Csize_t)::Cdouble;
julia> sum_simd_c(v::Vector{Float64}) = @ccall "./libsum_simd.so".sum(v::Ptr{Cdouble}, length(v)::Csize_t)::Cdouble;
julia> @btime sum_no_simd($v);
4.738 ms (0 allocations: 0 bytes)
julia> @btime sum_no_simd_c($v);
4.725 ms (0 allocations: 0 bytes)
julia> @btime sum_simd($v);
180.370 μs (0 allocations: 0 bytes)
julia> @btime sum_simd_c($v);
183.500 μs (0 allocations: 0 bytes)
julia> versioninfo()
Julia Version 1.10.0-DEV.635
Commit 12d329b6e3 (2023-02-17 20:01 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin21.6.0)
CPU: 8 × Apple M1
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
Threads: 1 on 4 virtual cores
julia> using BenchmarkTools
julia> v = randn(Float64, 2 ^ 20);
julia> function sum_no_simd(v)
sum = zero(eltype(v))
for x in v
sum += x
end
return sum
end;
julia> function sum_simd(v)
sum = zero(eltype(v))
@simd for x in v
sum += x
end
return sum
end;
julia> @btime sum_no_simd($v);
981.750 μs (0 allocations: 0 bytes)
julia> @btime sum_simd($v);
246.291 μs (0 allocations: 0 bytes)
#include <stddef.h>
double sum(double *v, size_t n) {
double sum = 0.0;
for(size_t i = 0; i < n; i++) {
sum += v[i];
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment