Skip to content
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

Add tuple_vector, particle_traits and views::all interface #6

Merged
merged 16 commits into from
Nov 4, 2022

Conversation

nahueespinosa
Copy link
Member

@nahueespinosa nahueespinosa commented Oct 30, 2022

This patch adds an implementation for two particle storage policies: StructureOfArrays and ArrayOfStructures.
It also adds a benchmark for the two most common use cases:

  1. Updating weights of a particle set based on its state (used to compute importance weight).
  2. Populating an empty set of particles (used in the most basic resampling strategy).

After compilation, the benchmark can be run with the following command:

./build/beluga/core/core_benchmark

Example results from my machine:

Run on (16 X 4680 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 512 KiB (x8)
  L3 Unified 16384 KiB (x1)
Load Average: 0.96, 0.90, 0.69
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
----------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                                        Time             CPU   Iterations
----------------------------------------------------------------------------------------------------------------------------------
BM_UpdateWeights_Baseline_StructureOfArrays/min_warmup_time:1.000                           112022 ns       111981 ns         6141
BM_UpdateWeights<beluga::core::storage::StructureOfArrays<State>>/min_warmup_time:1.000     121620 ns       121102 ns         6289
BM_UpdateWeights_Baseline_ArrayOfStructures/min_warmup_time:1.000                          2683125 ns      2681189 ns          251
BM_UpdateWeights<beluga::core::storage::ArrayOfStructures<State>>/min_warmup_time:1.000    2467630 ns      2465900 ns          275
BM_Resample_Baseline_StructureOfArrays/min_warmup_time:1.000                               6509108 ns      6505386 ns           97
BM_Resample<beluga::core::storage::StructureOfArrays<State>>/min_warmup_time:1.000         6886895 ns      6883261 ns           92
BM_Resample_Baseline_ArrayOfStructures/min_warmup_time:1.000                               2536930 ns      2535069 ns          272
BM_Resample<beluga::core::storage::ArrayOfStructures<State>>/min_warmup_time:1.000         2709011 ns      2707197 ns          269

From the results, we can see that this abstraction adds no overhead compared to the baseline implementation of both policies (without using iterators and STL algorithms). It's interesting to note that SoA already shows great performance when updating particle properties, but this naive population method is not the best when we have to maintain multiple containers.

Closes #4.

@nahueespinosa
Copy link
Member Author

Results updated after b16899e.

Run on (16 X 4680 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 512 KiB (x8)
  L3 Unified 16384 KiB (x1)
Load Average: 0.58, 0.60, 0.33
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
----------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                                        Time             CPU   Iterations
----------------------------------------------------------------------------------------------------------------------------------
BM_UpdateWeights_Baseline_StructureOfArrays/min_warmup_time:1.000                          1123308 ns      1122480 ns          564
BM_UpdateWeights<beluga::core::storage::StructureOfArrays<State>>/min_warmup_time:1.000    1198495 ns      1197673 ns          584
BM_UpdateWeights_Baseline_ArrayOfStructures/min_warmup_time:1.000                          2556119 ns      2554474 ns          271
BM_UpdateWeights<beluga::core::storage::ArrayOfStructures<State>>/min_warmup_time:1.000    2518186 ns      2516602 ns          276
BM_Resample_Baseline_StructureOfArrays/min_warmup_time:1.000                               6485737 ns      6481493 ns           95
BM_Resample<beluga::core::storage::StructureOfArrays<State>>/min_warmup_time:1.000         6780245 ns      6776426 ns           94
BM_Resample_Baseline_ArrayOfStructures/min_warmup_time:1.000                               2581740 ns      2579975 ns          242
BM_Resample<beluga::core::storage::ArrayOfStructures<State>>/min_warmup_time:1.000         2593295 ns      2591576 ns          272

@nahueespinosa
Copy link
Member Author

Looks good to start with? @camistolo @hidmic

Copy link
Collaborator

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting work and outcome @nahueespinosa. I left some questions and comments.

beluga/core/include/beluga/storage.h Outdated Show resolved Hide resolved
beluga/core/include/beluga/storage.h Outdated Show resolved Hide resolved
beluga/core/include/beluga/storage.h Outdated Show resolved Hide resolved
Base automatically changed from nahuel/range-v3 to master October 31, 2022 20:41
@nahueespinosa nahueespinosa force-pushed the nahuel/storage branch 2 times, most recently from 08cca1a to 79d4c04 Compare November 1, 2022 19:52
@nahueespinosa nahueespinosa changed the title Implement storage policies Implement tuple_vector and views::all interface Nov 1, 2022
hidmic
hidmic previously approved these changes Nov 3, 2022
Copy link
Collaborator

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nahueespinosa superb!

beluga/core/benchmark/tuple_vector_benchmark.cpp Outdated Show resolved Hide resolved
beluga/core/benchmark/tuple_vector_benchmark.cpp Outdated Show resolved Hide resolved
beluga/core/include/beluga/tuple_vector.h Show resolved Hide resolved
beluga/core/include/beluga/tuple_vector.h Outdated Show resolved Hide resolved
The benchmark and tests pass though...
... with an extra variadic template parameter.
@nahueespinosa nahueespinosa changed the title Implement tuple_vector and views::all interface Add tuple_vector, particle_traits and views::all interface Nov 4, 2022
@nahueespinosa nahueespinosa merged commit 1dd8fb6 into master Nov 4, 2022
@nahueespinosa nahueespinosa deleted the nahuel/storage branch November 4, 2022 22:36
@nahueespinosa nahueespinosa self-assigned this Nov 9, 2022
@nahueespinosa nahueespinosa added the cpp Related to C++ code label Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp Related to C++ code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic particle storage and access
2 participants