Skip to content

Change copy_if_safe to call thrust instead of the overload function - #15018

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:branch-24.04from
davidwendt:perf-copy-if-safe
Feb 13, 2024
Merged

rapids-bot[bot] merged 2 commits into
NVIDIA:branch-24.04from
davidwendt:perf-copy-if-safe

Conversation

@davidwendt

Copy link
Copy Markdown
Contributor

Description

Found while working on large strings where copy-if is called. In places where copy_if_safe utility is called the non-stencil overload calls the stencil-ed function by forwarding the first iterator as the stencil parameter. This works logically because both values will return the same result. Unfortunately, this can be a performance issue if the iterator is complex/slow transform iterator since it would be called twice (an inlined twice). Changing the non-stencil version to call thrust::copy_if directly fixes the potential issue.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@davidwendt davidwendt added bug Something isn't working 3 - Ready for Review Ready for review by team libcudf Affects libcudf (C++/CUDA) code. improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 9, 2024
@davidwendt davidwendt self-assigned this Feb 9, 2024
@davidwendt davidwendt removed the bug Something isn't working label Feb 9, 2024
@davidwendt

Copy link
Copy Markdown
Contributor Author

This showed the most measurable improvement in the nvtext::character_tokenize() function:

# tokenize

## [0] Quadro GV100

|  row_width  |  num_rows  |    type    |   Ref Time |   Cmp Time |        Diff |   %Diff |
|-------------|------------|------------|------------|------------|-------------|---------|
|     32      |    4096    | characters |  87.871 us |  63.101 us |  -24.770 us | -28.19% |
|     64      |    4096    | characters |  79.114 us |  60.909 us |  -18.206 us | -23.01% |
|     128     |    4096    | characters |  65.329 us |  62.791 us |   -2.538 us |  -3.89% |
|     256     |    4096    | characters |  70.331 us |  67.170 us |   -3.161 us |  -4.49% |
|     512     |    4096    | characters |  79.213 us |  76.530 us |   -2.682 us |  -3.39% |
|    1024     |    4096    | characters | 102.281 us |  98.202 us |   -4.079 us |  -3.99% |
|     32      |   32768    | characters |  68.676 us |  67.381 us |   -1.295 us |  -1.89% |
|     64      |   32768    | characters |  79.142 us |  76.610 us |   -2.533 us |  -3.20% |
|     128     |   32768    | characters | 102.208 us |  97.498 us |   -4.710 us |  -4.61% |
|     256     |   32768    | characters | 144.297 us | 141.406 us |   -2.892 us |  -2.00% |
|     512     |   32768    | characters | 229.324 us | 220.700 us |   -8.624 us |  -3.76% |
|    1024     |   32768    | characters | 392.243 us | 376.690 us |  -15.553 us |  -3.97% |
|     32      |   262144   | characters | 147.015 us | 142.147 us |   -4.869 us |  -3.31% |
|     64      |   262144   | characters | 230.706 us | 221.606 us |   -9.099 us |  -3.94% |
|     128     |   262144   | characters | 395.154 us | 379.763 us |  -15.391 us |  -3.89% |
|     256     |   262144   | characters | 720.286 us | 693.282 us |  -27.004 us |  -3.75% |
|     512     |   262144   | characters |   1.370 ms |   1.316 ms |  -54.215 us |  -3.96% |
|    1024     |   262144   | characters |   2.672 ms |   2.570 ms | -101.487 us |  -3.80% |
|     32      |  2097152   | characters | 721.000 us | 694.696 us |  -26.305 us |  -3.65% |
|     64      |  2097152   | characters |   1.373 ms |   1.321 ms |  -51.381 us |  -3.74% |
|     128     |  2097152   | characters |   2.689 ms |   2.586 ms | -102.549 us |  -3.81% |
|     256     |  2097152   | characters |   5.326 ms |   5.119 ms | -207.290 us |  -3.89% |
|     512     |  2097152   | characters |  10.592 ms |  10.179 ms | -413.005 us |  -3.90% |
|     32      |  16777216  | characters |   5.339 ms |   5.129 ms | -210.714 us |  -3.95% |
|     64      |  16777216  | characters |  10.645 ms |  10.224 ms | -420.886 us |  -3.95% |

@davidwendt
davidwendt marked this pull request as ready for review February 9, 2024 21:09
@davidwendt
davidwendt requested a review from a team as a code owner February 9, 2024 21:09

@bdice bdice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch. Looks good to me.

@PointKernel PointKernel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice fix

@davidwendt

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit d6902b0 into NVIDIA:branch-24.04 Feb 13, 2024
@davidwendt
davidwendt deleted the perf-copy-if-safe branch February 13, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants