2 * Copyright 2008-2013 NVIDIA Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <thrust/detail/config.h>
30 template <typename IndexType>
34 typedef IndexType index_type;
37 index_range(index_type begin, index_type end) : m_begin(begin), m_end(end) {}
40 index_type begin(void) const { return m_begin; }
43 index_type end(void) const { return m_end; }
46 index_type size(void) const { return m_end - m_begin; }
53 template <typename IndexType>
54 class uniform_decomposition
57 typedef IndexType index_type;
58 typedef index_range<index_type> range_type;
60 uniform_decomposition(index_type N, index_type granularity, index_type max_intervals)
62 m_intervals((N + granularity - 1) / granularity),
64 m_small_interval(granularity),
67 if(m_intervals > max_intervals)
69 m_small_interval = granularity * (m_intervals / max_intervals);
70 m_large_interval = m_small_interval + granularity;
71 m_threshold = m_intervals % max_intervals;
72 m_intervals = max_intervals;
77 index_range<index_type> operator[](const index_type& i) const
81 index_type begin = m_large_interval * i;
82 index_type end = begin + m_large_interval;
83 return range_type(begin, end);
87 index_type begin = m_large_interval * m_threshold + m_small_interval * (i - m_threshold);
88 index_type end = (begin + m_small_interval < m_N) ? begin + m_small_interval : m_N;
89 return range_type(begin, end);
94 index_type size(void) const
102 index_type m_intervals;
103 index_type m_threshold;
104 index_type m_small_interval;
105 index_type m_large_interval;
109 } // end namespace internal
110 } // end namespace detail
111 } // end namespace system
112 } // end namespace thrust