-
Notifications
You must be signed in to change notification settings - Fork 34
/
tstIndexableGetter.cpp
155 lines (127 loc) · 5.03 KB
/
tstIndexableGetter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/****************************************************************************
* Copyright (c) 2017-2022 by the ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#include "ArborX_EnableDeviceTypes.hpp" // ARBORX_DEVICE_TYPES
#include <ArborX_AccessTraits.hpp>
#include <ArborX_IndexableGetter.hpp>
#include "BoostTest_CUDA_clang_workarounds.hpp"
#include <boost/test/unit_test.hpp>
using namespace ArborX::Details;
#include <ArborX_HyperPoint.hpp>
template <typename MemorySpace>
struct PointCloud
{
ArborX::Point *data;
int n;
};
template <typename MemorySpace>
struct ArborX::AccessTraits<PointCloud<MemorySpace>, ArborX::PrimitivesTag>
{
using Points = PointCloud<MemorySpace>;
static KOKKOS_FUNCTION std::size_t size(Points const &points)
{
return points.n;
}
static KOKKOS_FUNCTION auto get(Points const &points, std::size_t i)
{
return points.data[i];
}
using memory_space = MemorySpace;
};
template <typename MemorySpace>
struct PairPointIndexCloud
{
ArborX::Point *data;
int n;
};
template <typename MemorySpace>
struct ArborX::AccessTraits<PairPointIndexCloud<MemorySpace>,
ArborX::PrimitivesTag>
{
using Points = PairPointIndexCloud<MemorySpace>;
static KOKKOS_FUNCTION std::size_t size(Points const &points)
{
return points.n;
}
static KOKKOS_FUNCTION auto get(Points const &points, std::size_t i)
{
return ArborX::PairValueIndex<ArborX::Point, int>{points.data[i], (int)i};
}
using memory_space = MemorySpace;
};
template <typename Indexables, typename BoundingVolume>
struct SceneReductionFunctor
{
Indexables _indexables;
KOKKOS_FUNCTION void init(BoundingVolume &volume)
{
volume = BoundingVolume{};
}
KOKKOS_FUNCTION void operator()(int i, BoundingVolume &update) const
{
ArborX::Details::expand(update, _indexables(i));
}
KOKKOS_FUNCTION void join(BoundingVolume &result,
BoundingVolume const &update)
{
expand(result, update);
}
};
template <typename ExecutionSpace, typename Indexables, typename Box>
inline void calculateBoundingBoxOfTheScene(ExecutionSpace const &space,
Indexables const &indexables,
Box &scene_bounding_box)
{
Kokkos::parallel_reduce(
"ArborX::TreeConstruction::calculate_bounding_box_of_the_scene",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, indexables.size()),
SceneReductionFunctor<Indexables, Box>{indexables}, scene_bounding_box);
}
BOOST_AUTO_TEST_SUITE(IndexableGetterAccess)
BOOST_AUTO_TEST_CASE_TEMPLATE(indexables, DeviceType, ARBORX_DEVICE_TYPES)
{
// Test that the two-level wrapping Data -> AccessValues -> Indexables by
// using DefaultIndexableGetter works correctly.
using ExecutionSpace = typename DeviceType::execution_space;
using MemorySpace = typename DeviceType::memory_space;
using ArborX::Details::equals;
Kokkos::View<ArborX::Point *, MemorySpace> points("Testing::points", 2);
auto points_host = Kokkos::create_mirror_view(points);
points_host(0) = {-1, -1, -1};
points_host(1) = {1, 1, 1};
Kokkos::deep_copy(points, points_host);
ArborX::Box scene_bounding_box = ArborX::Box{{-1, -1, -1}, {1, 1, 1}};
using IndexableGetter = ArborX::Details::DefaultIndexableGetter;
IndexableGetter indexable_getter;
{
PointCloud<MemorySpace> points_cloud{points.data(), (int)points.size()};
using Primitives = ArborX::Details::AccessValues<decltype(points_cloud),
ArborX::PrimitivesTag>;
Primitives primitives(points_cloud);
ArborX::Details::Indexables<Primitives, IndexableGetter> indexables{
primitives, indexable_getter};
ArborX::Box box;
calculateBoundingBoxOfTheScene(ExecutionSpace{}, indexables, box);
BOOST_TEST(equals(box, scene_bounding_box));
}
{
PairPointIndexCloud<MemorySpace> points_cloud{points.data(),
(int)points.size()};
using Primitives = ArborX::Details::AccessValues<decltype(points_cloud),
ArborX::PrimitivesTag>;
Primitives primitives(points_cloud);
ArborX::Details::Indexables<Primitives, IndexableGetter> indexables{
primitives, indexable_getter};
ArborX::Box box;
calculateBoundingBoxOfTheScene(ExecutionSpace{}, indexables, box);
BOOST_TEST(equals(box, scene_bounding_box));
}
}
BOOST_AUTO_TEST_SUITE_END()