Skip to content

[BUG] cudaErrorIllegalAddress when doing pl.concat([filter, filter]).sort().collect() when all filter expressions evaluate to 0 rows #21824

@jberg5

Description

@jberg5

Describe the bug

  import polars as pl

  df = pl.LazyFrame({"a": [1, 2, 3]})
  pl.concat([df.filter(pl.col("a") == 0), df.filter(pl.col("a") == 4)]).sort("a").collect(engine="gpu")
  # RuntimeError: CUDA error at: /__w/rmm/rmm/cpp/src/cuda_stream_view.cpp:45:
  # cudaErrorIllegalAddress an illegal memory access was encountered

Trouble starts here:

i * sorted_candidates.num_rows() // num_partitions

when sorted_candidates.num_rows() == 0 we end up with a list of indices [0, 0, ...], and then plc.copying.gather reads from an empty table at index 0 with OutOfBoundsPolicy.DONT_CHECK.

Should be fixable with a small

    if sort_boundaries_candidates.num_rows == 0:
        return sort_boundaries_candidates

guard in _get_final_sort_boundaries.

Steps/Code to reproduce bug

See above example

Expected behavior

Should return an empty dataframe.

Environment overview (please complete the following information)

  • Environment location: Cloud (AWS g4dn.xlarge, NVIDIA T4)
  • Method of cuDF install: pip (pip install cudf-cu12 cudf-polars-cu12 --extra-index-url https://pypi.nvidia.com)

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

  ***OS Information***
  DISTRIB_ID=Ubuntu
  DISTRIB_RELEASE=22.04
  DISTRIB_CODENAME=jammy
  DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
  Linux ip-172-31-75-157 6.8.0-1047-aws #50~22.04.1-Ubuntu SMP x86_64 GNU/Linux

  ***GPU Information***
  NVIDIA-SMI 580.126.09   Driver Version: 580.126.09   CUDA Version: 13.0
  Tesla T4, 15360MiB

  ***CPU***
  Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz, 4 vCPUs

  ***nvcc***
  Cuda compilation tools, release 12.9, V12.9.86

  ***Python***
  cudf-cu12                        26.2.1
  cudf-polars-cu12                 26.2.1
  pylibcudf-cu12                   26.2.1
  rmm-cu12                         26.2.0
  polars                           1.35.2
  pandas                           2.3.3
  pyarrow                          23.0.1
  numpy                            2.2.6

I'll raise a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions