-
Notifications
You must be signed in to change notification settings - Fork 9
Improve benchmarking code #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f25178a
Improve benchmarking code
efaulhaber 35a3d53
Rename plot.jl
efaulhaber f11ae90
Use realistic search radius
efaulhaber 63a7b36
Fix update benchmark
efaulhaber 0a7f5d1
Fix tests
efaulhaber 5ffb715
Reformat
efaulhaber 59c1ae9
Fix tests
efaulhaber 366a4c2
Fix tests
efaulhaber c3ba225
Merge branch 'main' into ef/improve-benchmarks
efaulhaber 5590257
Improve docs
efaulhaber 283b001
Merge branch 'ef/improve-benchmarks' of github.com:trixi-framework/Tr…
efaulhaber 6b9a08a
Merge branch 'main' into ef/improve-benchmarks
svchb 456e541
Merge branch 'main' into ef/improve-benchmarks
svchb 5daba76
Merge branch 'main' into ef/improve-benchmarks
LasNikas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| using Plots | ||
| using BenchmarkTools | ||
|
|
||
| # Generate a rectangular point cloud | ||
| include("../test/point_cloud.jl") | ||
|
|
||
| """ | ||
| plot_benchmarks(benchmark, n_points_per_dimension, iterations; | ||
| seed = 1, perturbation_factor_position = 1.0, | ||
| parallel = true, title = "") | ||
|
|
||
| Run a benchmark with several neighborhood searches multiple times for increasing numbers | ||
| of points and plot the results. | ||
|
|
||
| # Arguments | ||
| - `benchmark`: The benchmark function. See [`benchmark_count_neighbors`](@ref) | ||
| and [`benchmark_n_body`](@ref). | ||
| - `n_points_per_dimension`: Initial resolution as tuple. The product is the initial number | ||
| of points. For example, use `(100, 100)` for a 2D benchmark or | ||
| `(10, 10, 10)` for a 3D benchmark. | ||
| - `iterations`: Number of refinement iterations | ||
|
|
||
| # Keywords | ||
| - `parallel = true`: Loop over all points in parallel | ||
| - `title = ""`: Title of the plot | ||
| - `seed = 1`: Seed to perturb the point positions. Different seeds yield | ||
| slightly different point positions. | ||
| - `perturbation_factor_position = 1.0`: Scale the point position perturbation by this factor. | ||
| A factor of `1.0` corresponds to a standard deviation | ||
| similar to that of a realistic simulation. | ||
|
|
||
| # Examples | ||
| ```julia | ||
| include("benchmarks/benchmarks.jl") | ||
|
|
||
| plot_benchmarks(benchmark_count_neighbors, (10, 10), 3) | ||
| """ | ||
| function run_benchmark(benchmark, n_points_per_dimension, iterations, neighborhood_searches; | ||
| names = ["NeighborhoodSearch $i" | ||
|
efaulhaber marked this conversation as resolved.
Outdated
|
||
| for i in 1:length(neighborhood_searches)]', | ||
| parallelization_backend = PolyesterBackend(), | ||
| seed = 1, perturbation_factor_position = 1.0) | ||
| # Multiply number of points in each iteration (roughly) by this factor | ||
| scaling_factor = 4 | ||
| per_dimension_factor = scaling_factor^(1 / length(n_points_per_dimension)) | ||
| sizes = [round.(Int, n_points_per_dimension .* per_dimension_factor^(iter - 1)) | ||
| for iter in 1:iterations] | ||
|
|
||
| n_particles_vec = prod.(sizes) | ||
| times = zeros(iterations, length(neighborhood_searches)) | ||
|
|
||
| for iter in 1:iterations | ||
| coordinates = point_cloud(sizes[iter]; seed, perturbation_factor_position) | ||
| domain_size = maximum(sizes[iter]) + 1 | ||
|
|
||
| # Normalize domain size to 1 | ||
| coordinates ./= domain_size | ||
|
|
||
| # Make this Float32 to make sure that Float32 benchmarks use Float32 exclusively | ||
| search_radius = 4.0f0 / domain_size | ||
| n_particles = size(coordinates, 2) | ||
|
|
||
| neighborhood_searches_copy = copy_neighborhood_search.(neighborhood_searches, | ||
| search_radius, n_particles) | ||
|
|
||
| for i in eachindex(neighborhood_searches_copy) | ||
| neighborhood_search = neighborhood_searches_copy[i] | ||
| PointNeighbors.initialize!(neighborhood_search, coordinates, coordinates) | ||
|
|
||
| time = benchmark(neighborhood_search, coordinates; parallelization_backend) | ||
| times[iter, i] = time | ||
| time_string = BenchmarkTools.prettytime(time * 1e9) | ||
| time_string_per_particle = BenchmarkTools.prettytime(time * 1e9 / n_particles) | ||
| println("$(names[i])") | ||
| println("with $(join(sizes[iter], "x")) = $(prod(sizes[iter])) particles " * | ||
| "finished in $time_string ($time_string_per_particle per particle)\n") | ||
| end | ||
| end | ||
|
|
||
| return n_particles_vec, times | ||
| end | ||
|
|
||
| # Rum the benchmark with the most commonly used neighborhood search implementations | ||
| function run_benchmark_default(benchmark, n_points_per_dimension, iterations; kwargs...) | ||
| NDIMS = length(n_points_per_dimension) | ||
| min_corner = 0.0f0 .* n_points_per_dimension | ||
| max_corner = Float32.(n_points_per_dimension ./ maximum(n_points_per_dimension)) | ||
|
|
||
| neighborhood_searches = [ | ||
| GridNeighborhoodSearch{NDIMS}(), | ||
| GridNeighborhoodSearch{NDIMS}(search_radius = 0.0f0, | ||
| cell_list = FullGridCellList(; search_radius = 0.0f0, | ||
| min_corner, max_corner)), | ||
| PrecomputedNeighborhoodSearch{NDIMS}() | ||
| ] | ||
|
|
||
| names = ["GridNeighborhoodSearch";; | ||
| "GridNeighborhoodSearch with FullGridCellList";; | ||
|
efaulhaber marked this conversation as resolved.
|
||
| "PrecomputedNeighborhoodSearch"] | ||
|
|
||
| run_benchmark(benchmark, n_points_per_dimension, iterations, | ||
| neighborhood_searches; names, kwargs...) | ||
| end | ||
|
|
||
| # Rum the benchmark with all GPU-compatible neighborhood search implementations | ||
| function run_benchmark_gpu(benchmark, n_points_per_dimension, iterations; kwargs...) | ||
| NDIMS = length(n_points_per_dimension) | ||
|
|
||
| min_corner = 0.0f0 .* n_points_per_dimension | ||
| max_corner = Float32.(n_points_per_dimension ./ maximum(n_points_per_dimension)) | ||
| neighborhood_searches = [ | ||
| GridNeighborhoodSearch{NDIMS}(search_radius = 0.0f0, | ||
| cell_list = FullGridCellList(; search_radius = 0.0f0, | ||
| min_corner, max_corner)) | ||
| ] | ||
|
|
||
| names = ["GridNeighborhoodSearch with FullGridCellList";;] | ||
|
|
||
| run_benchmark(benchmark, n_points_per_dimension, iterations, | ||
| neighborhood_searches; names, kwargs...) | ||
| end | ||
|
|
||
| function plot_benchmark(n_particles_vec, times; kwargs...) | ||
| function format_n_particles(n) | ||
| if n >= 1_000_000 | ||
| return "$(round(Int, n / 1_000_000))M" | ||
| elseif n >= 1_000 | ||
| return "$(round(Int, n / 1_000))k" | ||
| else | ||
| return string(n) | ||
| end | ||
| end | ||
| xticks = format_n_particles.(n_particles_vec) | ||
|
|
||
| plot(n_particles_vec, times ./ n_particles_vec .* 1e9; | ||
| xaxis = :log, | ||
| xticks = (n_particles_vec, xticks), linewidth = 2, | ||
| xlabel = "#particles", ylabel = "runtime per particle [ns]", | ||
| legend = :outerright, size = (700, 350), dpi = 200, margin = 4 * Plots.mm, | ||
| palette = palette(:tab10), kwargs...) | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.