Skip to content

Commit

Permalink
Avoid massive stack-allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Nov 17, 2024
1 parent d05b8ff commit 379126a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
32 changes: 29 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/matt/github/mrcal-java/cmake_build/lib/libmrcal_jni.so",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Python debug calibrate cameras",
"type": "debugpy",
Expand All @@ -12,8 +27,19 @@
"console": "integratedTerminal",
"cwd": "/home/matt/mrcal_debug_tmp/output_will/images-trimmed",
"args": [
"--corners-cache","corners.vnl","--lensmodel","LENSMODEL_OPENCV8","--focal","1200",
"--object-spacing","0.03","--object-width-n","18","--object-height-n","13","*.png"
"--corners-cache",
"corners.vnl",
"--lensmodel",
"LENSMODEL_OPENCV8",
"--focal",
"1200",
"--object-spacing",
"0.03",
"--object-width-n",
"18",
"--object-height-n",
"13",
"*.png"
],
"justMyCode": false
},
Expand Down Expand Up @@ -63,4 +89,4 @@
]
}
]
}
}
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if (WITH_ASAN)
add_compile_options(-fsanitize=address -g -Wall -fsanitize=undefined)
endif ()


find_package(JNI)
if (JNI_FOUND)
# Fixes odd AWT dependency
Expand Down
15 changes: 11 additions & 4 deletions src/mrcal_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) Photon Vision.
*
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
Expand Down Expand Up @@ -115,7 +115,9 @@ static std::unique_ptr<mrcal_result> mrcal_calibrate(

// Copy from board/point pool above, using some code borrowed from
// mrcal-pywrap
mrcal_observation_board_t c_observations_board[Nobservations_board];
std::vector<mrcal_observation_board_t> observations_board_data;
observations_board_data.resize(Nobservations_board);
auto c_observations_board = observations_board_data.data();
// Try to make sure we don't accidentally make a zero-length array or
// something stupid
mrcal_observation_point_t
Expand Down Expand Up @@ -176,8 +178,13 @@ static std::unique_ptr<mrcal_result> mrcal_calibrate(
// call optimize

// Residuals
double c_b_packed_final[Nstate];
double c_x_final[Nmeasurements];
std::vector<double> b_packed_final;
b_packed_final.resize(Nstate);
auto c_b_packed_final = b_packed_final.data();

std::vector<double> x_final;
x_final.resize(Nmeasurements);
auto c_x_final = x_final.data();

// Seeds
double *c_intrinsics = intrinsics.data();
Expand Down

0 comments on commit 379126a

Please sign in to comment.