CUV  0.9.201304091348
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accessors.hpp
1 #ifndef __ACCCESSORS_HPP__
2 #define __ACCCESSORS_HPP__
3 #include <cstring>
4 #include <cuv/tools/cuv_general.hpp>
5 
6 namespace cuv
7 {
13  template <class value_type, class size_type, class memory_space_type>
14  struct allocator{
15  void alloc( value_type** ptr, size_type memsize)const;
16  void alloc2d( value_type** ptr, size_type& pitch, size_type height, size_type width)const;
17  void dealloc( value_type** ptr)const;
18 
22  void copy(value_type* dst, const value_type*src,size_type size, host_memory_space);
23 
28  template<class value_type2>
29  void copy(value_type* dst, const value_type2*src,size_type size, dev_memory_space);
30 
31  void copy2d(value_type* dst, const value_type*src,size_type dpitch, size_type spitch, size_type h, size_type w, host_memory_space);
32  void copy2d(value_type* dst, const value_type*src,size_type dpitch, size_type spitch, size_type h, size_type w, dev_memory_space);
33 
34  void alloc( const value_type** ptr, size_type memsize)const;
35  void dealloc( const value_type** ptr)const;
36  void copy(const value_type* dst, const value_type*src,size_type size, host_memory_space)const{cuvAssert(false);}
37  void copy(const value_type* dst, const value_type*src,size_type size, dev_memory_space)const{cuvAssert(false);};
38  };
39 
40  namespace detail
41  {
42 
46  template <class value_type, class size_type>
47  void entry_set(value_type* ptr, size_type idx, value_type val, host_memory_space);
51  template <class value_type, class size_type>
52  value_type entry_get(const value_type* ptr, size_type idx, host_memory_space);
53 
57  template <class value_type, class size_type>
58  void entry_set(value_type* ptr, size_type idx, value_type val, dev_memory_space);
62  template <class value_type, class size_type>
63  value_type entry_get(const value_type* ptr, size_type idx, dev_memory_space);
64 
65 
74  template <class value_type, class size_type>
75  void entry_set(value_type* ptr, size_type idx, value_type val, host_memory_space) {
76  ptr[idx]=val;
77  }
78 
79 
88  template <class value_type, class size_type>
89  value_type entry_get(const value_type* ptr, size_type idx, host_memory_space) {
90  return ptr[idx];
91  }
92 
93  }
94 
103  template<class value_type, class size_type>
104  struct allocator<value_type,size_type,host_memory_space>{
113  void alloc( value_type** ptr, size_type size) const;
122  void alloc2d( value_type** ptr, size_type& pitch, size_type height, size_type width)const;
123 
130  void dealloc( value_type** ptr)const ;
139  void alloc(const value_type** ptr, size_type size) const{
140  cuvAssert(false);
141  }
149  void dealloc(const value_type** ptr)const {
150  cuvAssert(false);
151  }
153  void copy(value_type* dst, const value_type*src,size_type size, host_memory_space){
154  std::memcpy(dst,src,size*sizeof(value_type));
155  }
159  template<class value_type2>
160  void copy(value_type* dst, const value_type2*src,size_type size, host_memory_space){
161  for(unsigned int i=0;i<size;i++)
162  dst[i] = (value_type)src[i];
163  }
165  void copy(value_type* dst, const value_type*src,size_type size, dev_memory_space);
166 
168  void copy(const value_type* dst, const value_type*src,size_type size, host_memory_space)const{
169  cuvAssert(false);
170  }
172  void copy(const value_type* dst, const value_type*src,size_type size, dev_memory_space)const{
173  cuvAssert(false);
174  }
175 
176  void copy2d(value_type* dst, const value_type*src,size_type dpitch, size_type spitch, size_type h, size_type w, host_memory_space);
177  void copy2d(value_type* dst, const value_type*src,size_type dpitch, size_type spitch, size_type h, size_type w, dev_memory_space);
178  };
179 }
180 
181 
182 #endif /* __ACCCESSORS_HPP__ */