-
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 find_duplicate_points
Internal API
#815
Changes from 5 commits
5749e43
198c35a
3558d44
3af6346
1813b0d
246d8ef
8753143
7d6314b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2022, 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/cuda_utils.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/exec_policy.hpp> | ||
|
||
#include <thrust/uninitialized_fill.h> | ||
|
||
namespace cuspatial { | ||
namespace detail { | ||
|
||
/** | ||
* @internal | ||
* @brief Kernel to compute duplicate points in each multipoint. Naive N^2 algorithm. | ||
*/ | ||
template <typename MultiPointRange, typename OutputIt> | ||
void __global__ combine_duplicate_points_kernel_simple(MultiPointRange multipoints, | ||
OutputIt stencils) | ||
{ | ||
for (auto idx = threadIdx.x + blockIdx.x * blockDim.x; idx < multipoints.num_points(); | ||
idx += gridDim.x * blockDim.x) { | ||
auto multipoint = multipoints[idx]; | ||
auto global_offset = multipoints.offsets_begin()[idx]; | ||
for (auto i = 0; i < multipoint.size() && stencils[i] != 1; ++i) | ||
for (auto j = i + 1; j < multipoint.size(); ++j) { | ||
if (multipoint[i] == multipoint[j]) stencils[j + global_offset] = 1; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @internal | ||
* @brief For each multipoint, computes duplicate points and stores as stencil. | ||
*/ | ||
template <typename MultiPointRange, typename OutputIt> | ||
void combine_duplicate_points(MultiPointRange multipoints, | ||
isVoid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
OutputIt output_stencils, | ||
rmm::cuda_stream_view stream) | ||
{ | ||
if (multipoints.size() == 0) return; | ||
|
||
thrust::uninitialized_fill_n( | ||
rmm::exec_policy(stream), output_stencils, multipoints.num_points(), 0); | ||
|
||
auto [threads_per_block, num_blocks] = grid_1d(multipoints.size()); | ||
combine_duplicate_points_kernel_simple<<<num_blocks, threads_per_block, 0, stream.value()>>>( | ||
multipoints, output_stencils); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace cuspatial |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
#pragma once | ||
#include <cuspatial/cuda_utils.hpp> | ||
|
||
#include <thrust/distance.h> | ||
|
||
namespace cuspatial { | ||
|
||
template <typename VecIterator> | ||
|
@@ -37,4 +39,17 @@ CUSPATIAL_HOST_DEVICE auto multipoint_ref<VecIterator>::point_end() const | |
return _points_end; | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multipoint_ref<VecIterator>::num_points() const | ||
{ | ||
return thrust::distance(_points_begin, _points_end); | ||
} | ||
|
||
template <typename VecIterator> | ||
template <typename IndexType> | ||
CUSPATIAL_HOST_DEVICE auto multipoint_ref<VecIterator>::operator[](IndexType i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thinking about host / device here. Is this really intended to work on the host? What if it is called from host when the iterator points to device memory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can work on host, if all vectors are host vectors. Although I don't really see a use case at the moment. Up till now I mostly rely on developer's prudence to not access device memory from host. |
||
{ | ||
return point_begin()[i]; | ||
} | ||
|
||
} // namespace cuspatial |
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.
What do you mean by "stores as stencil"? Do you mean an array of flags indicating which points are duplicates?
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.
Doc updated as a result of addressing: #815 (comment)