~ubuntu-branches/ubuntu/utopic/libthrust/utopic

« back to all changes in this revision

Viewing changes to system/detail/generic/select_system.h

  • Committer: Package Import Robot
  • Author(s): Andreas Beckmann
  • Date: 2013-07-10 12:57:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130710125733-my19jic71sqsabaj
Tags: 1.7.0-1
* New upstream release.  (Closes: #715362)
* Update watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#pragma once
18
18
 
19
19
#include <thrust/detail/config.h>
 
20
#include <thrust/detail/execution_policy.h>
20
21
#include <thrust/detail/type_traits.h>
 
22
#include <thrust/detail/type_traits/is_metafunction_defined.h>
21
23
#include <thrust/iterator/detail/minimum_system.h>
22
24
#include <thrust/system/detail/generic/type_traits.h>
23
25
#include <thrust/iterator/iterator_traits.h>
30
32
{
31
33
namespace generic
32
34
{
33
 
 
34
 
template<typename Tag>
 
35
namespace select_system_detail
 
36
{
 
37
 
 
38
 
 
39
// min_system case 1: both systems have the same type, just return the first one
 
40
template<typename System>
 
41
__host__ __device__
 
42
System &min_system(thrust::execution_policy<System> &system1,
 
43
                   thrust::execution_policy<System> &)
 
44
{
 
45
  return thrust::detail::derived_cast(system1);
 
46
} // end min_system()
 
47
 
 
48
 
 
49
// min_system case 2: systems have differing type and the first type is considered the minimum
 
50
template<typename System1, typename System2>
 
51
__host__ __device__
 
52
  typename thrust::detail::enable_if<
 
53
    thrust::detail::is_same<
 
54
      System1,
 
55
      typename thrust::detail::minimum_system<System1,System2>::type
 
56
    >::value,
 
57
    System1 &
 
58
  >::type
 
59
    min_system(thrust::execution_policy<System1> &system1, thrust::execution_policy<System2> &)
 
60
{
 
61
  return thrust::detail::derived_cast(system1);
 
62
} // end min_system()
 
63
 
 
64
 
 
65
// min_system case 3: systems have differing type and the second type is considered the minimum
 
66
template<typename System1, typename System2>
 
67
__host__ __device__
 
68
  typename thrust::detail::enable_if<
 
69
    thrust::detail::is_same<
 
70
      System2,
 
71
      typename thrust::detail::minimum_system<System1,System2>::type
 
72
    >::value,
 
73
    System2 &
 
74
  >::type
 
75
    min_system(thrust::execution_policy<System1> &, thrust::execution_policy<System2> &system2)
 
76
{
 
77
  return thrust::detail::derived_cast(system2);
 
78
} // end min_system()
 
79
 
 
80
 
 
81
} // end select_system_detail
 
82
 
 
83
 
 
84
template<typename System>
35
85
__host__ __device__
36
86
  typename thrust::detail::disable_if<
37
 
    select_system1_exists<Tag>::value,
38
 
    Tag
39
 
  >::type
40
 
    select_system(Tag)
41
 
{
42
 
  return Tag();
43
 
} // end select_system()
44
 
 
45
 
template<typename Tag1, typename Tag2>
46
 
__host__ __device__
47
 
  typename thrust::detail::lazy_disable_if<
48
 
    select_system2_exists<Tag1,Tag2>::value,
49
 
    thrust::detail::minimum_system<Tag1,Tag2>
50
 
  >::type
51
 
    select_system(Tag1, Tag2)
52
 
{
53
 
  // for now, return minimum_system
54
 
  return typename thrust::detail::minimum_system<Tag1,Tag2>::type();
55
 
} // end select_system()
56
 
 
57
 
template<typename Tag1, typename Tag2, typename Tag3>
58
 
__host__ __device__
59
 
  typename thrust::detail::lazy_disable_if<
60
 
    select_system3_exists<Tag1,Tag2,Tag3>::value,
61
 
    thrust::detail::minimum_system<Tag1,Tag2,Tag3>
62
 
  >::type
63
 
    select_system(Tag1, Tag2, Tag3)
64
 
{
65
 
  // for now, return minimum_system
66
 
  return typename thrust::detail::minimum_system<Tag1,Tag2,Tag3>::type();
67
 
} // end select_system()
68
 
 
69
 
template<typename Tag1, typename Tag2, typename Tag3, typename Tag4>
70
 
__host__ __device__
71
 
  typename thrust::detail::lazy_disable_if<
72
 
    select_system4_exists<Tag1,Tag2,Tag3,Tag4>::value,
73
 
    thrust::detail::minimum_system<Tag1,Tag2,Tag3,Tag4>
74
 
  >::type
75
 
    select_system(Tag1, Tag2, Tag3, Tag4)
76
 
{
77
 
  // for now, return minimum_system
78
 
  return typename thrust::detail::minimum_system<Tag1,Tag2,Tag3,Tag4>::type();
79
 
} // end select_system()
 
87
    select_system1_exists<System>::value,
 
88
    System &
 
89
  >::type
 
90
    select_system(thrust::execution_policy<System> &system)
 
91
{
 
92
  return thrust::detail::derived_cast(system);
 
93
} // end select_system()
 
94
 
 
95
 
 
96
template<typename System1, typename System2>
 
97
__host__ __device__
 
98
  typename thrust::detail::enable_if_defined<
 
99
    thrust::detail::minimum_system<System1,System2>
 
100
  >::type
 
101
    &select_system(thrust::execution_policy<System1> &system1,
 
102
                   thrust::execution_policy<System2> &system2)
 
103
{
 
104
  return select_system_detail::min_system(system1,system2);
 
105
} // end select_system()
 
106
 
 
107
 
 
108
template<typename System1, typename System2, typename System3>
 
109
__host__ __device__
 
110
  typename thrust::detail::lazy_disable_if<
 
111
    select_system3_exists<System1,System2,System3>::value,
 
112
    thrust::detail::minimum_system<System1,System2,System3>
 
113
  >::type
 
114
    &select_system(thrust::execution_policy<System1> &system1,
 
115
                   thrust::execution_policy<System2> &system2,
 
116
                   thrust::execution_policy<System3> &system3)
 
117
{
 
118
  return select_system(select_system(system1,system2), system3);
 
119
} // end select_system()
 
120
 
 
121
 
 
122
template<typename System1, typename System2, typename System3, typename System4>
 
123
__host__ __device__
 
124
  typename thrust::detail::lazy_disable_if<
 
125
    select_system4_exists<System1,System2,System3,System4>::value,
 
126
    thrust::detail::minimum_system<System1,System2,System3,System4>
 
127
  >::type
 
128
    &select_system(thrust::execution_policy<System1> &system1,
 
129
                   thrust::execution_policy<System2> &system2,
 
130
                   thrust::execution_policy<System3> &system3,
 
131
                   thrust::execution_policy<System4> &system4)
 
132
{
 
133
  return select_system(select_system(system1,system2,system3), system4);
 
134
} // end select_system()
 
135
 
 
136
 
 
137
template<typename System1, typename System2, typename System3, typename System4, typename System5>
 
138
__host__ __device__
 
139
  typename thrust::detail::lazy_disable_if<
 
140
    select_system5_exists<System1,System2,System3,System4,System5>::value,
 
141
    thrust::detail::minimum_system<System1,System2,System3,System4,System5>
 
142
  >::type
 
143
    &select_system(thrust::execution_policy<System1> &system1,
 
144
                   thrust::execution_policy<System2> &system2,
 
145
                   thrust::execution_policy<System3> &system3,
 
146
                   thrust::execution_policy<System4> &system4,
 
147
                   thrust::execution_policy<System5> &system5)
 
148
{
 
149
  return select_system(select_system(system1,system2,system3,system4), system5);
 
150
} // end select_system()
 
151
 
 
152
 
 
153
template<typename System1, typename System2, typename System3, typename System4, typename System5, typename System6>
 
154
__host__ __device__
 
155
  typename thrust::detail::lazy_disable_if<
 
156
    select_system6_exists<System1,System2,System3,System4,System5,System6>::value,
 
157
    thrust::detail::minimum_system<System1,System2,System3,System4,System5,System6>
 
158
  >::type
 
159
    &select_system(thrust::execution_policy<System1> &system1,
 
160
                   thrust::execution_policy<System2> &system2,
 
161
                   thrust::execution_policy<System3> &system3,
 
162
                   thrust::execution_policy<System4> &system4,
 
163
                   thrust::execution_policy<System5> &system5,
 
164
                   thrust::execution_policy<System6> &system6)
 
165
{
 
166
  return select_system(select_system(system1,system2,system3,system4,system5), system6);
 
167
} // end select_system()
 
168
 
80
169
 
81
170
// map a single any_system_tag to device_system_tag
82
171
inline __host__ __device__
85
174
  return thrust::device_system_tag();
86
175
} // end select_system()
87
176
 
 
177
 
88
178
} // end generic
89
179
} // end detail
90
180
} // end system