vector_fold.hpp
Go to the documentation of this file.
1 /*!
2  * \brief kernels for folding kernels with openCL
3  *
4  * \author O. Krause
5  * \date 2016
6  *
7  *
8  * \par Copyright 1995-2015 Shark Development Team
9  *
10  * <BR><HR>
11  * This file is part of Shark.
12  * <http://image.diku.dk/shark/>
13  *
14  * Shark is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * Shark is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
26  *
27  */
28 #ifndef REMORA_KERNELS_CLBLAS_VECTOR_FOLD_HPP
29 #define REMORA_KERNELS_CLBLAS_VECTOR_FOLD_HPP
30 
31 #include "../../expression_types.hpp"
32 #include "../../detail/traits.hpp"
33 #include <boost/compute/container/array.hpp>
34 #include <boost/compute/algorithm/reduce.hpp>
35 #include <boost/compute/algorithm/copy_n.hpp>
36 
37 namespace remora{namespace bindings{
38 
39 template<class F, class V>
40 void vector_fold(vector_expression<V, gpu_tag> const& v, typename F::result_type& value, dense_tag) {
41  boost::compute::array<typename F::result_type,1> val;
42  boost::compute::copy_n(&value,1,val.begin(), v().queue());
43  boost::compute::reduce(v().begin(), v().end(), val.begin(), F(), v().queue());
44  boost::compute::copy_n(val.begin(),1,&value, v().queue());
45 }
46 
47 
48 }}
49 #endif