Commit 8a861515 authored by incardon's avatar incardon
Browse files

Added copy grid test

parent 4fecaeb9
......@@ -66,6 +66,11 @@ public:
//! no properties
static const unsigned int max_prop = 0;
static inline bool noPointers()
{
return true;
}
};
template<typename V, typename E,
......@@ -101,12 +106,16 @@ public:
{
boost::fusion::at_c<0>(data) = vid_;
}
;
inline void seteid(size_t eid_)
{
boost::fusion::at_c<1>(data) = eid_;
}
;
static inline bool noPointers()
{
return true;
}
};
class edge_key
......
This diff is collapsed.
/*
* copy_grid_unit_test.hpp
*
* Created on: Dec 4, 2017
* Author: i-bird
*/
#ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_COPY_GRID_UNIT_TEST_HPP_
#define OPENFPM_DATA_SRC_GRID_ITERATORS_COPY_GRID_UNIT_TEST_HPP_
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "Grid/map_grid.hpp"
#include "data_type/aggregate.hpp"
#include "Vector/map_vector.hpp"
BOOST_AUTO_TEST_SUITE( copy_grid_test )
template<unsigned int dim, typename grid>
void Test_copy_grid(grid & g_src, grid & g_dst,
Box<dim,size_t> & bsrc_1, Box<dim,size_t> & bdst_1)
{
auto gs1 = g_src.getGrid();
auto gd1 = g_dst.getGrid();
auto it = g_src.getIterator();
grid_key_dx<dim> zero[1];
zero[0].zero();
while (it.isNext())
{
auto key = it.get();
g_src.template get<0>(key) = gs1.LinId(key);
++it;
}
copy_grid_fast<false,
dim,
grid_cpu<dim,aggregate<double>>,
grid_sm<dim,aggregate<double>>>::copy(gs1,gd1,
bsrc_1,bdst_1,
g_src,g_dst,
zero);
// Check
bool match = true;
grid_key_dx_iterator_sub<dim, no_stencil> its(gs1,bsrc_1.getKP1(), bsrc_1.getKP2());
grid_key_dx_iterator_sub<dim, no_stencil> itd(gd1,bdst_1.getKP1(), bdst_1.getKP2());
while (its.isNext())
{
auto key_s = its.get();
auto key_d = itd.get();
match &= g_src.template get<0>(key_s) == g_dst.template get<0>(key_d);
++its;
++itd;
}
BOOST_REQUIRE_EQUAL(match,true);
}
template<unsigned int dim, typename grid>
void Test_copy_grid_cmp(grid & g_src, grid & g_dst,
Box<dim,size_t> & bsrc_1, Box<dim,size_t> & bdst_1)
{
auto gs1 = g_src.getGrid();
auto gd1 = g_dst.getGrid();
auto it = g_src.getIterator();
grid_key_dx<dim> zero[1];
zero[0].zero();
while (it.isNext())
{
auto key = it.get();
for (size_t k = 0 ; k < (size_t)gs1.LinId(key) % 4 ; k++)
{
g_src.template get<0>(key).add(gs1.LinId(key) + 1);
}
++it;
}
copy_grid_fast<true,
dim,
grid_cpu<dim,aggregate<openfpm::vector<double>>>,
grid_sm<dim,aggregate<openfpm::vector<double>>>>::copy(gs1,gd1,
bsrc_1,bdst_1,
g_src,g_dst,
zero);
// Check
bool match = true;
grid_key_dx_iterator_sub<dim, no_stencil> its(gs1,bsrc_1.getKP1(), bsrc_1.getKP2());
grid_key_dx_iterator_sub<dim, no_stencil> itd(gd1,bdst_1.getKP1(), bdst_1.getKP2());
while (its.isNext())
{
auto key_s = its.get();
auto key_d = itd.get();
match &= g_src.template get<0>(key_s).size() == g_dst.template get<0>(key_d).size();
for (size_t i = 0 ; i < g_dst.template get<0>(key_d).size() ; i++)
{
match &= g_src.template get<0>(key_s).get(i) == g_dst.template get<0>(key_d).get(i);
}
++its;
++itd;
}
BOOST_REQUIRE_EQUAL(match,true);
}
BOOST_AUTO_TEST_CASE( copy_grid_test_use)
{
{
size_t sz1[1] = {37};
size_t sz2[2] = {37,37};
size_t sz3[3] = {37,37,37};
size_t sz4[4] = {37,37,37,37};
grid_cpu<1,aggregate<double>> g1_src(sz1);
grid_cpu<1,aggregate<double>> g1_dst(sz1);
grid_cpu<2,aggregate<double>> g2_src(sz2);
grid_cpu<2,aggregate<double>> g2_dst(sz2);
grid_cpu<3,aggregate<double>> g3_src(sz3);
grid_cpu<3,aggregate<double>> g3_dst(sz3);
grid_cpu<4,aggregate<double>> g4_src(sz4);
grid_cpu<4,aggregate<double>> g4_dst(sz4);
g1_src.setMemory();
g1_dst.setMemory();
g2_src.setMemory();
g2_dst.setMemory();
g3_src.setMemory();
g3_dst.setMemory();
g4_src.setMemory();
g4_dst.setMemory();
// fill all grids
Box<1,size_t> bsrc_1({4},{11});
Box<1,size_t> bdst_1{{20},{27}};
Test_copy_grid(g1_src,g1_dst,bsrc_1,bdst_1);
Box<2,size_t> bsrc_2({4,7},{11,20});
Box<2,size_t> bdst_2({20,5},{27,18});
Test_copy_grid(g2_src,g2_dst,bsrc_2,bdst_2);
Box<3,size_t> bsrc_3({4,7,1},{11,20,6});
Box<3,size_t> bdst_3({20,5,10},{27,18,15});
Test_copy_grid(g3_src,g3_dst,bsrc_3,bdst_3);
Box<4,size_t> bsrc_4({4,7,1,3},{11,20,6,6});
Box<4,size_t> bdst_4({20,5,10,13},{27,18,15,16});
Test_copy_grid(g4_src,g4_dst,bsrc_4,bdst_4);
}
///////////
{
size_t sz1[1] = {37};
size_t sz2[2] = {37,37};
size_t sz3[3] = {37,37,37};
size_t sz4[4] = {37,37,37,37};
grid_cpu<1,aggregate<openfpm::vector<double>>> g1_src(sz1);
grid_cpu<1,aggregate<openfpm::vector<double>>> g1_dst(sz1);
grid_cpu<2,aggregate<openfpm::vector<double>>> g2_src(sz2);
grid_cpu<2,aggregate<openfpm::vector<double>>> g2_dst(sz2);
grid_cpu<3,aggregate<openfpm::vector<double>>> g3_src(sz3);
grid_cpu<3,aggregate<openfpm::vector<double>>> g3_dst(sz3);
grid_cpu<4,aggregate<openfpm::vector<double>>> g4_src(sz4);
grid_cpu<4,aggregate<openfpm::vector<double>>> g4_dst(sz4);
g1_src.setMemory();
g1_dst.setMemory();
g2_src.setMemory();
g2_dst.setMemory();
g3_src.setMemory();
g3_dst.setMemory();
g4_src.setMemory();
g4_dst.setMemory();
// fill all grids
Box<1,size_t> bsrc_1({4},{11});
Box<1,size_t> bdst_1{{20},{27}};
Test_copy_grid_cmp(g1_src,g1_dst,bsrc_1,bdst_1);
Box<2,size_t> bsrc_2({4,7},{11,20});
Box<2,size_t> bdst_2({20,5},{27,18});
Test_copy_grid_cmp(g2_src,g2_dst,bsrc_2,bdst_2);
Box<3,size_t> bsrc_3({4,7,1},{11,20,6});
Box<3,size_t> bdst_3({20,5,10},{27,18,15});
Test_copy_grid_cmp(g3_src,g3_dst,bsrc_3,bdst_3);
Box<4,size_t> bsrc_4({4,7,1,3},{11,20,6,6});
Box<4,size_t> bdst_4({20,5,10,13},{27,18,15,16});
Test_copy_grid_cmp(g4_src,g4_dst,bsrc_4,bdst_4);
}
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_COPY_GRID_UNIT_TEST_HPP_ */
......@@ -9,6 +9,7 @@
#define OPENFPM_DATA_SRC_GRID_GRID_BASE_IMPLEMENTATION_HPP_
#include "grid_base_impl_layout.hpp"
#include "copy_grid_fast.hpp"
/*! \brief
*
......@@ -379,7 +380,7 @@ public:
data_.setMemory(m);
//! Allocate the memory and create the reppresentation
if (g1.size() != 0) data_.allocate(g1.size());
if (g1.size() != 0) data_.allocate(g1.size(),T::noPointers());
is_mem_init = true;
}
......
......@@ -49,12 +49,22 @@ struct pack_simple_cond
dest.setMemory(mem);
dest.resize(obj.size());
grid_key_dx<dim> cnt[1];
cnt[0].zero();
auto it = obj.getIteratorStencil(cnt);
obj.pack_with_iterator<decltype(it),dtype,prp...>(it,dest);
auto it = obj.getIterator();
// copy all the object in the send buffer
typedef encapc<dims,value_type,layout > encap_src;
// destination object type
typedef encapc<1,prp_object,typename dtype::layout_type > encap_dst;
pack_with_iterator<!is_contiguos<prp...>::type::value || has_pack_gen<prp_object>::value,
dim,
decltype(obj),
encap_src,
encap_dst,
typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,
decltype(it),
dtype,
prp...>::pack(obj,it,dest);
// Update statistic
sts.incReq();
......@@ -141,12 +151,22 @@ struct unpack_simple_cond
src.setMemory(ptr);
src.resize(obj.size());
grid_key_dx<dim> cnt[1];
cnt[0].zero();
auto it = obj.getIterator();
// copy all the object in the send buffer
typedef encapc<dim,grid_base_impl<dim,T,S,layout,layout_base>::value_type,layout > encap_dst;
// destination object type
typedef encapc<1,prp_object,typename memory_traits_lin<prp_object>::type > encap_src;
auto it = obj.getIteratorStencil(cnt);
obj.unpack_with_iterator<decltype(it),stype,prp...>(it,src);
unpack_with_iterator<dim,
decltype(obj),
encap_src,
encap_dst,
typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,
decltype(it),
stype,
prp...>::unpack(obj,it,src);
ps.addOffset(size);
}
......@@ -327,7 +347,7 @@ struct unpack_simple_cond<true, prp ...>
* \param sts pack statistic
*
*/
template<int ... prp> void pack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>> & sub_it, Pack_stat & sts)
template<int ... prp> void pack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims> & sub_it, Pack_stat & sts)
{
#ifdef SE_CLASS1
if (mem.ref() == 0)
......@@ -343,7 +363,20 @@ struct unpack_simple_cond<true, prp ...>
dest.setMemory(mem);
dest.resize(sub_it.getVolume());
pack_with_iterator<grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>>,dtype,prp...>(sub_it,dest);
// copy all the object in the send buffer
typedef encapc<dims,value_type,layout > encap_src;
// destination object type
typedef encapc<1,prp_object,typename dtype::layout_type > encap_dst;
pack_with_iterator<!is_contiguos<prp...>::type::value || has_pack_gen<prp_object>::value,
dims,
decltype(*this),
encap_src,
encap_dst,
typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,
grid_key_dx_iterator_sub<dims>,
dtype,
prp...>::pack(*this,sub_it,dest);
// Update statistic
sts.incReq();
......@@ -359,7 +392,7 @@ struct unpack_simple_cond<true, prp ...>
* \param vector of requests
*
*/
template<int ... prp> void packRequest(grid_key_dx_iterator_sub<dims,stencil_offset_compute<dim,1>> & sub, size_t & req)
template<int ... prp> void packRequest(grid_key_dx_iterator_sub<dims> & sub, size_t & req)
{
typedef openfpm::vector<typename grid_base_impl<dim,T,S,layout,layout_base>::value_type,ExtPreAlloc<S>,layout,layout_base,openfpm::grow_policy_identity> dtype;
dtype dvect;
......@@ -380,7 +413,7 @@ struct unpack_simple_cond<true, prp ...>
* \param obj object where to unpack
*
*/
template<unsigned int ... prp> void unpack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>> & sub_it, Unpack_stat & ps)
template<unsigned int ... prp> void unpack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims> & sub_it, Unpack_stat & ps)
{
// object that store the information in mem
typedef object<typename object_creator<typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,prp...>::type> prp_object;
......@@ -396,7 +429,19 @@ struct unpack_simple_cond<true, prp ...>
src.setMemory(ptr);
src.resize(sub_it.getVolume());
unpack_with_iterator<grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>>,stype,prp...>(sub_it,src);
// copy all the object in the send buffer
typedef encapc<dims,grid_base_impl<dim,T,S,layout,layout_base>::value_type,layout > encap_dst;
// destination object type
typedef encapc<1,prp_object,typename memory_traits_lin<prp_object>::type > encap_src;
unpack_with_iterator<dims,
decltype(*this),
encap_src,
encap_dst,
typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,
grid_key_dx_iterator_sub<dims>,
stype,
prp...>::unpack(*this,sub_it,src);
ps.addOffset(size);
}
......@@ -421,66 +466,4 @@ struct unpack_simple_cond<true, prp ...>
return n * sizeof(prp_object);
}
/*! \brief Pack an N-dimensional grid into a vector like structure B given an iterator of the grid
*
* \tparam it type of iterator of the grid-structure
* \tparam dtype type of the structure B
* \tparam dim Dimensionality of the grid
* \tparam properties to pack
*
* \param it Grid iterator
* \param obj object to pack
* \param dest where to pack
*
*/
template <typename it, typename dtype, int ... prp> void pack_with_iterator(it & sub_it, dtype & dest) const
{
// Sending property object
typedef object<typename object_creator<typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,prp...>::type> prp_object;
size_t id = 0;
// Packing the information
while (sub_it.isNext())
{
// copy all the object in the send buffer
typedef encapc<dims,value_type,layout > encap_src;
// destination object type
typedef encapc<1,prp_object,typename dtype::layout_type > encap_dst;
// Copy only the selected properties
object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(this->get_o(sub_it.template getStencil<0>()),dest.get(id));
++id;
++sub_it;
}
}
/*! \brief unpack the grid given an iterator
*
* \tparam it type of iterator
* \tparam prp of the grid object to unpack
*
*/
template <typename it, typename stype, unsigned int ... prp> void unpack_with_iterator(it & sub_it, stype & src)
{
size_t id = 0;
// Sending property object
typedef object<typename object_creator<typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,prp...>::type> prp_object;
// unpacking the information
while (sub_it.isNext())
{
// copy all the object in the send buffer
typedef encapc<dims,grid_base_impl<dim,T,S,layout,layout_base>::value_type,layout > encap_dst;
// destination object type
typedef encapc<1,prp_object,typename memory_traits_lin<prp_object>::type > encap_src;
// Copy only the selected properties
object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(id),this->get_o(sub_it.template getStencil<0>()));
++id;
++sub_it;
}
}
......@@ -319,6 +319,47 @@ public:
// calculate the offsets for the stencil code
stl_code.calc_offsets(grid_base,start_p);
}
/*! \brief Return the starting point of the iteration
*
* it is always the point (0,0) in 2D (0,0,0) in 3D ...
*
*/
grid_key_dx<dim> getStart()
{
grid_key_dx<dim> zero;
zero.zero();
return zero;
}
/*! \brief Return the stop point of the iteration
*
*
*/
grid_key_dx<dim> getStop()
{
grid_key_dx<dim> stop;
for (size_t i = 0 ; i < dim ; i++)
{
stop.set_d(i,grid_base.size(i) - 1);
}
return stop;
}
/*! \brief Get the volume spanned by this sub-grid iterator
*
* \return the volume
*
*/
inline size_t getVolume()
{
return Box<dim,long int>::getVolumeKey(getStart().k, getStop().k);
}
};
......
......@@ -111,6 +111,39 @@ public:
inline static void pw5() {}
};
template<unsigned int dim, typename stl_type>
struct post_increment_sub_impl
{
static inline void inc(grid_key_dx<dim> & gk,
grid_key_dx<dim> & gk_start,
grid_key_dx<dim> & gk_stop,
stl_type & stl_code,
grid_sm<dim,void> & grid_base)
{
long int i = 0;
for ( ; i < dim-1 ; i++)
{
/* coverity[dead_error_begin] */
size_t id = gk.get(i);
if ((long int)id > gk_stop.get(i))
{
// ! overflow, increment the next index
size_t idr = gk.get(i) - gk_start.get(i);
gk.set_d(i,gk_start.get(i));
id = gk.get(i+1);
gk.set_d(i+1,id+1);
stl_code.adjust_offset(i,idr,grid_base);
}
else
{
break;
}
}
}
};
/**
*
......@@ -207,10 +240,12 @@ class grid_key_dx_iterator_sub : public grid_key_dx_iterator<dim,stencil>
* any dimension and in case adjust the dimensions
*
*/
inline void post_increment()
void post_increment()
{
//! check the overflow of all the index with exception of the last dimensionality
// post_increment_sub_impl<dim,stencil>::inc(this->gk,gk_start,gk_stop,this->stl_code,grid_base);
long int i = 0;
for ( ; i < dim-1 ; i++)
{
......
......@@ -171,6 +171,16 @@ public:
return *this;
}
/*! \brief This structure has pointers
*
* \return false
*
*/
static bool noPointers()
{
return false;
}
};
#include "grid_gpu.hpp"
......
......@@ -8,14 +8,14 @@ else
endif
noinst_PROGRAMS = mem_map
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp Grid/copy_grid_unit_test.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_CXXFLAGS = $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -I/usr/local/libhilbert/include
mem_map_CFLAGS = $(CUDA_CFLAGS)
mem_map_LDADD = $(LINKLIBS)
nobase_include_HEADERS= data_type/scalar.hpp data_type/aggregate.hpp \
nobase_include_HEADERS= data_type/aggregate.hpp \
Graph/graph_unit_tests.hpp Graph/map_graph.hpp \
Grid/comb.hpp Grid/grid_base_implementation.hpp Grid/grid_pack_unpack.ipp Grid/grid_base_impl_layout.hpp Grid/grid_common.hpp Grid/grid_gpu.hpp Grid/Encap.hpp Grid/grid_key.hpp Grid/grid_key_dx_expression_unit_tests.hpp Grid/grid_key_expression.hpp Grid/grid_sm.hpp Grid/grid_unit_tests.hpp Grid/grid_util_test.hpp Grid/map_grid.hpp Grid/se_grid.hpp Grid/util.hpp \
Grid/comb.hpp Grid/copy_grid_fast.hpp Grid/grid_base_implementation.hpp Grid/grid_pack_unpack.ipp Grid/grid_base_impl_layout.hpp Grid/grid_common.hpp Grid/grid_gpu.hpp Grid/Encap.hpp Grid/grid_key.hpp Grid/grid_key_dx_expression_unit_tests.hpp Grid/grid_key_expression.hpp Grid/grid_sm.hpp Grid/grid_unit_tests.hpp Grid/grid_util_test.hpp Grid/map_grid.hpp Grid/se_grid.hpp Grid/util.hpp \
Grid/iterators/grid_key_dx_iterator_sp.hpp Grid/grid_key_dx_iterator_hilbert.hpp Grid/iterators/stencil_type.hpp Grid/iterators/grid_key_dx_iterator_sub_bc.hpp Grid/iterators/grid_key_dx_iterator_sub.hpp Grid/iterators/grid_key_dx_iterator.hpp Grid/iterators/grid_skin_iterator.hpp \
Point_test.hpp \
Point_orig.hpp \
......
......@@ -61,7 +61,8 @@ BOOST_AUTO_TEST_CASE( celllist_lin_and_iterator_test )
// Initialize a cell list
CellList_gen<dim,float,Process_keys_lin> NN;
NN.Initialize(box,div,k*0.9,1);
NN.Initialize(box,div,1);
NN.set_gm(k*0.9);
float pos[dim];
......@@ -117,7 +118,8 @@ BOOST_AUTO_TEST_CASE( celllist_hilb_and_iterator_test )