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

Function transform_if_impl

include/boost/compute/algorithm/transform_if.hpp:30–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29template<class InputIterator, class OutputIterator, class UnaryFunction, class Predicate>
30inline OutputIterator transform_if_impl(InputIterator first,
31 InputIterator last,
32 OutputIterator result,
33 UnaryFunction function,
34 Predicate predicate,
35 bool copyIndex,
36 command_queue &queue)
37{
38 typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;
39
40 size_t count = detail::iterator_range_size(first, last);
41 if(count == 0){
42 return result;
43 }
44
45 const context &context = queue.get_context();
46
47 // storage for destination indices
48 ::boost::compute::vector<cl_uint> indices(count, context);
49
50 // write counts
51 ::boost::compute::detail::meta_kernel k1("transform_if_write_counts");
52 k1 << indices.begin()[k1.get_global_id(0)] << " = "
53 << predicate(first[k1.get_global_id(0)]) << " ? 1 : 0;\n";
54 k1.exec_1d(queue, 0, count);
55
56 // count number of elements to be copied
57 size_t copied_element_count =
58 ::boost::compute::count(indices.begin(), indices.end(), 1, queue);
59
60 // scan indices
61 ::boost::compute::exclusive_scan(
62 indices.begin(), indices.end(), indices.begin(), queue
63 );
64
65 // copy values
66 ::boost::compute::detail::meta_kernel k2("transform_if_do_copy");
67 k2 << "if(" << predicate(first[k2.get_global_id(0)]) << ")" <<
68 " " << result[indices.begin()[k2.get_global_id(0)]] << "=";
69
70 if(copyIndex){
71 k2 << k2.get_global_id(0) << ";\n";
72 }
73 else {
74 k2 << function(first[k2.get_global_id(0)]) << ";\n";
75 }
76
77 k2.exec_1d(queue, 0, count);
78
79 return result + static_cast<difference_type>(copied_element_count);
80}
81
82template<class InputIterator, class UnaryFunction, class Predicate>
83inline discard_iterator transform_if_impl(InputIterator first,

Callers 2

transform_ifFunction · 0.85
copy_index_ifFunction · 0.85

Calls 10

iterator_range_sizeFunction · 0.85
countFunction · 0.85
exclusive_scanFunction · 0.85
functionClass · 0.85
count_ifFunction · 0.85
get_global_idMethod · 0.80
exec_1dMethod · 0.80
get_contextMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected