File size: 4,793 Bytes
be11144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/detail/seq.h>
#include <thrust/system/cpp/detail/par.h>
#include <thrust/system/omp/detail/par.h>
#include <thrust/system/tbb/detail/par.h>

#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
#  include <thrust/system/cuda/detail/par.h>
#endif

#if THRUST_CPP_DIALECT >= 2011

template<typename T>
struct test_allocator_t
{
};

test_allocator_t<int> test_allocator = test_allocator_t<int>();

template<int I>
struct test_dependency_t
{
};

template<int I>
test_dependency_t<I> test_dependency()
{
    return {};
}

template<typename Policy, template<typename> class CRTPBase>
struct policy_info
{
    using policy = Policy;

    template<template<template<typename> class, typename...> class Template, typename ...Arguments>
    using apply_base_first = Template<CRTPBase, Arguments...>;

    template<template<typename, template<typename> class, typename...> class Template, typename First, typename ...Arguments>
    using apply_base_second = Template<First, CRTPBase, Arguments...>;
};

template<typename PolicyInfo>
struct TestDependencyAttachment
{
    template<typename ...Expected, typename T>
    static void assert_correct(T)
    {
        ASSERT_EQUAL(
            (thrust::detail::is_same<
                T,
                typename PolicyInfo::template apply_base_first<
                    thrust::detail::execute_with_dependencies,
                    Expected...
                >
            >::value), true);
    }

    template<typename Allocator, typename ...Expected, typename T>
    static void assert_correct_with_allocator(T)
    {
        ASSERT_EQUAL(
            (thrust::detail::is_same<
                T,
                typename PolicyInfo::template apply_base_second<
                    thrust::detail::execute_with_allocator_and_dependencies,
                    Allocator,
                    Expected...
                >
            >::value), true);
    }

    void operator()()
    {
        typename PolicyInfo::policy policy;

        assert_correct<
            test_dependency_t<1>
        >(policy
            .after(
                test_dependency<1>()
            )
        );

        assert_correct<
            test_dependency_t<1>,
            test_dependency_t<2>
        >(policy
            .after(
                test_dependency<1>(),
                test_dependency<2>()
            )
        );

        assert_correct<
            test_dependency_t<1>,
            test_dependency_t<2>,
            test_dependency_t<3>
        >(policy
            .after(
                test_dependency<1>(),
                test_dependency<2>(),
                test_dependency<3>()
            )
        );

        assert_correct_with_allocator<
            test_allocator_t<int> &,
            test_dependency_t<1>
        >(policy(test_allocator)
            .after(
                test_dependency<1>()
            )
        );

        assert_correct_with_allocator<
            test_allocator_t<int> &,
            test_dependency_t<1>,
            test_dependency_t<2>
        >(policy(test_allocator)
            .after(
                test_dependency<1>(),
                test_dependency<2>()
            )
        );

        assert_correct_with_allocator<
            test_allocator_t<int> &,
            test_dependency_t<1>,
            test_dependency_t<2>,
            test_dependency_t<3>
        >(policy(test_allocator)
            .after(
                test_dependency<1>(),
                test_dependency<2>(),
                test_dependency<3>()
            )
        );
    }
};

typedef policy_info<
    thrust::detail::seq_t,
    thrust::system::detail::sequential::execution_policy
> sequential_info;
typedef policy_info<
    thrust::system::cpp::detail::par_t,
    thrust::system::cpp::detail::execution_policy
> cpp_par_info;
typedef policy_info<
    thrust::system::omp::detail::par_t,
    thrust::system::omp::detail::execution_policy
> omp_par_info;
typedef policy_info<
    thrust::system::tbb::detail::par_t,
    thrust::system::tbb::detail::execution_policy
> tbb_par_info;

#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
typedef policy_info<
    thrust::system::cuda::detail::par_t,
    thrust::cuda_cub::execute_on_stream_base
> cuda_par_info;
#endif

SimpleUnitTest<
    TestDependencyAttachment,
    unittest::type_list<
        // TODO: uncomment when dependencies are generalized to all backends
        // sequential_info,
        // cpp_par_info,
        // omp_par_info,
        // tbb_par_info,
#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
        cuda_par_info
#endif
    >
> TestDependencyAttachmentInstance;

#else // C++11

void TestDummy()
{
}
DECLARE_UNITTEST(TestDummy);

#endif // C++11