cuDF
Run the overview's pandas pipeline on a GPU with cudf.pandas, compare it with pandas and Polars, and see which operations fell back to the CPU.
This is the first hands-on lab in the RAPIDS series. The pipeline is the one already timed there: filter a year of card transactions, roll them up by account and month, join the account master, and rank branches. The script stays pandas. cudf.pandas sends the supported calls to the GPU.
The published timing on our lab server (Intel Xeon Gold 5420+, NVIDIA A2 16 GB, cuDF 26.10.00, CUDA 13, driver 580) is 60.68 s in pandas and 6.10 s on a warm GPU run. This lab is how you reproduce that run, read the profiler, and add a Polars column of your own. Do not quote the first GPU run: kernel compilation made that pass 14.94 s.
Prerequisites
- Linux with an NVIDIA GPU, Volta or newer, and a driver from the 535 series (CUDA 12) or the 580 series (CUDA 13). 16 GB of GPU memory is the practical minimum for the full files.
- Podman or Docker. The lab image is
rapidsai/notebooks:26.10-cuda13-py3.12. - For the OpenShift section: a cluster with the NVIDIA GPU Operator advertising
nvidia.com/gpu, as in the overview. Ours is OpenShift 4.22 with GPU Operator 26.7.2.
Check the card before you time anything:
nvidia-smi
python3 --version # 3.11 to 3.14; this lab uses 3.12
Install
Three equivalent environments. Use the container unless you already manage CUDA on the machine.
# Container, CUDA 13
podman run --rm -it --device nvidia.com/gpu=all \
-v "$PWD:/work:Z" -w /work \
--entrypoint bash \
docker.io/rapidsai/notebooks:26.10-cuda13-py3.12
# pip, outside a container. The cu13 packages must match the driver.
pip install --extra-index-url=https://pypi.nvidia.com \
"cudf-cu13==26.10.*" "dask-cudf-cu13==26.10.*"
# conda
conda create -n rapids-26.10 -c rapidsai -c conda-forge -c nvidia \
rapids=26.10 python=3.12 cuda-version=13.0
Docker uses --gpus all instead of --device nvidia.com/gpu=all. On OpenShift AI, the same notebooks image is the workbench image; the OpenShift AI series covers the workbench.
The pipeline
Save this as pipeline.py. It is the overview script, with timings around each stage. Point TX and ACC at the Parquet files (50 million transactions, 5 million accounts, about 1.3 GB). A fixed seed generated them; nothing in the files is real.
import os
import time
import pandas as pd
TX = os.environ.get("TX", "transactions.parquet")
ACC = os.environ.get("ACC", "accounts.parquet")
def stage(name, fn):
t = time.perf_counter()
out = fn()
print(f"{name:48} {time.perf_counter() - t:7.2f} s", flush=True)
return out
tx = stage("read", lambda: pd.read_parquet(TX))
acc = stage("read accounts", lambda: pd.read_parquet(ACC))
tx = stage("filter", lambda: tx[(tx["status"] == "posted") & (tx["amount"] > 0)])
tx = stage("month", lambda: tx.assign(month=tx["ts"].dt.year * 100 + tx["ts"].dt.month))
monthly = stage("groupby account", lambda: tx.groupby(["account_id", "month"], as_index=False).agg(
spend=("amount", "sum"), transactions=("tx_id", "count")))
enriched = stage("join", lambda: monthly.merge(acc, on="account_id", how="inner"))
branches = stage("groupby branch", lambda: enriched.groupby(
["branch_id", "segment", "month"], as_index=False).agg(
spend=("spend", "sum"), accounts=("account_id", "nunique")))
top = stage("rank", lambda: branches.sort_values(["month", "spend"], ascending=[True, False])
.groupby("month").head(5))
print("rows", len(top), "spend", round(float(top["spend"].sum()), 2))
assign returns a new frame, so the month step is written that way on purpose: a column write on a slice can fall back or warn. Sort the result before you compare two engines. GPU joins do not keep pandas row order.
Run it three ways, and warm the GPU before you write down a number:
python pipeline.py # pandas, one core
python -m cudf.pandas pipeline.py # first GPU run compiles kernels
python -m cudf.pandas pipeline.py # quote this one
In a notebook the accelerator is %load_ext cudf.pandas, imported before pandas.
| Stage | pandas on the lab server | GPU, warm |
|---|---|---|
| Whole pipeline | 60.68 s | 6.10 s |
| Group 46.5 million rows | 29.24 s | 1.27 s |
| Sort and rank 31,200 rows | 0.01 s | 0.07 s |
The last row is the point of the lab. Below a few hundred thousand rows the copy costs more than the work. The full stage table is in the overview.
Polars on all cores
pandas on one core is the honest notebook comparison, not the fastest CPU option. Add Polars on every core of the same machine and keep the number you measure. We have not published a Polars time.
pip install polars
import time, polars as pl
t = time.perf_counter()
top = (
pl.scan_parquet("transactions.parquet")
.filter((pl.col("status") == "posted") & (pl.col("amount") > 0))
.with_columns((pl.col("ts").dt.year() * 100 + pl.col("ts").dt.month()).alias("month"))
.group_by("account_id", "month")
.agg(pl.col("amount").sum().alias("spend"), pl.len().alias("transactions"))
.join(pl.scan_parquet("accounts.parquet"), on="account_id", how="inner")
.group_by("branch_id", "segment", "month")
.agg(pl.col("spend").sum(), pl.col("account_id").n_unique().alias("accounts"))
.sort(["month", "spend"], descending=[False, True])
.collect() # GPU: .collect(engine=pl.GPUEngine(raise_on_fail=True))
)
print(f"polars {time.perf_counter() - t:.2f} s, rows {top.height}")
raise_on_fail=True refuses a silent CPU fallback, which is what you want while timing. Install it with pip install "polars[gpu]". The GPU engine is still marked Open Beta in the 26.10 line.
What fell back
A single unsupported call copies the frame to host memory and back. Find it before you tune anything else.
python -m cudf.pandas --line-profile pipeline.py
In a notebook, %%cudf.pandas.profile prints GPU and CPU time per function. From a script, cudf.pandas.install() and then with Profiler() as profiler from cudf.pandas.profiler, finishing with profiler.print_per_function_stats().
Native cuDF is worth it when you cannot accept a fallback. The methods match pandas, the import does not:
import cudf
tx = cudf.read_parquet("transactions.parquet")
Use cudf.pandas for a script you already have. Use import cudf when an unsupported operation should fail instead of copying back to the host.
Files, memory, and more than one GPU
Prefer Parquet. A CSV of the same table parses as text and is slower to get onto the device. Inside the Parquet, fewer files with row groups around 128 MB beat thousands of tiny files. cudf.read_parquet reads into GPU memory; you do not stage a pandas frame first.
cudf.pandas uses a managed memory pool by default (CUDF_PANDAS_RMM_MODE=managed_pool), so a dataset larger than the card can run, more slowly, instead of falling back to pandas. pool stays in device memory and fails when the working set does not fit. cuda is device memory with no pool, which is how allocation shows up in a profile. Watch nvidia-smi during the group-by. If the process is killed, cut the input by month or move to Dask.
One A2 is what this lab server has. A second card is the same script under Dask. LocalCUDACluster() starts one worker per visible GPU:
from dask_cuda import LocalCUDACluster
from dask.distributed import Client
import dask_cudf
client = Client(LocalCUDACluster())
tx = dask_cudf.read_parquet("transactions.parquet")
On OpenShift the pod asks for the card. One GPU is enough.
apiVersion: batch/v1
kind: Job
metadata:
name: cudf-pipeline
namespace: rapids
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: cudf
image: docker.io/rapidsai/notebooks:26.10-cuda13-py3.12
command: ["python", "-m", "cudf.pandas", "/work/pipeline.py"]
env:
- { name: TX, value: /data/transactions.parquet }
- { name: ACC, value: /data/accounts.parquet }
resources:
limits:
nvidia.com/gpu: "1"
volumeMounts:
- { name: data, mountPath: /data }
volumes:
- name: data
persistentVolumeClaim:
claimName: rapids-data
oc new-project rapids
oc apply -f job.yaml
oc logs job/cudf-pipeline -f
Copy the Parquet onto the PVC first (oc rsync into a pod that mounts it). The job stays Pending if no node advertises nvidia.com/gpu.
What's next
- cuDF plugin for Apache Spark: the same roll-up as a Spark job, one GPU per executor.
- cuML: an XGBoost model on the account features this pipeline produces.