1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_SEARCH_ALL_HPP
12 #define BOOST_COMPUTE_ALGORITHM_DETAIL_SEARCH_ALL_HPP
14 #include <boost/compute/algorithm/copy.hpp>
15 #include <boost/compute/container/vector.hpp>
16 #include <boost/compute/detail/iterator_range_size.hpp>
17 #include <boost/compute/detail/meta_kernel.hpp>
18 #include <boost/compute/lambda.hpp>
19 #include <boost/compute/system.hpp>
26 /// \brief Search kernel class
28 /// Subclass of meta_kernel which is capable of performing pattern matching
30 template<class PatternIterator, class TextIterator, class OutputIterator>
31 class search_kernel : public meta_kernel
34 search_kernel() : meta_kernel("search")
37 void set_range(PatternIterator p_first,
38 PatternIterator p_last,
41 OutputIterator result)
43 m_p_count = iterator_range_size(p_first, p_last);
44 m_p_count_arg = add_arg<uint_>("p_count");
46 m_count = iterator_range_size(t_first, t_last);
47 m_count = m_count + 1 - m_p_count;
50 "uint i = get_global_id(0);\n" <<
51 "const uint i1 = i;\n" <<
53 "for(j = 0; j<p_count; j++,i++)\n" <<
55 " if(" << p_first[expr<uint_>("j")] << " != " <<
56 t_first[expr<uint_>("i")] << ")\n" <<
57 " j = p_count + 1;\n" <<
59 "if(j == p_count)\n" <<
60 result[expr<uint_>("i1")] << " = 1;\n" <<
62 result[expr<uint_>("i1")] << " = 0;\n";
65 event exec(command_queue &queue)
71 set_arg(m_p_count_arg, uint_(m_p_count));
73 return exec_1d(queue, 0, m_count);
82 } //end detail namespace
83 } //end compute namespace
84 } //end boost namespace
86 #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_SEARCH_ALL_HPP