Commit 39c438d2 authored by incardon's avatar incardon

Initial commit OpenFPM_data

parent f89dcb01
This diff is collapsed.
LINKLIBS = $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(CUDA_LIBS) $(BOOST_THREAD_LIB)
bin_PROGRAMS = mem_map
mem_map_SOURCES = memory_gpu_thrust.cu memory_cpu_thrust.cu main.cpp
mem_map_CXXFLAGS = $(CUDA_CFLAGS)
mem_map_CFLAGS = $(CUDA_CFLAGS)
mem_map_LDADD = $(LINKLIBS) -L/usr/lib64/nvidia-bumblebee/
.cu.o :
$(NVCC) $(NVCCFLAGS) -o $@ -c $<
/*template<typename T>
class Particles
{
layout<grid<T>> particles;
layouy<grid<T>> particles_ghost;
};*/
......@@ -34,7 +34,7 @@ template<typename T> class Point
{
public:
typedef boost::fusion::vector<T,T,T,T,boost::multi_array_ref<T,1+1>,boost::multi_array_ref<T,2+1>> type;
typedef boost::fusion::vector<T,T,T,T,T[3],T[3][3]> type;
type data;
......
#include <iostream.h>
template<typename T> class Point_orig
{
public:
T x;
T y;
T z;
T s;
T v[3];
T t[3][3];
inline void setx(T x_) {x = x_;};
inline void sety(T y_) {y = y_;};
inline void setz(T z_) {z = z_;};
};
......@@ -213,13 +213,13 @@ public:
boost::shared_array<mem_id> id;
};
template<typename T>
//#pragma openfpm create(layout)
template<unsigned int N, typename T>
class grid
{
size_t size_tot;
std::vector<size_t> sz;
std::vector<size_t> sz_s;
size_t sz[N];
size_t sz_s[N];
public:
......@@ -238,16 +238,18 @@ public:
}
grid(std::vector<size_t> & sz)
: size_tot(totalSize(sz)), sz(sz)
: size_tot(totalSize(sz))
{
sz_s.resize(sz.size());
sz_s[0] = sz[0];
this->sz[0] = sz[0];
for (size_t i = 1 ; i < sz.size() ; i++)
{
sz_s[i] = sz[i]*sz_s[i-1];
this->sz[i] = sz[i];
}
};
}
#pragma openfpm layout(get)
template<unsigned int dim> mem_id LinId(grid_key_dx<dim> & gk)
{
mem_id lid = gk.k[0];
......@@ -259,6 +261,7 @@ public:
return lid;
}
#pragma openfpm layout(get)
template<unsigned int p> mem_id LinId(grid_key_3<p> & gk)
{
mem_id lid = gk.k[0];
......@@ -268,6 +271,7 @@ public:
return lid;
}
#pragma openfpm layout(get)
template<unsigned int dim, unsigned int p> mem_id LinId(grid_key_d<dim,p> & gk)
{
mem_id lid = gk.k[0];
......@@ -279,11 +283,12 @@ public:
return lid;
}
#pragma openfpm layout(get)
mem_id LinId(mem_id * id)
{
mem_id lid = 0;
lid += id[0];
for (mem_id i = 1 ; i < (mem_id)sz.size() ; i++)
for (mem_id i = 1 ; i < N ; i++)
{
lid += id[i] * sz_s[i-1];
}
......@@ -291,11 +296,13 @@ public:
return lid;
}
#pragma openfpm layout(get)
mem_id LinId(mem_id i)
{
return i;
}
#pragma openfpm layout(get)
mem_id LinId(mem_id j, mem_id k)
{
mem_id lid = 0;
......@@ -305,6 +312,7 @@ public:
return lid;
}
#pragma openfpm layout(get)
mem_id LinId(mem_id i, mem_id j, mem_id k)
{
mem_id lid = 0;
......@@ -315,6 +323,7 @@ public:
return lid;
}
#pragma openfpm layout(get)
mem_id LinId(mem_id u, mem_id i, mem_id j, mem_id k)
{
mem_id lid = 0;
......@@ -328,10 +337,75 @@ public:
~grid() {};
#pragma openfpm layout(size)
size_t size()
{
return size_tot;
};
/**
*
* Get the size of the grid on direction i
*
* @param i direction
*
*/
size_t size(unsigned int i)
{
return sz_s[i];
}
};
/**
*
* Grid key class iterator, iterate through the grid_key
*
*/
template<unsigned int dim>
class grid_key_dx_iterator
{
grid<dim,void> & grid_base;
template<typename T> grid_key_dx_iterator(grid<dim,T> & g)
: grid_base(g)
{}
grid_key_dx<dim> gk;
grid_key_dx<dim> next()
{
size_t id = gk.get(0);
gk.set(0,id+1);
for (int i = 0 ; i < dim ; i++)
{
size_t id = gk.get(i);
if (id == grid_base.size(i))
{
gk.set(i,0);
id = gk.get(i+1);
gk.set(i+1,id+1);
}
else
{
break;
}
}
return gk++;
}
bool hasNext()
{
for (int i = dim-1 ; i >= 0 ; i--)
{
if (gk.get(i) < grid_base.size(i))
{
return false;
}
}
return true;
}
};
template<unsigned int s1, unsigned int s2, unsigned int s3>
......
/*
* integrator.hpp
*
* Created on: Feb 4, 2014
* Author: Pietro Incardona
*/
void lj_test()
{
}
#define BOOST_DISABLE_ASSERTS
#include "map.hpp"
#include "memory_cpu.hpp"
#include "memory_gpu.hpp"
......@@ -30,16 +32,17 @@ int main()
sz.push_back(GS_SIZE);
sz.push_back(GS_SIZE);
sz.push_back(GS_SIZE);
layout_gpu< grid<Point<float>>, memory_gpu<memory_gpu_type<Point<float>>::type> > c3(sz);
grid_gpu<3, Point<float>, memory_gpu<memory_gpu_type<Point<float>>::type> > c3(sz);
// cpu test
test1();
// layout_cpu< Particles<Point<float>, memory_cpu<float> >, particle_key > p1;
test2(c3);
test_layout_grid3d(c3);
// test3(c3);
......
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include <boost/fusion/include/at_c.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/container/vector/vector_fwd.hpp>
......@@ -11,68 +12,89 @@
#include "Point.hpp"
#include "memory_cpu.hpp"
#include "memory_gpu.hpp"
#include "memory_array.hpp"
#ifndef MAP_HPP_
#define MAP_HPP_
template<typename T, typename Mem> class layout_cpu
{
};
template<typename T, typename Mem> class layout_gpu
// Compiled based specialization
template<unsigned int p>
struct Point_type_cpu_prop
{
typedef typename boost::fusion::result_of::at<memory_cpu_type<Point<float>>::rtype,boost::mpl::int_<p> >::type type;
};
// Compiled based specialization
/*!
*
* \brief This is an N-dimensional grid or an N-dimensional array working on CPU
*
* This is an N-Dimensional grid or an N-dimensional array working on CPU
*
* \param dim Dimensionality of the grid
* \param T type of object the grid store
* \param Mem interface used to allocate memory
*
*/
template<typename T, typename Mem>
class layout_cpu<grid<T>,Mem>
template<unsigned int dim, typename T, typename Mem>
class grid_cpu
{
grid<T> g1;
Mem data;
public:
//! This is an header that store all information related to the grid
grid<dim,T> g1;
//! This is the interface to allocate an resize memory
//! and give also a representation to the allocated memory
Mem data;
public:
layout_cpu(std::vector<size_t> & sz)
:g1(sz)
{
data.allocate(g1.size());
}
//! Constructor allocate memory and give them a representation
grid_cpu(std::vector<size_t> & sz)
:g1(sz)
{
//! allocate the memory
data.mem.allocate(g1.size()*sizeof(T));
//! set the pointer
data.mem_r.set_pointer(data.getPointer());
}
template <unsigned int p>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key<p> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key<p> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1.getId())));
return boost::fusion::at_c<p>(data.mem_r.get(g1.LinId(v1.getId())));
}
template <unsigned int p>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key_1<p> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key_1<p> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1.k[0])));
return boost::fusion::at_c<p>(data.mem_r.get(g1.LinId(v1.k[0])));
}
template <unsigned int p>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key_2<p> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key_2<p> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1.k[1],v1.k[0])));
return boost::fusion::at_c<p>(data.mem_r.get(g1.LinId(v1.k[1],v1.k[0])));
}
template <unsigned int p>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key_3<p> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key_3<p> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1.k[2],v1.k[1],v1.k[0])));
return boost::fusion::at_c<p>(data.mem_a.get(g1.LinId(v1.k[2],v1.k[1],v1.k[0])));
}
template <unsigned int p>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key_4<p> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key_4<p> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1.k[3],v1.k[2],v1.k[1],v1.k[0])));
return boost::fusion::at_c<p>(data.mem_a.get(g1.LinId(v1.k[3],v1.k[2],v1.k[1],v1.k[0])));
}
template <unsigned int p, unsigned int dim>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key_d<dim,p> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key_d<dim,p> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1)));
return boost::fusion::at_c<p>(data.mem_a.get(g1.LinId(v1)));
}
template <unsigned int p, unsigned int dim>inline typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type & get(grid_key_dx<dim> & v1)
template <unsigned int p>inline typename Point_type_cpu_prop<p>::type & get(grid_key_dx<dim> & v1)
{
return boost::fusion::at_c<p>(data.get(g1.LinId(v1)));
return boost::fusion::at_c<p>(data.mem_a.get(g1.LinId(v1)));
}
inline size_t size()
......@@ -146,74 +168,130 @@ map_cpu<grid<grid<Point>>>
}
}*/
template<unsigned int p>
struct Point_type_prop
// nested_struct
/*template<typename S, typename T>
struct nested_struct
{
typedef typename boost::fusion::result_of::at<Point<float>::type,boost::mpl::int_<p> >::type type;
typedef typename boost::fusion::result_of::pop_back<T>::type popv;
nested_struct< S, popv > ggn;
S gn;
};
template<typename T, typename Mem>
class layout_gpu<grid<Point<T>>,Mem>
template<typename S>
struct nested_struct<S,boost::fusion::vector<>>
{
grid<T> g1;
nested_struct< S, boost::fusion::result_of::pop_back<T>::type > ggn;
S<boost::fusion::result_of::end<T>> gn;
};*/
typename Mem::type data;
public:
layout_gpu(std::vector<size_t> & sz)
:g1(sz)
{
boost::fusion::at_c<0>(data).allocate(g1.size());
boost::fusion::at_c<1>(data).allocate(g1.size());
boost::fusion::at_c<2>(data).allocate(g1.size());
boost::fusion::at_c<3>(data).allocate(g1.size());
boost::fusion::at_c<4>(data).allocate(g1.size());
boost::fusion::at_c<5>(data).allocate(g1.size());
}
template<unsigned int p,typename T>
struct type_gpu_prop
{
typedef typename memory_gpu_type<T>::rtype vtype;
typedef typename boost::fusion::result_of::at< vtype,boost::mpl::int_<p> >::type type;
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called
*
*/
template <unsigned int p>inline typename mem_reference<typename Point_type_prop<p>::type>::type get(grid_key<p> & v1)
struct allocate
{
size_t sz;
allocate(size_t sz)
:sz(sz){};
template<typename T>
void operator()(T& t) const
{
t.mem.allocate(sz*sizeof(t.mem_r::type));
t.mem_r.set_pointer(t.mem.getPointer());
}
};
template<unsigned int dim, typename T, typename Mem>
class grid_gpu
{
//! It store all the information regarding the grid
grid<dim,void> g1;
//! This is the interface to allocate an resize memory
//! and give also a representation to the allocated memory
typename Mem::type data;
public:
//! Constructor it initialize the memory and give representation
grid_gpu(std::vector<size_t> & sz)
:g1(sz)
{
for_each(data,allocate(g1.size()));
}
/* template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type>::type get(grid_key<p> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1.getId()));
}
template <unsigned int p>inline typename mem_reference<typename Point_type_prop<p>::type >::type get(grid_key_1<p> & v1)
template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type >::type get(grid_key_1<p> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1.k[0]));
}
template <unsigned int p>inline typename mem_reference<typename Point_type_prop<p>::type >::type get(grid_key_2<p> & v1)
template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type >::type get(grid_key_2<p> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1.k[1],v1.k[0]));
}
template <unsigned int p>inline typename mem_reference<typename Point_type_prop<p>::type >::type get(grid_key_3<p> & v1)
template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type >::type get(grid_key_3<p> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1.k[2],v1.k[1],v1.k[0]));
}
template <unsigned int p>inline typename mem_reference<typename Point_type_prop<p>::type >::type get(grid_key_4<p> & v1)
template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type >::type get(grid_key_4<p> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1.k[3],v1.k[2],v1.k[1],v1.k[0]));
}
}*/
template <unsigned int p, unsigned int dim>inline typename mem_reference<typename Point_type_prop<p>::type >::type get(grid_key_d<dim,p> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1));
}
template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type >::type get(grid_key_d<dim,p> & v1)
{
return boost::fusion::at_c<p>(data.mem_r).get(g1.LinId(v1));
}
template <unsigned int p, unsigned int dim>inline typename mem_reference<typename Point_type_prop<p>::type >::type get(grid_key_dx<dim> & v1)
{
return boost::fusion::at_c<p>(data).get(g1.LinId(v1));
}
template <unsigned int p>inline typename mem_reference<typename type_gpu_prop<p,T>::type >::type get(grid_key_dx<dim> & v1)
{
return boost::fusion::at_c<p>(data.mem_r).get(g1.LinId(v1));
}
inline size_t size()
{
return g1.size();
}
inline size_t size()
{
return g1.size();
}
//! this function set the memory interface if required
//! this operation is required when we define a void memory
//! allocator
void set_memory(memory & mem)
{
data.mem.set_memory(mem);
}
};
#ifdef GPU
use template<unsigned int n, typename T>grid_gpu<n,T> grid<n,T>
#else CPU
#endif
#endif
#include <iostream.h>
#pragma openfpm struct(align : 0, padding : 0 , order : none, options : none)
template<typename T> class Point_orig
{
public:
T x;
T y;
T z;
T s;
T v[3];
T t[3][3];
inline void setx(T x_) {x = x_;};
inline void sety(T y_) {y = y_;};
inline void setz(T z_) {z = z_;};
};
#include <iostream.h>
#pragma openfpm(align : 0, padding : 0 , order : none, options : none)
template<typename T> class Point_orig
{
public:
T x;
T y;
T z;
T s;
T v[3];
T t[3][3];
inline void setx(T x_) {x = x_;};
inline void sety(T y_) {y = y_;};
inline void setz(T z_) {z = z_;};
};
#include <iostream>
#include <boost/shared_array.hpp>
#include <vector>
#include "memory_cpu.hpp"
#include "memory_gpu.hpp"
#include <initializer_list>
#include <array>
#define HARDWARE 1
template<typename T, unsigned int s1, unsigned int s2, unsigned int s3>
class tensor
{
T g_mem[s1][s2][s3];
public:
tensor() {};
~tensor() {};
size_t size()
{
return s1*s2*s3*g_mem[0][0][0].size();
};
};
template<unsigned int dim>
class grid_key_dx
{
public:
grid_key_dx()
{
}
template<typename a, typename ...T>grid_key_dx(a v,T...t)
{
k[dim-1] = v;
invert_assign(t...);
}
template<typename a, typename ...T>void set(a v, T...t)
{
k[dim-1] = v;
invert_assign(t...);
}
mem_id k[dim];
private:
template<typename a, typename ...T>void invert_assign(a v,T...t)
{
k[sizeof...(T)] = v;
invert_assign(t...);
}
template<typename a, typename ...T>void invert_assign(a v)
{
k[0] = v;
}
};
template<unsigned int dim, unsigned int p>
class grid_key_d
{
public:
template<typename a, typename ...T>grid_key_d(a v,T...t)
{
k[dim-1] = v;
invert_assign(t...);
}
template<typename a, typename ...T>void invert_assign(a v,T...t)
{
k[sizeof...(T)] = v;
invert_assign(t...);
}
template<typename a, typename ...T>void invert_assign(a v)
{
k[0] = v;
}
mem_id k[dim];
};
template<unsigned int p>
class grid_key_1
{
public:
grid_key_1(int i_)
{
k[0] = i_;
}
mem_id k[1];
};
template<unsigned int p>