Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/release/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ DEPENDENCIES=(
dask-cuda
dask-cudf
cugraph
cuspatial
)
for DEP in "${DEPENDENCIES[@]}"; do
for FILE in dependencies.yaml conda/environments/*.yaml; do
Expand Down
1 change: 0 additions & 1 deletion conda/environments/all_cuda-118_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies:
- cudf==25.6.*,>=0.0.0a0
- cugraph==25.6.*,>=0.0.0a0
- cupy>=12.0.0
- cuspatial==25.6.*,>=0.0.0a0
- dask-cuda==25.6.*,>=0.0.0a0
- dask-cudf==25.6.*,>=0.0.0a0
- datashader>=0.15
Expand Down
1 change: 0 additions & 1 deletion conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies:
- cudf==25.6.*,>=0.0.0a0
- cugraph==25.6.*,>=0.0.0a0
- cupy>=12.0.0
- cuspatial==25.6.*,>=0.0.0a0
- dask-cuda==25.6.*,>=0.0.0a0
- dask-cudf==25.6.*,>=0.0.0a0
- datashader>=0.15
Expand Down
1 change: 0 additions & 1 deletion conda/environments/all_cuda-128_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
- cudf==25.6.*,>=0.0.0a0
- cugraph==25.6.*,>=0.0.0a0
- cupy>=12.0.0
- cuspatial==25.6.*,>=0.0.0a0
- dask-cuda==25.6.*,>=0.0.0a0
- dask-cudf==25.6.*,>=0.0.0a0
- datashader>=0.15
Expand Down
1 change: 0 additions & 1 deletion conda/environments/all_cuda-128_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
- cudf==25.6.*,>=0.0.0a0
- cugraph==25.6.*,>=0.0.0a0
- cupy>=12.0.0
- cuspatial==25.6.*,>=0.0.0a0
- dask-cuda==25.6.*,>=0.0.0a0
- dask-cudf==25.6.*,>=0.0.0a0
- datashader>=0.15
Expand Down
1 change: 0 additions & 1 deletion conda/recipes/cuxfilter/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ requirements:
- ${{ pin_compatible("cuda-version", upper_bound="x", lower_bound="x") }}
- cudf =${{ minor_version }}
- cupy >=12.0.0
- cuspatial =${{ minor_version }}
- dask-cudf =${{ minor_version }}
- datashader >=0.15
- geopandas >=0.11.0
Expand Down
7 changes: 0 additions & 7 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ dependencies:
packages:
- &cudf_unsuffixed cudf==25.6.*,>=0.0.0a0
- cupy>=12.0.0
- &cuspatial_unsuffixed cuspatial==25.6.*,>=0.0.0a0
- &dask_cudf_unsuffixed dask-cudf==25.6.*,>=0.0.0a0
- nodejs>=18
- libwebp-base
Expand All @@ -232,7 +231,6 @@ dependencies:
packages:
- cudf-cu12==25.6.*,>=0.0.0a0
- &cupy_cu12 cupy-cuda12x>=12.0.0
- cuspatial-cu12==25.6.*,>=0.0.0a0
- dask-cudf-cu12==25.6.*,>=0.0.0a0
- matrix:
cuda: "12.*"
Expand All @@ -242,15 +240,13 @@ dependencies:
# NOTE: cupy still has a "-cuda12x" suffix here, because it's suffixed
# in DLFW builds
- *cupy_cu12
- *cuspatial_unsuffixed
- *dask_cudf_unsuffixed
- matrix:
cuda: "11.*"
cuda_suffixed: "true"
packages:
- cudf-cu11==25.6.*,>=0.0.0a0
- &cupy_cu11 cupy-cuda11x>=12.0.0
- cuspatial-cu11==25.6.*,>=0.0.0a0
- dask-cudf-cu11==25.6.*,>=0.0.0a0
- matrix:
cuda: "11.*"
Expand All @@ -260,13 +256,11 @@ dependencies:
# NOTE: cupy still has a "-cuda11x" suffix here, because it's suffixed
# in DLFW builds
- *cupy_cu11
- *cuspatial_unsuffixed
- *dask_cudf_unsuffixed
- matrix:
packages:
- *cudf_unsuffixed
- *cupy_cu11
- *cuspatial_unsuffixed
- *dask_cudf_unsuffixed
test_python:
common:
Expand All @@ -283,7 +277,6 @@ dependencies:
- coverage
- *cudf_unsuffixed
- cupy>=12.0.0
- *cuspatial_unsuffixed
- *dask_cudf_unsuffixed
- cuxfilter==25.6.*,>=0.0.0a0
- python>=3.10,<3.13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"source": [
"### GPU Accelerated Interaction\n",
"\n",
"The below libraries directly use RAPIDS cuDF/Dask-cuDF and/or cuSpatial to create charts that support accelerated crossfiltering or rendering:\n",
"The below libraries directly use RAPIDS cuDF/Dask-cuDF to create charts that support accelerated crossfiltering or rendering:\n",
"- **[Holoviews with Linked Brushing](https://holoviews.org/user_guide/Linked_Brushing.html?highlight=linked%20brushing)**\n",
"- **[Datashader](https://datashader.org/user_guide/Performance.html)**\n",
"- **[Plotly Dash with Holoviews](https://dash.plotly.com/holoviews#gpu-accelerating-datashader-and-linked-selections-with-rapids)**\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"source": [
"# RAPIDS Visualization Guide Notebook\n",
"### A Streamlined Guide to RAPIDS Accelerated Visualization and Visual Analtyics\n",
"The guide will walk through using RAPIDS [cuDF](https://github.com/rapidsai/cudf), [cuSpatial](https://github.com/rapidsai/cuspatial), [cuML](https://github.com/rapidsai/cuml), [cuGraph](https://github.com/rapidsai/cugraph) and [cuxfilter](https://github.com/rapidsai/cuxfilter), with [hvPlot](https://hvplot.holoviz.org/), [Datashader](https://datashader.org/), and [Plotly Dash](https://github.com/plotly/dash) with the publicly available [Divvy Bike share dataset](https://divvybikes.com/system-data)."
"The guide will walk through using RAPIDS [cuDF](https://github.com/rapidsai/cudf), [cuML](https://github.com/rapidsai/cuml), [cuGraph](https://github.com/rapidsai/cugraph) and [cuxfilter](https://github.com/rapidsai/cuxfilter), with [hvPlot](https://hvplot.holoviz.org/), [Datashader](https://datashader.org/), and [Plotly Dash](https://github.com/plotly/dash) with the publicly available [Divvy Bike share dataset](https://divvybikes.com/system-data)."
]
},
{
Expand Down Expand Up @@ -69,7 +69,6 @@
" - cudf >= 23.06\n",
" - cuml >= 23.06\n",
" - cugraph >= 23.06\n",
" - cuspatial >= 23.06\n",
" - cuxfilter >= 23.06\n",
" - geoviews <= 1.9.6\n",
" - cupy\n",
Expand Down Expand Up @@ -103,7 +102,6 @@
"\n",
"# rapids etc\n",
"import cudf\n",
"import cuspatial\n",
"import cugraph\n",
"import cuml\n",
"import cuxfilter\n",
Expand Down Expand Up @@ -594,7 +592,7 @@
"id": "b04800a0-a1fc-443f-87a2-332e2b0ca6b7",
"metadata": {},
"source": [
"### Using cuSpatial"
"### Using cupy to calculate Haversine distance"
]
},
{
Expand All @@ -606,14 +604,29 @@
},
"outputs": [],
"source": [
"# Using cuSpatial, we can calculate distances from two points\n",
"# Create a cuSpatial GeoSeries from the latitude and longitude columns\n",
"start_points = cuspatial.GeoSeries.from_points_xy(df[['start_lng','start_lat']].interleave_columns().astype(\"float64\"))\n",
"end_points = cuspatial.GeoSeries.from_points_xy(df[['end_lng','end_lat']].interleave_columns().astype(\"float64\"))\n",
"def haversine_distance_cupy(lon1, lat1, lon2, lat2, earth_radius_km=6371.0):\n",
" \"\"\"\n",
" Calculate the Haversine distance between two sets of points.\n",
" \"\"\"\n",
" # Convert degrees to radians\n",
" lon1_rad = cupy.radians(lon1.values)\n",
" lat1_rad = cupy.radians(lat1.values)\n",
" lon2_rad = cupy.radians(lon2.values)\n",
" lat2_rad = cupy.radians(lat2.values)\n",
"\n",
" # Differences\n",
" dlon = lon2_rad - lon1_rad\n",
" dlat = lat2_rad - lat1_rad\n",
"\n",
" # Haversine formula\n",
" a = cupy.sin(dlat / 2)**2 + cupy.cos(lat1_rad) * cupy.cos(lat2_rad) * cupy.sin(dlon / 2)**2\n",
" c = 2 * cupy.arcsin(cupy.sqrt(a)) # Alternatively: 2 * cupy.arctan2(cupy.sqrt(a), cupy.sqrt(1 - a))\n",
" \n",
" distances_km = earth_radius_km * c\n",
" return distances_km\n",
"\n",
"# Calculate distance\n",
"distances_in_km = cuspatial.haversine_distance(start_points, end_points)\n",
"\n",
"distances_in_km = haversine_distance_cupy(df.start_lng, df.start_lat, df.end_lng, df.end_lat)\n",
"# Add the distances back into the dataframe, convert from KM to M, and rounding values to make it more obvious if the stopped at the same place it started\n",
"dist_m = cudf.Series(distances_in_km).values * 1000\n",
"df['dist_m'] = dist_m.round().astype('int32')\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/RAPIDS Visualization Guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Try a user guide notebook of an end-to-end RAPIDS visualization integrated workf
### The workflow includes integrated examples that use:
- cuDF for EDA
- cuML for KDE and Kmeans
- cuSpatial for Haversine Distance
- cupy for Haversine Distance
- cuGraph for FA2
- cuxfilter for cross-filtered bars, graph, and geospatial scatter charts
- hvPlot with bokeh, datashader, and panel for multiple chart types
Expand Down
190 changes: 177 additions & 13 deletions python/cuxfilter/charts/core/non_aggregate/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,177 @@
import cuspatial
from shapely.geometry import Polygon
import geopandas as gpd


def point_in_polygon(df, x, y, polygons):
points = cuspatial.GeoSeries.from_points_xy(
df[[x, y]].interleave_columns().astype("float64")
)
polygons = cuspatial.GeoSeries(
gpd.GeoSeries(Polygon(polygons)), index=["selection"]
)
return cuspatial.point_in_polygon(points, polygons).selection
from numba import cuda
from numba.core.errors import NumbaPerformanceWarning
import cupy as cp
import cudf
import warnings


# Define the CUDA kernel using numba.cuda.jit
# This kernel implements the ray casting algorithm
@cuda.jit(device=True)
def point_in_polygon_ray_cast(px, py, polygon_xy, num_vertices):
Comment thread
AjayThorve marked this conversation as resolved.
Resolved
"""
Check if a single point (px, py) is inside a polygon using ray casting.

This is a device function intended to be called from a CUDA kernel.

Parameters
----------
px : float
X-coordinate of the point.
py : float
Y-coordinate of the point.
polygon_xy : cupy.ndarray
Flat array of polygon vertices, interleaved [x0, y0, x1, y1, ...].
num_vertices : int
Number of vertices in the polygon.

Returns
-------
bool
True if the point is inside the polygon, False otherwise.
"""
intersections = 0
for j in range(num_vertices):
vjx = polygon_xy[2 * j]
vjy = polygon_xy[2 * j + 1]
# Get next vertex, wrapping around
j_plus_1 = (j + 1) % num_vertices
vj1x = polygon_xy[2 * j_plus_1]
vj1y = polygon_xy[2 * j_plus_1 + 1]

# Check if the horizontal ray crosses the edge (vj, vj1)
# Condition 1: Is the point's y-coordinate within the edge's y-range?
if (vjy <= py < vj1y) or (vj1y <= py < vjy):
# Condition 2: Is the edge not horizontal?
if vjy != vj1y:
# Calculate the x-coordinate of the intersection
x_intersection = vjx + (py - vjy) * (vj1x - vjx) / (vj1y - vjy)
# Condition 3: Is the intersection point to the right of
# the point?
if px < x_intersection:
intersections += 1

# Point is inside if the number of intersections is odd
return intersections % 2 == 1


@cuda.jit
def point_in_polygon_kernel(points_xy, polygon_xy, num_vertices, out):
"""
CUDA kernel to check an array of points against a single polygon.

Each thread checks one point.

Parameters
----------
points_xy : cupy.ndarray
Flat array of point coordinates, interleaved [px0, py0, px1, py1, ...].
polygon_xy : cupy.ndarray
Flat array of polygon vertices, interleaved [vx0, vy0, vx1, vy1, ...].
num_vertices : int
Number of vertices in the polygon.
out : cupy.ndarray
Output boolean array. out[i] is True if points_xy[2*i:2*i+2] is
inside the polygon.
"""
i = cuda.grid(1) # Global thread index

# Check if index is within bounds (number of points)
if i < points_xy.shape[0] // 2:
px = points_xy[2 * i]
py = points_xy[2 * i + 1]

# Call the device function for the actual check
out[i] = point_in_polygon_ray_cast(px, py, polygon_xy, num_vertices)


def point_in_polygon(df, x, y, polygon_coords):
"""
Checks which points in a DataFrame are inside a given polygon using a CUDA
kernel.

Parameters
----------
df : cudf.DataFrame
DataFrame containing the points.
x : str
Column name for the x-coordinates of the points.
y : str
Column name for the y-coordinates of the points.
polygon_coords : list of tuples or similar array-like
Coordinates of the polygon vertices, e.g., [(x1, y1), (x2, y2), ...].
The polygon should be closed.

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.

"closed" -- does this mean that the last vertex coordinates must be equal to the first vertex coordinates -- or that it assumes there is a line segment between the last and first vertex?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, closed here in this context means first and last vertex coordinates must be equal. The way lasso selection is setup in cuxfilter, the polygon will always be closed.

output dashboard


Returns
-------
cudf.Series
A boolean Series indicating whether each point is inside the polygon.
"""
if not isinstance(df, cudf.DataFrame):
raise TypeError("Input 'df' must be a cudf.DataFrame")

# 1. Prepare point data
num_points = len(df)
if num_points == 0:
return cudf.Series([], dtype="bool", index=df.index)

# Interleave columns directly using cudf and get cupy array
# .values returns a cupy array for cudf Series/DataFrame
points_xy_cp = df[[x, y]].astype(cp.float64).interleave_columns().values

# 2. Prepare polygon data
try:
# Directly create cupy array from polygon_coords
polygon_xy_cp = cp.array(polygon_coords, dtype=cp.float64)

# Flatten if it's a list of pairs (N, 2)
if polygon_xy_cp.ndim == 2 and polygon_xy_cp.shape[1] == 2:
polygon_xy_cp = polygon_xy_cp.flatten()
elif polygon_xy_cp.ndim != 1:
raise ValueError(
"Polygon coordinates must be list of pairs or flat list."
)

# Validate size
if polygon_xy_cp.size % 2 != 0:
raise ValueError(
"Polygon coordinates must have an even number of elements."
)

num_vertices = polygon_xy_cp.size // 2

if num_vertices < 3:
raise ValueError("Polygon must have at least 3 vertices.")

except (ValueError, TypeError):
# Handle invalid polygon formats or insufficient vertices
# Return all False as per the check at the start
if isinstance(df.index, cudf.MultiIndex):
idx = cudf.RangeIndex(len(df))
else:
idx = df.index
return cudf.Series(cp.zeros(len(df), dtype=cp.bool_), index=idx)

# 3. Prepare output array
out_gpu = cp.zeros(num_points, dtype=cp.bool_)

# 4. Configure and launch kernel
threads_per_block = 256
blocks_per_grid = (
num_points + (threads_per_block - 1)
) // threads_per_block

if blocks_per_grid > 0:
# Suppress NumbaPerformanceWarning for low grid size in tests
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=NumbaPerformanceWarning,
message="Grid size.*result in GPU under-utilization",
)
point_in_polygon_kernel[blocks_per_grid, threads_per_block](
points_xy_cp, polygon_xy_cp, num_vertices, out_gpu
)

# 5. Return result as cudf.Series, preserving original index
return cudf.Series(out_gpu, index=df.index)
Loading