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

Benchmark GeoSeries.distance #1242

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5672d5a
Merge pull request #118 from rapidsai/branch-0.12
raydouglass Feb 4, 2020
ce35d17
REL v0.12.0 release
GPUtester Feb 4, 2020
bcc7561
Update CHANGELOG.md
raydouglass Mar 31, 2020
128eed9
Merge pull request #152 from rapidsai/branch-0.13
raydouglass Mar 31, 2020
12ee694
REL v0.13.0 release
GPUtester Mar 31, 2020
d3c5a00
Merge pull request #230 from rapidsai/branch-0.14
raydouglass Jun 3, 2020
f6847fa
REL v0.14.0 release
GPUtester Jun 3, 2020
86e41dd
update master references
ajschmidt8 Jul 14, 2020
46e67c9
REL DOC Updates for main branch switch
mike-wendt Jul 16, 2020
1628b97
Merge pull request #276 from rapidsai/branch-0.15
raydouglass Aug 26, 2020
274275a
REL v0.15.0 release
GPUtester Aug 26, 2020
a3d6f3d
Merge pull request #282 from rapidsai/branch-0.15
raydouglass Aug 27, 2020
c5b7527
REL v0.15.0 release
GPUtester Aug 27, 2020
c337b32
Update CHANGELOG.md
raydouglass Oct 21, 2020
2d7e7d7
Merge pull request #311 from rapidsai/branch-0.16
raydouglass Oct 21, 2020
096f468
REL v0.16.0 release
GPUtester Oct 21, 2020
9aeebc8
Update CHANGELOG.md
raydouglass Dec 10, 2020
eb3096c
Merge pull request #330 from rapidsai/branch-0.17
ajschmidt8 Dec 10, 2020
897b304
REL v0.17.0 release
GPUtester Dec 10, 2020
c4ff738
Merge pull request #360 from rapidsai/branch-0.18
raydouglass Feb 24, 2021
f4da460
REL v0.18.0 release
GPUtester Feb 24, 2021
45e7b87
Merge pull request #380 from rapidsai/branch-0.19
raydouglass Apr 21, 2021
df1d93c
REL v0.19.0 release
GPUtester Apr 21, 2021
b5e0810
Merge pull request #409 from rapidsai/branch-21.06
raydouglass Jun 9, 2021
37798cd
REL v21.06.00 release
GPUtester Jun 9, 2021
4ed3e98
Merge pull request #417 from rapidsai/branch-21.06
ajschmidt8 Jun 10, 2021
5119e15
Merge pull request #439 from rapidsai/branch-21.08
raydouglass Aug 4, 2021
b8590f9
REL v21.08.00 release
GPUtester Aug 4, 2021
c4f0725
Merge pull request #442 from rapidsai/branch-21.08
raydouglass Aug 6, 2021
7c0151b
REL v21.08.01 release
GPUtester Aug 6, 2021
7ce6993
Merge pull request #456 from rapidsai/branch-21.10
ajschmidt8 Oct 6, 2021
ba20298
REL v21.10.00 release
GPUtester Oct 6, 2021
32782d8
Merge pull request #469 from rapidsai/branch-21.12
raydouglass Dec 9, 2021
ab6748f
REL v21.12.00 release
GPUtester Dec 9, 2021
13147b2
Merge pull request #484 from rapidsai/branch-22.02
raydouglass Feb 2, 2022
f5b48fc
REL v22.02.00 release
GPUtester Feb 2, 2022
09cfbe3
Merge pull request #509 from rapidsai/branch-22.04
raydouglass Apr 6, 2022
e8f9f84
REL v22.04.00 release
GPUtester Apr 6, 2022
24e3d39
Merge pull request #551 from rapidsai/branch-22.06
raydouglass Jun 7, 2022
96613ba
REL v22.06.00 release
GPUtester Jun 7, 2022
5ea1978
Merge pull request #634 from rapidsai/branch-22.08
raydouglass Aug 17, 2022
125c3c2
REL v22.08.00 release
GPUtester Aug 17, 2022
38e7d0c
Merge pull request #735 from rapidsai/branch-22.10
raydouglass Oct 12, 2022
4e13a37
REL v22.10.00 release
GPUtester Oct 12, 2022
defef45
Merge pull request #833 from rapidsai/branch-22.12
raydouglass Dec 12, 2022
56570d9
REL v22.12.00 release
GPUtester Dec 12, 2022
81b189d
Merge pull request #899 from rapidsai/branch-23.02
raydouglass Feb 9, 2023
6fe3841
REL v23.02.00 release
raydouglass Feb 9, 2023
54a7633
Merge pull request #1047 from rapidsai/branch-23.04
raydouglass Apr 12, 2023
6958dcb
REL v23.04.00 release
raydouglass Apr 12, 2023
71781ff
REL Merge pull request #1118 from rapidsai/branch-23.04
raydouglass May 3, 2023
564db10
Merge pull request #1172 from rapidsai/branch-23.06
raydouglass Jun 7, 2023
e9b3d7e
Merge pull request #1188 from rapidsai/branch-23.06
raydouglass Jun 7, 2023
7b3284a
REL v23.06.00 release
raydouglass Jun 7, 2023
49c2ff7
add distance method test
isVoid Jul 26, 2023
f606ef0
Add implementations of `distance_dispatch`
isVoid Jul 26, 2023
b84a8a2
Deal with geoseries that has unmatched indices
isVoid Jul 26, 2023
e6d5d36
Refine example in docstring
isVoid Jul 26, 2023
3ac2da0
support distance to a single shapely object
isVoid Jul 26, 2023
0c73fca
refine document
isVoid Jul 26, 2023
cabdb0e
Address review comments
isVoid Jul 27, 2023
79a550f
Add point-point distance benchmark
isVoid Jul 28, 2023
292b6bb
add linestring-polygon distance benchmark
isVoid Jul 31, 2023
644aba5
Merge branch 'branch-23.08' of https://github.com/rapidsai/cuspatial …
isVoid Jul 31, 2023
ae97c3c
Add all geometry combination tests
isVoid Aug 1, 2023
9c09c99
Update benchmarking config
isVoid Aug 7, 2023
8da018a
Add numba polygon generator
isVoid Aug 7, 2023
63c0a31
Merge branch 'branch-23.10' of https://github.com/rapidsai/cuspatial …
isVoid Aug 7, 2023
326b499
[skip ci]update polygon generator to add centroid randomness
isVoid Aug 8, 2023
5b89064
Reuse polygon generator for linestring generator to add linestring lo…
isVoid Aug 8, 2023
61ae461
update polygon generator with radius parameter, update linestring dis…
isVoid Aug 8, 2023
216c68b
Merge pull request #1252 from rapidsai/branch-23.08
raydouglass Aug 9, 2023
d8a31ee
REL v23.08.00 release
raydouglass Aug 9, 2023
150a566
Merge pull request #1256 from rapidsai/branch-23.08
raydouglass Aug 10, 2023
2660aba
REL v23.08.01 release
raydouglass Aug 10, 2023
54e87d9
Merge branch 'branch-23.10' of https://github.com/rapidsai/cuspatial …
isVoid Sep 27, 2023
e371e89
Merge branch 'main' of https://github.com/rapidsai/cuspatial into fea…
isVoid Sep 28, 2023
ce6dfc8
revert rename to benchmarks that's not touched
isVoid Sep 28, 2023
37a1bc8
Merge branch 'branch-23.10' into feature/distance_benchmark
isVoid Oct 3, 2023
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
141 changes: 138 additions & 3 deletions python/cuspatial/benchmarks/api/bench_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2022, NVIDIA CORPORATION.

# Copyright (c) 2022-2023, NVIDIA CORPORATION.
import cupy
import geopandas
import pytest

import cudf

Expand Down Expand Up @@ -125,7 +125,7 @@ def bench_haversine_distance(benchmark, gpu_dataframe):
benchmark(cuspatial.haversine_distance, points_first, points_second)


def bench_pairwise_linestring_distance(benchmark, gpu_dataframe):
def bench_distance_pairwise_linestring(benchmark, gpu_dataframe):
geometry = gpu_dataframe["geometry"]
benchmark(
cuspatial.pairwise_linestring_distance,
Expand Down Expand Up @@ -293,3 +293,138 @@ def bench_point_in_polygon(benchmark, polygons):
short_dataframe = polygons.iloc[0:31]
geometry = short_dataframe["geometry"]
benchmark(cuspatial.point_in_polygon, points, geometry)


# GeoSeries.distance benchmarking.


@pytest.mark.parametrize("align", [True, False])
@pytest.mark.parametrize("n", [1e3, 1e4, 1e5, 1e6, 1e7])
@pytest.mark.parametrize("lib", ["cuspatial", "geopandas"])
def bench_distance_point(benchmark, lib, point_generator_device, n, align):
points = point_generator_device(int(n))
other_points = point_generator_device(int(n))
index = cudf.Index(cupy.arange(len(other_points) - 1, -1, -1))

if lib == "geopandas":
points = points.to_geopandas()
other_points = other_points.to_geopandas()
index = index.to_pandas()

other_points.index = index
benchmark(points.distance, other_points, align)


@pytest.mark.parametrize("align", [True, False])
@pytest.mark.parametrize("n", [1e3, 1e4, 1e5, 1e6, 1e7])
@pytest.mark.parametrize("lib", ["cuspatial", "geopandas"])
def bench_distance_point_linestring(
benchmark,
point_generator_device,
linestring_generator_device,
lib,
n,
align,
):
points = point_generator_device(int(n))
linestrings = linestring_generator_device(int(n), 20)
index = cudf.Index(cupy.arange(len(linestrings) - 1, -1, -1))

if lib == "geopandas":
points = points.to_geopandas()
linestrings = linestrings.to_geopandas()
index = index.to_pandas()

linestrings.index = index
benchmark(points.distance, linestrings, align)


@pytest.mark.parametrize("align", [True, False])
@pytest.mark.parametrize("n", [1e3, 1e4, 1e5, 1e6, 1e7])
@pytest.mark.parametrize("lib", ["cuspatial", "geopandas"])
def bench_distance_point_polygon(
benchmark, point_generator_device, polygon_generator_device, lib, n, align
):
points = point_generator_device(int(n))
polygons = polygon_generator_device(int(n), 38)
index = cudf.Index(cupy.arange(len(polygons) - 1, -1, -1))

if lib == "geopandas":
points = points.to_geopandas()
polygons = polygons.to_geopandas()
index = index.to_pandas()

polygons.index = index
benchmark(points.distance, polygons, align)


@pytest.mark.parametrize("align", [True, False])
@pytest.mark.parametrize("n", [1e3, 1e4, 1e5, 1e6, 1e7])
@pytest.mark.parametrize("lib", ["cuspatial", "geopandas"])
def bench_distance_linestring_linestring(
benchmark, linestring_generator_device, lib, n, align
):
lines1 = linestring_generator_device(int(n), 20)
lines2 = linestring_generator_device(int(n), 20)
index = cudf.Index(cupy.arange(len(lines1) - 1, -1, -1))

if lib == "geopandas":
lines1 = lines1.to_geopandas()
lines2 = lines2.to_geopandas()
index = index.to_pandas()

lines1.index = index
benchmark(lines1.distance, lines2, align)


@pytest.mark.parametrize("align", [True, False])
@pytest.mark.parametrize("n", [1e3, 1e4, 1e5, 1e6, 1e7])
@pytest.mark.parametrize("lib", ["cuspatial", "geopandas"])
@pytest.mark.parametrize(
"num_segments, num_sides", [(5, 5), (20, 38), (100, 100), (1000, 1000)]
)
def bench_distance_linestring_polygon(
benchmark,
lib,
linestring_generator_device,
polygon_generator_device,
n,
align,
num_segments,
num_sides,
):
lines = linestring_generator_device(int(n), num_segments)
polygons = polygon_generator_device(int(n), num_sides)
index = cudf.Index(cupy.arange(len(lines) - 1, -1, -1))

if lib == "geopandas":
lines = lines.to_geopandas()
polygons = polygons.to_geopandas()
index = index.to_pandas()

lines.index = index
benchmark(lines.distance, polygons, align)


@pytest.mark.parametrize("align", [True, False])
@pytest.mark.parametrize("n", [1e3, 1e4, 1e5, 1e6, 1e7])
@pytest.mark.parametrize("lib", ["cuspatial", "geopandas"])
@pytest.mark.parametrize("intersects", [True, False])
def bench_distance_polygon(
benchmark, lib, polygon_generator_device, n, align, intersects
):
polygons1 = polygon_generator_device(
int(n), 38, radius=1.0, all_concentric=True
)
polygons2 = polygon_generator_device(
int(n), 38, radius=0.5, all_concentric=True
)
index = cudf.Index(cupy.arange(len(polygons1) - 1, -1, -1))

if lib == "geopandas":
polygons1 = polygons1.to_geopandas()
polygons2 = polygons2.to_geopandas()
index = index.to_pandas()

polygons1.index = index
benchmark(polygons1.distance, polygons2, align)
85 changes: 84 additions & 1 deletion python/cuspatial/benchmarks/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2023, NVIDIA CORPORATION.

"""Defines pytest fixtures for all benchmarks.

Expand All @@ -11,7 +11,9 @@
import geopandas as gpd
import numpy as np
import pandas as pd
import pytest
import pytest_cases
from numba import cuda
from shapely.geometry import (
LineString,
MultiLineString,
Expand Down Expand Up @@ -176,3 +178,84 @@ def shapefile(tmp_path, gpdf_100):
p = d / "read_polygon_shapefile"
gpdf_100.to_file(p)
return p


@pytest.fixture()
def point_generator_device():
def generator(n):
coords = cp.random.random(n * 2, dtype="f8")
return cuspatial.GeoSeries.from_points_xy(coords)

return generator


# Numba kernel to generate a closed ring for each polygon
@cuda.jit
def generate_polygon_coordinates(
coordinate_array, centroids, radius, num_vertices
):
i = cuda.grid(1)
if i >= coordinate_array.size:
return

point_idx = i // 2
geometry_idx = point_idx // (num_vertices + 1)

# The last index should wrap around to 0
intra_point_idx = point_idx % (num_vertices + 1)

centroid = centroids[geometry_idx]
angle = 2 * np.pi * intra_point_idx / num_vertices

if i % 2 == 0:
coordinate_array[i] = centroid[0] + radius * np.cos(angle)
else:
coordinate_array[i] = centroid[1] + radius * np.sin(angle)


@pytest.fixture()
def polygon_generator_device():
def generator(n, num_vertices, radius=1.0, all_concentric=False):
geometry_offsets = cp.arange(n + 1)
part_offsets = cp.arange(n + 1)

# Each polygon has a closed ring, so we need to add an extra point
ring_offsets = cp.arange(
(n + 1) * (num_vertices + 1), step=(num_vertices + 1)
)
num_points = int(ring_offsets[-1].get())

if not all_concentric:
centroids = cp.random.random((n, 2))
else:
centroids = cp.zeros((n, 2))
coords = cp.ndarray((num_points * 2,), dtype="f8")
generate_polygon_coordinates.forall(len(coords))(
coords, centroids, radius, num_vertices
)
return cuspatial.GeoSeries.from_polygons_xy(
coords, ring_offsets, part_offsets, geometry_offsets
)

return generator


@pytest.fixture()
def linestring_generator_device(polygon_generator_device):
"""Reusing polygon_generator_device, treating the rings of the
generated polygons as linestrings. This is to gain locality to
the generated linestrings.
"""

def generator(n, segment_per_linestring):
polygons = polygon_generator_device(
n, segment_per_linestring, all_concentric=False
)

return cuspatial.GeoSeries.from_linestrings_xy(
polygons.polygons.xy,
polygons.polygons.ring_offset,
polygons.polygons.geometry_offset,
)

return generator