sarlinpe · GitHub

@sarlinpe

Copy link Copy Markdown

Member

Bring upstream what we developed for LaMAR.

ahojnnes

@sarlinpe

@sarlinpe

Copy link Copy Markdown

Member Author

I added some benchmarking code. Results:

Running ./benchmark_cost_functions
Run on (16 X 3600 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 256 KiB (x8)
  L3 Unified 16384 KiB (x1)
main branch
-------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations
-------------------------------------------------------------------------------------------
BM_ReprojErrorCostFunction_mean                       50955 ns        50954 ns           50
BM_ReprojErrorCostFunction_median                     50917 ns        50914 ns           50
BM_ReprojErrorCostFunction_stddev                       175 ns          176 ns           50
BM_ReprojErrorConstantPoseCostFunction_mean           39073 ns        39072 ns           50
BM_ReprojErrorConstantPoseCostFunction_median         39046 ns        39044 ns           50
BM_ReprojErrorConstantPoseCostFunction_stddev           136 ns          136 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_mean        44643 ns        44642 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_median      44614 ns        44613 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_stddev        162 ns          162 ns           50
This PR - no inlining
-------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations
-------------------------------------------------------------------------------------------
BM_ReprojErrorCostFunction_mean                       51440 ns        51440 ns           50
BM_ReprojErrorCostFunction_median                     51347 ns        51348 ns           50
BM_ReprojErrorCostFunction_stddev                       242 ns          242 ns           50
BM_ReprojErrorConstantPoseCostFunction_mean           40791 ns        40791 ns           50
BM_ReprojErrorConstantPoseCostFunction_median         40750 ns        40750 ns           50
BM_ReprojErrorConstantPoseCostFunction_stddev           172 ns          172 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_mean        45659 ns        45659 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_median      45607 ns        45607 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_stddev        190 ns          190 ns           50
This PR - with inlining
-------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations
-------------------------------------------------------------------------------------------
BM_ReprojErrorCostFunction_mean                       51266 ns        51265 ns           50
BM_ReprojErrorCostFunction_median                     51214 ns        51214 ns           50
BM_ReprojErrorCostFunction_stddev                       196 ns          196 ns           50
BM_ReprojErrorConstantPoseCostFunction_mean           41002 ns        41001 ns           50
BM_ReprojErrorConstantPoseCostFunction_median         40819 ns        40819 ns           50
BM_ReprojErrorConstantPoseCostFunction_stddev           382 ns          382 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_mean        45580 ns        45579 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_median      45545 ns        45543 ns           50
BM_ReprojErrorConstantPoint3DCostFunction_stddev        156 ns          156 ns           50
  1. Inlining makes no difference.
  2. Compared to main, ReprojErrorConstantPoint3DCostFunction is 2% slower and ReprojErrorConstantPoseCostFunction is 4% slower. I will revert these changes if you judge that this is too large.

@sarlinpe

@sarlinpe

@ahojnnes

Copy link Copy Markdown

Contributor

Thanks a lot for the benchmark numbers. I guess the difference is marginal. With the benchmark setup, it's also a little unclear, if the cost function or the constructor leads to the increase, as you only evaluate it once.

@ahojnnes

Copy link Copy Markdown

Contributor

I will take another look later but then probably just merge.

@sarlinpe

Copy link Copy Markdown

Member Author

Updated the benchmark code to avoid measuring the construction:

main branch
-----------------------------------------------------------------------------------------------
Benchmark                                                     Time             CPU   Iterations
-----------------------------------------------------------------------------------------------
BM_ReprojErrorCostFunction/Run_mean                       51161 ns        51161 ns           50
BM_ReprojErrorCostFunction/Run_median                     51114 ns        51113 ns           50
BM_ReprojErrorCostFunction/Run_stddev                       170 ns          170 ns           50
BM_ReprojErrorConstantPoseCostFunction/Run_mean           39244 ns        39244 ns           50
BM_ReprojErrorConstantPoseCostFunction/Run_median         39217 ns        39216 ns           50
BM_ReprojErrorConstantPoseCostFunction/Run_stddev           122 ns          122 ns           50
BM_ReprojErrorConstantPoint3DCostFunction/Run_mean        44527 ns        44527 ns           50
BM_ReprojErrorConstantPoint3DCostFunction/Run_median      44493 ns        44493 ns           50
BM_ReprojErrorConstantPoint3DCostFunction/Run_stddev        177 ns          177 ns           50
This PR - no inlining
-----------------------------------------------------------------------------------------------
Benchmark                                                     Time             CPU   Iterations
-----------------------------------------------------------------------------------------------
BM_ReprojErrorCostFunction/Run_mean                       51454 ns        51454 ns           50
BM_ReprojErrorCostFunction/Run_median                     51417 ns        51417 ns           50
BM_ReprojErrorCostFunction/Run_stddev                       185 ns          185 ns           50
BM_ReprojErrorConstantPoseCostFunction/Run_mean           40587 ns        40587 ns           50
BM_ReprojErrorConstantPoseCostFunction/Run_median         40565 ns        40565 ns           50
BM_ReprojErrorConstantPoseCostFunction/Run_stddev           128 ns          128 ns           50
BM_ReprojErrorConstantPoint3DCostFunction/Run_mean        45538 ns        45537 ns           50
BM_ReprojErrorConstantPoint3DCostFunction/Run_median      45486 ns        45485 ns           50
BM_ReprojErrorConstantPoint3DCostFunction/Run_stddev        159 ns          159 ns           50

The numbers are mostly unchanged.

@sarlinpe

Merged

ahojnnes

@ahojnnes

@sarlinpe

sarlinpe deleted the sarlinpe/improve-cost-functions branch

February 8, 2024 14:52

Read the original on github.com ↗