Commit c54aef88 authored by Sebastian J. Mielke's avatar Sebastian J. Mielke
Browse files

Merge remote-tracking branch 'origin/develop' into AdaptiveNN

Also instead of return; stuff I now use --run_test=ARCL_and_ARCLvsCL/get_all_interactions_classiccelllist,get_all_interactions_arcl
parents dd27ab76 7fd2b977
......@@ -45,6 +45,79 @@ if test x"$test_cov" = x"yes"; then
CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage "
fi
###### Check for se-class1
AC_MSG_CHECKING(whether to build with security enhancement class1)
se_class1=no
AC_ARG_ENABLE(se-class1,
AC_HELP_STRING(
[--enable-se-class1],
[enable security enhancement class1]
),
se_class1="$enableval"
)
AC_MSG_RESULT($se_class1)
if test x"$se_class1" = x"yes"; then
AC_DEFINE([SE_CLASS1],[],[Security enhancement class 1])
fi
###### Check for se-class 2
AC_MSG_CHECKING(whether to build with security enhancement class 2)
se_class2=no
AC_ARG_ENABLE(se-class2,
AC_HELP_STRING(
[--enable-se-class2],
[enable security enhancement class 2]
),
se_class2="$enableval"
)
AC_MSG_RESULT($se_class2)
if test x"$se_class2" = x"yes"; then
AC_DEFINE([SE_CLASS2],[],[Security enhancement class 2])
fi
###### Check for se-class 3
AC_MSG_CHECKING(whether to build with security enhancement class 3)
se_class3=no
AC_ARG_ENABLE(se-class3,
AC_HELP_STRING(
[--enable-se-class3],
[enable security enhancement class 3]
),
se_class3="$enableval"
)
AC_MSG_RESULT($se_class3)
if test x"$se_class3" = x"yes"; then
AC_DEFINE([SE_CLASS3],[],[Security enhancement class 3])
fi
###### Check for action on error
action_on_e=continue
AC_ARG_WITH([action-on-error],
AS_HELP_STRING([--with-action-on-error=stop,throw,continue],
[specify the action to do in case of error]),
[action_on_e="$withval"],
[action_on_e=continue])
if test x"$action_on_e" = x"stop"; then
AC_DEFINE([STOP_ON_ERROR],[],[If an error occur stop the program])
fi
if test x"$action_on_e" = x"throw"; then
AC_DEFINE([THROW_ON_ERROR],[],[when an error accur continue but avoid unsafe operation])
fi
###### Check for debug compilation
AC_MSG_CHECKING(whether to build with debug information)
......@@ -165,6 +238,21 @@ if [ test x"$debuger" = x"yes" ]; then
else
echo "* debug: no *"
fi
if [ test x"$se_class1" = x"yes" ]; then
echo "* se-class1: yes *"
else
echo "* se-class1: no *"
fi
if [ test x"$se_class2" = x"yes" ]; then
echo "* se-class2: yes *"
else
echo "* se-class2: no *"
fi
if [ test x"$se_class3" = x"yes" ]; then
echo "* se-class3: yes *"
else
echo "* se-class3: no *"
fi
if [ test x"$gpu_support" = x"no" ]; then
echo "* gpu: no *"
else
......
......@@ -61,8 +61,11 @@ public:
}
};
// Declarations;
template<unsigned int dim> class grid_key_dx_iterator_sub;
template<unsigned int N, typename T> class grid_sm;
template <unsigned int dim> class print_warning_on_adjustment;
template<unsigned int dim,typename warn=print_warning_on_adjustment<dim>> class grid_key_dx_iterator_sub;
/*! \brief class that store the information of the grid like number of point on each direction and define the index linearization
* by stride
......@@ -187,7 +190,7 @@ public:
/*! \brief Return the box enclosing the grid
*
*/
const Box<N,size_t> & getBox()
const Box<N,size_t> & getBox() const
{
return box;
}
......@@ -524,9 +527,7 @@ public:
* \return the size of the grid
*
*/
//#pragma openfpm layout(size)
size_t size()
size_t size() const
{
return size_tot;
};
......@@ -616,7 +617,7 @@ public:
* \param stop stop point
*
*/
inline grid_key_dx_iterator_sub<N> getSubIterator(grid_key_dx<N> & start, grid_key_dx<N> & stop)
inline grid_key_dx_iterator_sub<N> getSubIterator(grid_key_dx<N> & start, grid_key_dx<N> & stop) const
{
return grid_key_dx_iterator_sub<N>(*this,start,stop);
}
......@@ -917,6 +918,41 @@ public:
}
};
/* \brief grid_key_dx_iterator_sub can adjust the domain if the border go out-of-side
* in this case a warning is produced
*
* \tparam dim dimensionality
*
*/
template <unsigned int dim>
class print_warning_on_adjustment
{
public:
inline static void pw1(size_t i, const grid_key_dx<dim> & gk_start) {std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " start with index smaller than zero x[" << i << "]=" << gk_start.get(i) << "\n";}
inline static void pw2(size_t i, const grid_key_dx<dim> & gk_start) {std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " Cropping start point x[" << i << "]=" << gk_start.get(i) << " to x[" << i << "]=0 \n" ;}
inline static void pw3() {std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " stop with smaller index than start \n";}
inline static void pw4(size_t i, const grid_key_dx<dim> & gk_stop, const grid_sm<dim,void> & grid_base) {std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " stop index bigger than cell domain x[" << i << "]=" << gk_stop.get(i) << " >= " << grid_base.size(i) << "\n";}
inline static void pw5() {std::cerr << "Warning grid_key_dx_iterator_sub: " << __FILE__ << ":" << __LINE__ << " the starting point is not smaller or equal than than the stop point in all the coordinates" << "\n";}
};
/* \brief grid_key_dx_iterator_sub can adjust the domain if the border go out-of-side
* in this case a warning is produced
*
* \tparam dim dimensionality
* \tparam gb type of grid
*
*/
template <unsigned int dim>
class do_not_print_warning_on_adjustment
{
public:
inline static void pw1(size_t i, const grid_key_dx<dim> & gk_start) {}
inline static void pw2(size_t i, const grid_key_dx<dim> & gk_start) {}
inline static void pw3() {}
inline static void pw4(size_t i, const grid_key_dx<dim> & gk_stop, const grid_sm<dim,void> & grid_base) {}
inline static void pw5() {}
};
/**
*
* Grid key class iterator, iterate through a sub-grid defined by an hyper-cube
......@@ -930,7 +966,7 @@ public:
*
*/
template<unsigned int dim>
template<unsigned int dim, typename warn>
class grid_key_dx_iterator_sub : public grid_key_dx_iterator<dim>
{
#ifdef DEBUG
......@@ -958,20 +994,20 @@ class grid_key_dx_iterator_sub : public grid_key_dx_iterator<dim>
// if start smaller than 0
if (gk_start.get(i) < 0)
{
#if defined(DEBUG) && !defined(NO_WARNING)
std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " start with index smaller than zero x[" << i << "]=" << gk_start.get(i) << "\n";
#ifdef DEBUG
warn::pw1(i,gk_start);
#endif
if (gk_start.get(i) < gk_stop.get(i))
{
#if defined(DEBUG) && !defined(NO_WARNING)
std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " Cropping start point x[" << i << "]=" << gk_start.get(i) << " to x[" << i << "]=0 \n" ;
#ifdef DEBUG
warn::pw2(i,gk_start);
#endif
gk_start.set_d(i,0);
}
else
{
#if defined(DEBUG) && !defined(NO_WARNING)
std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " stop with smaller index than start \n";
#ifdef DEBUG
warn::pw3();
#endif
// No points are available
gk_start.set_d(dim-1,gk_stop.get(dim-1)+1);
......@@ -982,8 +1018,8 @@ class grid_key_dx_iterator_sub : public grid_key_dx_iterator<dim>
// if stop bigger than the domain
if (gk_stop.get(i) >= (long int)grid_base.size(i))
{
#if defined(DEBUG) && !defined(NO_WARNING)
std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " stop index bigger than cell domain x[" << i << "]=" << gk_stop.get(i) << " >= " << grid_base.size(i) << "\n";
#ifdef DEBUG
warn::pw4(i,gk_stop,grid_base);
#endif
if (gk_start.get(i) < (long int)grid_base.size(i))
......@@ -1049,7 +1085,7 @@ public:
template<typename T> grid_key_dx_iterator_sub(const grid_sm<dim,T> & g, const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop)
: grid_key_dx_iterator<dim>(g),grid_base(g),gk_start(start), gk_stop(stop)
{
#if defined(DEBUG) && !defined(NO_WARNING)
#ifdef DEBUG
//! If we are on debug check that the stop grid_key id bigger than the start
//! grid_key
......@@ -1057,7 +1093,7 @@ public:
{
if (gk_start.get(i) > gk_stop.get(i))
{
std::cerr << "Warning grid_key_dx_iterator: " << __FILE__ << " " << __LINE__ << " the starting point of the grid bigger than the stop point at any coordinate" << "\n";
warn::pw5();
}
}
#endif
......@@ -1114,7 +1150,7 @@ public:
{
if (start[i] > stop[i])
{
std::cerr << "Error grid_key_dx_iterator : " << __FILE__ << ":" << __LINE__ << " the starting point of the grid cannot be bigger than the stop point at any coordinate" << "\n";
warn::pw5();
}
}
#endif
......@@ -1231,7 +1267,7 @@ public:
{
if (gk_start.get(i) > gk_stop.get(i))
{
std::cerr << "Error grid_key_dx_iterator : " << __FILE__ << ":" << __LINE__ << " the starting point of the grid cannot be bigger than the stop point at any coordinate" << "\n";
warn::pw5();
}
}
......
......@@ -572,6 +572,111 @@ BOOST_AUTO_TEST_CASE( grid_iterator_test_use)
}
}
BOOST_AUTO_TEST_CASE( grid_safety_check )
{
#if defined(SE_CLASS1) && defined (THROW_ON_ERROR)
bool error = false;
typedef Point_test<float> p;
size_t sz[] = {16,16,16};
// Create a grid
grid_cpu<3,Point_test<float>> g(sz);
grid_cpu<3,Point_test<float>> g2(sz);
// try to access uninitialized grid
grid_key_dx<3> keyOut(23,1,1);
grid_key_dx<3> keyGood(15,1,1);
grid_key_dx<3> keyNeg(-1,0,0);
error = false;
try
{g.template get<p::x>(keyOut);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1001);
}
BOOST_REQUIRE_EQUAL(error,true);
error = false;
g.template setMemory<HeapMemory>();
try
{g.template get<p::x>(keyOut);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1002);
}
BOOST_REQUIRE_EQUAL(error,true);
error = false;
Point_test<float> t;
try
{g.set(keyOut,t);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1002);
}
BOOST_REQUIRE_EQUAL(error,true);
error = false;
try
{g.set(keyGood,g2,keyOut);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1004);
}
BOOST_REQUIRE_EQUAL(error,true);
//// Negative key
error = false;
try
{g.template get<p::x>(keyNeg);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1003);
}
BOOST_REQUIRE_EQUAL(error,true);
error = false;
Point_test<float> t2;
try
{g.set(keyNeg,t2);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1003);
}
BOOST_REQUIRE_EQUAL(error,true);
error = false;
try
{g.set(keyGood,g2,keyNeg);}
catch (size_t e)
{
error = true;
BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
BOOST_REQUIRE_EQUAL(g.getLastError(),1005);
}
BOOST_REQUIRE_EQUAL(error,true);
#endif
}
BOOST_AUTO_TEST_CASE( grid_use)
{
/* tensor<int,3,3,3> c;
......
......@@ -31,6 +31,11 @@
#include "memory_ly/memory_array.hpp"
#include "memory_ly/memory_c.hpp"
#include <vector>
#include "se_grid.hpp"
// Debugging macro
/*! \brief this class is a functor for "for_each" algorithm
*
......@@ -56,10 +61,10 @@ struct copy_cpu_encap
S & grid_dst;
//! type of the object we have to set
typedef typename S::type obj_type;
typedef typename S::value_type obj_type;
//! type of the object boost::sequence
typedef typename S::type::type ov_seq;
typedef typename S::value_type::type ov_seq;
//! object we have to store
const encapc<1,obj_type,Memory> & obj;
......@@ -77,7 +82,7 @@ struct copy_cpu_encap
:key(key),grid_dst(grid_dst),obj(obj){};
#ifdef DEBUG
#ifdef SE_CLASS1
/*! \brief Constructor
*
* Calling this constructor produce an error. This class store the reference of the object,
......@@ -126,10 +131,10 @@ struct copy_cpu
S & grid_dst;
//! type of the object we have to set
typedef typename S::type obj_type;
typedef typename S::value_type obj_type;
//! type of the object boost::sequence
typedef typename S::type::type ov_seq;
typedef typename S::value_type::type ov_seq;
//! object we have to store
const obj_type & obj;
......@@ -146,7 +151,7 @@ struct copy_cpu
copy_cpu(grid_key_dx<dim> & key, S & grid_dst, const obj_type & obj)
:key(key),grid_dst(grid_dst),obj(obj){};
#ifdef DEBUG
#ifdef SE_CLASS1
/*! \brief Constructor
*
* Calling this constructor produce an error. This class store the reference of the object,
......@@ -198,7 +203,7 @@ struct copy_cpu_sd
S & grid_dst;
//! type of the object boost::sequence
typedef typename S::type::type ov_seq;
typedef typename S::value_type::type ov_seq;
//! constructor
copy_cpu_sd(grid_key_dx<dim> & key, const S & grid_src, S & grid_dst)
......@@ -248,7 +253,7 @@ struct copy_cpu_sd_k
S & grid_dst;
//! type of the object boost::sequence
typedef typename S::type::type ov_seq;
typedef typename S::value_type::type ov_seq;
//! constructor
copy_cpu_sd_k(grid_key_dx<dim> & key_s, grid_key_dx<dim> & key_d, const S & grid_src, S & grid_dst)
......@@ -323,6 +328,14 @@ public:
typedef Mem memory_conf;
private:
//! Error code
size_t err_code;
//! Is the memory initialized
bool is_mem_init = false;
//! This is an header that store all information related to the grid
grid_sm<dim,T> g1;
......@@ -366,7 +379,7 @@ public:
typedef encapc<dim,T,Mem> container;
// The object type the grid is storing
typedef T type;
typedef T value_type;
//! Default constructor
grid_cpu()
......@@ -468,7 +481,7 @@ public:
*
*/
grid_sm<dim,T> getGrid()
const grid_sm<dim,T> & getGrid() const
{
return g1;
}
......@@ -490,6 +503,8 @@ public:
//! Allocate the memory and create the representation
if (g1.size() != 0) data.allocate(g1.size());
is_mem_init = true;
}
/*! \brief Get the object that provide memory
......@@ -513,6 +528,8 @@ public:
//! Allocate the memory and create the reppresentation
if (g1.size() != 0) data.allocate(g1.size());
is_mem_init = true;
}
/*! \brief Return a plain pointer to the internal data
......@@ -541,6 +558,10 @@ public:
*/
template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(grid_key<p> & v1)
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(&data.mem_r->operator[](g1.LinId(v1.getId()))));
#endif
......@@ -557,6 +578,10 @@ public:
*/
template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(grid_key<p> & v1) const
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(&data.mem_r->operator[](g1.LinId(v1.getId()))));
#endif
......@@ -572,6 +597,10 @@ public:
*/
template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(grid_key_d<dim,p> & v1)
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))));
#endif
......@@ -587,6 +616,10 @@ public:
*/
template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(grid_key_d<dim,p> & v1) const
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))));
#endif
......@@ -602,6 +635,10 @@ public:
*/
template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(const grid_key_dx<dim> & v1)
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))),sizeof(typename type_cpu_prop<p,memory_lin>::type));
#endif
......@@ -617,6 +654,10 @@ public:
*/
template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(const grid_key_dx<dim> & v1) const
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))),sizeof(typename type_cpu_prop<p,memory_lin>::type));
#endif
......@@ -632,6 +673,10 @@ public:
*/
inline encapc<dim,T,Mem> get_o(const grid_key_dx<dim> & v1)
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&data.mem_r->operator[](g1.LinId(v1)),sizeof(T));
#endif
......@@ -647,6 +692,10 @@ public:
*/
inline const encapc<dim,T,Mem> get_o(const grid_key_dx<dim> & v1) const
{
#ifdef SE_CLASS1
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&data.mem_r->operator[](g1.LinId(v1)),sizeof(T));
#endif
......@@ -734,8 +783,8 @@ public:
{
if (dim != 1)
{
#ifdef DEBUG
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " trying to remove " << "\n";
#ifdef SE_CLASS1
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " remove work only on dimension == 1 " << "\n";
#endif
return;
}
......@@ -782,6 +831,16 @@ public:
// move the grid info
g1 = grid.g1;
// exchange the init status
bool exg = is_mem_init;
is_mem_init = grid.is_mem_init;
grid.is_mem_init = exg;
// exchange the is external status
exg = isExternal;
isExternal = grid.isExternal;
grid.isExternal = exg;
}
/*! \brief It move the allocated object from one grid to another
......@@ -809,16 +868,9 @@ public:
template<typename Memory> inline void set(grid_key_dx<dim> dx, const encapc<1,T,Memory> & obj)
{
#ifdef DEBUG
// Check that the element exist
for (size_t i = 0 ; i < dim ; i++)
{
if (dx.get(i) >= (long int)g1.size(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " out of bound" << "\n";