JuliaSIMD / JuliaSIMD/LoopVectorization.jl

Plot against theoretical peak performance

オープン
#355 コメント 23 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Julia
スター
789
フォーク
73
PR マージ指標
30日以内にマージされた PR はありません

説明

I started with these plots:

https://juliasimd.github.io/LoopVectorization.jl/stable/examples/matrix_vector_ops/

The issue is that I can't tell from the plot if the performance is already the best you can do, or if there is still room for improvement. To answer that question, I like to plot clock cycles (per loop body / array element) on the vertical axis, and also plot the theoretical performance peak into the same graph. Let's do that for the very first benchmark:
```console
julia> function jgemvavx!(𝐲, 𝐀, 𝐱)
@turbo for i ∈ eachindex(𝐲)
𝐲i = zero(eltype(𝐲))
for j ∈ eachindex(𝐱)
𝐲i += 𝐀[i,j] * 𝐱[j]
end
𝐲[i] = 𝐲i
end
end
jgemvavx! (generic function with 1 method)

julia> N = 64
64

julia> y = rand(N);

julia> A = rand(N, N);

julia> x = rand(N);

julia> @benchmark jgemvavx!(y, A, x)
BenchmarkTools.Trial: 10000 samples with 199 evaluations.
Range (min … max): 427.970 ns … 610.970 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 428.603 ns ┊ GC (median): 0.00%
Time (mean ± σ): 430.210 ns ± 9.385 ns ┊ GC (mean ± σ): 0.00% ± 0.00%

▇█▅▁ ▃ ▂
████▅▄▄▄▃▄▅▄▅▅▅▅▆▄▅▄▃▁▃███▇▆▄▁▄▁▄▁▄▄▄▅▅▅▆▇▅▃▄▁▁▃▁▁▁▁▁▁▁▃▁▅▅▅▅ █
428 ns Histogram: log(frequency) by time 463 ns <

Memory estimate: 0 bytes, allocs estimate: 0.

julia> cpu_freq = 3.2e9 # Ghz
3.2e9

julia> 427.136e-9 * cpu_freq / N^2
0.3337
```

So for `N=64`, using double precision, it seems the body of the loop takes 0.333 clock cycles.

I use Apple M1. I installed the macOS Julia, I assume that is Intel based? Somehow it works for me.

Regarding the theoretical peak, the loop body is just:
```julia
𝐲i += 𝐀[i,j] * 𝐱[j]
```
Everything else I think gets amortized. So it is two memory reads from L1 cache, each takes 0.1665 clock cycles (`ldr q0, [x1]` takes 0.333). And one fma, which takes 0.125 (`fmla.2d v0, v0, v0` takes 0.25). The bottleneck in this case is the memory read, total of 0.333 clock cycles. The fma runs at the same time, so we do not include it.

So according to my analysis, the code runs at 100% of the theoretical peak. Which sounds too good to be true. I am worried I made some mistake in my analysis somewhere. But I am posting what I have so far.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start with the linked matrix_vector_ops example and its first benchmark. Review how the existing plots are produced, then determine how to show clock cycles per loop body alongside the theoretical peak for the Julia SIMD benchmark. Done means the example graph makes the comparison clear and the peak calculation is supported by the benchmark context.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
julia
領域
data-visualization, performance
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。