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

Experiment on pulling NVTX3 via CPM #1002

Draft
wants to merge 79 commits into
base: branch-23.08
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
965b80a
initial
isVoid Feb 28, 2023
38af8e6
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 1, 2023
02f61fe
add pragma once for floating_point.cuh
isVoid Mar 7, 2023
7bd797f
add polygon_ref structure
isVoid Mar 7, 2023
0968c15
add multipolygon_ref class
isVoid Mar 7, 2023
a659eab
update multipolygon_range class
isVoid Mar 7, 2023
c274070
update multipoint_range class
isVoid Mar 7, 2023
12ffa53
update is_point_in_polygon usage with polygon_ref
isVoid Mar 7, 2023
7490333
update multilinestring_range
isVoid Mar 7, 2023
f665287
add point to polygon kernel
isVoid Mar 7, 2023
291f6e6
add segment deduction guide
isVoid Mar 7, 2023
efa6883
add owning object type to vector factories
isVoid Mar 7, 2023
23146ef
add tests
isVoid Mar 7, 2023
ead160a
add helper files
isVoid Mar 7, 2023
09bd35f
add more tests
isVoid Mar 8, 2023
92760d1
bug fixes
isVoid Mar 8, 2023
8acb5dc
cleanups
isVoid Mar 8, 2023
a2b94fe
fix tests
isVoid Mar 8, 2023
46a67fe
optimize single point range input
isVoid Mar 8, 2023
b725b52
docs, type checks in range ctor
isVoid Mar 8, 2023
cb5706a
Merge branch 'branch-23.04' into feature/polygon_distances
isVoid Mar 8, 2023
ab59e7d
use range based for loop in is_point_in_polygon
isVoid Mar 8, 2023
b136c0b
Apply suggestions from code review
isVoid Mar 9, 2023
744f32f
add docs
isVoid Mar 9, 2023
bb6c637
style
isVoid Mar 9, 2023
756650b
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 9, 2023
8319e7c
fix bug in PiP tests
isVoid Mar 10, 2023
86d36d9
updates with test docs and API docs, address review
isVoid Mar 14, 2023
7bf8cbf
update offsets_to_keys
isVoid Mar 14, 2023
ff48dc7
update floating_point docs
isVoid Mar 14, 2023
b4420a7
use any_of
isVoid Mar 14, 2023
44e2843
add large (multigrid) tests, address reviews
isVoid Mar 14, 2023
57e6196
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 15, 2023
49972d4
add upper_bound_index.cuh
isVoid Mar 15, 2023
f000e00
remove upper_bound_index
isVoid Mar 15, 2023
57504e6
update geometry id factory
isVoid Mar 15, 2023
4865922
add get gtest scripts in cmake
isVoid Mar 15, 2023
ab52bc2
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 16, 2023
eff0e43
add generators and generator tests
isVoid Mar 17, 2023
6d14d69
add parameterized test fixture
isVoid Mar 17, 2023
5f347fd
adopt single kernel launch device multipolygon generation
isVoid Mar 18, 2023
bd78dfd
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 18, 2023
293ee0f
documentation
isVoid Mar 20, 2023
00a6728
document function
isVoid Mar 20, 2023
d910a7c
enable value parameterized test
isVoid Mar 20, 2023
bd6a4eb
revert distance benchmark
isVoid Mar 20, 2023
9e74468
mixin doc
isVoid Mar 20, 2023
fabc5ad
add point-polygon distance benchmark
isVoid Mar 20, 2023
de5a663
add benchmark file
isVoid Mar 21, 2023
5c67a80
address review comments
isVoid Mar 21, 2023
757057c
Merge branch 'benchmark/point_polygon_distance' into benchmark/point_…
isVoid Mar 21, 2023
2b46f18
Merge branch 'branch-23.04' into benchmark/point_polygon_distance_dev
isVoid Mar 21, 2023
eab8089
update sides->edge
isVoid Mar 21, 2023
dea6568
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 22, 2023
7b19c45
Merge branch 'benchmark/point_polygon_distance_dev' of github.com:isV…
isVoid Mar 22, 2023
1143977
add nvtx range and fix fixtures
isVoid Mar 23, 2023
72fc085
Merge branch 'branch-23.04' into benchmark/point_polygon_distance_dev
isVoid Mar 28, 2023
1c1fbc4
rename plural->singular form
isVoid Apr 14, 2023
4e56fe8
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid Apr 14, 2023
e662f1b
Merge branch 'benchmark/point_polygon_distance_dev' of github.com:isV…
isVoid Apr 14, 2023
80d92e4
style
isVoid Apr 14, 2023
c2e4390
Merge branch 'branch-23.06' into benchmark/point_polygon_distance_dev
harrism Apr 18, 2023
2ecb8d5
use cpm to pull nvtx
isVoid Apr 25, 2023
79416e8
Merge branch 'benchmark/point_polygon_distance_dev' of github.com:isV…
isVoid Apr 25, 2023
2688284
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid Apr 25, 2023
76b26ab
fixes broken API usage
isVoid Apr 25, 2023
8d34780
using rapids-cpm-find
isVoid Apr 25, 2023
0e66450
style
isVoid Apr 26, 2023
b089297
add build export set arg
isVoid Apr 26, 2023
172055e
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid May 3, 2023
545fdc2
update cmakelists.txt
isVoid May 3, 2023
e8e2dbe
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid May 4, 2023
aa8169b
Move
isVoid May 4, 2023
db628be
Fix bad renames
isVoid May 4, 2023
cc6ff27
Record progress
isVoid May 5, 2023
ae9fe35
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid May 9, 2023
4d4cf28
revert non nvtx3 cmake releated changes
isVoid May 10, 2023
1b978cd
add file that got removed
isVoid May 10, 2023
960d921
remove file
isVoid May 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ ConfigureBench(HAUSDORFF_BENCH
hausdorff_benchmark.cpp)

ConfigureNVBench(DISTANCES_BENCH
pairwise_linestring_distance.cu)
pairwise_linestring_distance.cu
pairwise_point_polygon_distance.cu)

ConfigureNVBench(POINTS_IN_RANGE_BENCH
points_in_range.cu)
Expand Down
134 changes: 134 additions & 0 deletions cpp/benchmarks/pairwise_point_polygon_distance.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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 <benchmarks/fixture/rmm_pool_raii.hpp>
#include <nvbench/nvbench.cuh>

#include <cuspatial_test/geometry_generator.cuh>

#include <cuspatial/experimental/point_polygon_distance.cuh>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>

using namespace cuspatial;
using namespace cuspatial::test;

template <typename T>
void pairwise_point_polygon_distance_benchmark(nvbench::state& state, nvbench::type_list<T>)
{
// TODO: to be replaced by nvbench fixture once it's ready
cuspatial::rmm_pool_raii rmm_pool;
rmm::cuda_stream_view stream{rmm::cuda_stream_default};

auto const num_pairs{static_cast<std::size_t>(state.get_int64("num_pairs"))};

auto const num_polygons_per_multipolygon{
static_cast<std::size_t>(state.get_int64("num_polygons_per_multipolygon"))};
auto const num_holes_per_polygon{
static_cast<std::size_t>(state.get_int64("num_holes_per_polygon"))};
auto const num_edges_per_ring{static_cast<std::size_t>(state.get_int64("num_edges_per_ring"))};

auto const num_points_per_multipoint{
static_cast<std::size_t>(state.get_int64("num_points_per_multipoint"))};

auto mpoly_generator_param = multipolygon_generator_parameter<T>{
num_pairs, num_polygons_per_multipolygon, num_holes_per_polygon, num_edges_per_ring};

auto mpoint_generator_param = multipoint_generator_parameter<T>{
num_pairs, num_points_per_multipoint, vec_2d<T>{-1, -1}, vec_2d<T>{0, 0}};

auto multipolygons = generate_multipolygon_array<T>(mpoly_generator_param, stream);
auto multipoints = generate_multipoint_array<T>(mpoint_generator_param, stream);

auto distances = rmm::device_vector<T>(num_pairs);
auto out_it = distances.begin();

auto mpoly_view = multipolygons.range();
auto mpoint_view = multipoints.range();

state.add_element_count(num_pairs, "NumPairs");
state.add_element_count(mpoly_generator_param.num_polygons(), "NumPolygons");
state.add_element_count(mpoly_generator_param.num_rings(), "NumRings");
state.add_element_count(mpoly_generator_param.num_coords(), "NumPoints (in mpoly)");
state.add_element_count(static_cast<std::size_t>(mpoly_generator_param.num_coords() *
mpoly_generator_param.num_rings() *
mpoly_generator_param.num_polygons()),
"Multipolygon Complexity");
state.add_element_count(mpoint_generator_param.num_points(), "NumPoints (in multipoints)");

state.add_global_memory_reads<T>(
mpoly_generator_param.num_coords() + mpoint_generator_param.num_points(),
"CoordinatesReadSize");
state.add_global_memory_reads<std::size_t>(
(mpoly_generator_param.num_rings() + 1) + (mpoly_generator_param.num_polygons() + 1) +
(mpoly_generator_param.num_multipolygons + 1) + (mpoint_generator_param.num_multipoints + 1),
"OffsetsDataSize");

state.add_global_memory_writes<T>(num_pairs);

state.exec(nvbench::exec_tag::sync,
[&mpoly_view, &mpoint_view, &out_it, &stream](nvbench::launch& launch) {
pairwise_point_polygon_distance(mpoint_view, mpoly_view, out_it, stream);
});
}

using floating_point_types = nvbench::type_list<float, double>;

// Benchmark scalability with simple multipolygon (3 sides, 0 hole, 1 poly)
NVBENCH_BENCH_TYPES(pairwise_point_polygon_distance_benchmark,
NVBENCH_TYPE_AXES(floating_point_types))
.set_type_axes_names({"CoordsType"})
.add_int64_axis("num_pairs", {1, 1'00, 10'000, 1'000'000, 100'000'000})
.add_int64_axis("num_polygons_per_multipolygon", {1})
.add_int64_axis("num_holes_per_polygon", {0})
.add_int64_axis("num_edges_per_ring", {3})
.add_int64_axis("num_points_per_multipoint", {1})
.set_name("point_polygon_distance_benchmark_simple_polygon");

// Benchmark scalability with complex multipolygon (100 sides, 10 holes, 3 polys)
NVBENCH_BENCH_TYPES(pairwise_point_polygon_distance_benchmark,
NVBENCH_TYPE_AXES(floating_point_types))
.set_type_axes_names({"CoordsType"})
.add_int64_axis("num_pairs", {1'000, 10'000, 100'000, 1'000'000})
.add_int64_axis("num_polygons_per_multipolygon", {2})
.add_int64_axis("num_holes_per_polygon", {3})
.add_int64_axis("num_edges_per_ring", {50})
.add_int64_axis("num_points_per_multipoint", {1})
.set_name("point_polygon_distance_benchmark_complex_polygon");

// // Benchmark impact of rings (100K pairs, 1 polygon, 3 sides)
NVBENCH_BENCH_TYPES(pairwise_point_polygon_distance_benchmark,
NVBENCH_TYPE_AXES(floating_point_types))
.set_type_axes_names({"CoordsType"})
.add_int64_axis("num_pairs", {10'000})
.add_int64_axis("num_polygons_per_multipolygon", {1})
.add_int64_axis("num_holes_per_polygon", {0, 10, 100, 1000})
.add_int64_axis("num_edges_per_ring", {3})
.add_int64_axis("num_points_per_multipoint", {1})
.set_name("point_polygon_distance_benchmark_ring_numbers");

// Benchmark impact of rings (1M pairs, 1 polygon, 0 holes, 3 sides)
NVBENCH_BENCH_TYPES(pairwise_point_polygon_distance_benchmark,
NVBENCH_TYPE_AXES(floating_point_types))
.set_type_axes_names({"CoordsType"})
.add_int64_axis("num_pairs", {100})
.add_int64_axis("num_polygons_per_multipolygon", {1})
.add_int64_axis("num_holes_per_polygon", {0})
.add_int64_axis("num_edges_per_ring", {3})
.add_int64_axis("num_points_per_multipoint", {50, 5'00, 5'000, 50'000, 500'000})
.set_name("point_polygon_distance_benchmark_points_in_multipoint");
10 changes: 5 additions & 5 deletions cpp/include/cuspatial/detail/nvtx/ranges.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-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.
Expand All @@ -20,16 +20,16 @@

namespace cuspatial {
/**
* @brief Tag type for libcudf's NVTX domain.
* @brief Tag type for libcuspatial's NVTX domain.
*/
struct libcuspatial_domain {
static constexpr char const* name{"libcuspatial"}; ///< Name of the libcudf domain
static constexpr char const* name{"libcuspatial"}; ///< Name of the libcuspatial domain
};

/**
* @brief Alias for an NVTX range in the libcudf domain.
* @brief Alias for an NVTX range in the libcuspatial domain.
*/
using thread_range = ::nvtx3::domain_thread_range<libcudf_domain>;
using thread_range = ::nvtx3::domain_thread_range<libcuspatial_domain>;

} // namespace cuspatial

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cuspatial/cuda_utils.hpp>
#include <cuspatial/detail/iterator.hpp>
#include <cuspatial/detail/nvtx/ranges.hpp>
#include <cuspatial/detail/utility/device_atomics.cuh>
#include <cuspatial/detail/utility/linestring.cuh>
#include <cuspatial/detail/utility/zero_data.cuh>
Expand Down Expand Up @@ -120,6 +121,8 @@ OutputIt pairwise_point_polygon_distance(MultiPointRange multipoints,
OutputIt distances_first,
rmm::cuda_stream_view stream)
{
CUSPATIAL_FUNC_RANGE();

using T = typename MultiPointRange::element_t;
using index_t = typename MultiPointRange::index_t;

Expand Down
56 changes: 56 additions & 0 deletions cpp/include/cuspatial_test/geometry_generator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <cuspatial_test/random.cuh>
#include <cuspatial_test/vector_factories.cuh>

#include <cuspatial/cuda_utils.hpp>
Expand Down Expand Up @@ -249,5 +250,60 @@ auto generate_multipolygon_array(multipolygon_generator_parameter<T> params,
std::move(coordinates));
}

/**
* @brief Struct to store the parameters of the multipoint aray
*
* @tparam T Type of the coordinates
*/
template <typename T>
struct multipoint_generator_parameter {
using element_t = T;

std::size_t num_multipoints;
std::size_t num_points_per_multipoints;
vec_2d<T> lower_left;
vec_2d<T> upper_right;

CUSPATIAL_HOST_DEVICE std::size_t num_points()
{
return num_multipoints * num_points_per_multipoints;
}
};

/**
* @brief Helper to generate random multipoints within a range
*
* @tparam T The floating point type for the coordinates
* @param params Parameters to specify for the multipoints
* @param stream The CUDA stream to use for device memory operations and kernel launches
* @return a cuspatial::test::multipoint_array object
*/
template <typename T>
auto generate_multipoint_array(multipoint_generator_parameter<T> params,
rmm::cuda_stream_view stream)
{
rmm::device_uvector<vec_2d<T>> coordinates(params.num_points(), stream);
rmm::device_uvector<std::size_t> offsets(params.num_multipoints + 1, stream);

thrust::sequence(rmm::exec_policy(stream),
offsets.begin(),
offsets.end(),
std::size_t{0},
params.num_points_per_multipoints);

auto engine_x = deterministic_engine(params.num_points());
auto engine_y = deterministic_engine(2 * params.num_points());

auto x_dist = make_uniform_dist(params.lower_left.x, params.upper_right.x);
auto y_dist = make_uniform_dist(params.lower_left.y, params.upper_right.y);

auto point_gen =
point_generator(params.lower_left, params.upper_right, engine_x, engine_y, x_dist, y_dist);

thrust::tabulate(rmm::exec_policy(stream), coordinates.begin(), coordinates.end(), point_gen);

return make_multipoints_array(std::move(offsets), std::move(coordinates));
}

} // namespace test
} // namespace cuspatial
19 changes: 14 additions & 5 deletions cpp/include/cuspatial_test/random.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <algorithm>
#include <memory>

using namespace cuspatial;

/**
* @brief Identifies a probability distribution type.
*/
Expand Down Expand Up @@ -150,14 +152,21 @@ struct value_generator {
template <typename T, typename Generator>
struct point_generator {
using Cart2D = cuspatial::vec_2d<T>;
value_generator<T, Generator> vgen;

point_generator(T lower_bound, T upper_bound, thrust::minstd_rand& engine, Generator gen)
: vgen(lower_bound, upper_bound, engine, gen)
value_generator<T, Generator> vgenx;
value_generator<T, Generator> vgeny;

point_generator(vec_2d<T> lower_left,
vec_2d<T> upper_right,
thrust::minstd_rand& engine_x,
thrust::minstd_rand& engine_y,
Generator gen_x,
Generator gen_y)
: vgenx(lower_left.x, upper_right.x, engine_x, gen_x),
vgeny(lower_left.y, upper_right.y, engine_y, gen_y)
{
}

__device__ Cart2D operator()(size_t n) { return {vgen(n), vgen(n)}; }
__device__ Cart2D operator()(size_t n) { return {vgenx(n), vgeny(n)}; }
};

/**
Expand Down
29 changes: 26 additions & 3 deletions cpp/include/cuspatial_test/vector_factories.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,22 @@ auto make_multilinestring_array(std::initializer_list<std::size_t> geometry_inl,
template <typename GeometryArray, typename CoordinateArray>
class multipoint_array {
public:
multipoint_array(GeometryArray geometry_offsets_array, CoordinateArray coordinate_array)
using geometry_t = typename GeometryArray::value_type;
using coord_t = typename CoordinateArray::value_type;

multipoint_array(thrust::device_vector<geometry_t> geometry_offsets_array,
thrust::device_vector<coord_t> coordinate_array)
: _geometry_offsets(geometry_offsets_array), _coordinates(coordinate_array)
{
}

multipoint_array(rmm::device_uvector<geometry_t>&& geometry_offsets_array,
rmm::device_uvector<coord_t>&& coordinate_array)
: _geometry_offsets(std::move(geometry_offsets_array)),
_coordinates(std::move(coordinate_array))
{
}

/// Return the number of multipoints
auto size() { return _geometry_offsets.size() - 1; }

Expand Down Expand Up @@ -322,8 +333,20 @@ auto make_multipoints_array(std::initializer_list<std::initializer_list<vec_2d<T
return init;
});

return multipoint_array{rmm::device_vector<std::size_t>(offsets),
rmm::device_vector<vec_2d<T>>(coordinates)};
return multipoint_array<rmm::device_vector<std::size_t>, rmm::device_vector<vec_2d<T>>>{
rmm::device_vector<std::size_t>(offsets), rmm::device_vector<vec_2d<T>>(coordinates)};
}

/**
* @brief Factory method to construct multipoint array by moving the offsets and coordinates from
* `rmm::device_uvector`.
*/
template <typename IndexType, typename T>
auto make_multipoints_array(rmm::device_uvector<IndexType> geometry_offsets,
isVoid marked this conversation as resolved.
Show resolved Hide resolved
rmm::device_uvector<vec_2d<T>> coords)
{
return multipoint_array<rmm::device_uvector<std::size_t>, rmm::device_uvector<vec_2d<T>>>{
std::move(geometry_offsets), std::move(coords)};
}

} // namespace test
Expand Down
9 changes: 6 additions & 3 deletions cpp/tests/experimental/spatial/point_distance_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ struct PairwisePointDistanceTest : public ::testing::Test {
std::size_t seed,
rmm::cuda_stream_view stream = rmm::cuda_stream_default)
{
auto engine = deterministic_engine(0);
auto uniform = make_normal_dist<T>(0.0, 1.0);
auto pgen = point_generator(T{0.0}, T{1.0}, engine, uniform);
auto engine_x = deterministic_engine(0);
auto engine_y = deterministic_engine(0);
auto uniform_x = make_normal_dist<T>(0.0, 1.0);
auto uniform_y = make_normal_dist<T>(0.0, 1.0);
auto pgen =
point_generator(vec_2d<T>{0, 0}, vec_2d<T>{1, 1}, engine_x, engine_y, uniform_x, uniform_y);
rmm::device_vector<vec_2d<T>> points(num_points);
auto counting_iter = thrust::make_counting_iterator(seed);
thrust::transform(
Expand Down