SciML / PSOGPU.jl

GPU accelerated Particle Swarm Optimization
MIT License
13 stars 1 forks source link

Add asynchronous particle swarm algorithm #8

Closed utkarsh530 closed 11 months ago

utkarsh530 commented 11 months ago

Fixes #2

It is faster than synchronous and has better convergence due to existing race conditions in the synchronous version. However, the difference appears in higher dimensions and relatively lesser particle count.


julia> sol = PSOGPU.pso_solve_gpu!(prob, gbest, copy(gpu_particles))
1-element CuArray{PSOGPU.PSOGBest{SVector{5, Float32}, Float32}, 1, CUDA.Mem.DeviceBuffer}:
 PSOGPU.PSOGBest{SVector{5, Float32}, Float32}(Float32[0.6680306, 0.5075332, 0.32604104, 0.19544826, -0.05712638], 12.607485f0)

julia> asol = PSOGPU.pso_solve_async_gpu!(prob, gbest, copy(gpu_particles))
PSOGPU.PSOGBest{SVector{5, Float32}, Float32}(Float32[1.0, 1.0, 1.0, 1.0, 1.0], 4.0f0)

julia> @benchmark sol = PSOGPU.pso_solve_gpu!($prob, $gbest, $copy(gpu_particles))
BenchmarkTools.Trial: 6585 samples with 1 evaluation.
 Range (min … max):  601.843 μs …  32.449 ms  ┊ GC (min … max): 0.00% … 90.52%
 Time  (median):     700.201 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   752.426 μs ± 885.126 μs  ┊ GC (mean ± σ):  5.33% ±  4.44%

                     ▄█▆▄▄▃▂                                     
  ▂▁▂▂▂▂▂▂▂▃▄▄▄▄▃▄▃▄▆███████▇▆▆▆▅▄▄▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  602 μs           Histogram: frequency by time          866 μs <

 Memory estimate: 135.42 KiB, allocs estimate: 2125.

julia> @benchmark asol = PSOGPU.pso_solve_async_gpu!($prob, $gbest, $copy(gpu_particles))
BenchmarkTools.Trial: 9776 samples with 1 evaluation.
 Range (min … max):  376.350 μs … 106.776 ms  ┊ GC (min … max): 0.00% … 43.92%
 Time  (median):     478.553 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   499.660 μs ±   1.421 ms  ┊ GC (mean ± σ):  1.64% ±  0.57%

                                      ▃▄▅▆▆▇▆▄▄▃▄▆██▇▃▁          
  ▂▂▁▁▂▁▁▁▁▂▂▂▂▂▂▂▂▂▂▂▂▃▃▃▃▄▄▅▅▅▆▆▅▆▇██████████████████▆▅▅▅▅▅▃▃ ▅
  376 μs           Histogram: frequency by time          520 μs <

 Memory estimate: 9.39 KiB, allocs estimate: 180.

@ChrisRackauckas FYI

codecov[bot] commented 11 months ago

Codecov Report

Attention: 42 lines in your changes are missing coverage. Please review.

Comparison is base (69b38f6) 35.88% compared to head (126afe8) 29.75%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #8 +/- ## ========================================== - Coverage 35.88% 29.75% -6.13% ========================================== Files 4 5 +1 Lines 170 205 +35 ========================================== Hits 61 61 - Misses 109 144 +35 ``` | [Files](https://app.codecov.io/gh/utkarsh530/PSOGPU.jl/pull/8?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Utkarsh) | Coverage Δ | | |---|---|---| | [src/pso\_gpu.jl](https://app.codecov.io/gh/utkarsh530/PSOGPU.jl/pull/8?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Utkarsh#diff-c3JjL3Bzb19ncHUuamw=) | `62.50% <0.00%> (+3.67%)` | :arrow_up: | | [src/PSOGPU.jl](https://app.codecov.io/gh/utkarsh530/PSOGPU.jl/pull/8?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Utkarsh#diff-c3JjL1BTT0dQVS5qbA==) | `6.66% <0.00%> (-2.43%)` | :arrow_down: | | [src/pso\_async\_gpu.jl](https://app.codecov.io/gh/utkarsh530/PSOGPU.jl/pull/8?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Utkarsh#diff-c3JjL3Bzb19hc3luY19ncHUuamw=) | `0.00% <0.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.