-
Notifications
You must be signed in to change notification settings - Fork 154
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 multilinestring_segment_manager
for segment related methods in multilinestring ranges
#1134
Merged
rapids-bot
merged 30 commits into
rapidsai:branch-23.06
from
isVoid:fix/segment_iterator
Jun 1, 2023
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ac872e7
[skip ci] initial segment_counter working
isVoid 84f317c
segment iterator works with empty linestrings
isVoid ce28b3c
enable polygon segment count test
isVoid cd2d229
add polygon segment methods
isVoid fcbe105
remove incomplete validations and add implicit assumptions in documen…
isVoid ee3576e
enable multipolygon range tests
isVoid 7a53d05
improve doc of validators
isVoid 2181e96
replace all multilinestring range tests with segment method test
isVoid 5e3a45a
updates multipolygon tests to make use the new segment methods view
isVoid 53e3ce0
remove segment methods from ranges and update all usage to `segment_m…
isVoid 789f7a2
Cleanup: Remove all debug prints
isVoid 2390acc
Cleanup: Remove segment functions in multilinestring_range and dead c…
isVoid 728caa4
remove num_segments
isVoid 5df7ea0
rename segment_methods -> multilinestring_segment
isVoid e030449
Updates segment_range and tests to make sure APIs exposed are all mul…
isVoid 771f340
Refactors `linestring_polygon_distance` and add tests to include empt…
isVoid 81e05bd
Move all segment range only functors to local file
isVoid 9d00b41
Documentation for segment_range
isVoid f6255b8
typo
isVoid 9ec9882
Merge branch 'branch-23.06' into fix/segment_iterator
isVoid 0f151a5
Cleanups & doc improvement
isVoid 57a2327
Merge branch 'fix/segment_iterator' of github.com:isVoid/cuspatial in…
isVoid 3ae30fc
address review changes, updates docs
isVoid 9ac791c
Merge branch 'branch-23.06' into fix/segment_iterator
isVoid 3689dc4
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid 0f77783
Merge branch 'fix/segment_iterator' of github.com:isVoid/cuspatial in…
isVoid 866e25c
rename owning object
isVoid b7b51e3
handle NaNs in the new kernel
isVoid 7849384
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid 9e045ec
relax test suite relating to validator relax
isVoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
cpp/include/cuspatial/detail/multilinestring_segment.cuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright (c) 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cuspatial/detail/functors.cuh> | ||
#include <cuspatial/detail/range/multilinestring_segment_range.cuh> | ||
#include <cuspatial/detail/utility/zero_data.cuh> | ||
#include <cuspatial/iterator_factory.cuh> | ||
#include <cuspatial/range/range.cuh> | ||
#include <cuspatial/traits.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/device_uvector.hpp> | ||
#include <rmm/exec_policy.hpp> | ||
#include <rmm/mr/device/per_device_resource.hpp> | ||
|
||
#include <thrust/device_vector.h> | ||
#include <thrust/iterator/discard_iterator.h> | ||
#include <thrust/iterator/transform_iterator.h> | ||
#include <thrust/logical.h> | ||
|
||
namespace cuspatial { | ||
namespace detail { | ||
|
||
/** | ||
* @internal | ||
* @brief Functor that returns true if current value is greater than 0. | ||
*/ | ||
template <typename IndexType> | ||
struct greater_than_zero_functor { | ||
__device__ IndexType operator()(IndexType x) const { return x > 0; } | ||
}; | ||
|
||
/** | ||
* @internal | ||
* @brief Owning class to provide iterators to segments in a multilinestring range | ||
* | ||
* The owned memory in this struct is the vector `_non_empty_linestring_prefix_sum` of size equal to | ||
* the number of linestrings in the multilinestring range plus 1. This vector holds the number | ||
* of non empty linestrings that precedes the current linestring. | ||
* | ||
* This class is only meant for tracking the life time of the owned memory. To access the | ||
* segment iterators, call `segment_range()` function to create a non-owning object of this class. | ||
* | ||
* For detailed explanation on the implementation of the segment iterators, see documentation | ||
* of `multilinestring_segment_range`. | ||
* | ||
* @note To use this class with a multipolygon range, cast the multipolygon range as a | ||
* multilinestring range. | ||
* | ||
* TODO: Optimization: for ranges that do not contain any empty linestrings, | ||
* `_non_empty_linestring_prefix_sum` can replaced by a `counting_iterator`. | ||
* | ||
* @tparam MultilinestringRange The multilinestring range to initialize this class with. | ||
*/ | ||
template <typename MultilinestringRange> | ||
class multilinestring_segment_manager { | ||
using index_t = iterator_value_type<typename MultilinestringRange::part_it_t>; | ||
|
||
public: | ||
/** | ||
* @brief Construct a new multilinestring segment object | ||
* | ||
* @note multilinestring_segment is always internal use, thus memory consumed is always | ||
* temporary, therefore always use default device memory resource. | ||
* | ||
* @param parent The parent multilinestring object to construct from | ||
* @param stream The stream to perform computation on | ||
*/ | ||
multilinestring_segment_manager(MultilinestringRange parent, rmm::cuda_stream_view stream) | ||
: _parent(parent), _non_empty_linestring_prefix_sum(parent.num_linestrings() + 1, stream) | ||
{ | ||
auto offset_range = ::cuspatial::range{_parent.part_offset_begin(), _parent.part_offset_end()}; | ||
auto count_begin = thrust::make_transform_iterator( | ||
thrust::make_zip_iterator(offset_range.begin(), thrust::next(offset_range.begin())), | ||
offset_pair_to_count_functor{}); | ||
|
||
auto count_greater_than_zero = | ||
thrust::make_transform_iterator(count_begin, greater_than_zero_functor<index_t>{}); | ||
|
||
zero_data_async( | ||
_non_empty_linestring_prefix_sum.begin(), _non_empty_linestring_prefix_sum.end(), stream); | ||
|
||
thrust::inclusive_scan(rmm::exec_policy(stream), | ||
count_greater_than_zero, | ||
count_greater_than_zero + _parent.num_linestrings(), | ||
thrust::next(_non_empty_linestring_prefix_sum.begin())); | ||
|
||
_num_segments = _parent.num_points() - _non_empty_linestring_prefix_sum.element( | ||
_non_empty_linestring_prefix_sum.size() - 1, stream); | ||
} | ||
|
||
/** | ||
* @brief Return a non-owning `multilinestring_segment_range` object from this class | ||
* | ||
* @return multilinestring_segment_range | ||
*/ | ||
auto segment_range() | ||
{ | ||
auto index_range = ::cuspatial::range{_non_empty_linestring_prefix_sum.begin(), | ||
_non_empty_linestring_prefix_sum.end()}; | ||
return multilinestring_segment_range<MultilinestringRange, decltype(index_range)>{ | ||
_parent, index_range, _num_segments}; | ||
} | ||
|
||
private: | ||
MultilinestringRange _parent; | ||
index_t _num_segments; | ||
rmm::device_uvector<index_t> _non_empty_linestring_prefix_sum; | ||
}; | ||
|
||
} // namespace detail | ||
|
||
} // namespace cuspatial |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does quoting documented symbol names prevent Doxygen from making them into clickable links?