OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_gpu.hpp
1 /*
2  * grid_gpu.hpp
3  *
4  * Created on: Oct 31, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_GRID_GPU_HPP_
9 #define OPENFPM_DATA_SRC_GRID_GRID_GPU_HPP_
10 
27 template<unsigned int dim, typename T, typename S=CudaMemory , typename Mem = typename memory_traits_inte< typename T::type >::type >
28 class grid_gpu
29 {
30  // Indicate if set memory has been called
31  bool is_mem_init = false;
32 
35 
38 
41  Mem data_;
42 
43 public:
44 
46  typedef int yes_i_am_grid;
47 
50 
52  typedef Mem memory_conf;
53 
55  // you can access all the properties of T
57 
58  // The object type the grid is storing
59  typedef T type;
60 
62  grid_gpu() THROW
63  {
64  }
65 
67  void setDimensions(std::vector<size_t> & sz)
68  {
69  g1.setDimension(sz);
70  }
71 
73  grid_gpu(std::vector<size_t> & sz) THROW
74  :g1(sz)
75  {
76  }
77 
84  const grid_sm<dim,void> & getGrid() const
85  {
86  return g1;
87  }
88 
95  void setMemory()
96  {
98  allocate<S> all(g1.size());
99 
101  boost::fusion::for_each(data_,all);
102 
103  is_mem_init = true;
104  }
105 
106  template <unsigned int p>inline typename type_gpu_prop<p,memory_int>::type::reference get(grid_key_d<dim,p> & v1)
107  {
108  return boost::fusion::at_c<p>(data_).mem_r->operator[](g1.LinId(v1));
109  }
110 
111  template <unsigned int p>inline typename type_gpu_prop<p,memory_int>::type::reference get(grid_key_dx<dim> & v1)
112  {
113  return boost::fusion::at_c<p>(data_).mem_r->operator[](g1.LinId(v1));
114  }
115 
124  {
125  return encapg<dim,T,Mem>(data_,g1.LinId(v1));
126  }
127 
135  inline const encapg<dim,T,Mem> get_o(grid_key_dx<dim> & v1) const
136  {
137  return encapg<dim,T,Mem>(data_,g1.LinId(v1));
138  }
139 
140  inline size_t size()
141  {
142  return g1.size();
143  }
144 
148  void set_memory(memory & mem)
149  {
150  data_.mem.set_memory(mem);
151  }
152 
160  {
162  }
163 
164 
172  {
173  return grid_key_dx_iterator_sub<dim>(g1,start,stop);
174  }
175 
184  {
185  g1.swap(obj.g1);
186  data_.swap(obj.data_);
187  }
188 };
189 
196 template<unsigned int dim, typename T>
197 struct device_g
198 {
203 };
204 
205 
206 #endif /* OPENFPM_DATA_SRC_GRID_GRID_GPU_HPP_ */
encapg< dim, T, Mem > container
Object container for T, it is the return type of get_o it return a object type trough.
Definition: grid_gpu.hpp:56
This is an N-dimensional grid or an N-dimensional array with memory_traits_inte layout.
Definition: grid_gpu.hpp:28
void setDimensions(std::vector< size_t > &sz)
Set the grid dimensions.
Definition: grid_gpu.hpp:67
Mem data_
Definition: grid_gpu.hpp:41
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
void setMemory()
Create the object that provide memory.
Definition: grid_gpu.hpp:95
Mem memory_conf
Memory traits.
Definition: grid_gpu.hpp:52
size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:552
int yes_i_am_grid
it define that it is a grid
Definition: grid_gpu.hpp:46
This class is an helper to get the return type of get for each property.
Definition: Encap.hpp:183
const grid_sm< dim, void > & getGrid() const
Return the internal grid information.
Definition: grid_gpu.hpp:84
grid_key_dx_iterator< dim > getIterator()
Return a grid iterator.
Definition: grid_gpu.hpp:159
void set_memory(memory &mem)
Definition: grid_gpu.hpp:148
memory_traits_inte< typename T::type >::type memory_int
Definition of the layout.
Definition: grid_gpu.hpp:49
grid_gpu(std::vector< size_t > &sz) THROW
Constructor it initialize the memory and give representation.
Definition: grid_gpu.hpp:73
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
Definition: grid_sm.hpp:697
void swap(grid_gpu< dim, T, S, Mem > &obj)
Swap the memory of another grid.
Definition: grid_gpu.hpp:183
this class is a functor for "for_each" algorithm
Definition: map_grid.hpp:1264
inter_memc< T >::type type
for each element in the vector interleave memory_c
Definition: memory_conf.hpp:55
grid_gpu< dim, T > gpu
gpu
Definition: grid_gpu.hpp:202
grid_sm< dim, void > g1
It store all the information regarding the grid.
Definition: grid_gpu.hpp:37
encapg< dim, T, Mem > get_o(grid_key_dx< dim > &v1)
Get the of the selected element as a boost::fusion::vector.
Definition: grid_gpu.hpp:123
grid_key_dx_iterator_sub< dim > getSubIterator(grid_key_dx< dim > &start, grid_key_dx< dim > &stop)
Return a sub-grid iterator.
Definition: grid_gpu.hpp:171
this structure encapsulate an object of the grid
Definition: Encap.hpp:370
grid_key_d is the key to access any element in the grid
Definition: grid_key.hpp:364
grid_cpu< dim, T > cpu
cpu
Definition: grid_gpu.hpp:200
grid_key_dx< dim > access_key
Access the key.
Definition: grid_gpu.hpp:34
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N], const size_t(&bc)[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition: grid_sm.hpp:354
const encapg< dim, T, Mem > get_o(grid_key_dx< dim > &v1) const
Get the of the selected element as a boost::fusion::vector.
Definition: grid_gpu.hpp:135
grid_gpu() THROW
Default constructor.
Definition: grid_gpu.hpp:62