rapidsai / cudf

cuDF - GPU DataFrame Library
https://docs.rapids.ai/api/cudf/stable/
Apache License 2.0
8.43k stars 904 forks source link

[BUG] UDF functions for `apply_chunks` returns non-deterministic output #9423

Closed roshkins closed 2 years ago

roshkins commented 3 years ago

Describe the bug A clear and concise description of what the bug is. When I reference an adjacent cell in apply_chunks, the result is non-deterministic when executed repeatedly.

Steps/Code to reproduce bug Follow this guide http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports to craft a minimal bug report. This helps us reproduce the issue you're having and resolve the issue more quickly.

from numba import cuda
import cudf as pd
def test_fn(in_col, out_col):
            # Thread id in a 1D block
            tx = cuda.threadIdx.x
            # Block id in a 1D grid
            ty = cuda.blockIdx.x
            # Block width, i.e. number of threads per block
            bw = cuda.blockDim.x
            # Compute flattened index inside the array
            row_idx = tx + ty * bw
            if row_idx+1 >= in_col.size:
                out_col[row_idx] = in_col[row_idx]
                return

            if row_idx % 2 == 0:
                out_col[row_idx] = in_col[row_idx + 1]
            else:
                out_col[row_idx] = in_col[row_idx]

df = pd.DataFrame([[1,4], [2,5],[3,6]], columns= ['col1', 'col2'])
df = df.repeat(10)
df.reset_index(drop=True, inplace=True)
out_df = pd.DataFrame()
for col in df.columns:
    res = df.apply_chunks(test_fn, incols={str(col): 'in_col'}, outcols={'out_col': np.float64}, chunks=len(df[col]))
    out_df[col] = res['out_col']
    import time

out_df

Expected behavior A clear and concise description of what you expected to happen. Should always output a column that has the computed data, rather than sporadically a column of zeros.

Environment overview (please complete the following information)

Environment details Please run and paste the output of the cudf/print_env.sh script here, to gather any other relevant environment details

Click here to see environment details

     **git***
     commit cdf97d89340989446ebecffb2598915cc0870a9d (HEAD -> devEDMClone, origin/devEDMClone)
     Author: Rashi Abramson 
     Date:   Mon Oct 11 13:17:48 2021 -0700

     embeddings starting to work!
     **git submodules***

     ***OS Information***
     DISTRIB_ID=Ubuntu
     DISTRIB_RELEASE=20.04
     DISTRIB_CODENAME=focal
     DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
     NAME="Ubuntu"
     VERSION="20.04.3 LTS (Focal Fossa)"
     ID=ubuntu
     ID_LIKE=debian
     PRETTY_NAME="Ubuntu 20.04.3 LTS"
     VERSION_ID="20.04"
     HOME_URL="https://www.ubuntu.com/"
     SUPPORT_URL="https://help.ubuntu.com/"
     BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
     PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
     VERSION_CODENAME=focal
     UBUNTU_CODENAME=focal
     Linux LAPTOP-K7HKLLNH 5.10.43.3-microsoft-standard-WSL2 #1 SMP Wed Jun 16 23:47:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

     ***GPU Information***
     Tue Oct 12 16:34:00 2021
     +-----------------------------------------------------------------------------+
     | NVIDIA-SMI 470.73       Driver Version: 472.12       CUDA Version: 11.4     |
     |-------------------------------+----------------------+----------------------+
     | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
     | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
     |                               |                      |               MIG M. |
     |===============================+======================+======================|
     |   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
     | N/A   44C    P8     6W /  N/A |   1117MiB /  8192MiB |    ERR!      Default |
     |                               |                      |                  N/A |
     +-------------------------------+----------------------+----------------------+

     +-----------------------------------------------------------------------------+
     | Processes:                                                                  |
     |  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
     |        ID   ID                                                   Usage      |
     |=============================================================================|
     |  No running processes found                                                 |
     +-----------------------------------------------------------------------------+

     ***CPU***
     Architecture:                    x86_64
     CPU op-mode(s):                  32-bit, 64-bit
     Byte Order:                      Little Endian
     Address sizes:                   39 bits physical, 48 bits virtual
     CPU(s):                          16
     On-line CPU(s) list:             0-15
     Thread(s) per core:              2
     Core(s) per socket:              8
     Socket(s):                       1
     Vendor ID:                       GenuineIntel
     CPU family:                      6
     Model:                           165
     Model name:                      Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
     Stepping:                        2
     CPU MHz:                         2304.006
     BogoMIPS:                        4608.01
     Virtualization:                  VT-x
     Hypervisor vendor:               Microsoft
     Virtualization type:             full
     L1d cache:                       256 KiB
     L1i cache:                       256 KiB
     L2 cache:                        2 MiB
     L3 cache:                        16 MiB
     Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
     Vulnerability L1tf:              Not affected
     Vulnerability Mds:               Not affected
     Vulnerability Meltdown:          Not affected
     Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
     Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
     Vulnerability Spectre v2:        Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
     Vulnerability Srbds:             Not affected
     Vulnerability Tsx async abort:   Not affected
     Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves flush_l1d arch_capabilities

     ***CMake***

     ***g++***
     /usr/bin/g++
     g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
     Copyright (C) 2019 Free Software Foundation, Inc.
     This is free software; see the source for copying conditions.  There is NO
     warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

     ***nvcc***

     ***Python***
     /home/rashi/anaconda3/envs/rapids-21.10/bin/python
     Python 3.8.12

     ***Environment Variables***
     PATH                            : /home/rashi/.meteor:/home/rashi/.cargo/bin:/home/rashi/anaconda3/envs/rapids-21.10/bin:/home/rashi/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program
     Files                           : (x86)/Razer
     Chroma                          : SDK/bin:/mnt/c/Program
     Files/Razer                     : Chroma
     SDK/bin:/mnt/c/Program          : Files
     (x86)/Razer/ChromaBroadcast/bin:/mnt/c/Program: Files/Razer/ChromaBroadcast/bin:/mnt/c/Program
     Files/Oculus/Support/oculus-runtime:/mnt/c/Program: Files/NVIDIA
     GPU                             : Computing
     Toolkit/CUDA/v11.3/bin:/mnt/c/Program: Files/NVIDIA
     GPU                             : Computing
     Toolkit/CUDA/v11.3/libnvvp:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:/mnt/c/Program: Files
     (x86)/NVIDIA                    : Corporation/PhysX/Common:/mnt/c/Program
     Files/NVIDIA                    : Corporation/NVIDIA
     NvDLISR:/mnt/c/Program          : Files/dotnet:/mnt/c/Program
     Files/NVIDIA                    : Corporation/Nsight
     Compute                         : 2021.1.1:/mnt/c/Program
     Files/Microsoft                 : SQL
     Server/130/Tools/Binn:/mnt/c/Program: Files/Microsoft
     SQL                             : Server/Client
     SDK/ODBC/170/Tools/Binn:/mnt/c/Program: Files/gnuplot/bin:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program
     Files                           : (x86)/Yarn/bin:/mnt/c/Program
     Files/nodejs:/mnt/c/lazarus/fpc/3.2.2/bin/i386-Win32:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program: Files/Git/cmd:/mnt/c/WINDOWS/system32/config/systemprofile/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/roshk/AppData/Local/Programs/Python/Python39/Scripts:/mnt/c/Users/roshk/AppData/Local/Programs/Python/Python39:/mnt/c/Users/roshk/.cargo/bin:/mnt/c/Users/roshk/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/roshk/AppData/Local/GitHubDesktop/bin:/mnt/c/Users/roshk/AppData/Local/Programs/Microsoft
     VS                              : Code/bin:/mnt/c/Users/roshk/.dotnet/tools:/mnt/c/Program
     Files/NVIDIA                    : GPU
     Computing                       : Toolkit/CUDA/v11.3/extras/CUPTI/lib64:/mnt/c/Program
     Files/NVIDIA                    : GPU
     Computing                       : Toolkit/CUDA/v11.3/include:/mnt/c/tools/cuda/bin:/mnt/c/Users/roshk/utils_for_path:/mnt/c/Users/roshk/Downloads/TensorRT-7.1.3.4.Windows10.x86_64.cuda-11.0.cudnn8.0/TensorRT-7.1.3.4/lib:/mnt/c/ProgramData/roshk/GitHubDesktop/bin:/mnt/c/Users/roshk/AppData/Local/Programs/Julia-1.6.1/bin:/mnt/c/Users/roshk/AppData/Local/Yarn/bin:/mnt/c/Users/roshk/AppData/Roaming/npm:/mnt/c/Users/roshk/AppData/Local/Programs/Python/Python39/Scripts:/mnt/c/Users/roshk/AppData/Local/Programs/Python/Python39:/mnt/c/Users/roshk/.cargo/bin:/mnt/c/Users/roshk/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/roshk/AppData/Local/GitHubDesktop/bin:/mnt/c/Users/roshk/AppData/Local/Programs/Microsoft
     VS                              : Code/bin:/mnt/c/Users/roshk/.dotnet/tools:/mnt/c/Program
     Files/NVIDIA                    : GPU
     Computing                       : Toolkit/CUDA/v11.3/bin:/mnt/c/Program
     Files/NVIDIA                    : GPU
     Computing                       : Toolkit/CUDA/v11.3/extras/CUPTI/lib64:/mnt/c/Program
     Files/NVIDIA                    : GPU
     Computing                       : Toolkit/CUDA/v11.3/include:/mnt/c/tools/cuda/bin:/mnt/c/Users/roshk/utils_for_path:/mnt/c/Users/roshk/Downloads/TensorRT-7.1.3.4.Windows10.x86_64.cuda-11.0.cudnn8.0/TensorRT-7.1.3.4/lib:/mnt/c/ProgramData/roshk/GitHubDesktop/bin:/mnt/c/Users/roshk/AppData/Local/Programs/Julia-1.6.1/bin:/mnt/c/Users/roshk/AppData/Local/Yarn/bin:/mnt/c/Users/roshk/AppData/Roaming/npm:/mnt/c/Users/roshk/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/Script
     LD_LIBRARY_PATH                 :
     NUMBAPRO_NVVM                   :
     NUMBAPRO_LIBDEVICE              :
     CONDA_PREFIX                    : /home/rashi/anaconda3/envs/rapids-21.10
     PYTHON_PATH                     :

     ***conda packages***
     /home/rashi/anaconda3/condabin/conda
     # packages in environment at /home/rashi/anaconda3/envs/rapids-21.10:
     #
     # Name                    Version                   Build  Channel
     _libgcc_mutex             0.1                 conda_forge    conda-forge
     _openmp_mutex             4.5                       1_gnu    conda-forge
     abseil-cpp                20210324.2           h9c3ff4c_0    conda-forge
     aiohttp                   3.7.4.post0      py38h497a2fe_0    conda-forge
     anyio                     3.3.2            py38h578d9bd_0    conda-forge
     appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
     argon2-cffi               20.1.0           py38h497a2fe_2    conda-forge
     arrow-cpp                 5.0.0           py38h327e1ba_4_cuda    conda-forge
     arrow-cpp-proc            3.0.0                      cuda    conda-forge
     async-timeout             3.0.1                   py_1000    conda-forge
     async_generator           1.10                       py_0    conda-forge
     attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
     autopep8                  1.5.7                    pypi_0    pypi
     aws-c-cal                 0.5.11               h95a6274_0    conda-forge
     aws-c-common              0.6.2                h7f98852_0    conda-forge
     aws-c-event-stream        0.2.7               h3541f99_13    conda-forge
     aws-c-io                  0.10.5               hfb6a706_0    conda-forge
     aws-checksums             0.1.11               ha31a3da_7    conda-forge
     aws-sdk-cpp               1.8.186              hb4091e7_3    conda-forge
     backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
     backports                 1.0                        py_2    conda-forge
     backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
     blazingsql                21.10.0                  pypi_0    pypi
     bleach                    4.1.0              pyhd8ed1ab_0    conda-forge
     blosc                     1.21.0               h9c3ff4c_0    conda-forge
     bokeh                     2.4.0            py38h578d9bd_0    conda-forge
     boost                     1.72.0           py38h1e42940_1    conda-forge
     boost-cpp                 1.72.0               h312852a_5    conda-forge
     brotli                    1.0.9                h7f98852_5    conda-forge
     brotli-bin                1.0.9                h7f98852_5    conda-forge
     brotlipy                  0.7.0           py38h497a2fe_1001    conda-forge
     brunsli                   0.1                  h9c3ff4c_0    conda-forge
     bzip2                     1.0.8                h7f98852_4    conda-forge
     c-ares                    1.17.2               h7f98852_0    conda-forge
     ca-certificates           2021.9.30            h06a4308_1
     cachetools                4.2.4              pyhd8ed1ab_0    conda-forge
     cairo                     1.16.0            h6cf1ce9_1008    conda-forge
     certifi                   2021.5.30        py38h06a4308_0
     cffi                      1.14.6           py38h3931269_1    conda-forge
     cfitsio                   3.470                hb418390_7    conda-forge
     chardet                   4.0.0            py38h578d9bd_1    conda-forge
     charls                    2.2.0                h9c3ff4c_0    conda-forge
     click                     7.1.2              pyh9f0ad1d_0    conda-forge
     click-plugins             1.1.1                      py_0    conda-forge
     cligj                     0.7.2              pyhd8ed1ab_1    conda-forge
     cloudpickle               2.0.0              pyhd8ed1ab_0    conda-forge
     colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
     colorcet                  2.0.6              pyhd8ed1ab_0    conda-forge
     cryptography              3.4.7            py38ha5dfef3_0    conda-forge
     cucim                     21.10.00        cuda_11.2_py38_gd7ac21f_0    rapidsai
     cudatoolkit               11.2.72              h2bc3f7f_0    nvidia
     cudf                      21.10.00        cuda_11.2_py38_g072fd862cc_0    rapidsai
     cudf_kafka                21.10.00        py38_g072fd862cc_0    rapidsai
     cugraph                   21.10.00        cuda11.2_py38_g84617024_0    rapidsai
     cuml                      21.10.00        cuda11.2_py38_g0fd3503ba_0    rapidsai
     cupy                      9.0.0            py38ha69542f_0    conda-forge
     curl                      7.79.1               h2574ce0_1    conda-forge
     cusignal                  21.10.00        py37_gff14a10_0    rapidsai
     cuspatial                 21.10.00        py38_gba20298_0    rapidsai
     custreamz                 21.10.00        py38_g072fd862cc_0    rapidsai
     cuxfilter                 21.10.00        py38_g003d3d6_0    rapidsai
     cycler                    0.10.0                     py_2    conda-forge
     cyrus-sasl                2.1.27               h230043b_3    conda-forge
     cytoolz                   0.11.0           py38h497a2fe_3    conda-forge
     dask                      2021.9.1           pyhd8ed1ab_0    conda-forge
     dask-core                 2021.9.1           pyhd8ed1ab_0    conda-forge
     dask-cuda                 21.10.00                 py38_0    rapidsai
     dask-cudf                 21.10.00        py38_g072fd862cc_0    rapidsai
     datashader                0.11.1             pyh9f0ad1d_0    conda-forge
     datashape                 0.5.4                      py_1    conda-forge
     debugpy                   1.4.1            py38h709712a_0    conda-forge
     decorator                 4.4.2                      py_0    conda-forge
     defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
     distributed               2021.9.1         py38h578d9bd_0    conda-forge
     dlpack                    0.5                  h9c3ff4c_0    conda-forge
     entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
     expat                     2.4.1                h9c3ff4c_0    conda-forge
     faiss-proc                1.0.0                      cuda    rapidsai
     fastavro                  1.4.5            py38h497a2fe_0    conda-forge
     fastrlock                 0.6              py38h709712a_1    conda-forge
     fiona                     1.8.20           py38hbb147eb_1    conda-forge
     fontconfig                2.13.1            hba837de_1005    conda-forge
     freetype                  2.10.4               h0708190_1    conda-forge
     freexl                    1.0.6                h7f98852_0    conda-forge
     fsspec                    2021.10.0          pyhd8ed1ab_0    conda-forge
     future                    0.18.2           py38h578d9bd_3    conda-forge
     gdal                      3.3.1            py38h81a01a0_3    conda-forge
     geopandas                 0.9.0              pyhd8ed1ab_1    conda-forge
     geopandas-base            0.9.0              pyhd8ed1ab_1    conda-forge
     geos                      3.9.1                h9c3ff4c_2    conda-forge
     geotiff                   1.6.0                h4f31c25_6    conda-forge
     gettext                   0.19.8.1          h73d1719_1008    conda-forge
     gflags                    2.2.2             he1b5a44_1004    conda-forge
     giflib                    5.2.1                h36c2ea0_2    conda-forge
     glog                      0.5.0                h48cff8f_0    conda-forge
     google-cloud-cpp          1.29.0               hb967e95_1    conda-forge
     greenlet                  1.1.2            py38h709712a_0    conda-forge
     grpc-cpp                  1.39.1               h850795e_1    conda-forge
     hdf4                      4.2.15               h10796ff_3    conda-forge
     hdf5                      1.12.1          nompi_h2750804_101    conda-forge
     heapdict                  1.0.1                      py_0    conda-forge
     icu                       68.1                 h58526e2_0    conda-forge
     idna                      2.10               pyh9f0ad1d_0    conda-forge
     imagecodecs               2021.7.30        py38hb5ce8f7_1    conda-forge
     imageio                   2.9.0                      py_0    conda-forge
     importlib-metadata        4.8.1            py38h578d9bd_0    conda-forge
     ipykernel                 6.4.1            py38h06a4308_1
     ipython                   7.28.0           py38he5a9106_0    conda-forge
     ipython_genutils          0.2.0                      py_1    conda-forge
     ipywidgets                7.6.5              pyhd8ed1ab_0    conda-forge
     jbig                      2.1               h7f98852_2003    conda-forge
     jedi                      0.18.0           py38h578d9bd_2    conda-forge
     jinja2                    3.0.2              pyhd8ed1ab_0    conda-forge
     joblib                    1.1.0              pyhd8ed1ab_0    conda-forge
     jpeg                      9d                   h36c2ea0_0    conda-forge
     jpype1                    1.3.0            py38h1fd1430_0    conda-forge
     json-c                    0.15                 h98cffda_0    conda-forge
     jsonschema                4.0.1              pyhd8ed1ab_0    conda-forge
     jupyter-server-proxy      3.1.0              pyhd8ed1ab_0    conda-forge
     jupyter_client            7.0.6              pyhd8ed1ab_0    conda-forge
     jupyter_core              4.8.1            py38h578d9bd_0    conda-forge
     jupyter_server            1.11.1             pyhd8ed1ab_0    conda-forge
     jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
     jupyterlab_widgets        1.0.2              pyhd8ed1ab_0    conda-forge
     jxrlib                    1.1                  h7f98852_2    conda-forge
     kealib                    1.4.14               h87e4c3c_3    conda-forge
     kiwisolver                1.3.2            py38h1fd1430_0    conda-forge
     krb5                      1.19.2               hcc1bbae_2    conda-forge
     lcms2                     2.12                 hddcbb42_0    conda-forge
     ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
     lerc                      2.2.1                h9c3ff4c_0    conda-forge
     libaec                    1.0.6                h9c3ff4c_0    conda-forge
     libblas                   3.9.0           11_linux64_openblas    conda-forge
     libbrotlicommon           1.0.9                h7f98852_5    conda-forge
     libbrotlidec              1.0.9                h7f98852_5    conda-forge
     libbrotlienc              1.0.9                h7f98852_5    conda-forge
     libcblas                  3.9.0           11_linux64_openblas    conda-forge
     libcrc32c                 1.1.2                h9c3ff4c_0    conda-forge
     libcucim                  21.10.00        cuda11.2_gd7ac21f_0    rapidsai
     libcudf                   21.10.00        cuda11.2_g072fd862cc_0    rapidsai
     libcudf_kafka             21.10.00          g072fd862cc_0    rapidsai
     libcugraph                21.10.00        cuda11.2_g84617024_0    rapidsai
     libcuml                   21.10.00        cuda11.2_g0fd3503ba_0    rapidsai
     libcumlprims              21.10.00        cuda11.2_g167dc59_0    nvidia
     libcurl                   7.79.1               h2574ce0_1    conda-forge
     libcuspatial              21.10.00        cuda11.2_gba20298_0    rapidsai
     libdap4                   3.20.6               hd7c4107_2    conda-forge
     libdeflate                1.7                  h7f98852_5    conda-forge
     libedit                   3.1.20191231         he28a2e2_2    conda-forge
     libev                     4.33                 h516909a_1    conda-forge
     libevent                  2.1.10               h9b69904_4    conda-forge
     libfaiss                  1.7.0           cuda112h5bea7ad_8_cuda    conda-forge
     libffi                    3.4.2                h9c3ff4c_4    conda-forge
     libgcc-ng                 11.2.0               h1d223b6_9    conda-forge
     libgcrypt                 1.9.4                h7f98852_0    conda-forge
     libgdal                   3.3.1                h6214c1d_3    conda-forge
     libgfortran-ng            11.2.0               h69a702a_9    conda-forge
     libgfortran5              11.2.0               h5c6108e_9    conda-forge
     libglib                   2.68.4               h174f98d_1    conda-forge
     libgomp                   11.2.0               h1d223b6_9    conda-forge
     libgpg-error              1.42                 h9c3ff4c_0    conda-forge
     libgsasl                  1.10.0               h5b4c23d_0    conda-forge
     libhwloc                  2.3.0                h5e5b7d1_1    conda-forge
     libiconv                  1.16                 h516909a_0    conda-forge
     libkml                    1.3.0             hd79254b_1012    conda-forge
     liblapack                 3.9.0           11_linux64_openblas    conda-forge
     libllvm10                 10.0.1               he513fc3_3    conda-forge
     libnetcdf                 4.8.1           nompi_hb3fd0d9_101    conda-forge
     libnghttp2                1.43.0               h812cca2_1    conda-forge
     libntlm                   1.4               h7f98852_1002    conda-forge
     libopenblas               0.3.17          pthreads_h8fe5266_1    conda-forge
     libpng                    1.6.37               h21135ba_2    conda-forge
     libpq                     13.3                 hd57d9b9_1    conda-forge
     libprotobuf               3.16.0               h780b84a_0    conda-forge
     librdkafka                1.6.1                hc49e61c_1    conda-forge
     librmm                    21.10.00        cuda11.2_g72ee41f_0    rapidsai
     librttopo                 1.1.0                h1185371_6    conda-forge
     libsodium                 1.0.18               h36c2ea0_1    conda-forge
     libspatialindex           1.9.3                h9c3ff4c_4    conda-forge
     libspatialite             5.0.1                h8694cbe_6    conda-forge
     libssh2                   1.10.0               ha56f1ee_2    conda-forge
     libstdcxx-ng              11.2.0               he4da1e4_9    conda-forge
     libthrift                 0.14.2               he6d91bd_1    conda-forge
     libtiff                   4.3.0                hf544144_1    conda-forge
     libutf8proc               2.6.1                h7f98852_0    conda-forge
     libuuid                   2.32.1            h7f98852_1000    conda-forge
     libuv                     1.42.0               h7f98852_0    conda-forge
     libwebp                   1.2.1                h3452ae3_0    conda-forge
     libwebp-base              1.2.1                h7f98852_0    conda-forge
     libxcb                    1.13              h7f98852_1003    conda-forge
     libxgboost                1.4.2dev.rapidsai21.10      cuda11.2_0    rapidsai
     libxml2                   2.9.12               h72842e0_0    conda-forge
     libzip                    1.8.0                h4de3113_1    conda-forge
     libzlib                   1.2.11            h36c2ea0_1013    conda-forge
     libzopfli                 1.0.3                h9c3ff4c_0    conda-forge
     llvmlite                  0.36.0           py38h4630a5e_0    conda-forge
     locket                    0.2.0                      py_2    conda-forge
     lz4-c                     1.9.3                h9c3ff4c_1    conda-forge
     mapclassify               2.4.3              pyhd8ed1ab_0    conda-forge
     markdown                  3.3.4              pyhd8ed1ab_0    conda-forge
     markupsafe                2.0.1            py38h497a2fe_0    conda-forge
     matplotlib-base           3.4.3            py38hf4fb855_1    conda-forge
     matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge
     mistune                   0.8.4           py38h497a2fe_1004    conda-forge
     msgpack-python            1.0.2            py38h1fd1430_1    conda-forge
     multidict                 5.2.0            py38h497a2fe_0    conda-forge
     multipledispatch          0.6.0                      py_0    conda-forge
     munch                     2.5.0                      py_0    conda-forge
     nbclient                  0.5.4              pyhd8ed1ab_0    conda-forge
     nbconvert                 6.2.0            py38h578d9bd_0    conda-forge
     nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
     nccl                      2.11.4.1             hdc17891_0    conda-forge
     ncurses                   6.2                  h58526e2_4    conda-forge
     nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
     netifaces                 0.10.9          py38h497a2fe_1003    conda-forge
     networkx                  2.6.3              pyhd8ed1ab_0    conda-forge
     nlohmann_json             3.9.1                h9c3ff4c_1    conda-forge
     nodejs                    14.17.4              h92b4a50_0    conda-forge
     notebook                  6.4.4              pyha770c72_0    conda-forge
     numba                     0.53.1           py38h8b71fd7_1    conda-forge
     numpy                     1.21.2           py38he2449b9_0    conda-forge
     nvtx                      0.2.3            py38h497a2fe_0    conda-forge
     olefile                   0.46               pyh9f0ad1d_1    conda-forge
     openjdk                   8.0.302              h7f98852_0    conda-forge
     openjpeg                  2.4.0                hb52868f_1    conda-forge
     openssl                   1.1.1l               h7f8727e_0
     orc                       1.6.10               h58a87f1_0    conda-forge
     packaging                 21.0               pyhd8ed1ab_0    conda-forge
     pandas                    1.3.3            py38h43a58ef_0    conda-forge
     pandoc                    2.14.2               h7f98852_0    conda-forge
     pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
     panel                     0.12.4             pyhd8ed1ab_0    conda-forge
     param                     1.11.1             pyh6c4a22f_0    conda-forge
     parquet-cpp               1.5.1                         2    conda-forge
     parso                     0.8.2              pyhd8ed1ab_0    conda-forge
     partd                     1.2.0              pyhd8ed1ab_0    conda-forge
     pcre                      8.45                 h9c3ff4c_0    conda-forge
     pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
     pickleshare               0.7.5                   py_1003    conda-forge
     pillow                    8.3.2            py38h8e6f84c_0    conda-forge
     pip                       21.2.4             pyhd8ed1ab_0    conda-forge
     pixman                    0.40.0               h36c2ea0_0    conda-forge
     pooch                     1.5.1              pyhd8ed1ab_0    conda-forge
     poppler                   21.03.0              h93df280_0    conda-forge
     poppler-data              0.4.11               hd8ed1ab_0    conda-forge
     postgresql                13.3                 h2510834_1    conda-forge
     proj                      8.0.1                h277dcde_0    conda-forge
     prometheus_client         0.11.0             pyhd8ed1ab_0    conda-forge
     prompt-toolkit            3.0.20             pyha770c72_0    conda-forge
     protobuf                  3.16.0           py38h709712a_0    conda-forge
     psutil                    5.8.0            py38h497a2fe_1    conda-forge
     pthread-stubs             0.4               h36c2ea0_1001    conda-forge
     ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
     pure-sasl                 0.6.2              pyhd8ed1ab_0    conda-forge
     py-xgboost                1.4.2dev.rapidsai21.10  cuda11.2py38_0    rapidsai
     pyarrow                   5.0.0           py38hed47224_4_cuda    conda-forge
     pycodestyle               2.7.0                    pypi_0    pypi
     pycparser                 2.20               pyh9f0ad1d_2    conda-forge
     pyct                      0.4.6                      py_0    conda-forge
     pyct-core                 0.4.6                      py_0    conda-forge
     pydeck                    0.5.0              pyh9f0ad1d_0    conda-forge
     pyee                      8.1.0              pyh9f0ad1d_0    conda-forge
     pygments                  2.10.0             pyhd8ed1ab_0    conda-forge
     pyhive                    0.6.4              pyhd8ed1ab_0    conda-forge
     pynvml                    11.0.0             pyhd8ed1ab_0    conda-forge
     pyopenssl                 21.0.0             pyhd8ed1ab_0    conda-forge
     pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
     pyppeteer                 0.2.6              pyhd8ed1ab_0    conda-forge
     pyproj                    3.1.0            py38h4df08a6_4    conda-forge
     pyrsistent                0.17.3           py38h497a2fe_2    conda-forge
     pysocks                   1.7.1            py38h578d9bd_3    conda-forge
     python                    3.8.12          hb7a2778_1_cpython    conda-forge
     python-confluent-kafka    1.6.0            py38h497a2fe_1    conda-forge
     python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
     python_abi                3.8                      2_cp38    conda-forge
     pytz                      2021.3             pyhd8ed1ab_0    conda-forge
     pyviz_comms               2.1.0              pyhd8ed1ab_0    conda-forge
     pywavelets                1.1.1            py38h6c62de6_3    conda-forge
     pyyaml                    5.4.1            py38h497a2fe_1    conda-forge
     pyzmq                     22.3.0           py38h2035c66_0    conda-forge
     rapids                    21.10.00        cuda11.2_py38_ge66f011_114    rapidsai
     rapids-blazing            21.10.00        cuda11.2_py38_ge66f011_114    rapidsai
     rapids-xgboost            21.10.00        cuda11.2_py38_ge66f011_114    rapidsai
     re2                       2021.09.01           h9c3ff4c_0    conda-forge
     readline                  8.1                  h46c0cb4_0    conda-forge
     requests                  2.25.1             pyhd3deb0d_0    conda-forge
     requests-unixsocket       0.2.0                      py_0    conda-forge
     rmm                       21.10.00        cuda_11.2_py38_g72ee41f_0    rapidsai
     rtree                     0.9.7            py38h02d302b_2    conda-forge
     s2n                       1.0.10               h9b69904_0    conda-forge
     scikit-image              0.18.1           py38h51da96c_0    conda-forge
     scikit-learn              1.0              py38hacb3eff_1    conda-forge
     scipy                     1.7.1            py38h56a6a73_0    conda-forge
     send2trash                1.8.0              pyhd8ed1ab_0    conda-forge
     setuptools                49.6.0           py38h578d9bd_3    conda-forge
     shapely                   1.7.1            py38hb7fe4a8_5    conda-forge
     simpervisor               0.4                pyhd8ed1ab_0    conda-forge
     six                       1.16.0             pyh6c4a22f_0    conda-forge
     snappy                    1.1.8                he1b5a44_3    conda-forge
     sniffio                   1.2.0            py38h578d9bd_1    conda-forge
     sortedcontainers          2.4.0              pyhd8ed1ab_0    conda-forge
     spdlog                    1.8.5                h4bd325d_0    conda-forge
     sqlalchemy                1.4.25           py38h497a2fe_0    conda-forge
     sqlite                    3.36.0               h9cd32fc_2    conda-forge
     streamz                   0.6.3              pyh6c4a22f_0    conda-forge
     tblib                     1.7.0              pyhd8ed1ab_0    conda-forge
     terminado                 0.12.1           py38h578d9bd_0    conda-forge
     testpath                  0.5.0              pyhd8ed1ab_0    conda-forge
     threadpoolctl             3.0.0              pyh8a188c0_0    conda-forge
     thrift                    0.14.0           py38h709712a_0    conda-forge
     thrift_sasl               0.4.3              pyhd8ed1ab_1    conda-forge
     tifffile                  2021.8.30          pyhd8ed1ab_0    conda-forge
     tiledb                    2.3.4                he87e0bf_0    conda-forge
     tk                        8.6.11               h27826a3_1    conda-forge
     toml                      0.10.2                   pypi_0    pypi
     toolz                     0.11.1                     py_0    conda-forge
     tornado                   6.1              py38h497a2fe_1    conda-forge
     tqdm                      4.62.3             pyhd8ed1ab_0    conda-forge
     traitlets                 5.1.0              pyhd8ed1ab_0    conda-forge
     treelite                  2.1.0            py38hdd725b4_0    conda-forge
     treelite-runtime          2.1.0                    pypi_0    pypi
     typing-extensions         3.10.0.2             hd8ed1ab_0    conda-forge
     typing_extensions         3.10.0.2           pyha770c72_0    conda-forge
     tzcode                    2021c                h7f98852_0    conda-forge
     tzdata                    2021c                he74cb21_0    conda-forge
     ucx                       1.11.1+gc58db6b      cuda11.2_0    rapidsai
     ucx-proc                  1.0.0                       gpu    rapidsai
     ucx-py                    0.22.0          py38_gc58db6b_0    rapidsai
     urllib3                   1.26.7             pyhd8ed1ab_0    conda-forge
     wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
     webencodings              0.5.1                      py_1    conda-forge
     websocket-client          0.57.0           py38h578d9bd_4    conda-forge
     websockets                9.1              py38h497a2fe_0    conda-forge
     wheel                     0.37.0             pyhd8ed1ab_1    conda-forge
     widgetsnbextension        3.5.1            py38h578d9bd_4    conda-forge
     xarray                    0.19.0             pyhd8ed1ab_1    conda-forge
     xerces-c                  3.2.3                h9d8b166_2    conda-forge
     xgboost                   1.4.2dev.rapidsai21.10  cuda11.2py38_0    rapidsai
     xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
     xorg-libice               1.0.10               h7f98852_0    conda-forge
     xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
     xorg-libx11               1.7.2                h7f98852_0    conda-forge
     xorg-libxau               1.0.9                h7f98852_0    conda-forge
     xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
     xorg-libxext              1.3.4                h7f98852_1    conda-forge
     xorg-libxrender           0.9.10            h7f98852_1003    conda-forge
     xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
     xorg-xextproto            7.3.0             h7f98852_1002    conda-forge
     xorg-xproto               7.0.31            h7f98852_1007    conda-forge
     xz                        5.2.5                h516909a_1    conda-forge
     yaml                      0.2.5                h516909a_0    conda-forge
     yarl                      1.7.0            py38h497a2fe_0    conda-forge
     zeromq                    4.3.4                h9c3ff4c_1    conda-forge
     zfp                       0.5.5                h9c3ff4c_7    conda-forge
     zict                      2.0.0                      py_0    conda-forge
     zipp                      3.6.0              pyhd8ed1ab_0    conda-forge
     zlib                      1.2.11            h36c2ea0_1013    conda-forge
     zstd                      1.5.0                ha95c52a_0    conda-forge

Additional context Add any other context about the problem here.

beckernick commented 3 years ago

The undefined behavior in the kernel due to the reverse guard appears to be overwriting the input data buffer when it occurs. We'll take a look into what's happening here, but "protecting" against undefined behavior in user code is challenging.

Hopefully the examples and documentation below resolve your issue.

df = cudf.DataFrame([[1,4], [2,5],[3,6]], columns= ['col1', 'col2'])
df = df.repeat(10)
df.reset_index(drop=True, inplace=True)
out_df = cudf.DataFrame()

print(df.head())
for i in range(5):
    res = df.apply_chunks(test_fn,
                    incols={"col2": 'in_col'},
                    outcols={'out_col': np.float64},
                    chunks=len(df[col])
                   )
    print(res.head())
   col1  col2
0     1     4
1     1     4
2     1     4
3     1     4
4     1     4
   col1  col2  out_col
0     1     4      4.0
1     1     4      4.0
2     1     4      4.0
3     1     4      4.0
4     1     4      4.0
                  col1                 col2       out_col
0  4607182418800017408  4629137466983448576  4.607182e+18
1                    0  4607182418800017408  4.607182e+18
2                    0  4611686018427387904  4.613938e+18
3                    0  4613937818241073152  4.613938e+18
4                    0  4616189618054758400  0.000000e+00
                  col1                 col2       out_col
0  4607182418800017408  4629137466983448576  4.607182e+18
1                    0  4607182418800017408  4.607182e+18
2                    0  4611686018427387904  4.613938e+18
3                    0  4613937818241073152  4.613938e+18
4                    0  4616189618054758400  0.000000e+00
                  col1                 col2       out_col
0  4607182418800017408  4629137466983448576  4.607182e+18
1                    0  4607182418800017408  4.607182e+18
2                    0  4611686018427387904  4.613938e+18
3                    0  4613937818241073152  4.613938e+18
4                    0  4616189618054758400  0.000000e+00
                  col1                 col2       out_col
0  4607182418800017408  4629137466983448576  4.607182e+18
1                    0  4607182418800017408  4.607182e+18
2                    0  4611686018427387904  4.613938e+18
3                    0  4613937818241073152  4.613938e+18
4                    0  4616189618054758400  0.000000e+00

With a thread boundary guard to ensure we don't access memory beyond the buffer, I don't see any undefined behavior.

def test_fn2(in_col, out_col):
    # Thread id in a 1D block
    tx = cuda.threadIdx.x
    # Block id in a 1D grid
    ty = cuda.blockIdx.x
    # Block width, i.e. number of threads per block
    bw = cuda.blockDim.x
    # Compute flattened index inside the array
    row_idx = tx + ty * bw
    if row_idx < in_col.size: # thread boundary guard
        if row_idx % 2 == 0:
            out_col[row_idx] = in_col[row_idx + 1]
        else:
            out_col[row_idx] = in_col[row_idx]

df = cudf.DataFrame([[1,4], [2,5],[3,6]], columns= ['col1', 'col2'])
df = df.repeat(10)
df.reset_index(drop=True, inplace=True)
out_df = cudf.DataFrame()

print(df.head())
for i in range(5):
    res = df.apply_chunks(test_fn2,
                    incols={"col2": 'in_col'},
                    outcols={'out_col': np.float64},
                    chunks=len(df[col])
                   )
    print(res.head())
   col1  col2
0     1     4
1     1     4
2     1     4
3     1     4
4     1     4
   col1  col2  out_col
0     1     4      4.0
1     1     4      4.0
2     1     4      4.0
3     1     4      4.0
4     1     4      4.0
   col1  col2  out_col
0     1     4      4.0
1     1     4      4.0
2     1     4      4.0
3     1     4      4.0
4     1     4      4.0
   col1  col2  out_col
0     1     4      4.0
1     1     4      4.0
2     1     4      4.0
3     1     4      4.0
4     1     4      4.0
   col1  col2  out_col
0     1     4      4.0
1     1     4      4.0
2     1     4      4.0
3     1     4      4.0
4     1     4      4.0
   col1  col2  out_col
0     1     4      4.0
1     1     4      4.0
2     1     4      4.0
3     1     4      4.0
4     1     4      4.0

Note that you could express this test function as a rolling window UDF as well:

def func(window):
    current = window[0]
    if current % 2 == 0:
        return window[1] # assume at least window size 2
    else:
        return current

df.col2.rolling(2).apply(func)

We're also actively enhancing the user experience for UDFs. We've added df.apply and "row" abstractions, similar to pandas. You may be interested in this section of our nightly documentation: https://docs.rapids.ai/api/cudf/nightly/user_guide/guide-to-udfs.html#Generalized-NA-Support

github-actions[bot] commented 2 years ago

This issue has been labeled inactive-30d due to no recent activity in the past 30 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. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] commented 2 years ago

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.

vyasr commented 2 years ago

I'm going to close this because users writing apply functions are effectively writing kernels, and we just don't have mechanisms for making all such cases safe.