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

Header-only refactoring of points_in_spatial_window #579

Merged

Conversation

harrism
Copy link
Member

@harrism harrism commented Jun 23, 2022

Fixes #564

A couple of notes:

  1. For clarity and generality, this name for the header-only version of the function is now copy_points_in_range() rather than points_in_spatial_window(). This is the reflect that it is a range filter, and we may want to enable constraining the dimensions of the range in the future.
  2. I have renamed the parameters for the range delimiters and clarified their documentation. This API is not limited to Cartesian coordinates and the documents make that clear by specifying that the input points and the range limits are specified using points in the same coordinate system. It also uses "quadrilateral" rather than "rectangle", since in lon/lat (spherical) coordinates the range is not a rectangle, but it is a quadrilateral.
  3. Note that the change to the iterator-based API means that the user is responsible for allocating the output (as they are with STL and Thrust). Therefore, they need a way to know how much to allocate. In addition to the header-only copy_points_in_range(), this PR also adds a new function, cuspatial::count_points_in_range().

Previously, the cuDF-based API used cudf::copy_if, which does the equivalent of both of the above functions and returns a properly sized pair of columns. The new column-based implementation calls count_points_in_range, then allocates the result columns, and then calls cuspatial::copy_points_in_range().

@harrism harrism requested a review from a team as a code owner June 23, 2022 04:21
@harrism harrism requested review from cwharris and isVoid June 23, 2022 04:21
@harrism harrism added this to the header-only C++ API milestone Jun 23, 2022
@github-actions github-actions bot added the libcuspatial Relates to the cuSpatial C++ library label Jun 23, 2022
@harrism harrism added non-breaking Non-breaking change 2 - In Progress Currenty a work in progress c++ improvement Improvement / enhancement to an existing function labels Jun 23, 2022
@harrism harrism self-assigned this Jun 23, 2022
@harrism harrism requested a review from a team as a code owner July 13, 2022 05:55
@github-actions github-actions bot added the cmake Related to CMake code or build configuration label Jul 13, 2022
@harrism harrism added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currenty a work in progress labels Jul 13, 2022
Copy link
Contributor

@isVoid isVoid left a comment

Choose a reason for hiding this comment

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

Only several minor comments. At first I find it striking to see the refactor breaks the original function into two kernel calls. Later I realized cudf::copy_if does two kernel launches internally (one pass to count the output size and another pass to copy the result).

cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
@harrism
Copy link
Member Author

harrism commented Jul 13, 2022

Only several minor comments. At first I find it striking to see the refactor breaks the original function into two kernel calls. Later I realized cudf::copy_if does two kernel launches internally (one pass to count the output size and another pass to copy the result).

Yes that's what I explained here: #579 (comment)

Copy link
Contributor

@isVoid isVoid left a comment

Choose a reason for hiding this comment

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

Just some doc related issue.

cpp/tests/experimental/spatial/spatial_window_test.cu Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
rmm::cuda_stream_view stream = rmm::cuda_stream_default);

/**
* @brief Find all points (x,y) that fall within a rectangular query window.
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify cartesian coordinates, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Down the road this, along with pip, would be really effective if they took a coordinate system pair as arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I don't think we have to limit this to cartesian coordinates. This is effectively a 2D range query. There's no reason you can't use lonlat points and a 2D lonlat range.

Copy link
Member Author

Choose a reason for hiding this comment

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

(In the future we may want to replace this API with a generic ND range query API...)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's strictly true - lon/lat is not cartesian. There exist points along a line of longitude that fall inside of the spherical "rectangle" defined by a lower left and upper right pair of coordinates that do not fall inside of the cartesian rectangle that is defined by those same coordinates.

Copy link
Member Author

Choose a reason for hiding this comment

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

The API doesn't specify that the points are in any projection -- they can be Cartesian, Lon/Lat, or anything else, as long as the query window and the points are coordinates in the same dimensions. This is a good reason to replace this with an API called "points_in_range" or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've renamed the APIs and clarified the docs. See commit #88e7ee1 and after.

cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/experimental/spatial_window.cuh Outdated Show resolved Hide resolved
cpp/tests/experimental/spatial/spatial_window_test.cu Outdated Show resolved Hide resolved
@harrism harrism requested a review from thomcom July 27, 2022 05:02
@harrism
Copy link
Member Author

harrism commented Jul 27, 2022

Did you create a new file for the new tests? I see one new test, Empty, and that you renamed the file from .cpp to .cu, but I don't see an all points or edge test.

@thomcom I think you went looking in an old commit for new changes. :) Click "Files Changed" at the top or see here: 464cbcc

@harrism
Copy link
Member Author

harrism commented Jul 29, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit de40517 into rapidsai:branch-22.08 Jul 29, 2022
@harrism harrism removed the c++ label Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team cmake Related to CMake code or build configuration improvement Improvement / enhancement to an existing function libcuspatial Relates to the cuSpatial C++ library non-breaking Non-breaking change
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[FEA] Refactor cuspatial::points_in_spatial_window() to header-only API
3 participants