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

Reduce create problem allocations #215

Conversation

efernandez
Copy link
Collaborator

@efernandez efernandez commented Dec 3, 2020

On top of #214, this moves parameter_blocks out of the loop that adds the residual blocks to the ceres::Problem created with the graph constraints.

This turns out to be a marginal improvement. Indeed, the CPU time is roughly the same according to the benchmark results:

2020-12-03 10:08:41
Running ./benchmark_create_problem
Run on (16 X 3600 MHz CPU s)
CPU Caches:
  L1 Data 32K (x8)
  L1 Instruction 32K (x8)
  L2 Unified 512K (x8)
  L3 Unified 16384K (x2)
Load Average: 0.03, 0.28, 0.40
-------------------------------------------------------------------
Benchmark                         Time             CPU   Iterations
-------------------------------------------------------------------
BM_createProblem/200/2       124606 ns       124607 ns         5905
BM_createProblem/256/2       164698 ns       164695 ns         4280
BM_createProblem/512/2       359864 ns       359847 ns         1890
BM_createProblem/1024/2      813617 ns       813624 ns          920
BM_createProblem/2048/2     1674784 ns      1674737 ns          426
BM_createProblem/4000/2     3352385 ns      3352229 ns          212
BM_createProblem/200/4       192466 ns       192455 ns         3410
BM_createProblem/256/4       259837 ns       259829 ns         2505
BM_createProblem/512/4       577659 ns       577648 ns         1194
BM_createProblem/1024/4     1240251 ns      1240231 ns          569
BM_createProblem/2048/4     2596711 ns      2596421 ns          267
BM_createProblem/4000/4     5539479 ns      5539413 ns          123
BM_createProblem/200/8       373014 ns       373006 ns         1932
BM_createProblem/256/8       508080 ns       508050 ns         1278
BM_createProblem/512/8      1026084 ns      1026050 ns          692
BM_createProblem/1024/8     2241448 ns      2241251 ns          318
BM_createProblem/2048/8     4686068 ns      4685903 ns          149
BM_createProblem/4000/8    11403262 ns     11402702 ns           58
BM_createProblem/200/12      525974 ns       525941 ns         1385
BM_createProblem/256/12      733360 ns       733343 ns          923
BM_createProblem/512/12     1514037 ns      1513944 ns          460
BM_createProblem/1024/12    3178791 ns      3178632 ns          218
BM_createProblem/2048/12    7275065 ns      7274640 ns           93
BM_createProblem/4000/12   21954607 ns     21953315 ns           30

The numbers of allocations and allocated memory goes down for the parameter_blocks vector, but that wasn't the main contributor to memory allocations in fuse_graphs::HashGraph::createProblem:
heaptrack-allocated-Screenshot from 2020-12-02 22-19-23
heaptrack-allocations-Screenshot from 2020-12-02 22-19-02
heaptrack-Screenshot from 2020-12-02 22-12-10
heaptrack-Screenshot from 2020-12-02 22-16-25

When compared with the results in #214, we have the following for the benchmark executable:

Case Allocations Allocated
#214 4810920 211,8MB
#215 10730 479.1kB

It's a big improvement for parameter_blocks alone, but almost nothing overall. And almost no impact on CPU time. But I believe it's a good change.

@efernandez efernandez self-assigned this Dec 3, 2020
@efernandez efernandez added the enhancement New feature or request label Dec 3, 2020
@efernandez efernandez force-pushed the reduce-create-problem-allocations branch 2 times, most recently from 9539dd6 to 66efb5d Compare December 3, 2020 16:46
This reduces the amount of allocations required, since the same vector
and its previously allocated memory is reused among all the graph
constraints when the ceres::Problem is created.
@efernandez efernandez force-pushed the reduce-create-problem-allocations branch from 66efb5d to acafaba Compare December 5, 2020 18:22
@efernandez
Copy link
Collaborator Author

Rebased, just in case

@svwilliams svwilliams merged commit ede291c into locusrobotics:devel Dec 5, 2020
@efernandez efernandez deleted the reduce-create-problem-allocations branch December 10, 2020 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

3 participants