JuliaSIMD / JuliaSIMD/LoopVectorization.jl

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

Abierto
#489 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Julia
Estrellas
789
Forks
73
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Start with the derivative loop in DynamicExpressions.jl's src/EvaluateEquationDerivative.jl and the Zygote-generated operators in src/OperatorEnumConstruction.jl. Reproduce the linked benchmarks or reduce them to a minimal example comparing @turbo with @inbounds @simd for the listed operators. Done means identifying why the derivative kernels regress and documenting or fixing the cause.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
julia
Área
performance
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.