JuliaSIMD / JuliaSIMD/LoopVectorization.jl

Performance issue with Zygote.jl-generated function within `@turbo`

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

説明

I am trying to understand a performance issue I am seeing in [DynamicExpressions.jl](https://github.com/SymbolicML/DynamicExpressions.jl) where using `@turbo` makes the evaluation kernels 4x faster, but makes the derivative kernels 10% _slower_. See the detailed benchmarks here: https://github.com/SymbolicML/DynamicExpressions.jl/pull/28#issuecomment-1529108964

My derivative kernels look like [this](https://github.com/SymbolicML/DynamicExpressions.jl/blob/1fa158687f3d3a0e9c53d13fa99ac7b04a2c6aed/src/EvaluateEquationDerivative.jl#L128-L134):

```julia
@maybe_turbo turbo for j in indices((cumulator, dcumulator))
x = op(cumulator[j])::T
dx = diff_op(cumulator[j])::T * dcumulator[j]

cumulator[j] = x
dcumulator[j] = dx
end
```

(The `@maybe_turbo turbo ...` will turn into `@turbo ...` when `turbo=true`, but just `@inbounds @simd ...` otherwise. It will also remove the various type assertions in the scope.)

To create the `diff_op`, I generate it using Zygote.jl [here](https://github.com/SymbolicML/DynamicExpressions.jl/blob/1fa158687f3d3a0e9c53d13fa99ac7b04a2c6aed/src/OperatorEnumConstruction.jl#L229-L232):

```julia
for op in unary_operators
diff_op(x) = gradient(op, x)[1]
push!(diff_unary_operators, diff_op)
end
```

I can try to create a MWE for this, but I quickly wanted to check if anything was obvious in how I am using `@turbo` here that might hurt performance rather than help it. For example, perhaps this `diff_op` is not being inlined correctly, and therefore not being optimized by `@turbo`? For the record I am not seeing any warnings about the derivative operator being incompatible, so I'm not quite sure why this is occurring.

Also - the `diff_op` in the benchmark is the derivative of one of `+, -, *, /, cos, exp` so nothing too crazy.

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

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

調査の方向性

DynamicExpressions.jl's src/EvaluateEquationDerivative.jl にある微分ループと、src/OperatorEnumConstruction.jl にある Zygote 生成の演算子から始めます。リンクされているベンチマークを再現するか、列挙された演算子について @turbo と @inbounds @simd を比較する最小限の例に縮小します。微分カーネルがなぜ退行するのかを特定し、その原因を文書化または修正できれば完了です。

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

評価

技術スタック
julia
領域
performance
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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