microsoft / ADBench

Benchmarking various AD tools.
MIT License
107 stars 39 forks source link

Ensure type stability for Julia benchmarks #191

Open GiggleLiu opened 4 years ago

GiggleLiu commented 4 years ago

The julia code in this repo is not type stable, which causes more than 10x slow down.

Whenever the type is not stable, Julia can not compile efficient code for you. For example, using global variables like this would cause type instability. https://github.com/microsoft/ADBench/blob/6c25250928d3fa8836bdb9bcd07046ddebbb270e/tools/Julia/gmm_F.jl#L58 To avoid type instability, one should

Type instability can be seen by typing @code_warntype f(x). For more information, see performance tips https://docs.julialang.org/en/v1/manual/performance-tips/

Also, please take a look at this package for benchmark. https://github.com/JuliaCI/BenchmarkTools.jl

Fixing this issue will definitely make the benchmark in your paper more reliable.

GiggleLiu commented 4 years ago

I have setup a new repo to show how to fix the gaussian mixture Julia code here: https://github.com/JuliaReverse/NiGaussianMixture.jl

ForwardDiff shows at least 1 order speed up. The forwarddiff code is here https://github.com/JuliaReverse/NiGaussianMixture.jl/blob/master/src/forwarddiff.jl

The benchmark script is here https://github.com/JuliaReverse/NiGaussianMixture.jl/blob/master/benchmarks/forwarddiff.jl

It will definitely make the benchmark results more reliable.

If you are interested in benchmarking reversible programming AD framework NiLang. I will be happy to contribute to this part.

GiggleLiu commented 4 years ago

The code for the second benchmark, BA is here:

https://github.com/JuliaReverse/NiBundleAdjustment.jl/blob/master/README.md

ForwardDiff should still have some room for improvements judging from the allocation. NiLang also shows a comparable performance with Tapenade.