Skip to content

Commit

Permalink
add multipoint_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isVoid committed Jun 12, 2023
1 parent 39f66d0 commit b4a2421
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
"source=${localWorkspaceFolder}/../.cache,target=/home/coder/.cache,type=bind,consistency=consistent",
"source=${localWorkspaceFolder}/../.config,target=/home/coder/.config,type=bind,consistency=consistent",
"source=${localWorkspaceFolder}/../.conda/pkgs,target=/home/coder/.conda/pkgs,type=bind,consistency=consistent",
"source=${localWorkspaceFolder}/../.conda/${localWorkspaceFolderBasename}/single,target=/home/coder/.conda/envs,type=bind,consistency=consistent"
"source=${localWorkspaceFolder}/../.conda/${localWorkspaceFolderBasename}/single,target=/home/coder/.conda/envs,type=bind,consistency=consistent",
"source=${localWorkspaceFolder}/../scratch,target=/home/coder/scratch,type=bind,consistency=consistent"
],

"customizations": {
"vscode": {
"extensions": [
"mutantdino.resourcemonitor",
"tamasfe.even-better-toml"
"tamasfe.even-better-toml",
"ms-toolsai.jupyter"
],
"settings": {
"files.trimFinalNewlines": true,
Expand Down
6 changes: 3 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF)
option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF)
option(DISABLE_DEPRECATION_WARNING "Disable warnings generated from deprecated declarations." OFF)
# Option to enable line info in CUDA device compilation to allow introspection when profiling / memchecking
option(CUDA_ENABLE_LINEINFO "Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler" OFF)
option(CUDA_ENABLE_LINEINFO "Enable the -lineinfo option for nvcc (useful for cuda-memcheck / profiler" ON)
# cudart can be statically linked or dynamically linked. The python ecosystem wants dynamic linking
option(CUDA_STATIC_RUNTIME "Statically link the CUDA toolkit runtime and libraries" OFF)

Expand All @@ -63,12 +63,12 @@ message(STATUS "CUSPATIAL: Enable the -lineinfo option for nvcc (useful for cuda
message(STATUS "CUSPATIAL: Statically link the CUDA toolkit runtime and libraries: ${CUDA_STATIC_RUNTIME}")

# Set a default build type if none was specified
rapids_cmake_build_type("Release")
rapids_cmake_build_type("Debug")
set(CUSPATIAL_BUILD_TESTS ${BUILD_TESTS})
set(CUSPATIAL_BUILD_BENCHMARKS ${BUILD_BENCHMARKS})

set(CUSPATIAL_CXX_FLAGS "")
set(CUSPATIAL_CUDA_FLAGS "")
set(CUSPATIAL_CUDA_FLAGS "-ftemplate-backtrace-limit=0")
set(CUSPATIAL_CXX_DEFINITIONS "")
set(CUSPATIAL_CUDA_DEFINITIONS "")

Expand Down
1 change: 1 addition & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ ConfigureTest(SINUSOIDAL_PROJECTION_TEST_EXP

# range
ConfigureTest(RANGE_TEST_EXP
range/multipoint_range_test.cu
range/multilinestring_range_test.cu
range/multipolygon_range_test.cu)

Expand Down
267 changes: 267 additions & 0 deletions cpp/tests/range/multipoint_range_test.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
* 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 <cudf/detail/utilities/vector_factories.hpp>
#include <cuspatial_test/base_fixture.hpp>
#include <cuspatial_test/vector_equality.hpp>
#include <cuspatial_test/vector_factories.cuh>

#include <cuspatial/geometry/segment.cuh>
#include <cuspatial/geometry/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/device_uvector.hpp>
#include <rmm/exec_policy.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <thrust/sequence.h>

#include <initializer_list>

using namespace cuspatial;
using namespace cuspatial::test;

template <typename T>
class MultipointRangeTest : public BaseFixture {
public:
struct copy_leading_point_per_multipoint {
template<typename MultiPointRef>
vec_2d<T> __device__ operator()(MultiPointRef multipoint)
{
return multipoint.size() > 0 ? multipoint[0] : vec_2d<T>{-1, -1};
}
};

template<typename MultiPointRange>
struct point_idx_to_geometry_idx {

MultiPointRange rng;

std::size_t __device__ operator()(std::size_t pidx)
{
return rng.geometry_idx_from_point_idx(pidx);
}
};

void SetUp() { make_test_multipoints(); }
auto range() { return test_multipoints.range(); }

virtual void make_test_multipoints() = 0;

void run_test()
{
test_num_multipoints();

test_num_points();

test_size();

test_multipoint_it();

test_begin();

test_end();

test_point_it();

test_offsets_it();

test_geometry_idx_from_point_idx();

test_subscript_operator();

test_point();

test_is_single_point_range();
}

virtual void test_num_multipoints() = 0;

virtual void test_num_points() = 0;

virtual void test_size() = 0;

virtual void test_multipoint_it() = 0;

virtual void test_begin() = 0;

virtual void test_end() = 0;

virtual void test_point_it() = 0;

virtual void test_offsets_it() = 0;

virtual void test_geometry_idx_from_point_idx() = 0;

virtual void test_subscript_operator() = 0;

virtual void test_point() = 0;

virtual void test_is_single_point_range() = 0;

protected:
rmm::device_uvector<vec_2d<T>> copy_leading_points()
{
auto rng = this->range();
rmm::device_uvector<vec_2d<T>> leading_points(rng.num_multipoints(), this->stream());
thrust::transform(rmm::exec_policy(this->stream()),
rng.multipoint_begin(),
rng.multipoin_end(),
leading_points.begin(),
copy_leading_point_per_multipoint{});

return leading_points;
}

rmm::device_uvector<vec_2d<T>> copy_all_points()
{
auto rng = this->range();
rmm::device_uvector<vec_2d<T>> points(rng.num_points(), this->stream());
thrust::copy(
rmm::exec_policy(this->stream()), rng.point_begin(), rng.point_end(), points.begin());
return points;
};

rmm::device_uvector<vec_2d<T>> copy_offsets()
{
auto rng = this->range();
rmm::device_uvector<std::size_t> offsets(rng.num_multipoints()+1, this->stream());
thrust::copy(
rmm::exec_policy(this->stream()), rng.offset_begin(), rng.offset_end(), offsets.begin());
return offsets;
};

rmm::device_uvector<std::size_t> copy_geoemtry_idx()
{
auto rng = this->range();
rmm::device_uvector<std::size_t> idx(rng.num_points(), this->stream());

thrust::tabulate(
rmm::exec_policy(this->stream()),
idx.begin(),
idx.end(),
point_idx_to_geometry_idx{rng}
);
return idx;
}

rmm::device_uvector<vec_2d<T>> copy_ith_multipoint(std::size_t i)
{
rmm::device_scalar<std::size_t> num_points(this->stream());

}

multipoint_array<T, std::size_t> test_multipoints;
};

template <typename T>
class EmptyMultiPointRangeTest : public MultipointRangeTest<T> {
public:
void make_test_multipoints() { this->test_multipoints = make_multipoint_array<T>({}); }

void test_num_multipoints() { EXPECT_EQ(this->range().num_multipoints(), 0); }

void test_num_points() { EXPECT_EQ(this->range().num_points(), 0); }

void test_size() { EXPECT_EQ(this->range().size(), 0); }

void test_multipoint_it()
{
auto leading_points = this->copy_leading_points();
auto expected = rmm::device_uvector<vec_2d<T>>(0, this->stream());
CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(leading_points, expected);
}

void test_begin() { EXPECT_EQ(this->range().begin(), this->range().multipoint_begin()); }

void test_end() { EXPECT_EQ(this->range().end(), this->range().multipoint_end()); }

void test_point_it()
{
auto points = this->copy_all_points();
auto expected = rmm::device_uvector<vec_2d<T>>(0, this->stream());
CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(points, expected);
}

void test_offsets_it() {
auto offsets = this->copy_all_points();
auto expected = make_device_vector<std::size_t>({0});
CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(offsets, expected);
}

void test_geometry_idx_from_point_idx()
{
auto geometry_indices = rmm::device_uvector<std::size_t>(0, this->stream());
auto expected = rmm::device_uvector<std::size_t>(0, this->stream()) ;

CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(geometry_indices, expected);
}

void test_subscript_operator()
{

}

};

template <typename T>
class LengthOneMultiPointRangeTest : public MultipointRangeTest<T> {
public:
void make_test_multipoints()
{
this->test_multipoints = make_multipoint_array<T>({{{1.0, 1.0}}});
}
};

template <typename T>
class LengthFiveMultiPointRangeTest : public MultipointRangeTest<T> {
public:
void make_test_multipoints()
{
this->test_multipoints = make_multipoint_array<T>({{{0.0, 0.0}, {1.0, 1.0}},
{{10.0, 10.0}},
{{20.0, 21.0}, {22.0, 23.0}},
{{30.0, 31.0}, {32.0, 33.0}, {34.0, 35.0}},
{{}}});
}
};

template <typename T>
class LengthOneThousandRangeTest : public MultipointRangeTest<T> {
public:
void make_test_multipoints()
{
std::size_t constexpr num_multipoints = 1000;
std::size_t constexpr num_point_per_multipoint = 3;

rmm::device_uvector<std::size_t> geometry_offsets(num_multipoints + 1, this->stream());
rmm::device_uvector<vec_2d<T>> coordinates(num_multipoints * num_point_per_multipoint,
this->stream());

thrust::sequence(
rmm::exec_policy(this->stream()), geometry_offsets.begin(), geometry_offsets.end(), 0, 3);

thrust::generate_n(rmm::exec_policy(this->stream()),
geometry_offsets.begin(),
geometry_offsets.end(),
[] __device__() {
return vec_2d<T>{0.0, 10.0};
});

this->test_multipoints =
make_multipoint_array<T>(std::move(geometry_offsets), std::move(coordinates));
}
};

0 comments on commit b4a2421

Please sign in to comment.