Commit b6f3d2f6 authored by Pietro Incardona's avatar Pietro Incardona

Adding performance benchmark Grid and Vector

parent 51c621a2
......@@ -60,6 +60,28 @@ if test x"$test_cov" = x"yes"; then
CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage "
fi
###### Check for performance test
AC_MSG_CHECKING(whether to build with performance test)
test_per=no
AC_ARG_ENABLE(test-performance,
AC_HELP_STRING(
[--enable-test-performance],
[enable test performance]
),
test_per="$enableval"
)
AC_MSG_RESULT($test_per)
if test x"$test_per" = x"yes"; then
AC_DEFINE([PERFORMANCE_TEST],[],[Test performance mode])
fi
###### Check for se-class1
###### Check for se-class1
AC_MSG_CHECKING(whether to build with security enhancement class1)
......@@ -179,7 +201,7 @@ fi
####### include openfpm_devices include path
INCLUDES_PATH+="-I. -Iconfig -I../../openfpm_devices/src"
INCLUDES_PATH+="-I. -Iconfig -I../../openfpm_devices/src -I../../openfpm_io/src"
####### Checking for GPU support
......
......@@ -50,6 +50,13 @@ public:
this->k[i] = k[i];
}
//! Construct a grid key from a list of numbers
template<typename ...T> inline grid_key_dx(const comb<dim> & cmb)
{
for (size_t i = 0 ; i < dim ; i++)
k[i] = cmb[i];
}
//! Construct a grid key from a list of numbers
template<typename ...T> inline grid_key_dx(const size_t v,const T...t)
{
......
......@@ -9,15 +9,9 @@
#define OPENFPM_DATA_SRC_GRID_GRID_PERFORMANCE_TESTS_HPP_
#include "grid_util_test.hpp"
#include "timer.hpp"
#define N_STAT 256
#define N_STAT_SMALL 32
#define N_TRY 8
#ifdef PERFORMANCE_TEST
BOOST_AUTO_TEST_SUITE( grid_performance )
openfpm::vector<std::string> testsg;
openfpm::vector<float> per_timesg;
BOOST_AUTO_TEST_CASE(grid_performance_set_obj)
{
......@@ -58,7 +52,8 @@ BOOST_AUTO_TEST_CASE(grid_performance_set_obj)
sleep(5);
}
std::cout << "Time : " << times[0] << "s ";
testsg.add("Grid so");
per_timesg.add(times[0]);
}
......@@ -99,7 +94,8 @@ BOOST_AUTO_TEST_CASE(grid_performance_set_other_grid)
sleep(5);
}
std::cout << "Time : " << times[0] << "s ";
testsg.add("Grid sog");
per_timesg.add(times[0]);
}
......@@ -140,7 +136,8 @@ BOOST_AUTO_TEST_CASE(grid_performance_set_other_grid_encap)
sleep(5);
}
std::cout << "Time : " << times[0] << "s ";
testsg.add("Grid soge");
per_timesg.add(times[0]);
}
BOOST_AUTO_TEST_CASE(grid_performance_duplicate)
......@@ -173,11 +170,8 @@ BOOST_AUTO_TEST_CASE(grid_performance_duplicate)
sleep(5);
}
std::cout << "Time : " << times[0] << "s ";
testsg.add("Grid dup");
per_timesg.add(times[0]);
}
BOOST_AUTO_TEST_SUITE_END()
#endif
#endif /* OPENFPM_DATA_SRC_GRID_GRID_PERFORMANCE_TESTS_HPP_ */
......@@ -346,8 +346,6 @@ public:
typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,PtrMemory,openfpm::grow_policy_identity> stype;
typedef openfpm::vector<typename grid_cpu<dim,T,S,Mem>::value_type,PtrMemory,openfpm::grow_policy_identity> stype2;
size_t size = stype::template calculateMem(sub_it.getVolume(),0);
// Create an object over the preallocated memory (No allocation is produced)
......
......@@ -85,10 +85,6 @@ public:
*/
inline static void pack(ExtPreAlloc<Mem> & ext, const T & obj, Pack_stat & sts)
{
#ifdef DEBUG
if (ext.ref() == 0)
std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
#endif
ext.allocate(sizeof(T));
*(T *)ext.getPointer() = obj;
......@@ -127,10 +123,6 @@ public:
*/
inline static void pack(ExtPreAlloc<Mem> & ext, const T & obj, Pack_stat & sts, size_t n)
{
#ifdef DEBUG
if (ext.ref() == 0)
std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
#endif
//Pack the size of a vector
Packer<size_t, Mem>::pack(ext,obj.size(),sts);
......
......@@ -395,6 +395,15 @@ public:
base = v.base;
}
/*! \brief Initializer from constructor
*
* \param v Initializer list
*
*/
vector(const std::initializer_list<T> & v)
:base(v)
{}
//! Constructor from another vector
vector(vector<T,HeapMemory,grow_policy_double,STD_VECTOR> && v) noexcept
:v_size(0),err_code(0)
......
/*
* vector_performance_test.hpp
*
* Created on: Jan 11, 2016
* Author: i-bird
*/
#ifndef OPENFPM_DATA_SRC_VECTOR_VECTOR_PERFORMANCE_TEST_HPP_
#define OPENFPM_DATA_SRC_VECTOR_VECTOR_PERFORMANCE_TEST_HPP_
#define NADD 128*128
openfpm::vector<std::string> testsv;
openfpm::vector<float> per_timesv;
BOOST_AUTO_TEST_CASE(vector_add_performance)
{
std::vector<double> times(N_STAT + 1);
times[0] = 1000;
for (size_t j = 0 ; j < 8 ; j++)
{
for (size_t i = 1 ; i < N_STAT+1 ; i++)
{
timer t;
t.start();
// create a vector
openfpm::vector<Point_test<float>> v1;
// Point
Point_test<float> p;
p.setx(1.0);
p.sety(2.0);
p.setz(3.0);
p.sets(4.0);
p.get<P::v>()[0] = 1.0;
p.get<P::v>()[1] = 2.0;
p.get<P::v>()[2] = 7.0;
p.get<P::t>()[0][0] = 10.0;
p.get<P::t>()[0][1] = 13.0;
p.get<P::t>()[0][2] = 8.0;
p.get<P::t>()[1][0] = 19.0;
p.get<P::t>()[1][1] = 23.0;
p.get<P::t>()[1][2] = 5.0;
p.get<P::t>()[2][0] = 4.0;
p.get<P::t>()[2][1] = 3.0;
p.get<P::t>()[2][2] = 11.0;
// push objects
for (size_t i = 0 ; i < NADD ; i++)
{
v1.add(p);
}
}
std::sort(times.begin(),times.end());
sleep(5);
}
testsv.add("Vector add");
per_timesv.add(times[0]);
}
#endif /* OPENFPM_DATA_SRC_VECTOR_VECTOR_PERFORMANCE_TEST_HPP_ */
......@@ -185,11 +185,6 @@
template<int ... prp> void pack(ExtPreAlloc<HeapMemory> & mem, Pack_stat & sts)
{
#ifdef DEBUG
if (mem.ref() == 0)
std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
#endif
#ifdef DEBUG
std::cout << "Inside pack() function! (map_vector_std)" << std::endl;
#endif
......@@ -229,3 +224,79 @@
unp.unpacking(mem, *this, ps);
}
/*! \brief Save this object into file
*
* \param file filename
*
* \return true if succed
*
*/
bool save(std::string file)
{
std::vector<size_t> pap_prp;
Packer<openfpm::vector<T,HeapMemory,grow_policy_double,STD_VECTOR>,HeapMemory>::packRequest(*this,pap_prp);
// Calculate how much preallocated memory we need to pack all the objects
size_t req = ExtPreAlloc<HeapMemory>::calculateMem(pap_prp);
// allocate the memory
HeapMemory pmem;
pmem.allocate(req);
ExtPreAlloc<HeapMemory> mem(pap_prp,pmem);
//Packing
Pack_stat sts;
Packer<openfpm::vector<T,HeapMemory,grow_policy_double,STD_VECTOR>,HeapMemory>::pack(mem,*this,sts);
// Save into a binary file
std::ofstream dump (file, std::ios::out | std::ios::binary);
dump.write ((const char *)pmem.getPointer(), pmem.size());
return true;
}
/*! \brief Load this object from file
*
* \param file filename
*
* \return true if succed
*
*/
bool load(std::string file)
{
std::ifstream fs (file, std::ios::in | std::ios::binary | std::ios::ate );
if (fs.is_open() == false)
return false;
// take the size of the file
size_t sz = fs.tellg();
fs.close();
// reopen the file without ios::ate to read
std::ifstream input (file, std::ios::in | std::ios::binary );
if (input.is_open() == false)
return false;
// Create the HeapMemory and the ExtPreAlloc memory
std::vector<size_t> pap_prp;
pap_prp.push_back(sz);
HeapMemory pmem;
ExtPreAlloc<HeapMemory> mem(pap_prp,pmem);
// read
input.read((char *)pmem.getPointer(), sz);
//close the file
input.close();
//Unpacking
Unpack_stat ps;
Unpacker<openfpm::vector<T,HeapMemory,grow_policy_double,STD_VECTOR>,HeapMemory>::unpack(mem,*this,ps);
return true;
}
......@@ -708,6 +708,38 @@ BOOST_AUTO_TEST_CASE( vector_safety_check )
#endif
}
BOOST_AUTO_TEST_CASE( vector_load_and_save_check )
{
openfpm::vector<openfpm::vector<float>> v1;
for (size_t i = 0; i < 5; i++)
{
v1.add();
for (size_t j = 0; j < 6; j++)
{
v1.get(i).add(j);
}
}
v1.save("test_save");
openfpm::vector<openfpm::vector<float>> v2;
v2.load("test_save");
// check the v1 and v2 match
BOOST_REQUIRE_EQUAL(v1.size(),v2.size());
for (size_t i = 0; i < v1.size(); i++)
{
BOOST_REQUIRE_EQUAL(v1.get(i).size(),v2.get(i).size());
for (size_t j = 0; j < 6; j++)
{
BOOST_REQUIRE_EQUAL(v1.get(i).get(j),v2.get(i).get(j));
}
}
}
BOOST_AUTO_TEST_SUITE_END()
#endif
......@@ -12,7 +12,6 @@
#include "Packer_Unpacker/Packer_unit_tests.hpp"
#include "Packer_Unpacker/Packer_nested_tests.hpp"
#include "Grid/grid_performance_tests.hpp"
#include "util/copy_compare/meta_cc_unit_tests.hpp"
#include "util/variadic_to_vmpl_unit_test.hpp"
#include "Space/Shape/Point_unit_test.hpp"
......@@ -29,3 +28,6 @@
#include "Grid/grid_unit_tests.hpp"
#include "Grid/grid_sm_unit_tests.hpp"
#include "util/mathutil_unit_test.hpp"
#ifdef PERFORMANCE_TEST
#include "performance.hpp"
#endif
/*
* performance.hpp
*
* Created on: Jan 11, 2016
* Author: i-bird
*/
#ifndef OPENFPM_DATA_SRC_PERFORMANCE_HPP_
#define OPENFPM_DATA_SRC_PERFORMANCE_HPP_
#include "Plot/GoogleChart.hpp"
#include "timer.hpp"
#define N_STAT 256
#define N_STAT_SMALL 32
#define N_TRY 8
#ifdef PERFORMANCE_TEST
BOOST_AUTO_TEST_SUITE( performance )
//// Include tests ////////
#include "Grid/grid_performance_tests.hpp"
#include "Vector/vector_performance_test.hpp"
#define MEASURE_SET 5
/*! \brief Load the previous test result combine with the actual result and save
*
* \param file file that contain the previous result
* \param yn vector with the name of the dataset
* \param y vector with the data to load
* \param nc number of colums
*
*/
void load_and_combine(std::string file, openfpm::vector<std::string> & yn, openfpm::vector<openfpm::vector<float>> & y, openfpm::vector<float> & per_times, size_t nc)
{
// Load the previous measure and combine the previous measure with the actual measure
y.clear();
yn.clear();
y.load(file);
y.resize(nc);
for(size_t i = 0 ; i < y.size() ; i++)
{
if (y.get(i).size() >= MEASURE_SET)
y.get(i).remove(0);
y.get(i).add(per_times.get(i));
}
for (size_t j = 0; j < y.get(0).size(); j++)
{
if (j < y.get(0).size() - 1)
yn.add("previous " + std::to_string(j));
else
yn.add("actual");
}
y.save(file);
}
BOOST_AUTO_TEST_CASE(performance_report_out)
{
GoogleChart cg;
openfpm::vector<std::string> yn;
openfpm::vector<openfpm::vector<float>> y;
load_and_combine("/home/i-bird/Desktop/MOSAIC/OpenFPM_project/openfpm_pdata/openfpm_data/previous_measureg",yn,y,per_timesg,testsg.size());
// Google charts options
GCoptions options;
options.title = std::string("Grid Performances");
options.yAxis = std::string("Time (seconds)");
options.xAxis = std::string("Benchmark");
options.stype = std::string("bars");
cg.addHTML("<h2>Grid performance test</h2>");
cg.AddColumsGraph(testsg,y,yn,options);
load_and_combine("/home/i-bird/Desktop/MOSAIC/OpenFPM_project/openfpm_pdata/openfpm_data/previous_measurev",yn,y,per_timesv,testsv.size());
options.title = std::string("Vector Performances");
options.yAxis = std::string("Time (seconds)");
options.xAxis = std::string("Benchmark");
options.stype = std::string("bars");
cg.addHTML("<h2>Vector performance test</h2>");
cg.AddColumsGraph(testsv,y,yn,options);
cg.write("gc_out.html");
}
BOOST_AUTO_TEST_SUITE_END()
#endif
#endif /* OPENFPM_DATA_SRC_PERFORMANCE_HPP_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment