vector_assign.hpp
Go to the documentation of this file.
1 /*!
2  * \brief Assignment kernels for vector expressions
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_ASSIGN_HPP
29 #define REMORA_KERNELS_CLBLAS_VECTOR_ASSIGN_HPP
30 
31 #include "../../expression_types.hpp"
32 #include "../../detail/traits.hpp"
33 #include <boost/compute/iterator/zip_iterator.hpp>
34 #include <boost/compute/algorithm/copy.hpp>
35 #include <boost/compute/algorithm/transform.hpp>
36 #include <boost/compute/functional/bind.hpp>
37 
38 namespace remora{namespace bindings{
39 
40 template<class F, class V>
41 void assign(vector_expression<V, gpu_tag>& v, typename V::value_type t) {
42  auto unary = boost::compute::bind(F(),boost::compute::placeholders::_1, t);
43  boost::compute::transform(v().begin(),v().end(), v().begin(), unary, v().queue());
44 }
45 
46 /////////////////////////////////////////////////////////
47 //direct assignment of two vectors
48 ////////////////////////////////////////////////////////
49 
50 // Dense-Dense case
51 template< class V, class E>
52 void vector_assign(
53  vector_expression<V, gpu_tag>& v, vector_expression<E, gpu_tag> const& e,
54  dense_tag, dense_tag
55 ) {
56  boost::compute::copy(e().begin(),e().end(), v().begin(), v().queue());
57 }
58 
59 
60 ////////////////////////////////////////////
61 //assignment with functor
62 ////////////////////////////////////////////
63 
64 // Dense-Dense case
65 template<class V, class E, class F>
66 void vector_assign_functor(
67  vector_expression<V, gpu_tag>& v,
68  vector_expression<E, gpu_tag> const& e,
69  F f,
70  dense_tag, dense_tag
71 ) {
72  auto zip_begin = boost::compute::make_zip_iterator(boost::make_tuple(v().begin(), e().begin()));
73  auto zip_end = boost::compute::make_zip_iterator(boost::make_tuple(v().end(), e().end()));
74  boost::compute::transform( zip_begin,zip_end, v().begin(), boost::compute::detail::unpack(f), v().queue());
75 }
76 
77 }}
78 #endif