-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Column API for
pairwise_polygon_distance
(#1073)
This PR adds column API for `pairwise_polygon_distance`. This PR also adds `CUSPATIAL_HOST_DEVICE_EXPECTS` macro to help error assertion in `__host__ __device__` functions. closes #1053 depends on #1065 Authors: - Michael Wang (https://github.com/isVoid) Approvers: - H. Thomson Comer (https://github.com/thomcom) - Mark Harris (https://github.com/harrism) URL: #1073
- Loading branch information
Showing
10 changed files
with
404 additions
and
31 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 <cuda_runtime.h> | ||
|
||
/** | ||
* @brief `assert`-like macro for device code | ||
* | ||
* This is effectively the same as the standard `assert` macro, except it | ||
* relies on the `__PRETTY_FUNCTION__` macro which is specific to GCC and Clang | ||
* to produce better assert messages. | ||
*/ | ||
#if !defined(NDEBUG) && defined(__CUDA_ARCH__) && (defined(__clang__) || defined(__GNUC__)) | ||
#define __ASSERT_STR_HELPER(x) #x | ||
#define cuspatial_assert(e) \ | ||
((e) ? static_cast<void>(0) \ | ||
: __assert_fail(__ASSERT_STR_HELPER(e), __FILE__, __LINE__, __PRETTY_FUNCTION__)) | ||
#else | ||
#define cuspatial_assert(e) (static_cast<void>(0)) | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include <cuspatial/column/geometry_column_view.hpp> | ||
|
||
#include <cudf/column/column.hpp> | ||
|
||
#include <rmm/mr/device/device_memory_resource.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace cuspatial { | ||
|
||
/** | ||
* @brief Compute pairwise (multi)polygon-to-(multi)polygon Cartesian distance | ||
* | ||
* Computes the cartesian distance between each pair of the multipolygons. | ||
* | ||
* @param lhs Geometry column of the multipolygons to compute distance from | ||
* @param rhs Geometry column of the multipolygons to compute distance to | ||
* @param mr Device memory resource used to allocate the returned column. | ||
* | ||
* @return Column of distances between each pair of input geometries, same type as input coordinate | ||
* types. | ||
*/ | ||
std::unique_ptr<cudf::column> pairwise_polygon_distance( | ||
geometry_column_view const& lhs, | ||
geometry_column_view const& rhs, | ||
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); | ||
|
||
} // namespace cuspatial |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "../utility/iterator.hpp" | ||
#include "../utility/multi_geometry_dispatch.hpp" | ||
|
||
#include <cudf/column/column.hpp> | ||
#include <cudf/column/column_factories.hpp> | ||
#include <cudf/column/column_view.hpp> | ||
#include <cudf/copying.hpp> | ||
#include <cudf/types.hpp> | ||
#include <cudf/utilities/traits.hpp> | ||
#include <cudf/utilities/type_dispatcher.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
|
||
#include <cuspatial/column/geometry_column_view.hpp> | ||
#include <cuspatial/error.hpp> | ||
#include <cuspatial/iterator_factory.cuh> | ||
#include <cuspatial/polygon_distance.cuh> | ||
#include <cuspatial/range/multipolygon_range.cuh> | ||
#include <cuspatial/types.hpp> | ||
|
||
#include <thrust/iterator/counting_iterator.h> | ||
|
||
#include <memory> | ||
#include <type_traits> | ||
|
||
namespace cuspatial { | ||
|
||
namespace detail { | ||
|
||
namespace { | ||
|
||
template <collection_type_id is_multi_polygon_lhs, collection_type_id is_multi_polygon_rhs> | ||
struct pairwise_polygon_distance_impl { | ||
using SizeType = cudf::device_span<cudf::size_type const>::size_type; | ||
|
||
template <typename T, CUDF_ENABLE_IF(std::is_floating_point_v<T>)> | ||
std::unique_ptr<cudf::column> operator()(geometry_column_view const& lhs, | ||
geometry_column_view const& rhs, | ||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
auto lhs_range = make_multipolygon_range<is_multi_polygon_lhs, T, cudf::size_type>(lhs); | ||
auto rhs_range = make_multipolygon_range<is_multi_polygon_rhs, T, cudf::size_type>(rhs); | ||
|
||
auto output = cudf::make_numeric_column( | ||
lhs.coordinate_type(), lhs.size(), cudf::mask_state::UNALLOCATED, stream, mr); | ||
|
||
cuspatial::pairwise_polygon_distance( | ||
lhs_range, rhs_range, output->mutable_view().begin<T>(), stream); | ||
return output; | ||
} | ||
|
||
template <typename T, CUDF_ENABLE_IF(!std::is_floating_point_v<T>), typename... Args> | ||
std::unique_ptr<cudf::column> operator()(Args&&...) | ||
|
||
{ | ||
CUSPATIAL_FAIL("polygon distance API only supports floating point coordinates."); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
template <collection_type_id is_multi_polygon_lhs, collection_type_id is_multi_polygon_rhs> | ||
struct pairwise_polygon_distance { | ||
std::unique_ptr<cudf::column> operator()(geometry_column_view const& lhs, | ||
geometry_column_view const& rhs, | ||
rmm::cuda_stream_view stream, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
return cudf::type_dispatcher( | ||
lhs.coordinate_type(), | ||
pairwise_polygon_distance_impl<is_multi_polygon_lhs, is_multi_polygon_rhs>{}, | ||
lhs, | ||
rhs, | ||
stream, | ||
mr); | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
|
||
std::unique_ptr<cudf::column> pairwise_polygon_distance(geometry_column_view const& lhs, | ||
geometry_column_view const& rhs, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
CUSPATIAL_EXPECTS(lhs.geometry_type() == geometry_type_id::POLYGON && | ||
rhs.geometry_type() == geometry_type_id::POLYGON, | ||
"Unexpected input geometry types."); | ||
|
||
CUSPATIAL_EXPECTS(lhs.coordinate_type() == rhs.coordinate_type(), | ||
"Input geometries must have the same coordinate data types."); | ||
|
||
return multi_geometry_double_dispatch<detail::pairwise_polygon_distance>( | ||
lhs.collection_type(), rhs.collection_type(), lhs, rhs, rmm::cuda_stream_default, mr); | ||
} | ||
|
||
} // namespace cuspatial |
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
File renamed without changes.
Oops, something went wrong.