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

Add Header Only API for Linestring-Polygon Distance #1011

Conversation

isVoid
Copy link
Contributor

@isVoid isVoid commented Mar 24, 2023

Description

This PR adds linestring-polygon distance API. This API divides up the work into two parts: point-in-polygon test and a load-balanced all-pairs segment-segment distance compute kernel.

Closes #1027
Depends on #1026
Contributes to #757

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@github-actions github-actions bot added the libcuspatial Relates to the cuSpatial C++ library label Mar 24, 2023
@github-actions github-actions bot added the cmake Related to CMake code or build configuration label Mar 28, 2023
@isVoid isVoid changed the title [skip-ci] Add Header Only API for Linestring-Polygon Distance Add Header Only API for Linestring-Polygon Distance Apr 3, 2023
@isVoid isVoid requested a review from a team as a code owner April 3, 2023 17:36
@isVoid isVoid requested review from trxcllnt and harrism April 3, 2023 17:36
@isVoid
Copy link
Contributor Author

isVoid commented Apr 4, 2023

There is OOB error with compute sanitizer, hold on..

@isVoid isVoid added the 5 - DO NOT MERGE Hold off on merging; see PR for details label Apr 4, 2023
@isVoid
Copy link
Contributor Author

isVoid commented Apr 4, 2023

There is OOB error with compute sanitizer, hold on..

Fixed

@isVoid isVoid removed the 5 - DO NOT MERGE Hold off on merging; see PR for details label Apr 4, 2023
@isVoid isVoid requested a review from thomcom April 4, 2023 17:42
Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines +128 to +144
// Compute the "boundary" of threads. Threads are partitioned based on the number of linestrings
// times the number of polygons in a multipoint-multipolygon pair.
auto segment_count_product_it = thrust::make_transform_iterator(
thrust::make_zip_iterator(multilinestrings.multilinestring_segment_count_begin(),
multipolygons.multipolygon_segment_count_begin()),
thrust::make_zip_function(thrust::multiplies<index_t>{}));

// Computes the "thread boundary" of each pair. This array partitions the thread range by
// geometries. E.g. threadIdx within [thread_bounds[i], thread_bounds[i+1]) computes distances of
// the ith pair.
auto thread_bounds = rmm::device_uvector<index_t>(multilinestrings.size() + 1, stream);
detail::zero_data_async(thread_bounds.begin(), thread_bounds.end(), stream);

thrust::inclusive_scan(rmm::exec_policy(stream),
segment_count_product_it,
segment_count_product_it + thread_bounds.size() - 1,
thrust::next(thread_bounds.begin()));
Copy link
Contributor

Choose a reason for hiding this comment

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

You've probably already thought of this but I see you wanting to have the thread partitioning code here and above refactored into a utility space for reuse in other algorithms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this will come pretty handy when I start applying this parallel modality to other algorithms. I'm writing a refactor plan to st_distance and this will be factored out as part of that.

@isVoid
Copy link
Contributor Author

isVoid commented Apr 6, 2023

/merge

@rapids-bot rapids-bot bot merged commit fdacbb2 into rapidsai:branch-23.04 Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Related to CMake code or build configuration feature request New feature or request libcuspatial Relates to the cuSpatial C++ library non-breaking Non-breaking change
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Header only API for pairwise linestring-polygon distance
3 participants