vector_performance_test.hpp 10.7 KB
Newer Older
incardon's avatar
incardon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * vector_performance_test.hpp
 *
 *  Created on: Jul 15, 2019
 *      Author: i-bird
 */

#ifndef VECTOR_PERFORMANCE_TEST_HPP_
#define VECTOR_PERFORMANCE_TEST_HPP_

/*
 * 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*128

// Property tree
struct report_vector_func_tests
{
	boost::property_tree::ptree graphs;
};

report_vector_func_tests report_vector_funcs;

BOOST_AUTO_TEST_SUITE( vector_performance )

BOOST_AUTO_TEST_CASE(vector_performance)
{
	report_vector_funcs.graphs.put("performance.vector(0).funcs.nele",NADD);
	report_vector_funcs.graphs.put("performance.vector(0).funcs.name","add");

	report_vector_funcs.graphs.put("performance.vector(1).funcs.nele",NADD);
	report_vector_funcs.graphs.put("performance.vector(1).funcs.name","get");

	std::vector<double> times(N_STAT + 1);
	std::vector<double> times_g(N_STAT + 1);

	// get test
	double tot_accu = 0.0;

	for (size_t i = 0 ; 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;

		// Add test

		for (size_t i = 0 ; i < NADD ; i++)
		{
			v1.add(p);
		}

		t.stop();
		times[i] = t.getwct();

		timer tg;
		tg.start();

		for (size_t i = 0 ; i < NADD ; i++)
		{
			double accu1 = v1.template get<P::x>(i);
			double accu2 = v1.template get<P::y>(i);
			double accu3 = v1.template get<P::z>(i);
			double accu4 = v1.template get<P::s>(i);

			double accu5 = v1.template get<P::v>(i)[0];
			double accu6 = v1.template get<P::v>(i)[1];
			double accu7 = v1.template get<P::v>(i)[2];

			double accu8 = v1.template get<P::t>(i)[0][0];
			double accu9 = v1.template get<P::t>(i)[0][1];
			double accu10 = v1.template get<P::t>(i)[0][2];
			double accu11 = v1.template get<P::t>(i)[1][0];
			double accu12 = v1.template get<P::t>(i)[1][1];
			double accu13 = v1.template get<P::t>(i)[1][2];
			double accu14 = v1.template get<P::t>(i)[2][0];
			double accu15 = v1.template get<P::t>(i)[2][1];
			double accu16 = v1.template get<P::t>(i)[2][2];

			tot_accu += accu1 + accu2 + accu3 + accu4 + accu5 + accu6 + accu7 + accu8 + accu9 + accu10 + accu11 + accu12 +
					   accu13 + accu14 + accu15 + accu16;
		}

		tg.stop();

		times_g[i] = tg.getwct();
	}

	double mean;
	double dev;
	standard_deviation(times,mean,dev);

	report_vector_funcs.graphs.put("performance.vector(0).y.data.mean",mean);
	report_vector_funcs.graphs.put("performance.vector(0).y.data.dev",dev);

	standard_deviation(times_g,mean,dev);

	report_vector_funcs.graphs.put("performance.vector(1).y.data.mean",mean);
	report_vector_funcs.graphs.put("performance.vector(1).y.data.dev",dev);
}

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
template<typename vector_prop_type, typename vector_pos_type>
__device__ __host__ void read_write(vector_prop_type & vd_prop, vector_pos_type & vd_pos, unsigned int p)
{
	vd_prop.template get<0>(p) = vd_pos.template get<0>(p)[0] + vd_pos.template get<0>(p)[1];

	vd_prop.template get<1>(p)[0] = vd_pos.template get<0>(p)[0];
	vd_prop.template get<1>(p)[1] = vd_pos.template get<0>(p)[1];

	vd_prop.template get<2>(p)[0][0] = vd_pos.template get<0>(p)[0];
	vd_prop.template get<2>(p)[0][1] = vd_pos.template get<0>(p)[1];
	vd_prop.template get<2>(p)[1][0] = vd_pos.template get<0>(p)[0] + 
                                      	   vd_pos.template get<0>(p)[1];
	vd_prop.template get<2>(p)[1][1] = vd_pos.template get<0>(p)[1] - 
                                      	   vd_pos.template get<0>(p)[0];

	vd_pos.template get<0>(p)[0] += 0.01f;
	vd_pos.template get<0>(p)[1] += 0.01f;
}


struct ele
{
	double s;
	double v[2];
	double t[2][2];
};

__device__ __host__ void read_write_lin(double * pos, ele * prp, unsigned int p)
{
    prp[p].s = pos[2*p] + pos[2*p+1];

    prp[p].v[0] = pos[2*p];
    prp[p].v[1] = pos[2*p+1];

    prp[p].t[0][0] = pos[2*p];
    prp[p].t[0][1] = pos[2*p+1];
    prp[p].t[1][0] = pos[2*p] + 
                                  pos[2*p+1];
    prp[p].t[1][1] = pos[2*p+1] - 
                                  pos[2*p];

    pos[2*p] += 0.01f;
    pos[2*p+1] += 0.01f;
}

__device__ __host__ void read_write_inte(double * pos, double * prp0, double * prp1, double * prp2, unsigned int p, unsigned int n_pos)
{
    prp0[0*n_pos + p] = pos[0*n_pos + p] + pos[1*n_pos+p];

    prp1[0*n_pos + p] = pos[0*n_pos + p];
    prp1[1*n_pos + p] = pos[1*n_pos + p];

    prp2[0*n_pos*2+0*n_pos + p] = pos[0*n_pos + p];
    prp2[0*n_pos*2+1*n_pos + p] = pos[1*n_pos + p];
    prp2[1*n_pos*2+0*n_pos + p] = pos[0*n_pos + p] + 
                                  pos[1*n_pos + p];
    prp2[1*n_pos*2+1*n_pos + p] = pos[1*n_pos + p] - 
                                  pos[0*n_pos + p];

    pos[0*n_pos + p] += 0.01f;
    pos[1*n_pos + p] += 0.01f;
}

BOOST_AUTO_TEST_CASE(vector_performance_layout_vs_plain_array)
{
	std::vector<double> times(N_STAT + 1);
	std::vector<double> times_g(N_STAT + 1);

	std::vector<double> times2(N_STAT + 1);
	std::vector<double> times2_g(N_STAT + 1);

	// get test
	double tot_accu = 0.0;

	report_vector_funcs.graphs.put("performance.vector_layout(0).funcs.nele",NADD);
	report_vector_funcs.graphs.put("performance.vector_layout(0).funcs.name","read_write_lin");

	for (size_t i = 0 ; i < N_STAT+1 ; i++)
	{
		// create a vector
		openfpm::vector<aggregate<double,double[2],double[2][2]>> v1;
		openfpm::vector<aggregate<double[2]>> v2;

		// Point
		aggregate<double[2]> p;
		p.get<0>()[0] = 1.0;
		p.get<0>()[1] = 2.0;

		aggregate<double,double[2],double[2][2]> pa;
		pa.get<0>() = 1.0;

		pa.get<1>()[0] = 1.0;
		pa.get<1>()[1] = 1.0;

		pa.get<2>()[0][0] = 1.0;
		pa.get<2>()[0][1] = 1.0;
		pa.get<2>()[1][0] = 1.0;
		pa.get<2>()[1][1] = 1.0;

		// Add test

		for (size_t i = 0 ; i < NADD ; i++)
		{
			v1.add(pa);
			v2.add(p);
		}

		timer tg;
		tg.start();

		for (size_t i = 0 ; i < NADD ; i++)
		{
			read_write(v1,v2,i);
		}

		tg.stop();

		times_g[i] = tg.getwct();

		timer tga;
		tga.start();

		double * prp = (double *)v1.getPointer<0>();
		double * pos = (double *)v2.getPointer<0>();

		for (size_t i = 0 ; i < NADD ; i++)
		{
			read_write_lin(pos,(struct ele *)prp,i);
		}

		tga.stop();

		times[i] = tga.getwct();
	}

	double mean;
	double dev;
	standard_deviation(times_g,mean,dev);

	double mean_;
	double dev_;
	standard_deviation(times,mean_,dev_);

	report_vector_funcs.graphs.put("performance.vector_layout(0).y.data.mean",mean_/mean);

	// Deviation od x/y = x/y^2 dy + 1/y dx

	report_vector_funcs.graphs.put("performance.vector_layout(0).y.data.dev",mean_/(mean*mean)*dev + dev_ / mean );

	report_vector_funcs.graphs.put("performance.vector_layout(1).funcs.nele",NADD);
	report_vector_funcs.graphs.put("performance.vector_layout(1).funcs.name","read_write_inte");

	for (size_t i = 0 ; i < N_STAT+1 ; i++)
	{
		// create a vector
		openfpm::vector<aggregate<double,double[2],double[2][2]>,HeapMemory,memory_traits_inte> v1;
		openfpm::vector<aggregate<double[2]>,HeapMemory,memory_traits_inte> v2;

		// Point
		aggregate<double[2]> p;
		p.get<0>()[0] = 1.0;
		p.get<0>()[1] = 2.0;

		aggregate<double,double[2],double[2][2]> pa;
		pa.get<0>() = 1.0;

		pa.get<1>()[0] = 1.0;
		pa.get<1>()[1] = 1.0;

		pa.get<2>()[0][0] = 1.0;
		pa.get<2>()[0][1] = 1.0;
		pa.get<2>()[1][0] = 1.0;
		pa.get<2>()[1][1] = 1.0;

		// Add test

		for (size_t i = 0 ; i < NADD ; i++)
		{
			v1.add(pa);
			v2.add(p);
		}

		timer tg;
		tg.start();

		for (size_t i = 0 ; i < NADD ; i++)
		{
			read_write(v1,v2,i);
		}

		tg.stop();

		times2_g[i] = tg.getwct();
		int sz = v1.size();

		timer tga;
		tga.start();

		double * prp0 = (double *)v1.getPointer<0>();
		double * prp1 = (double *)v1.getPointer<1>();
		double * prp2 = (double *)v1.getPointer<2>();

		double * pos = (double *)v2.getPointer<0>();

		for (size_t i = 0 ; i < NADD ; i++)
		{
			read_write_inte(pos,prp0,prp1,prp2,i,sz);
		}

		tga.stop();

		times2[i] = tga.getwct();
	}

	double mean2;
	double dev2;
	standard_deviation(times2_g,mean2,dev2);

	double mean2_;
	double dev2_;
	standard_deviation(times2,mean2_,dev2_);

	report_vector_funcs.graphs.put("performance.vector_layout(1).y.data.mean",mean2_/mean2);

	// Deviation od x/y = x/y^2 dy + 1/y dx

	report_vector_funcs.graphs.put("performance.vector_layout(1).y.data.dev",mean2_/(mean2*mean2)*dev2 + dev2_ / mean2 );
}

incardon's avatar
incardon committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/////// THIS IS NOT A TEST IT WRITE THE PERFORMANCE RESULT ///////

BOOST_AUTO_TEST_CASE(vector_performance_write_report)
{
	// Create a graphs

	report_vector_funcs.graphs.put("graphs.graph(0).type","line");
	report_vector_funcs.graphs.add("graphs.graph(0).title","Vector add and get");
	report_vector_funcs.graphs.add("graphs.graph(0).x.title","Tests");
	report_vector_funcs.graphs.add("graphs.graph(0).y.title","Time seconds");
	report_vector_funcs.graphs.add("graphs.graph(0).y.data(0).source","performance.vector(#).y.data.mean");
	report_vector_funcs.graphs.add("graphs.graph(0).x.data(0).source","performance.vector(#).funcs.name");
	report_vector_funcs.graphs.add("graphs.graph(0).y.data(0).title","Actual");
	report_vector_funcs.graphs.add("graphs.graph(0).interpolation","lines");

376
377
378
379
380
381
382
383
384
	report_vector_funcs.graphs.put("graphs.graph(1).type","line");
	report_vector_funcs.graphs.add("graphs.graph(1).title","Vector read write");
	report_vector_funcs.graphs.add("graphs.graph(1).x.title","Layout");
	report_vector_funcs.graphs.add("graphs.graph(1).y.title","Time seconds");
	report_vector_funcs.graphs.add("graphs.graph(1).y.data(0).source","performance.vector_layout(#).y.data.mean");
	report_vector_funcs.graphs.add("graphs.graph(1).x.data(0).source","performance.vector_layout(#).funcs.name");
	report_vector_funcs.graphs.add("graphs.graph(1).y.data(0).title","Actual");
	report_vector_funcs.graphs.add("graphs.graph(1).interpolation","lines");

incardon's avatar
incardon committed
385
386
387
388
389
390
391
392
393
394
	boost::property_tree::xml_writer_settings<std::string> settings(' ', 4);
	boost::property_tree::write_xml("vector_performance_funcs.xml", report_vector_funcs.graphs,std::locale(),settings);

	GoogleChart cg;

	std::string file_xml_ref(test_dir);
	file_xml_ref += std::string("/openfpm_data/vector_performance_funcs_ref.xml");

	StandardXMLPerformanceGraph("vector_performance_funcs.xml",file_xml_ref,cg);

incardon's avatar
incardon committed
395
	addUpdtateTime(cg,1,"data","vector_performance_funcs");
incardon's avatar
incardon committed
396
397
398
399
400
401
402
403
404
405
406

	cg.write("vector_performance_funcs.html");
}

BOOST_AUTO_TEST_SUITE_END()

#endif /* OPENFPM_DATA_SRC_VECTOR_VECTOR_PERFORMANCE_TEST_HPP_ */



#endif /* VECTOR_PERFORMANCE_TEST_HPP_ */