Skip to content

Conversation

@charmoniumQ
Copy link
Member

@charmoniumQ charmoniumQ commented Jan 24, 2021

Once #3 is merged, the target branch should change (done).

This PR fixes #2 and fixes #4. It's not too much trouble to review them simultaneously.

I elected to use OpenCV parallel_for_ because it means I wouldn't have to implement my own threadpool, bring in the multithread queue, it responds to the same cv::setNumThreads, and its two-level for-loop unifies the single-threaded and mult-threaded cases.

When numthreads is greater than 2, the ranges will be [0, 1] and [1, 2], so one thread will go for (size_t i = 0; i < 1; ++i) (aka i gets 1, and then terminates).

In many places we have i == 0 ? img0 : img1. A slightly better way of doing this would be: std::array<Img, 2> imgs; and imgs[i], but this would require changing every usage of these in the rest of OpenVINS, which I considered too burdensome.

The reviewer should:

  • Verify that ILLIXR still works with this commit.
  • Make sure my code does the same thing the old code does.
  • Give their opinion if the std::array<T, 2> trick or others are worth it or worth it in specific cases.

@e3m3 e3m3 changed the base branch from illixr-main to master May 11, 2021 00:05
@e3m3 e3m3 force-pushed the issue-209-cpu-timer branch from d62df82 to 533178e Compare May 11, 2021 17:29
@e3m3 e3m3 requested review from e3m3 and mhuzai May 11, 2021 17:37
@e3m3 e3m3 added the enhancement New feature or request label May 11, 2021
Comment on lines +229 to +230
parallel_for_(cv::Range(0, 2), [&](const cv::Range& range){
for (int i = range.start; i < range.end; i++) {
Copy link

@e3m3 e3m3 May 13, 2021

Choose a reason for hiding this comment

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

Out of curiosity, does this spawn 2 threads, or 3 threads (where the 3rd thread fails the for guard immediately)?

Copy link
Member Author

Choose a reason for hiding this comment

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

cv::Range is inclusive of the lower-bound and exclusive of the upper-bound, so the range contains 0 and 1.

@e3m3
Copy link

e3m3 commented May 13, 2021

Give their opinion if the std::array<T, 2> trick or others are worth it or worth it in specific cases.

This sounds like a nice improvement (maybe as its own PR) as long as updating OpenVINS with upstream changes isn't affected too much.

@e3m3
Copy link

e3m3 commented May 13, 2021

Give their opinion if the std::array<T, 2> trick or others are worth it or worth it in specific cases.

This sounds like a nice improvement (maybe as its own PR) as long as updating OpenVINS with upstream changes isn't affected too much.

If the size will ever greater than 2 (swapchains?), then this is likely worth it.

@charmoniumQ
Copy link
Member Author

It's not swapchains; it's the number of eyes on the stereo camera.

Copy link
Member

@mhuzai mhuzai left a comment

Choose a reason for hiding this comment

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

Looks good in general. My only concern is that the threading changes will make rebasing on top of latest OV more painful. But I wonder if mainline OV will be willing to accept the threading changes (I think they are good for them too). Would you like to ask them?


{
#ifdef ILLIXR_INTEGRATION
CPU_TIMER_TIME_BLOCK("preform_detection");
Copy link
Member

Choose a reason for hiding this comment

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

perform

Comment on lines -196 to -198
// Disabling OpenCV threading is faster on x86 desktop but slower on
// jetson. Keeping this here for manual disabling.
// cv::setNumThreads(0);
Copy link
Member

Choose a reason for hiding this comment

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

I think it's useful to keep this around.

@charmoniumQ
Copy link
Member Author

See upstream, open_vins #167.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cpu_timer support Keep long-lived threads instead of short-lived ones

5 participants