forked from arborx/ArborX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tstCompileOnlyAccessTraits.cpp
128 lines (107 loc) · 4.53 KB
/
tstCompileOnlyAccessTraits.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
/****************************************************************************
* 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_AccessTraits.hpp>
#include <ArborX_AttachIndices.hpp>
#include <ArborX_HyperPoint.hpp>
#include <ArborX_Point.hpp>
#include <Kokkos_Core.hpp>
using ArborX::PredicatesTag;
using ArborX::PrimitivesTag;
using ArborX::Details::check_valid_access_traits;
// NOTE Let's not bother with __host__ __device__ annotations here
struct NoAccessTraitsSpecialization
{};
struct EmptySpecialization
{};
template <typename Tag>
struct ArborX::AccessTraits<EmptySpecialization, Tag>
{};
struct InvalidMemorySpace
{};
template <typename Tag>
struct ArborX::AccessTraits<InvalidMemorySpace, Tag>
{
using memory_space = void;
};
struct SizeMemberFunctionNotStatic
{};
template <typename Tag>
struct ArborX::AccessTraits<SizeMemberFunctionNotStatic, Tag>
{
using memory_space = Kokkos::HostSpace;
int size(SizeMemberFunctionNotStatic) { return 255; }
};
template <class V, class Tag>
using deduce_type_t =
decltype(ArborX::AccessTraits<V, Tag>::get(std::declval<V>(), 0));
void test_access_traits_compile_only()
{
Kokkos::View<ArborX::Point *> p;
Kokkos::View<float **> v;
check_valid_access_traits(PrimitivesTag{}, p);
check_valid_access_traits(PrimitivesTag{}, v);
auto p_with_indices = ArborX::Experimental::attach_indices(p);
check_valid_access_traits(PrimitivesTag{}, p_with_indices,
ArborX::Details::DoNotCheckGetReturnType());
static_assert(
std::is_same_v<deduce_type_t<decltype(p_with_indices), PrimitivesTag>,
ArborX::PairValueIndex<ArborX::Point, unsigned>>);
auto p_with_indices_long = ArborX::Experimental::attach_indices<long>(p);
static_assert(std::is_same_v<
deduce_type_t<decltype(p_with_indices_long), PrimitivesTag>,
ArborX::PairValueIndex<ArborX::Point, long>>);
using NearestPredicate = decltype(ArborX::nearest(ArborX::Point{}));
Kokkos::View<NearestPredicate *> q;
check_valid_access_traits(PredicatesTag{}, q);
auto q_with_indices = ArborX::Experimental::attach_indices<long>(q);
check_valid_access_traits(PredicatesTag{}, q_with_indices);
using predicate = deduce_type_t<decltype(q_with_indices), PredicatesTag>;
static_assert(
std::is_same_v<
std::decay_t<decltype(ArborX::getData(std::declval<predicate>()))>,
long>);
struct CustomIndex
{
char index;
CustomIndex(int i) { index = i; }
};
auto q_with_custom_indices =
ArborX::Experimental::attach_indices<CustomIndex>(q);
check_valid_access_traits(PredicatesTag{}, q_with_custom_indices);
using predicate_custom =
deduce_type_t<decltype(q_with_custom_indices), PredicatesTag>;
static_assert(std::is_same_v<std::decay_t<decltype(ArborX::getData(
std::declval<predicate_custom>()))>,
CustomIndex>);
// Uncomment to see error messages
// check_valid_access_traits(PrimitivesTag{}, NoAccessTraitsSpecialization{});
// check_valid_access_traits(PrimitivesTag{}, EmptySpecialization{});
// check_valid_access_traits(PrimitivesTag{}, InvalidMemorySpace{});
// check_valid_access_traits(PrimitivesTag{}, SizeMemberFunctionNotStatic{});
}
void test_deduce_point_type_from_view()
{
using GoodOlePoint = ArborX::Point;
using ArborX::PrimitivesTag;
using ArborX::ExperimentalHyperGeometry::Point;
static_assert(
std::is_same_v<deduce_type_t<Kokkos::View<float **>, PrimitivesTag>,
GoodOlePoint>);
static_assert(
std::is_same_v<deduce_type_t<Kokkos::View<float *[3]>, PrimitivesTag>,
Point<3>>);
static_assert(
std::is_same_v<deduce_type_t<Kokkos::View<float *[2]>, PrimitivesTag>,
Point<2>>);
static_assert(
std::is_same_v<deduce_type_t<Kokkos::View<float *[5]>, PrimitivesTag>,
Point<5>>);
}