8#ifndef VECTOR_PERFORMANCE_TEST_HPP_
9#define VECTOR_PERFORMANCE_TEST_HPP_
18#ifndef OPENFPM_DATA_SRC_VECTOR_VECTOR_PERFORMANCE_TEST_HPP_
19#define OPENFPM_DATA_SRC_VECTOR_VECTOR_PERFORMANCE_TEST_HPP_
21#define NADD 128*128*128
26 boost::property_tree::ptree graphs;
31BOOST_AUTO_TEST_SUITE( vector_performance )
33BOOST_AUTO_TEST_CASE(vector_performance)
35 report_vector_funcs.graphs.put(
"performance.vector(0).funcs.nele",NADD);
36 report_vector_funcs.graphs.put(
"performance.vector(0).funcs.name",
"add");
38 report_vector_funcs.graphs.put(
"performance.vector(1).funcs.nele",NADD);
39 report_vector_funcs.graphs.put(
"performance.vector(1).funcs.name",
"get");
41 std::vector<double> times(N_STAT + 1);
42 std::vector<double> times_g(N_STAT + 1);
45 double tot_accu = 0.0;
47 for (
size_t i = 0 ; i < N_STAT+1 ; i++)
78 for (
size_t i = 0 ; i < NADD ; i++)
89 for (
size_t i = 0 ; i < NADD ; i++)
91 double accu1 = v1.template get<P::x>(i);
92 double accu2 = v1.template get<P::y>(i);
93 double accu3 = v1.template get<P::z>(i);
94 double accu4 = v1.template get<P::s>(i);
96 double accu5 = v1.template get<P::v>(i)[0];
97 double accu6 = v1.template get<P::v>(i)[1];
98 double accu7 = v1.template get<P::v>(i)[2];
100 double accu8 = v1.template get<P::t>(i)[0][0];
101 double accu9 = v1.template get<P::t>(i)[0][1];
102 double accu10 = v1.template get<P::t>(i)[0][2];
103 double accu11 = v1.template get<P::t>(i)[1][0];
104 double accu12 = v1.template get<P::t>(i)[1][1];
105 double accu13 = v1.template get<P::t>(i)[1][2];
106 double accu14 = v1.template get<P::t>(i)[2][0];
107 double accu15 = v1.template get<P::t>(i)[2][1];
108 double accu16 = v1.template get<P::t>(i)[2][2];
110 tot_accu += accu1 + accu2 + accu3 + accu4 + accu5 + accu6 + accu7 + accu8 + accu9 + accu10 + accu11 + accu12 +
111 accu13 + accu14 + accu15 + accu16;
121 standard_deviation(times,mean,dev);
123 report_vector_funcs.graphs.put(
"performance.vector(0).y.data.mean",mean);
124 report_vector_funcs.graphs.put(
"performance.vector(0).y.data.dev",dev);
126 standard_deviation(times_g,mean,dev);
128 report_vector_funcs.graphs.put(
"performance.vector(1).y.data.mean",mean);
129 report_vector_funcs.graphs.put(
"performance.vector(1).y.data.dev",dev);
132template<
typename vector_prop_type,
typename vector_pos_type>
133__device__ __host__
void read_write(vector_prop_type & vd_prop, vector_pos_type & vd_pos,
unsigned int p)
135 vd_prop.template get<0>(p) = vd_pos.template get<0>(p)[0] + vd_pos.template get<0>(p)[1];
137 vd_prop.template get<1>(p)[0] = vd_pos.template get<0>(p)[0];
138 vd_prop.template get<1>(p)[1] = vd_pos.template get<0>(p)[1];
140 vd_prop.template get<2>(p)[0][0] = vd_pos.template get<0>(p)[0];
141 vd_prop.template get<2>(p)[0][1] = vd_pos.template get<0>(p)[1];
142 vd_prop.template get<2>(p)[1][0] = vd_pos.template get<0>(p)[0] +
143 vd_pos.template get<0>(p)[1];
144 vd_prop.template get<2>(p)[1][1] = vd_pos.template get<0>(p)[1] -
145 vd_pos.template get<0>(p)[0];
147 vd_pos.template get<0>(p)[0] += 0.01f;
148 vd_pos.template get<0>(p)[1] += 0.01f;
159__device__ __host__
void read_write_lin(
double * pos,
ele * prp,
unsigned int p)
161 prp[p].s = pos[2*p] + pos[2*p+1];
163 prp[p].v[0] = pos[2*p];
164 prp[p].v[1] = pos[2*p+1];
166 prp[p].t[0][0] = pos[2*p];
167 prp[p].t[0][1] = pos[2*p+1];
168 prp[p].t[1][0] = pos[2*p] +
170 prp[p].t[1][1] = pos[2*p+1] -
177__device__ __host__
void read_write_inte(
double * pos,
double * prp0,
double * prp1,
double * prp2,
unsigned int p,
unsigned int n_pos)
179 prp0[0*n_pos + p] = pos[0*n_pos + p] + pos[1*n_pos+p];
181 prp1[0*n_pos + p] = pos[0*n_pos + p];
182 prp1[1*n_pos + p] = pos[1*n_pos + p];
184 prp2[0*n_pos*2+0*n_pos + p] = pos[0*n_pos + p];
185 prp2[0*n_pos*2+1*n_pos + p] = pos[1*n_pos + p];
186 prp2[1*n_pos*2+0*n_pos + p] = pos[0*n_pos + p] +
188 prp2[1*n_pos*2+1*n_pos + p] = pos[1*n_pos + p] -
191 pos[0*n_pos + p] += 0.01f;
192 pos[1*n_pos + p] += 0.01f;
195BOOST_AUTO_TEST_CASE(vector_performance_layout_vs_plain_array)
197 std::vector<double> times(N_STAT + 1);
198 std::vector<double> times_g(N_STAT + 1);
200 std::vector<double> times2(N_STAT + 1);
201 std::vector<double> times2_g(N_STAT + 1);
204 double tot_accu = 0.0;
206 report_vector_funcs.graphs.put(
"performance.vector_layout(0).funcs.nele",NADD);
207 report_vector_funcs.graphs.put(
"performance.vector_layout(0).funcs.name",
"read_write_lin");
209 for (
size_t i = 0 ; i < N_STAT+1 ; i++)
223 pa.
get<1>()[0] = 1.0;
224 pa.
get<1>()[1] = 1.0;
226 pa.
get<2>()[0][0] = 1.0;
227 pa.
get<2>()[0][1] = 1.0;
228 pa.
get<2>()[1][0] = 1.0;
229 pa.
get<2>()[1][1] = 1.0;
233 for (
size_t i = 0 ; i < NADD ; i++)
242 for (
size_t i = 0 ; i < NADD ; i++)
254 double * prp = (
double *)v1.getPointer<0>();
255 double * pos = (
double *)v2.getPointer<0>();
257 for (
size_t i = 0 ; i < NADD ; i++)
259 read_write_lin(pos,(
struct ele *)prp,i);
269 standard_deviation(times_g,mean,dev);
273 standard_deviation(times,mean_,dev_);
275 report_vector_funcs.graphs.put(
"performance.vector_layout(0).y.data.mean",mean_/mean);
279 report_vector_funcs.graphs.put(
"performance.vector_layout(0).y.data.dev",mean_/(mean*mean)*dev + dev_ / mean );
281 report_vector_funcs.graphs.put(
"performance.vector_layout(1).funcs.nele",NADD);
282 report_vector_funcs.graphs.put(
"performance.vector_layout(1).funcs.name",
"read_write_inte");
284 for (
size_t i = 0 ; i < N_STAT+1 ; i++)
298 pa.
get<1>()[0] = 1.0;
299 pa.
get<1>()[1] = 1.0;
301 pa.
get<2>()[0][0] = 1.0;
302 pa.
get<2>()[0][1] = 1.0;
303 pa.
get<2>()[1][0] = 1.0;
304 pa.
get<2>()[1][1] = 1.0;
308 for (
size_t i = 0 ; i < NADD ; i++)
317 for (
size_t i = 0 ; i < NADD ; i++)
324 times2_g[i] = tg.
getwct();
330 double * prp0 = (
double *)v1.getPointer<0>();
331 double * prp1 = (
double *)v1.getPointer<1>();
332 double * prp2 = (
double *)v1.getPointer<2>();
334 double * pos = (
double *)v2.getPointer<0>();
336 for (
size_t i = 0 ; i < NADD ; i++)
338 read_write_inte(pos,prp0,prp1,prp2,i,sz);
348 standard_deviation(times2_g,mean2,dev2);
352 standard_deviation(times2,mean2_,dev2_);
354 report_vector_funcs.graphs.put(
"performance.vector_layout(1).y.data.mean",mean2_/mean2);
358 report_vector_funcs.graphs.put(
"performance.vector_layout(1).y.data.dev",mean2_/(mean2*mean2)*dev2 + dev2_ / mean2 );
363BOOST_AUTO_TEST_CASE(vector_performance_write_report)
367 report_vector_funcs.graphs.put(
"graphs.graph(0).type",
"line");
368 report_vector_funcs.graphs.add(
"graphs.graph(0).title",
"Vector add and get");
369 report_vector_funcs.graphs.add(
"graphs.graph(0).x.title",
"Tests");
370 report_vector_funcs.graphs.add(
"graphs.graph(0).y.title",
"Time seconds");
371 report_vector_funcs.graphs.add(
"graphs.graph(0).y.data(0).source",
"performance.vector(#).y.data.mean");
372 report_vector_funcs.graphs.add(
"graphs.graph(0).x.data(0).source",
"performance.vector(#).funcs.name");
373 report_vector_funcs.graphs.add(
"graphs.graph(0).y.data(0).title",
"Actual");
374 report_vector_funcs.graphs.add(
"graphs.graph(0).interpolation",
"lines");
376 report_vector_funcs.graphs.put(
"graphs.graph(1).type",
"line");
377 report_vector_funcs.graphs.add(
"graphs.graph(1).title",
"Vector read write");
378 report_vector_funcs.graphs.add(
"graphs.graph(1).x.title",
"Layout");
379 report_vector_funcs.graphs.add(
"graphs.graph(1).y.title",
"Time seconds");
380 report_vector_funcs.graphs.add(
"graphs.graph(1).y.data(0).source",
"performance.vector_layout(#).y.data.mean");
381 report_vector_funcs.graphs.add(
"graphs.graph(1).x.data(0).source",
"performance.vector_layout(#).funcs.name");
382 report_vector_funcs.graphs.add(
"graphs.graph(1).y.data(0).title",
"Actual");
383 report_vector_funcs.graphs.add(
"graphs.graph(1).interpolation",
"lines");
385 boost::property_tree::xml_writer_settings<std::string> settings(
' ', 4);
386 boost::property_tree::write_xml(
"vector_performance_funcs.xml", report_vector_funcs.graphs,std::locale(),settings);
390 std::string file_xml_ref(test_dir);
391 file_xml_ref += std::string(
"/openfpm_data/vector_performance_funcs_ref.xml");
393 StandardXMLPerformanceGraph(
"vector_performance_funcs.xml",file_xml_ref,cg);
395 addUpdtateTime(cg,1,
"data",
"vector_performance_funcs");
397 cg.
write(
"vector_performance_funcs.html");
400BOOST_AUTO_TEST_SUITE_END()
Small class to produce graph with Google chart in HTML.
void write(std::string file)
It write the graphs on file in html format using Google charts.
This class allocate, and destroy CPU memory.
Test structure used for several test.
void sety(T y_)
set the y property
void setz(T z_)
set the z property
auto get() -> decltype(boost::fusion::at_c< i >(data))
getter method for a general property i
static const unsigned int v
v property is at position 4 in the boost::fusion::vector
void sets(T s_)
set the s property
void setx(T x_)
set the x property
static const unsigned int t
t property is at position 5 in the boost::fusion::vector
Implementation of 1-D std::vector like structure.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
__device__ __host__ boost::mpl::at< type, boost::mpl::int_< i > >::type & get()
get the properties i
Transform the boost::fusion::vector into memory specification (memory_traits)