Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEA] Use libcudf's boolean mask scattering for setitem #8667

Closed
vyasr opened this issue Jul 7, 2021 · 1 comment · Fixed by #10202
Closed

[FEA] Use libcudf's boolean mask scattering for setitem #8667

vyasr opened this issue Jul 7, 2021 · 1 comment · Fixed by #10202
Labels
feature request New feature or request Performance Performance related issue Python Affects Python cuDF API.

Comments

@vyasr
Copy link
Contributor

vyasr commented Jul 7, 2021

Is your feature request related to a problem? Please describe.
#3681 introduced a directly boolean scattering API that could be leveraged for setting items on columns using a boolean mask in a single pass. The libcudf feature has been exposed in Cython (in _lib/copying.pyx) but cuDF currently still implements that feature manually.

Describe the solution you'd like
We should change cuDF to take advantage of the direct boolean scattering approach.

Additional context
@rgsl888prabhu may have more insight into how this should be accomplished.

@vyasr vyasr added feature request New feature or request Needs Triage Need team to review and classify labels Jul 7, 2021
@vyasr vyasr added Python Affects Python cuDF API. Performance Performance related issue labels Jul 7, 2021
@beckernick beckernick removed the Needs Triage Need team to review and classify label Jul 7, 2021
@beckernick beckernick added this to the cuDF Python Refactoring milestone Jul 27, 2021
@github-actions
Copy link

This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.

rapids-bot bot pushed a commit that referenced this issue Feb 23, 2022
closes #8667 

This PR rewrites `column.__setitem__` and calls `boolean_mask_scatter` if keys and values meet some criteria.
Benchmark shows in low-order problem size (10K ish), there are 30% speed up for aligned values and 10% for unaligned values. Note standard deviation of the unaligned case is quite high after refactor. For larger problem sizes performance is rather unaffected.

Benchmarks:
<details>

<summary>10K</summary>

```
---------------------------------------------------------------- benchmark 'boolean_mask_col_aligned': 2 tests -----------------------------------------------------------------
Name (time in ms)                                      Min               Max              Mean            StdDev            Median               IQR            Outliers  Rounds
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[boolean_mask_col_aligned] (afte)     1.2809 (1.0)      1.6781 (1.0)      1.3064 (1.0)      0.0364 (1.0)      1.2996 (1.0)      0.0137 (1.0)         22;34     761
column_setitem[boolean_mask_col_aligned] (befo)     1.7024 (1.33)     2.3863 (1.42)     1.7270 (1.32)     0.0523 (1.43)     1.7187 (1.32)     0.0138 (1.01)        20;31     563
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------- benchmark 'boolean_mask_col_unaligned': 2 tests --------------------------------------------------------------------------
Name (time in us)                                            Min                   Max                  Mean             StdDev                Median                IQR            Outliers  Rounds
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[boolean_mask_col_unaligned] (afte)       972.3390 (1.0)      1,520.7559 (1.29)     1,008.6033 (1.0)      77.0920 (9.45)       984.0354 (1.0)      13.2429 (1.45)       83;132     984
column_setitem[boolean_mask_col_unaligned] (befo)     1,106.3821 (1.14)     1,179.5689 (1.0)      1,118.7759 (1.11)      8.1539 (1.0)      1,116.2200 (1.13)      9.1530 (1.0)        149;30     874
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------- benchmark 'boolean_mask_scalar': 2 tests ---------------------------------------------------------------------
Name (time in us)                                   Min                 Max                Mean             StdDev              Median               IQR            Outliers  Rounds
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[boolean_mask_scalar] (afte)     532.2532 (1.0)      605.4689 (1.0)      542.2607 (1.0)      11.1111 (1.10)     537.9058 (1.0)      5.2921 (1.0)       178;213    1461
column_setitem[boolean_mask_scalar] (befo)     770.1530 (1.45)     863.1549 (1.43)     781.4038 (1.44)     10.0834 (1.0)      778.3370 (1.45)     7.0044 (1.32)       114;90    1219
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------- benchmark 'integer_scatter_map_col': 2 tests ----------------------------------------------------------------
Name (time in ms)                                     Min               Max              Mean            StdDev            Median               IQR            Outliers  Rounds
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[integer_scatter_map_col] (afte)     1.4785 (1.0)      1.9170 (1.21)     1.5176 (1.01)     0.0438 (3.91)     1.5098 (1.00)     0.0171 (1.37)        18;26     644
column_setitem[integer_scatter_map_col] (befo)     1.4882 (1.01)     1.5802 (1.0)      1.5084 (1.0)      0.0112 (1.0)      1.5068 (1.0)      0.0124 (1.0)        140;22     650
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------- benchmark 'integer_scatter_map_scalar': 2 tests ----------------------------------------------------------------------
Name (time in us)                                          Min                   Max                Mean             StdDev              Median               IQR            Outliers  Rounds
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[integer_scatter_map_scalar] (afte)     878.2479 (1.0)      1,343.0519 (1.39)     897.1496 (1.01)     27.5109 (3.23)     892.9770 (1.00)     7.8208 (1.0)         29;60    1074
column_setitem[integer_scatter_map_scalar] (befo)     879.3280 (1.00)       966.9410 (1.0)      890.8573 (1.0)       8.5287 (1.0)      888.7504 (1.0)      8.4981 (1.09)       171;50    1086
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------- benchmark 'stride-1_slice_col': 2 tests -----------------------------------------------------------------------
Name (time in us)                                  Min                   Max                Mean             StdDev              Median                IQR            Outliers  Rounds
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[stride-1_slice_col] (afte)     752.6411 (1.0)        852.3620 (1.0)      775.1790 (1.0)      10.9726 (1.0)      772.6796 (1.0)      14.1604 (1.32)       245;23    1152
column_setitem[stride-1_slice_col] (befo)     974.8179 (1.30)     1,307.2360 (1.53)     991.1287 (1.28)     25.8696 (2.36)     985.5330 (1.28)     10.6919 (1.0)         30;51     763
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------- benchmark 'stride-1_slice_scalar': 2 tests -------------------------------------------------------------------
Name (time in us)                                    Min                 Max               Mean            StdDev             Median               IQR            Outliers  Rounds
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[stride-1_slice_scalar] (afte)     87.3711 (1.16)     134.7861 (1.0)      89.7566 (1.15)     2.4861 (1.0)      89.5601 (1.16)     1.6061 (1.13)        95;87    2106
column_setitem[stride-1_slice_scalar] (befo)     75.3789 (1.0)      136.7659 (1.01)     78.0297 (1.0)      4.8186 (1.94)     77.0842 (1.0)      1.4230 (1.0)       122;184    2403
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------- benchmark 'stride-2_slice_col': 2 tests ----------------------------------------------------------------------
Name (time in us)                                  Min                 Max                Mean             StdDev              Median                IQR            Outliers  Rounds
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[stride-2_slice_col] (afte)     684.7882 (1.02)     972.5131 (1.01)     712.5983 (1.04)     54.4972 (3.04)     693.8996 (1.02)     10.3808 (1.18)      109;163    1338
column_setitem[stride-2_slice_col] (befo)     672.3758 (1.0)      964.4001 (1.0)      684.2917 (1.0)      17.9163 (1.0)      679.5955 (1.0)       8.7875 (1.0)        85;106    1368
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------- benchmark 'stride-2_slice_scalar': 2 tests --------------------------------------------------------------------
Name (time in us)                                     Min                 Max                Mean            StdDev              Median               IQR            Outliers  Rounds
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
column_setitem[stride-2_slice_scalar] (afte)     302.0421 (1.04)     374.3470 (1.0)      307.5677 (1.04)     4.3768 (1.0)      306.4690 (1.04)     2.4854 (1.17)      258;253    2532
column_setitem[stride-2_slice_scalar] (befo)     290.4800 (1.0)      378.1999 (1.01)     295.3950 (1.0)      4.6778 (1.07)     294.1729 (1.0)      2.1292 (1.0)       273;324    2977
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
```
</details>

<details>

<summary> 1M </summary>

```
------------------------------ benchmark 'boolean_mask_col_aligned': 2 tests ------------------------------
Name (time in ms)                                       Min                Max               Mean          
-----------------------------------------------------------------------------------------------------------
column_setitem[boolean_mask_col_aligned] (afte)     75.3847 (1.0)      79.0559 (1.0)      76.2878 (1.0)    
column_setitem[boolean_mask_col_aligned] (befo)     76.3708 (1.01)     79.7394 (1.01)     77.0892 (1.01)   
-----------------------------------------------------------------------------------------------------------

------------------------------ benchmark 'boolean_mask_col_unaligned': 2 tests ------------------------------
Name (time in ms)                                         Min                Max               Mean          
-------------------------------------------------------------------------------------------------------------
column_setitem[boolean_mask_col_unaligned] (afte)     46.5199 (1.0)      48.3434 (1.0)      46.9222 (1.0)    
column_setitem[boolean_mask_col_unaligned] (befo)     46.6314 (1.00)     48.5938 (1.01)     47.1492 (1.00)   
-------------------------------------------------------------------------------------------------------------

------------------------------ benchmark 'boolean_mask_scalar': 2 tests ------------------------------
Name (time in ms)                                  Min                Max               Mean          
------------------------------------------------------------------------------------------------------
column_setitem[boolean_mask_scalar] (afte)     17.0548 (1.0)      17.8006 (1.0)      17.5430 (1.0)    
column_setitem[boolean_mask_scalar] (befo)     18.4329 (1.08)     18.6918 (1.05)     18.5073 (1.05)   
------------------------------------------------------------------------------------------------------

-------------------------------- benchmark 'integer_scatter_map_col': 2 tests -------------------------------
Name (time in ms)                                       Min                 Max                Mean          
-------------------------------------------------------------------------------------------------------------
column_setitem[integer_scatter_map_col] (afte)     115.7189 (1.01)     120.0585 (1.0)      116.6452 (1.0)    
column_setitem[integer_scatter_map_col] (befo)     114.7481 (1.0)      122.7263 (1.02)     117.5000 (1.01)   
-------------------------------------------------------------------------------------------------------------

------------------------------ benchmark 'integer_scatter_map_scalar': 2 tests ------------------------------
Name (time in ms)                                         Min                Max               Mean          
-------------------------------------------------------------------------------------------------------------
column_setitem[integer_scatter_map_scalar] (afte)     57.9951 (1.0)      62.2284 (1.0)      59.8864 (1.0)    
column_setitem[integer_scatter_map_scalar] (befo)     60.9071 (1.05)     62.2952 (1.00)     61.6422 (1.03)   
-------------------------------------------------------------------------------------------------------------

------------------------------ benchmark 'stride-1_slice_col': 2 tests ------------------------------
Name (time in ms)                                 Min                Max               Mean          
-----------------------------------------------------------------------------------------------------
column_setitem[stride-1_slice_col] (afte)     56.9203 (1.0)      58.0924 (1.0)      57.4940 (1.0)    
column_setitem[stride-1_slice_col] (befo)     58.1888 (1.02)     59.2996 (1.02)     58.5722 (1.02)   
-----------------------------------------------------------------------------------------------------

-------------------------------- benchmark 'stride-1_slice_scalar': 2 tests -------------------------------
Name (time in us)                                     Min                 Max                Mean          
-----------------------------------------------------------------------------------------------------------
column_setitem[stride-1_slice_scalar] (afte)     287.1200 (1.08)     515.4130 (1.24)     298.1191 (1.09)   
column_setitem[stride-1_slice_scalar] (befo)     265.6982 (1.0)      415.9641 (1.0)      273.5206 (1.0)    
-----------------------------------------------------------------------------------------------------------

------------------------------ benchmark 'stride-2_slice_col': 2 tests ------------------------------
Name (time in ms)                                 Min                Max               Mean          
-----------------------------------------------------------------------------------------------------
column_setitem[stride-2_slice_col] (afte)     29.1543 (1.01)     31.0217 (1.00)     29.6341 (1.00)   
column_setitem[stride-2_slice_col] (befo)     28.9718 (1.0)      30.8824 (1.0)      29.5045 (1.0)    
-----------------------------------------------------------------------------------------------------

--------------------------------- benchmark 'stride-2_slice_scalar': 2 tests --------------------------------
Name (time in us)                                     Min                   Max                Mean          
-------------------------------------------------------------------------------------------------------------
column_setitem[stride-2_slice_scalar] (afte)     780.7089 (1.00)     1,407.5749 (1.0)      817.0583 (1.0)    
column_setitem[stride-2_slice_scalar] (befo)     777.0571 (1.0)      2,036.4628 (1.45)     832.0608 (1.02)   
-------------------------------------------------------------------------------------------------------------
```
</details>

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #10202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Performance Performance related issue Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants