28 #ifndef REMORA_GPU_VECTOR_PROXY_HPP 29 #define REMORA_GPU_VECTOR_PROXY_HPP 31 #include "../expression_types.hpp" 33 #include <boost/compute/iterator/strided_iterator.hpp> 34 #include <boost/compute/iterator/buffer_iterator.hpp> 39 template<
class Arg,
class T>
40 struct induced_vector_adaptor_element{
41 typedef T result_type;
43 gpu::dense_vector_storage<T> storage;
46 template<
class Arg1,
class Arg2,
class T>
47 boost::compute::detail::meta_kernel& operator<< (
48 boost::compute::detail::meta_kernel& k,
49 induced_vector_adaptor_element<Arg1, Arg2, T>
const& e
51 return k<< k.get_buffer_identifier<T>(e.storage.buffer, boost::compute::memory_object::global_memory)
52 <<
" [ "<<e.storage.offset <<
"+("<<e.arg <<
")*"<<e.storage.stride<<
']';
57 class dense_vector_adaptor<T,gpu_tag>:
public vector_expression<dense_vector_adaptor<T, gpu_tag>, gpu_tag > {
59 typedef std::size_t size_type;
60 typedef typename std::remove_const<T>::type value_type;
61 typedef value_type
const& const_reference;
64 typedef dense_vector_adaptor<T const> const_closure_type;
65 typedef dense_vector_adaptor closure_type;
66 typedef gpu::dense_vector_storage<T> storage_type;
67 typedef gpu::dense_vector_storage<value_type const> const_storage_type;
68 typedef elementwise<dense_tag> evaluation_category;
77 dense_vector_adaptor(vector_expression<E, gpu_tag>
const& expression)
78 : m_storage(expression().raw_storage())
79 , m_queue(&expression().queue())
80 , m_size(expression().size()){}
87 dense_vector_adaptor(vector_expression<E,gpu_tag>& expression)
88 : m_storage(expression().raw_storage())
89 , m_queue(&expression().queue())
90 , m_size(expression().size()){}
94 dense_vector_adaptor(matrix_expression<E, gpu_tag>
const& expression)
95 : m_size(expression().size1() * expression().size2()), m_queue(&expression().queue()){
96 gpu::dense_matrix_storage<T> storage = expression().raw_storage();
97 m_storage.buffer = storage.buffer;
98 m_storage.offset = storage.offset;
99 m_storage.stride = storage.leading_dimension;
103 dense_vector_adaptor(matrix_expression<E, gpu_tag>& expression)
104 : m_size(expression().size1() * expression().size2()), m_queue(&expression().queue()){
105 gpu::dense_matrix_storage<T> storage = expression().raw_storage();
106 m_storage.buffer = storage.buffer;
107 m_storage.offset = storage.offset;
108 m_storage.stride = storage.leading_dimension;
114 dense_vector_adaptor(dense_vector_adaptor<U>
const& v)
115 : m_storage(v.raw_storage())
116 , m_queue(&v.queue())
120 size_type size()
const {
125 storage_type raw_storage()
const{
129 boost::compute::command_queue& queue(){
138 template <
class IndexExpr>
139 induced_vector_adaptor_element<IndexExpr,T> operator()(IndexExpr
const& i){
140 return {i, m_storage};
148 typedef boost::compute::strided_iterator<boost::compute::buffer_iterator<T> > iterator;
149 typedef boost::compute::strided_iterator<boost::compute::buffer_iterator<T> > const_iterator;
152 const_iterator begin()
const {
153 return const_iterator(boost::compute::buffer_iterator<T>(m_storage.buffer, m_storage.offset),m_storage.stride);
157 const_iterator end()
const {
158 return const_iterator(
159 boost::compute::buffer_iterator<T>(m_storage.buffer, m_size * m_storage.stride + m_storage.offset)
166 return iterator(boost::compute::buffer_iterator<T>(m_storage.buffer, m_storage.offset),m_storage.stride);
172 boost::compute::buffer_iterator<T>(m_storage.buffer, m_size * m_storage.stride + m_storage.offset)
177 storage_type m_storage;
178 boost::compute::command_queue* m_queue;