Skip to content

Commit

Permalink
Branch 23.06 merge 23.04 (#1021)
Browse files Browse the repository at this point in the history
* Implement `geom_equals` and binary predicates that depend only on it. (#926)

This PR implements binary predicates that depend only on equality, which is implemented here using columnar comparison in python.

I'm playing with benchmarks of this feature now. On only Point geometries, we begin to outperform geopandas at 50k points, with 60x performance at 10m points.

Authors:
  - H. Thomson Comer (https://github.com/thomcom)

Approvers:
  - Michael Wang (https://github.com/isVoid)

URL: #926

* Add python API `pairwise_point_polygon_distance` (#988)

This PR closes #756 , add `pairwise_point_polygon_distance` for python.

Depend on #984 #976

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - H. Thomson Comer (https://github.com/thomcom)

URL: #988

* Add `dependency-file-generator` as `pre-commit` hook (#1008)

Similarly to these [cudf](rapidsai/cudf#12819) and [cuml](rapidsai/cuml#5246) PRs, this PR adds an entry to `.pre-commit-config.yaml` to run the [dependency-file-generator](https://github.com/rapidsai/dependency-file-generator).

It also adds an argument to the `rapidsai/shared-action-workflows/.github/workflows/checks.yaml` shared workflow to disable the `dependency-file-generator` from running in that shared workflow. This avoids having the `dependency-file-generator` run in two places since pre-commit is run in CI [here](https://github.com/rapidsai/cuspatial/blob/branch-23.04/ci/check_style.sh#L23).

Authors:
  - AJ Schmidt (https://github.com/ajschmidt8)

Approvers:
  - Ray Douglass (https://github.com/raydouglass)

URL: #1008

* Add ZipCode Counting Notebook (#919)

This PR adds a notebook that demonstrate the use of quadtree PiP with a custom `QuadTree` structure and joins dataframe. We can use this PR to discuss the possibility of adding the custom structure to the codebase.

This also updates the dependency list to include notebook environment in "all" targeted conda envs.

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - H. Thomson Comer (https://github.com/thomcom)
  - Mark Harris (https://github.com/harrism)
  - AJ Schmidt (https://github.com/ajschmidt8)

URL: #919

* Header-only `quadtree_point_in_polygon` (#979)

Closes #985 

Also contains cleanup of docs for other spatial join functions, correct ordering of stream and MR parameters, and adds missing C++17 property from tests cmake configuration.

Authors:
  - Mark Harris (https://github.com/harrism)

Approvers:
  - Michael Wang (https://github.com/isVoid)
  - Paul Taylor (https://github.com/trxcllnt)

URL: #979

* Reduce gtest times (#1018)

Fixes #1017. 

Reduces C++ gtest total time (on my PC) from 47.9 seconds to 20.08 seconds.

Several tests were running large datasets and combinations of size parameters that would be better to run as benchmarks rather than gtests. Reducing these by a factor of 10-100 saves a lot of development time and still exercises the code. In the case of `HausdorffTest/1.10000Spaces10Points (4850 ms)`, reducing it to 1000 spaces, 10 points reduced the time by nearly 100x, likely because it's $O(N^2)$. 

I modified any test that used close to 1s or more total time, since most column-API tests use under that, and most header-only tests use under 0.2s. 


| Test | Time Before (s) | Time After (s)  | Speedup |
|---|---|---|---|
| DERIVE_TRAJECTORIES_TEST_EXP | 14.49 | 0.27 | 53.7x |
| HAUSDORFF_TEST_EXP | 9.21 | 0.26 | 35.4x |
| UTILITY_TEST | 1.86 | 0.30 | 6.2x |
|  POINT_BOUNDING_BOXES_TEST_EXP | 1.35 | 0.15 | 9x |
| TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_EXP | 0.80 | 0.13 | 6.2x |
| TOTAL | 47.9 | 20.08 | 2.4x |


Before:

```
(rapids) coder ➜ ~/cuspatial/cpp/build/release $ ninja test
[0/1] Running tests...
Test project /home/coder/cuspatial/cpp/build/release
      Start  1: SINUSOIDAL_PROJECTION_TEST
 1/45 Test  #1: SINUSOIDAL_PROJECTION_TEST .................   Passed    0.81 sec
      Start  2: HAVERSINE_TEST
 2/45 Test  #2: HAVERSINE_TEST .............................   Passed    0.77 sec
      Start  3: HAUSDORFF_TEST
 3/45 Test  #3: HAUSDORFF_TEST .............................   Passed    0.75 sec
      Start  4: JOIN_POINT_TO_LINESTRING_SMALL_TEST
 4/45 Test  #4: JOIN_POINT_TO_LINESTRING_SMALL_TEST ........   Passed    0.73 sec
      Start  5: JOIN_POINT_IN_POLYGON_TEST
 5/45 Test  #5: JOIN_POINT_IN_POLYGON_TEST .................   Passed    0.79 sec
      Start  6: POINT_IN_POLYGON_TEST
 6/45 Test  #6: POINT_IN_POLYGON_TEST ......................   Passed    0.80 sec
      Start  7: PAIRWISE_POINT_IN_POLYGON_TEST
 7/45 Test  #7: PAIRWISE_POINT_IN_POLYGON_TEST .............   Passed    0.76 sec
      Start  8: POINT_QUADTREE_TEST
 8/45 Test  #8: POINT_QUADTREE_TEST ........................   Passed    0.76 sec
      Start  9: LINESTRING_BOUNDING_BOXES_TEST
 9/45 Test  #9: LINESTRING_BOUNDING_BOXES_TEST .............   Passed    0.76 sec
      Start 10: POLYGON_BOUNDING_BOXES_TEST
10/45 Test #10: POLYGON_BOUNDING_BOXES_TEST ................   Passed    0.80 sec
      Start 11: POINT_DISTANCE_TEST
11/45 Test #11: POINT_DISTANCE_TEST ........................   Passed    0.79 sec
      Start 12: POINT_LINESTRING_DISTANCE_TEST
12/45 Test #12: POINT_LINESTRING_DISTANCE_TEST .............   Passed    0.78 sec
      Start 13: LINESTRING_DISTANCE_TEST
13/45 Test #13: LINESTRING_DISTANCE_TEST ...................   Passed    0.78 sec
      Start 14: POINT_POLYGON_DISTANCE_TEST
14/45 Test #14: POINT_POLYGON_DISTANCE_TEST ................   Passed    0.76 sec
      Start 15: LINESTRING_INTERSECTION_TEST
15/45 Test #15: LINESTRING_INTERSECTION_TEST ...............   Passed    0.83 sec
      Start 16: POINT_LINESTRING_NEAREST_POINT_TEST
16/45 Test #16: POINT_LINESTRING_NEAREST_POINT_TEST ........   Passed    0.77 sec
      Start 17: QUADTREE_POLYGON_FILTERING_TEST
17/45 Test #17: QUADTREE_POLYGON_FILTERING_TEST ............   Passed    0.79 sec
      Start 18: QUADTREE_LINESTRING_FILTERING_TEST
18/45 Test #18: QUADTREE_LINESTRING_FILTERING_TEST .........   Passed    0.76 sec
      Start 19: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST
19/45 Test #19: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST .......   Passed    0.79 sec
      Start 20: DERIVE_TRAJECTORIES_TEST
20/45 Test #20: DERIVE_TRAJECTORIES_TEST ...................   Passed    0.76 sec
      Start 21: TRAJECTORY_BOUNDING_BOXES_TEST
21/45 Test #21: TRAJECTORY_BOUNDING_BOXES_TEST .............   Passed    0.75 sec
      Start 22: SPATIAL_WINDOW_POINT_TEST
22/45 Test #22: SPATIAL_WINDOW_POINT_TEST ..................   Passed    0.75 sec
      Start 23: UTILITY_TEST
23/45 Test #23: UTILITY_TEST ...............................   Passed    1.86 sec
      Start 24: HAVERSINE_TEST_EXP
24/45 Test #24: HAVERSINE_TEST_EXP .........................   Passed    0.14 sec
      Start 25: POINT_DISTANCE_TEST_EXP
25/45 Test #25: POINT_DISTANCE_TEST_EXP ....................   Passed    0.11 sec
      Start 26: POINT_LINESTRING_DISTANCE_TEST_EXP
26/45 Test #26: POINT_LINESTRING_DISTANCE_TEST_EXP .........   Passed    0.11 sec
      Start 27: POINT_POLYGON_DISTANCE_TEST_EXP
27/45 Test #27: POINT_POLYGON_DISTANCE_TEST_EXP ............   Passed    0.13 sec
      Start 28: HAUSDORFF_TEST_EXP
28/45 Test #28: HAUSDORFF_TEST_EXP .........................   Passed    9.21 sec
      Start 29: LINESTRING_DISTANCE_TEST_EXP
29/45 Test #29: LINESTRING_DISTANCE_TEST_EXP ...............   Passed    0.17 sec
      Start 30: LINESTRING_INTERSECTION_TEST_EXP
30/45 Test #30: LINESTRING_INTERSECTION_TEST_EXP ...........   Passed    0.19 sec
      Start 31: POINT_LINESTRING_NEAREST_POINT_TEST_EXP
31/45 Test #31: POINT_LINESTRING_NEAREST_POINT_TEST_EXP ....   Passed    0.12 sec
      Start 32: SINUSOIDAL_PROJECTION_TEST_EXP
32/45 Test #32: SINUSOIDAL_PROJECTION_TEST_EXP .............   Passed    0.12 sec
      Start 33: POINTS_IN_RANGE_TEST_EXP
33/45 Test #33: POINTS_IN_RANGE_TEST_EXP ...................   Passed    0.11 sec
      Start 34: POINT_IN_POLYGON_TEST_EXP
34/45 Test #34: POINT_IN_POLYGON_TEST_EXP ..................   Passed    0.12 sec
      Start 35: PAIRWISE_POINT_IN_POLYGON_TEST_EXP
35/45 Test #35: PAIRWISE_POINT_IN_POLYGON_TEST_EXP .........   Passed    0.11 sec
      Start 36: DERIVE_TRAJECTORIES_TEST_EXP
36/45 Test #36: DERIVE_TRAJECTORIES_TEST_EXP ...............   Passed   14.49 sec
      Start 37: POINT_BOUNDING_BOXES_TEST_EXP
37/45 Test #37: POINT_BOUNDING_BOXES_TEST_EXP ..............   Passed    1.35 sec
      Start 38: POLYGON_BOUNDING_BOXES_TEST_EXP
38/45 Test #38: POLYGON_BOUNDING_BOXES_TEST_EXP ............   Passed    0.11 sec
      Start 39: LINESTRING_BOUNDING_BOXES_TEST_EXP
39/45 Test #39: LINESTRING_BOUNDING_BOXES_TEST_EXP .........   Passed    0.11 sec
      Start 40: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_EXP
40/45 Test #40: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_EXP ...   Passed    0.80 sec
      Start 41: POINT_QUADTREE_TEST_EXP
41/45 Test #41: POINT_QUADTREE_TEST_EXP ....................   Passed    0.12 sec
      Start 42: OPERATOR_TEST_EXP
42/45 Test #42: OPERATOR_TEST_EXP ..........................   Passed    0.14 sec
      Start 43: FIND_TEST_EXP
43/45 Test #43: FIND_TEST_EXP ..............................   Passed    0.13 sec
      Start 44: JOIN_POINT_IN_POLYGON_SMALL_TEST_EXP
44/45 Test #44: JOIN_POINT_IN_POLYGON_SMALL_TEST_EXP .......   Passed    0.11 sec
      Start 45: JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP
45/45 Test #45: JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP .......   Passed    0.13 sec

100% tests passed, 0 tests failed out of 45

Total Test time (real) =  47.07 sec
```

After:

```
(rapids) coder ➜ ~/cuspatial/cpp/build/release $ ninja test
[0/1] Running tests...
Test project /home/coder/cuspatial/cpp/build/release
      Start  1: SINUSOIDAL_PROJECTION_TEST
 1/45 Test  #1: SINUSOIDAL_PROJECTION_TEST .................   Passed    0.78 sec
      Start  2: HAVERSINE_TEST
 2/45 Test  #2: HAVERSINE_TEST .............................   Passed    0.75 sec
      Start  3: HAUSDORFF_TEST
 3/45 Test  #3: HAUSDORFF_TEST .............................   Passed    0.74 sec
      Start  4: JOIN_POINT_TO_LINESTRING_SMALL_TEST
 4/45 Test  #4: JOIN_POINT_TO_LINESTRING_SMALL_TEST ........   Passed    0.77 sec
      Start  5: JOIN_POINT_IN_POLYGON_TEST
 5/45 Test  #5: JOIN_POINT_IN_POLYGON_TEST .................   Passed    0.76 sec
      Start  6: POINT_IN_POLYGON_TEST
 6/45 Test  #6: POINT_IN_POLYGON_TEST ......................   Passed    0.78 sec
      Start  7: PAIRWISE_POINT_IN_POLYGON_TEST
 7/45 Test  #7: PAIRWISE_POINT_IN_POLYGON_TEST .............   Passed    0.74 sec
      Start  8: POINT_QUADTREE_TEST
 8/45 Test  #8: POINT_QUADTREE_TEST ........................   Passed    0.75 sec
      Start  9: LINESTRING_BOUNDING_BOXES_TEST
 9/45 Test  #9: LINESTRING_BOUNDING_BOXES_TEST .............   Passed    0.75 sec
      Start 10: POLYGON_BOUNDING_BOXES_TEST
10/45 Test #10: POLYGON_BOUNDING_BOXES_TEST ................   Passed    0.73 sec
      Start 11: POINT_DISTANCE_TEST
11/45 Test #11: POINT_DISTANCE_TEST ........................   Passed    0.73 sec
      Start 12: POINT_LINESTRING_DISTANCE_TEST
12/45 Test #12: POINT_LINESTRING_DISTANCE_TEST .............   Passed    0.74 sec
      Start 13: LINESTRING_DISTANCE_TEST
13/45 Test #13: LINESTRING_DISTANCE_TEST ...................   Passed    0.76 sec
      Start 14: POINT_POLYGON_DISTANCE_TEST
14/45 Test #14: POINT_POLYGON_DISTANCE_TEST ................   Passed    0.76 sec
      Start 15: LINESTRING_INTERSECTION_TEST
15/45 Test #15: LINESTRING_INTERSECTION_TEST ...............   Passed    0.78 sec
      Start 16: POINT_LINESTRING_NEAREST_POINT_TEST
16/45 Test #16: POINT_LINESTRING_NEAREST_POINT_TEST ........   Passed    0.77 sec
      Start 17: QUADTREE_POLYGON_FILTERING_TEST
17/45 Test #17: QUADTREE_POLYGON_FILTERING_TEST ............   Passed    0.75 sec
      Start 18: QUADTREE_LINESTRING_FILTERING_TEST
18/45 Test #18: QUADTREE_LINESTRING_FILTERING_TEST .........   Passed    0.77 sec
      Start 19: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST
19/45 Test #19: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST .......   Passed    0.74 sec
      Start 20: DERIVE_TRAJECTORIES_TEST
20/45 Test #20: DERIVE_TRAJECTORIES_TEST ...................   Passed    0.75 sec
      Start 21: TRAJECTORY_BOUNDING_BOXES_TEST
21/45 Test #21: TRAJECTORY_BOUNDING_BOXES_TEST .............   Passed    0.74 sec
      Start 22: SPATIAL_WINDOW_POINT_TEST
22/45 Test #22: SPATIAL_WINDOW_POINT_TEST ..................   Passed    0.75 sec
      Start 23: UTILITY_TEST
23/45 Test #23: UTILITY_TEST ...............................   Passed    0.30 sec
      Start 24: HAVERSINE_TEST_EXP
24/45 Test #24: HAVERSINE_TEST_EXP .........................   Passed    0.12 sec
      Start 25: POINT_DISTANCE_TEST_EXP
25/45 Test #25: POINT_DISTANCE_TEST_EXP ....................   Passed    0.12 sec
      Start 26: POINT_LINESTRING_DISTANCE_TEST_EXP
26/45 Test #26: POINT_LINESTRING_DISTANCE_TEST_EXP .........   Passed    0.12 sec
      Start 27: POINT_POLYGON_DISTANCE_TEST_EXP
27/45 Test #27: POINT_POLYGON_DISTANCE_TEST_EXP ............   Passed    0.13 sec
      Start 28: HAUSDORFF_TEST_EXP
28/45 Test #28: HAUSDORFF_TEST_EXP .........................   Passed    0.26 sec
      Start 29: LINESTRING_DISTANCE_TEST_EXP
29/45 Test #29: LINESTRING_DISTANCE_TEST_EXP ...............   Passed    0.14 sec
      Start 30: LINESTRING_INTERSECTION_TEST_EXP
30/45 Test #30: LINESTRING_INTERSECTION_TEST_EXP ...........   Passed    0.19 sec
      Start 31: POINT_LINESTRING_NEAREST_POINT_TEST_EXP
31/45 Test #31: POINT_LINESTRING_NEAREST_POINT_TEST_EXP ....   Passed    0.11 sec
      Start 32: SINUSOIDAL_PROJECTION_TEST_EXP
32/45 Test #32: SINUSOIDAL_PROJECTION_TEST_EXP .............   Passed    0.11 sec
      Start 33: POINTS_IN_RANGE_TEST_EXP
33/45 Test #33: POINTS_IN_RANGE_TEST_EXP ...................   Passed    0.13 sec
      Start 34: POINT_IN_POLYGON_TEST_EXP
34/45 Test #34: POINT_IN_POLYGON_TEST_EXP ..................   Passed    0.11 sec
      Start 35: PAIRWISE_POINT_IN_POLYGON_TEST_EXP
35/45 Test #35: PAIRWISE_POINT_IN_POLYGON_TEST_EXP .........   Passed    0.14 sec
      Start 36: DERIVE_TRAJECTORIES_TEST_EXP
36/45 Test #36: DERIVE_TRAJECTORIES_TEST_EXP ...............   Passed    0.27 sec
      Start 37: POINT_BOUNDING_BOXES_TEST_EXP
37/45 Test #37: POINT_BOUNDING_BOXES_TEST_EXP ..............   Passed    0.15 sec
      Start 38: POLYGON_BOUNDING_BOXES_TEST_EXP
38/45 Test #38: POLYGON_BOUNDING_BOXES_TEST_EXP ............   Passed    0.13 sec
      Start 39: LINESTRING_BOUNDING_BOXES_TEST_EXP
39/45 Test #39: LINESTRING_BOUNDING_BOXES_TEST_EXP .........   Passed    0.12 sec
      Start 40: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_EXP
40/45 Test #40: TRAJECTORY_DISTANCES_AND_SPEEDS_TEST_EXP ...   Passed    0.13 sec
      Start 41: POINT_QUADTREE_TEST_EXP
41/45 Test #41: POINT_QUADTREE_TEST_EXP ....................   Passed    0.14 sec
      Start 42: OPERATOR_TEST_EXP
42/45 Test #42: OPERATOR_TEST_EXP ..........................   Passed    0.14 sec
      Start 43: FIND_TEST_EXP
43/45 Test #43: FIND_TEST_EXP ..............................   Passed    0.15 sec
      Start 44: JOIN_POINT_IN_POLYGON_SMALL_TEST_EXP
44/45 Test #44: JOIN_POINT_IN_POLYGON_SMALL_TEST_EXP .......   Passed    0.12 sec
      Start 45: JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP
45/45 Test #45: JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP .......   Passed    0.13 sec

100% tests passed, 0 tests failed out of 45

Total Test time (real) =  20.08 sec
```

Authors:
  - Mark Harris (https://github.com/harrism)

Approvers:
  - Michael Wang (https://github.com/isVoid)
  - Paul Taylor (https://github.com/trxcllnt)

URL: #1018

* Re-add enabled_check_generated_files:false

---------

Co-authored-by: H. Thomson Comer <thomcom@gmail.com>
Co-authored-by: Michael Wang <isVoid@users.noreply.github.com>
Co-authored-by: AJ Schmidt <ajschmidt8@users.noreply.github.com>
  • Loading branch information
4 people authored Mar 30, 2023
1 parent 6b88aa8 commit a7466af
Show file tree
Hide file tree
Showing 53 changed files with 3,767 additions and 851 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
checks:
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/checks.yaml@branch-23.06
with:
enable_check_generated_files: false
conda-cpp-build:
needs: checks
secrets: inherit
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ repos:
- id: codespell
args: ["--config pyproject.toml"]
additional_dependencies: ["tomli"]
- repo: https://github.com/rapidsai/dependency-file-generator
rev: v1.5.1
hooks:
- id: rapids-dependency-file-generator
args: ["--clean"]

default_language_version:
python: python3
3 changes: 3 additions & 0 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ dependencies:
- myst-parser
- nbsphinx
- ninja
- notebook
- numpydoc
- nvcc_linux-64=11.8
- pre-commit
- pydata-sphinx-theme
- pydeck
- pytest
- pytest-cov
- pytest-xdist
- python>=3.8,<3.11
- rmm=23.06
- scikit-build>=0.13.1
- setuptools
- shapely
- sphinx<6
- sysroot_linux-64==2.17
name: all_cuda-118_arch-x86_64
6 changes: 3 additions & 3 deletions cpp/benchmarks/floating_point_equality.cu
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ template <class FloatsIter>
void generate_floats(FloatsIter begin, FloatsIter end)
{
using T = typename std::iterator_traits<FloatsIter>::value_type;
auto engine_x = deterministic_engine(std::distance(begin, end));
auto engine_x = cuspatial::test::deterministic_engine(std::distance(begin, end));

auto lo = std::numeric_limits<T>::min();
auto hi = std::numeric_limits<T>::max();

auto x_dist = make_uniform_dist(lo, hi);
auto x_dist = cuspatial::test::make_uniform_dist(lo, hi);

auto x_gen = value_generator{lo, hi, engine_x, x_dist};
auto x_gen = cuspatial::test::value_generator{lo, hi, engine_x, x_dist};

thrust::tabulate(
rmm::exec_policy(), begin, end, [x_gen] __device__(size_t n) mutable { return x_gen(n); });
Expand Down
13 changes: 7 additions & 6 deletions cpp/benchmarks/points_in_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>

#include <cuspatial_test/random.cuh>

#include <cuspatial/detail/iterator.hpp>
Expand Down Expand Up @@ -54,14 +55,14 @@ using namespace cuspatial;
template <class PointsIter, typename T>
void generate_points(PointsIter begin, PointsIter end, vec_2d<T> range_min, vec_2d<T> range_max)
{
auto engine_x = deterministic_engine(std::distance(begin, end));
auto engine_y = deterministic_engine(2 * std::distance(begin, end));
auto engine_x = cuspatial::test::deterministic_engine(std::distance(begin, end));
auto engine_y = cuspatial::test::deterministic_engine(2 * std::distance(begin, end));

auto x_dist = make_uniform_dist(range_min.x, range_max.x);
auto y_dist = make_uniform_dist(range_min.y, range_max.y);
auto x_dist = cuspatial::test::make_uniform_dist(range_min.x, range_max.x);
auto y_dist = cuspatial::test::make_uniform_dist(range_min.y, range_max.y);

auto x_gen = value_generator{range_min.x, range_max.x, engine_x, x_dist};
auto y_gen = value_generator{range_min.y, range_max.y, engine_y, y_dist};
auto x_gen = cuspatial::test::value_generator{range_min.x, range_max.x, engine_x, x_dist};
auto y_gen = cuspatial::test::value_generator{range_min.y, range_max.y, engine_y, y_dist};

thrust::tabulate(rmm::exec_policy(), begin, end, [x_gen, y_gen] __device__(size_t n) mutable {
return vec_2d<T>{x_gen(n), y_gen(n)};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
namespace cuspatial {
namespace detail {

inline __device__ std::pair<uint32_t, uint32_t> get_quad_and_local_point_indices(
uint32_t const global_index, uint32_t const* point_offsets, uint32_t const* point_offsets_end)
template <typename IndexType, typename PointOffsetIterator>
inline __device__ std::pair<IndexType, IndexType> get_quad_and_local_point_indices(
IndexType const global_index,
PointOffsetIterator point_offsets_begin,
PointOffsetIterator point_offsets_end)
{
// Calculate the position in "point_offsets" that `global_index` falls between.
// This position is the index of the poly/quad pair for this `global_index`.
Expand All @@ -33,10 +36,10 @@ inline __device__ std::pair<uint32_t, uint32_t> get_quad_and_local_point_indices
// quadrant. Adding this zero-based position to the quadrant's first point position in the
// quadtree yields the "global" position in the `point_indices` map.
auto const local_point_offset =
thrust::upper_bound(thrust::seq, point_offsets, point_offsets_end, global_index) - 1;
thrust::upper_bound(thrust::seq, point_offsets_begin, point_offsets_end, global_index) - 1;
return std::make_pair(
// quad_poly_index
thrust::distance(point_offsets, local_point_offset),
thrust::distance(point_offsets_begin, local_point_offset),
// local_point_index
global_index - *local_point_offset);
}
Expand Down
39 changes: 16 additions & 23 deletions cpp/include/cuspatial/experimental/detail/join/intersection.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#pragma once

#include <cuspatial/detail/utility/z_order.cuh>
#include <cuspatial/experimental/geometry/box.hpp>
#include <cuspatial/experimental/point_quadtree.cuh>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/device_uvector.hpp>
Expand Down Expand Up @@ -69,37 +71,32 @@ inline int32_t remove_non_quad_intersections(InputIterator input_begin,
}

template <class T,
class KeyIterator,
class LevelIterator,
class IsInternalIterator,
class BoundingBoxIterator,
class NodeIndicesIterator,
class BBoxIndicesIterator,
class NodePairsIterator,
class LeafPairsIterator>
inline std::pair<int32_t, int32_t> find_intersections(KeyIterator keys_first,
LevelIterator levels_first,
IsInternalIterator is_internal_node_first,
inline std::pair<int32_t, int32_t> find_intersections(point_quadtree_ref quadtree,
BoundingBoxIterator bounding_box_first,
NodeIndicesIterator node_indices,
BBoxIndicesIterator bbox_indices,
NodePairsIterator node_pairs,
LeafPairsIterator leaf_pairs,
int32_t num_pairs,
T x_min,
T y_min,
vec_2d<T> const& v_min,
T scale,
int8_t max_depth,
rmm::cuda_stream_view stream)
{
auto nodes_first = thrust::make_zip_iterator(keys_first, levels_first, is_internal_node_first);
auto nodes_first = thrust::make_zip_iterator(
quadtree.key_begin(), quadtree.level_begin(), quadtree.internal_node_flag_begin());

thrust::transform(
rmm::exec_policy(stream),
thrust::make_zip_iterator(node_indices, bbox_indices),
thrust::make_zip_iterator(node_indices, bbox_indices) + num_pairs,
node_pairs,
[x_min, y_min, scale, max_depth, nodes = nodes_first, bboxes = bounding_box_first] __device__(
[v_min, scale, max_depth, nodes = nodes_first, bboxes = bounding_box_first] __device__(
auto const& node_and_bbox) {
auto const& node_idx = thrust::get<0>(node_and_bbox);
auto const& bbox_idx = thrust::get<1>(node_and_bbox);
Expand All @@ -109,24 +106,20 @@ inline std::pair<int32_t, int32_t> find_intersections(KeyIterator keys_first,
uint8_t const& level = thrust::get<1>(node);
uint8_t const& is_internal_node = thrust::get<2>(node);

auto const& bbox = bboxes[bbox_idx];
auto const& bbox_min = bbox.v1;
auto const& bbox_max = bbox.v2;
auto const& poly_x_min = bbox_min.x;
auto const& poly_y_min = bbox_min.y;
auto const& poly_x_max = bbox_max.x;
auto const& poly_y_max = bbox_max.y;
box<T> const bbox = bboxes[bbox_idx];
vec_2d<T> const bbox_min = bbox.v1;
vec_2d<T> const bbox_max = bbox.v2;

T const key_x = utility::z_order_x(key);
T const key_y = utility::z_order_y(key);
T const level_scale = scale * (1 << (max_depth - 1 - level));
T const node_x_min = x_min + (key_x + 0) * level_scale;
T const node_y_min = y_min + (key_y + 0) * level_scale;
T const node_x_max = x_min + (key_x + 1) * level_scale;
T const node_y_max = y_min + (key_y + 1) * level_scale;
T const node_x_min = v_min.x + (key_x + 0) * level_scale;
T const node_y_min = v_min.y + (key_y + 0) * level_scale;
T const node_x_max = v_min.x + (key_x + 1) * level_scale;
T const node_y_max = v_min.y + (key_y + 1) * level_scale;

if ((node_x_min > poly_x_max) || (node_x_max < poly_x_min) || (node_y_min > poly_y_max) ||
(node_y_max < poly_y_min)) {
if ((node_x_min > bbox_max.x) || (node_x_max < bbox_min.x) || (node_y_min > bbox_max.y) ||
(node_y_max < bbox_min.y)) {
// if no overlap, return type = none_indicator
return thrust::make_tuple(none_indicator, level, node_idx, bbox_idx);
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/cuspatial/experimental/detail/point_quadtree.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -241,8 +241,8 @@ std::pair<rmm::device_uvector<uint32_t>, point_quadtree> quadtree_on_points(
T scale,
int8_t max_depth,
int32_t max_size,
rmm::mr::device_memory_resource* mr,
rmm::cuda_stream_view stream)
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
auto num_points = thrust::distance(points_first, points_last);
if (num_points <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,27 @@

namespace cuspatial {

template <class KeyIterator,
class LevelIterator,
class IsInternalIterator,
class BoundingBoxIterator,
class T>
template <class BoundingBoxIterator, class T>
std::pair<rmm::device_uvector<uint32_t>, rmm::device_uvector<uint32_t>>
join_quadtree_and_bounding_boxes(KeyIterator keys_first,
KeyIterator keys_last,
LevelIterator levels_first,
IsInternalIterator is_internal_nodes_first,
KeyIterator lengths_first,
KeyIterator offsets_first,
join_quadtree_and_bounding_boxes(point_quadtree_ref quadtree,
BoundingBoxIterator bounding_boxes_first,
BoundingBoxIterator bounding_boxes_last,
T x_min,
T y_min,
vec_2d<T> const& v_min,
T scale,
int8_t max_depth,
rmm::mr::device_memory_resource* mr,
rmm::cuda_stream_view stream)
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
static_assert(is_same<T, cuspatial::iterator_vec_base_type<BoundingBoxIterator>>(),
"Iterator value_type mismatch");

auto const num_nodes = std::distance(keys_first, keys_last);
auto const num_boxes = std::distance(bounding_boxes_first, bounding_boxes_last);

// Count the number of top-level nodes to start.
// This could be provided explicitly, but count_if should be fast enough.
auto num_top_level_leaves = thrust::count_if(rmm::exec_policy(stream),
levels_first,
levels_first + num_nodes,
quadtree.level_begin(),
quadtree.level_end(),
thrust::placeholders::_1 == 0);

auto num_pairs = num_top_level_leaves * num_boxes;
Expand Down Expand Up @@ -96,9 +85,7 @@ join_quadtree_and_bounding_boxes(KeyIterator keys_first,

// Find intersections for all the top level quadrants and bounding boxes
std::tie(num_parents, num_leaves) =
detail::find_intersections(keys_first,
levels_first,
is_internal_nodes_first,
detail::find_intersections(quadtree,
bounding_boxes_first,
// The top-level node indices
detail::make_counting_transform_iterator(
Expand All @@ -111,8 +98,7 @@ join_quadtree_and_bounding_boxes(KeyIterator keys_first,
// found intersecting quadrant and bbox indices for output
make_output_values_iter(),
num_pairs,
x_min,
y_min,
v_min,
scale,
max_depth,
stream);
Expand Down Expand Up @@ -141,8 +127,8 @@ join_quadtree_and_bounding_boxes(KeyIterator keys_first,
// Walk one level down and fill the current level's vectors with
// the next level's quadrant info and bbox indices.
std::tie(num_pairs, cur_types, cur_levels, cur_node_idxs, cur_bbox_idxs) =
detail::descend_quadtree(lengths_first,
offsets_first,
detail::descend_quadtree(quadtree.length_begin(),
quadtree.offset_begin(),
num_parents,
cur_types,
cur_levels,
Expand All @@ -152,9 +138,7 @@ join_quadtree_and_bounding_boxes(KeyIterator keys_first,

// Find intersections for the the next level's quadrants and bboxes
std::tie(num_parents, num_leaves) =
detail::find_intersections(keys_first,
levels_first,
is_internal_nodes_first,
detail::find_intersections(quadtree,
bounding_boxes_first,
cur_node_idxs.begin(),
cur_bbox_idxs.begin(),
Expand All @@ -163,8 +147,7 @@ join_quadtree_and_bounding_boxes(KeyIterator keys_first,
// found intersecting quadrant and bbox indices for output
make_output_values_iter(),
num_pairs,
x_min,
y_min,
v_min,
scale,
max_depth,
stream);
Expand All @@ -177,7 +160,8 @@ join_quadtree_and_bounding_boxes(KeyIterator keys_first,
// Copy the relevant node offsets into a temporary vector so we don't modify the quadtree column
rmm::device_uvector<uint32_t> tmp_node_offsets(num_results, stream);

auto const iter = thrust::make_permutation_iterator(offsets_first, out_node_idxs.begin());
auto const iter =
thrust::make_permutation_iterator(quadtree.offset_begin(), out_node_idxs.begin());

thrust::copy(rmm::exec_policy(stream), iter, iter + num_results, tmp_node_offsets.begin());

Expand Down
Loading

0 comments on commit a7466af

Please sign in to comment.