28#ifndef REMORA_KERNELS_CLBLAS_VECTOR_ASSIGN_HPP
29#define REMORA_KERNELS_CLBLAS_VECTOR_ASSIGN_HPP
31#include "../../expression_types.hpp"
32#include "../../detail/traits.hpp"
34namespace remora{
namespace bindings{
36template<
class F,
class V>
37void apply(vector_expression<V, gpu_tag>& v_unreg, F
const& f_unreg) {
38 if(v_unreg().size() == 0)
return;
39 gpu::detail::meta_kernel k(
"blas_vector_apply_dense");
41 auto v = k.register_args(to_functor(v_unreg));
42 auto f = k.register_args(f_unreg);
45 k<<v(k.get_global_id(0))<<
" = " << f(v(k.get_global_id(0)))<<
";";
46 boost::compute::kernel kernel = k.compile(v_unreg().queue().get_context());
48 std::size_t global_work_size[1] = {v_unreg().size()};
49 v_unreg().queue().enqueue_nd_range_kernel(kernel, 1,
nullptr, global_work_size,
nullptr);
52template<
class F,
class V>
53void assign(vector_expression<V, gpu_tag>& v,
typename V::value_type t) {
54 static_assert(std::is_base_of<dense_tag, typename V::storage_type::storage_tag>::value,
"target must have dense storage for assignment");
55 auto f = device_traits<gpu_tag>::make_bind_second(F(), t);
64template<
class V,
class E,
class F>
65void vector_assign_functor(
66 vector_expression<V, gpu_tag>& v_unreg,
67 vector_expression<E, gpu_tag>
const& e_unreg,
71 if(v_unreg().size() == 0)
return;
73 gpu::detail::meta_kernel k(
"blas_vector_assign_functor_dense");
75 auto v = k.register_args(to_functor(v_unreg));
76 auto e = k.register_args(to_functor(e_unreg));
77 auto f = k.register_args(f_unreg);
80 k<<v(k.get_global_id(0))<<
" = " << f(v(k.get_global_id(0)), e(k.get_global_id(0)))<<
";";
81 boost::compute::kernel kernel = k.compile(v_unreg().queue().get_context());
83 std::size_t global_work_size[1] = {v_unreg().size()};
84 v_unreg().queue().enqueue_nd_range_kernel(kernel, 1,
nullptr, global_work_size,
nullptr);
92template<
class V,
class E>
94 vector_expression<V, gpu_tag>& v, vector_expression<E, gpu_tag>
const& e,
95 dense_tag t, dense_tag
97 vector_assign_functor(v, e, device_traits<gpu_tag>::right_arg<typename E::value_type>(), t, t);