MCPcopy Create free account
hub / github.com/boostorg/compute / generic_reduce

Function generic_reduce

include/boost/compute/algorithm/reduce.hpp:157–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155
156template<class InputIterator, class OutputIterator, class BinaryFunction>
157inline void generic_reduce(InputIterator first,
158 InputIterator last,
159 OutputIterator result,
160 BinaryFunction function,
161 command_queue &queue)
162{
163 typedef typename
164 std::iterator_traits<InputIterator>::value_type
165 input_type;
166 typedef typename
167 boost::compute::result_of<BinaryFunction(input_type, input_type)>::type
168 result_type;
169
170 const device &device = queue.get_device();
171 const context &context = queue.get_context();
172
173 size_t count = detail::iterator_range_size(first, last);
174
175 if(device.type() & device::cpu){
176 boost::compute::vector<result_type> value(1, context);
177 detail::serial_reduce(first, last, value.begin(), function, queue);
178 boost::compute::copy_n(value.begin(), 1, result, queue);
179 }
180 else {
181 size_t block_size = 256;
182
183 // first pass
184 vector<result_type> results = detail::block_reduce(first,
185 count,
186 block_size,
187 function,
188 queue);
189
190 if(results.size() > 1){
191 detail::inplace_reduce(results.begin(),
192 results.end(),
193 function,
194 queue);
195 }
196
197 boost::compute::copy_n(results.begin(), 1, result, queue);
198 }
199}
200
201template<class InputIterator, class OutputIterator, class T>
202inline void dispatch_reduce(InputIterator first,

Callers 1

dispatch_reduceFunction · 0.85

Calls 11

iterator_range_sizeFunction · 0.85
serial_reduceFunction · 0.85
copy_nFunction · 0.85
block_reduceFunction · 0.85
inplace_reduceFunction · 0.85
get_deviceMethod · 0.45
get_contextMethod · 0.45
typeMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected