Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@clementinboittiaux
Copy link

@clementinboittiaux clementinboittiaux commented Jun 12, 2025

Hey @ahojnnes ,

We've recently had a computation bottleneck when trying to merge big reconstructions (2,500 to 35,000 common images). The heaviest step is computing the residuals for alignment. This PR simply computes the residuals with a threadpool.
On two models with 2,706 common images the alignment step drops from 646 s to 51 s with 64 threads.

N.B.: THROW_CHECK_EQ exceptions in threads are propagated in the main thread through future.get().

const Image& src_image = *src_images[i];
const Image& tgt_image = *tgt_images[i];
if (thread_pool_ && src_images.size() > 10) {
std::vector<std::future<void>> futures;
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to accumulate the futures. You can just do thread_pool_->Wait(); to finish all tasks in the pool.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed but does not propagate THROW_CHECK_EQ exceptions. How could this be solved?

Copy link
Author

Choose a reason for hiding this comment

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

I removed THROW_CHECK_EQ from ComputeImageResidual, and only perform the checks once before computing the residuals.

#include "colmap/scene/image.h"
#include "colmap/scene/reconstruction.h"
#include "colmap/scene/track.h"
#include "colmap/util/threading.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's forward-decl threadpool here as well instead of including this header.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@clementinboittiaux
Copy link
Author

Hey @ahojnnes ,
Do you think this would be okay to merge ?

} else {
for (size_t i = 0; i < src_images.size(); ++i) {
ComputeImageResidual(
i, src_images, tgt_images, tgt_from_src, src_from_tgt, residuals);
Copy link
Member

Choose a reason for hiding this comment

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

How about instead passing src_images[i], tgt_images[i], and residuals[i]?

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@clementinboittiaux
Copy link
Author

Hey @sarlinpe , is this okay to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants