KeitaNakamura / Tensorial.jl

Statically sized tensors and related operations for Julia
https://keitanakamura.github.io/Tensorial.jl/
MIT License
40 stars 1 forks source link

Remove sumargs, SIMD only for summation #173

Closed KeitaNakamura closed 1 year ago

KeitaNakamura commented 1 year ago

This solves unexpected slow AD calculations. For example, norm becomes 4 times faster. I don't know why...

Before:

julia> using Tensorial, BenchmarkTools

julia> x = rand(SymmetricSecondOrderTensor{3});

julia> @benchmark gradient(norm, $(Ref(x))[], :all)
BenchmarkTools.Trial: 10000 samples with 996 evaluations.
 Range (min … max):  27.108 ns … 61.998 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     28.196 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   28.419 ns ±  1.415 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

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

 Memory estimate: 0 bytes, allocs estimate: 0.

After:

julia> using Tensorial, BenchmarkTools

julia> x = rand(SymmetricSecondOrderTensor{3});

julia> @benchmark gradient(norm, $(Ref(x))[], :all)
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  7.041 ns … 33.791 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     7.333 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   7.301 ns ±  0.590 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

             ▁     █                      █     █
  ▂▁▁▁▁▂▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁▃▁▁▁▁▁▂▁▁▁▁▃▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁▃▁▁▁▁▂ ▃
  7.04 ns        Histogram: frequency by time        7.46 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
codecov[bot] commented 1 year ago

Codecov Report

Merging #173 (0f5ecbd) into main (941d776) will decrease coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #173      +/-   ##
==========================================
- Coverage   92.64%   92.64%   -0.01%     
==========================================
  Files          18       18              
  Lines        1469     1468       -1     
==========================================
- Hits         1361     1360       -1     
  Misses        108      108              
Impacted Files Coverage Δ
src/einsum.jl 97.63% <100.00%> (-0.02%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.