File indexing completed on 2025-01-18 09:29:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_SEARCH_ALL_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_DETAIL_SEARCH_ALL_HPP
0013
0014 #include <boost/compute/algorithm/copy.hpp>
0015 #include <boost/compute/container/vector.hpp>
0016 #include <boost/compute/detail/iterator_range_size.hpp>
0017 #include <boost/compute/detail/meta_kernel.hpp>
0018 #include <boost/compute/lambda.hpp>
0019 #include <boost/compute/system.hpp>
0020
0021 namespace boost {
0022 namespace compute {
0023 namespace detail {
0024
0025
0026
0027
0028
0029
0030 template<class PatternIterator, class TextIterator, class OutputIterator>
0031 class search_kernel : public meta_kernel
0032 {
0033 public:
0034 search_kernel() : meta_kernel("search")
0035 {}
0036
0037 void set_range(PatternIterator p_first,
0038 PatternIterator p_last,
0039 TextIterator t_first,
0040 TextIterator t_last,
0041 OutputIterator result)
0042 {
0043 m_p_count = iterator_range_size(p_first, p_last);
0044 m_p_count_arg = add_arg<uint_>("p_count");
0045
0046 m_count = iterator_range_size(t_first, t_last);
0047 m_count = m_count + 1 - m_p_count;
0048
0049 *this <<
0050 "uint i = get_global_id(0);\n" <<
0051 "const uint i1 = i;\n" <<
0052 "uint j;\n" <<
0053 "for(j = 0; j<p_count; j++,i++)\n" <<
0054 "{\n" <<
0055 " if(" << p_first[expr<uint_>("j")] << " != " <<
0056 t_first[expr<uint_>("i")] << ")\n" <<
0057 " j = p_count + 1;\n" <<
0058 "}\n" <<
0059 "if(j == p_count)\n" <<
0060 result[expr<uint_>("i1")] << " = 1;\n" <<
0061 "else\n" <<
0062 result[expr<uint_>("i1")] << " = 0;\n";
0063 }
0064
0065 event exec(command_queue &queue)
0066 {
0067 if(m_count == 0) {
0068 return event();
0069 }
0070
0071 set_arg(m_p_count_arg, uint_(m_p_count));
0072
0073 return exec_1d(queue, 0, m_count);
0074 }
0075
0076 private:
0077 size_t m_p_count;
0078 size_t m_p_count_arg;
0079 size_t m_count;
0080 };
0081
0082 }
0083 }
0084 }
0085
0086 #endif