-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial 3.cpp
More file actions
1361 lines (1138 loc) · 65.1 KB
/
Tutorial 3.cpp
File metadata and controls
1361 lines (1138 loc) · 65.1 KB
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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#define __CL_ENABLE_EXCEPTIONS
#include <iostream>
#include <vector>
#ifdef __APPLE__
#include <OpenCL/cl.hpp>
#else
#include <CL/cl.hpp>
#endif
#include <chrono>
#include "Utils.h"
#include <math.h>
#include <algorithm>
#include <chrono>
#include <iostream>
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::high_resolution_clock::time_point TimePoint;
///
/// Function takes the filepath and uses ifstream to read in the contents of that file.
/// The contents are read as a string but then the final column of data (after the 5th space character) is parsed to a float
/// The float is * by 100 and saved as an int so it can be passed into OpenCL kernels and still retain the decimal place data
///
// read the file as an integer (done through multiplying the float by 100 to remove the decimals)
vector<int> readFile(string filename)
{
// stores the temperatures for all data
std::vector<int> input_data;
// stream the data through the file path passed to function
ifstream infile(filename);
// Run through each line of the file and store it as a string.
// Then parse the string to get the 6th column of data and return those values
string LOCATION, YEAR, DAY, MONTH, TIME;
float TEMPERATURE;
// iterate through each line and store the temperature
while (infile >> LOCATION >> YEAR >> DAY >> MONTH >> TIME >> TEMPERATURE)
{
input_data.push_back(TEMPERATURE * 100); // push data to top of file
}
// close file
infile.close();
// return
return input_data;
}
/*
// read the file as a float
vector<float> read_file_float(string filename)
{
// stores the temperatures for all data
vector<float> data;
// stream the data through the file path passed to function
ifstream infile(filename);
// Run through each line of the file and store it as a string.
// Then parse the string to get the 6th column of data and return those values
string LOCATION, YEAR, DAY, MONTH, TIME;
float TEMPERATURE;
// iterate through each line and store the temperature
while (infile >> LOCATION >> YEAR >> DAY >> MONTH >> TIME >> TEMPERATURE)
{
data.push_back(TEMPERATURE); // push data to top of file
}
// close file
infile.close();
// return
return data;
}
*/
// read the file as a float
void read_file_float(string filename, vector<float>* data_float1, vector<float>* data_float2, vector<int>* data_int)
{
// stores the temperatures for all data
// stream the data through the file path passed to function
ifstream infile(filename);
// Run through each line of the file and store it as a string.
// Then parse the string to get the 6th column of data and return those values
string LOCATION, YEAR, DAY, MONTH, TIME;
float TEMPERATURE;
// iterate through each line and store the temperature
while (infile >> LOCATION >> YEAR >> DAY >> MONTH >> TIME >> TEMPERATURE)
{
(*data_float1).push_back(TEMPERATURE); // push data to top of file
(*data_float2).push_back(TEMPERATURE); // push data to top of file
(*data_int).push_back(TEMPERATURE*100); // push data to top of file
}
// close file
infile.close();
}
void print_help() {
std::cerr << "Application usage:" << std::endl;
std::cerr << " -p : select platform " << std::endl;
std::cerr << " -d : select device" << std::endl;
std::cerr << " -l : list all platforms and devices" << std::endl;
std::cerr << " -h : print this message" << std::endl;
}
// calculates the standard deviation SQUENTIALLY
void standard_deviation(vector<float> data_set, float _mean, float* _sum)
{
float std = 0.0;
float sum = 0.0;
for (int i = 0; i < data_set.size(); i++)
{
std = (data_set[i] - _mean);
std = std * std;
sum += std;
}
*_sum = sum / data_set.size();
}
// calculates the mean SQUENTIALLY
void mean(vector<float> data_set, float* _mean)
{
float sum = 0.0;
for (int i = 0; i < data_set.size(); i++)
{
sum = sum + data_set[i];
}
*_mean = sum / data_set.size();
}
// calculates the min and max SQUENTIALLY
void min_max(vector<float> data_set, float* _min, float* _max)
{
float min = data_set[0];
float max = data_set[0];
for (int i = 1; i < data_set.size(); i++)
{
if (min > data_set[i])
{
min = data_set[i];
}
if (max < data_set[i])
{
max = data_set[i];
}
*_min = min;
*_max = max;
}
}
// A function to sort the algorithm using Odd Even sort
//REFERENCE: https://www.geeksforgeeks.org/odd-even-sort-brick-sort/
void oddEvenSort(vector<float> arr, int n)
{
bool isSorted = false; // Initially array is unsorted
while (!isSorted)
{
isSorted = true;
// Perform Bubble sort on odd indexed element
for (int i = 1; i <= n - 2; i = i + 2)
{
if (arr[i] > arr[i + 1])
{
swap(arr[i], arr[i + 1]);
isSorted = false;
}
}
// Perform Bubble sort on even indexed element
for (int i = 0; i <= n - 2; i = i + 2)
{
if (arr[i] > arr[i + 1])
{
swap(arr[i], arr[i + 1]);
isSorted = false;
}
}
}
return;
}
int main(int argc, char **argv)
{
//=====================================================================================
//=====================================================================================
//============================== HOST OPERTATIONS =====================================
//=====================================================================================
//=====================================================================================
// assign the file path for the short and long .txt file
std::string fileName_long = "temp_lincolnshire.txt";
std::string fileName_short = "temp_lincolnshire_short.txt";
// Read in file
std::vector<int> data_int;
std::vector<float> data_float;
std::vector<float> data_float_Zero_Pad;
read_file_float(fileName_long, &data_float, &data_float_Zero_Pad, &data_int);
// stores the lengths of each of the int and float data sets
int dat_int_original_size = data_int.size();
int dat_float_original_size = data_float.size();
//=====================================================================================
//=====================================================================================
//==================================Squential TESTING==================================
//=====================================================================================
//=====================================================================================
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "============== SQUENTIAL TESTING ==============" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
// initialisation of vars
float _mean, _min, _max, _sum;
auto start = std::chrono::high_resolution_clock::now();
auto finish = std::chrono::high_resolution_clock::now();
chrono::duration<double> elapsed;
// mean calculation sequential
//=====================================================================================
start = std::chrono::high_resolution_clock::now();// start timer
mean(data_float, &_mean);
finish = std::chrono::high_resolution_clock::now(); // end timer
elapsed = finish - start;
// OUTPUTS
std::cout << "" << std::endl;
std::cout << "MEAN FLOAT: " << _mean << std::endl;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "===============================================" << std::endl;
std::cout << "" << std::endl;
//=====================================================================================
// min max calculation sequential
//=====================================================================================
// start timer
start = std::chrono::high_resolution_clock::now();
min_max(data_float, &_min, &_max);
finish = std::chrono::high_resolution_clock::now();
elapsed = finish - start;
// end timer
// OUTPUTS
std::cout << "" << std::endl;
std::cout << "MIN FLOAT: " << _min << std::endl;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "===============================================" << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "MAX FLOAT: " << _max << std::endl;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "===============================================" << std::endl;
std::cout << "" << std::endl;
//=====================================================================================
// standard deviation calculation sequential
//=====================================================================================
// start timer
start = std::chrono::high_resolution_clock::now();
standard_deviation(data_float, _mean, &_sum);
finish = std::chrono::high_resolution_clock::now();
elapsed = finish - start;
// end timer
// OUTPUTS
std::cout << "" << std::endl;
std::cout << "STD FLOAT: " << sqrt(_sum) << std::endl;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "===============================================" << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
//=====================================================================================
// odd even sort sequential
//=====================================================================================
// start timer
start = std::chrono::high_resolution_clock::now();
//oddEvenSort(data_float, data_float.size());
finish = std::chrono::high_resolution_clock::now();
elapsed = finish - start;
// end timer
// OUTPUTS
std::cout << "" << std::endl;
std::cout << "Sorted " << data_float.size() << "floats" <<std::endl;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "===============================================" << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
//=====================================================================================
// CPU GPU
int platform_id = 0;
// device id on CPU/GPU
int device_id = 0;
for (int i = 1; i < argc; i++) {
if ((strcmp(argv[i], "-p") == 0) && (i < (argc - 1))) { platform_id = atoi(argv[++i]); }
else if ((strcmp(argv[i], "-d") == 0) && (i < (argc - 1))) { device_id = atoi(argv[++i]); }
else if (strcmp(argv[i], "-l") == 0) { std::cout << ListPlatformsDevices() << std::endl; }
else if (strcmp(argv[i], "-h") == 0) { print_help(); }
}
// tries the code, catches exceptions
try {
// initialisation of the host open cl operations
//=====================================================================================
cl::Context context = GetContext(platform_id, device_id); // Select computing devices
std::cout << "Runinng on " << GetPlatformName(platform_id) << ", " << GetDeviceName(platform_id, device_id) << std::endl; // display the selected device
cl::CommandQueue queue(context, CL_QUEUE_PROFILING_ENABLE); //create a queue to which we will push commands for the device
// Load & build the device code
cl::Program::Sources sources;
AddSources(sources, "my_kernels_3.cl");
cl::Program program(context, sources);
// build and debug the kernel code
try {
program.build();
}
catch (const cl::Error& err) {
std::cout << "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << std::endl;
std::cout << "Build Options:\t" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << std::endl;
std::cout << "Build Log:\t " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << std::endl;
throw err;
}
// initialise the local size for local memory
size_t local_size = 256;
//=====================================================================================
//=====================================================================================
//====================================INTEGERS=========================================
//=====================================================================================
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "================ PARALLEL =====================" << std::endl;
std::cout << "============ INTEGERS TESTING =================" << std::endl;
std::cout << "===============================================" << std::endl;
// initialisation of the padding size required
size_t padding_size_int = data_int.size() % local_size;
//if the input vector is not a multiple of the local_size
//insert additional neutral elements (0 for addition) so that the total will not be affected
if (padding_size_int) {
//create an extra vector with neutral values
std::vector<int> A_ext(local_size - padding_size_int, 0);
//append that extra vector to our input
data_int.insert(data_int.end(), A_ext.begin(), A_ext.end());
}
// initialises the the sizes, in bytes and outputs
size_t input_int_elements = data_int.size();
size_t input_int_size = data_int.size() * sizeof(int);
size_t nr_groups_int = input_int_elements / local_size;
size_t output_size;
size_t local_size_bytes_integer = local_size * sizeof(float);
// the buffer used for storing the data set for parsing the memory block to kernel
cl::Buffer buffer_int(context, CL_MEM_READ_ONLY, input_int_size);
//=====================================================================================
// SUM - MEAN - INTEGERS - Non ATOMIC
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "SUM - MEAN - INTEGERS - NON - ATOMIC" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Integer_mean_sum_non_atomic_Write;
cl::Event Integer_mean_sum_non_atomic;
cl::Event Integer_mean_sum_non_atomic_Read;
// stores the number vector of 1 size
std::vector<int> Int_Mean_Local_Non_Atomic(1);
// the output size of the above vector in bytes
output_size = Int_Mean_Local_Non_Atomic.size() * sizeof(int);
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_Int_Mean_Local_Non_Atomic(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_int, CL_TRUE, 0, input_int_size, &data_int[0], NULL, &Integer_mean_sum_non_atomic_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Reduction_Int_Local_non_atomic = cl::Kernel(program, "Local_Reduction_NON_Atomic_Integer");
Reduction_Int_Local_non_atomic.setArg(0, buffer_int);
Reduction_Int_Local_non_atomic.setArg(1, Buffer_Int_Mean_Local_Non_Atomic);
Reduction_Int_Local_non_atomic.setArg(2, cl::Local(local_size * sizeof(int)));
// enques the kernel to be executes on the device
queue.enqueueNDRangeKernel(Reduction_Int_Local_non_atomic, cl::NullRange, cl::NDRange(input_int_elements), cl::NDRange(local_size), NULL, &Integer_mean_sum_non_atomic);
// reads from the buffer object into host memory after kernel processing complete
queue.enqueueReadBuffer(Buffer_Int_Mean_Local_Non_Atomic, CL_TRUE, 0, output_size, &Int_Mean_Local_Non_Atomic[0], NULL, &Integer_mean_sum_non_atomic_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Integer_mean_sum_non_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_mean_sum_non_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_mean_sum_non_atomic_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Integer_mean_sum_non_atomic.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_mean_sum_non_atomic.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_mean_sum_non_atomic, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Integer_mean_sum_non_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_mean_sum_non_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_mean_sum_non_atomic_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_int: " << input_int_size << std::endl;
std::cout << "Int_Mean_Local_Non_Atomic: " << output_size << std::endl;
std::cout << "Local memory: " << local_size_bytes_integer << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nSum: " << ((Int_Mean_Local_Non_Atomic[0])) << std::endl;
std::cout << "\nMean: " << ((Int_Mean_Local_Non_Atomic[0] / 100) / input_int_elements) << std::endl;
//=====================================================================================
// SUM - MEAN - INTEGERS - ATOMIC
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "SUM - MEAN - INTEGERS - ATOMIC" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Integer_mean_sum_Read;
cl::Event Integer_mean_sum;
cl::Event Integer_mean_sum_Write;
// stores the number vector of 1 size
std::vector<int> Int_Mean_Local(1);
// the output size of the above vector in bytes
output_size = Int_Mean_Local.size() * sizeof(int);
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_Int_Mean_Local(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_int, CL_TRUE, 0, input_int_size, &data_int[0], NULL, &Integer_mean_sum_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Reduction_Int_Local = cl::Kernel(program, "Local_Atomic_Reduction_Integer");
Reduction_Int_Local.setArg(0, buffer_int);
Reduction_Int_Local.setArg(1, Buffer_Int_Mean_Local);
Reduction_Int_Local.setArg(2, cl::Local(local_size * sizeof(int)));
// enques the kernel to be executes on the device
queue.enqueueNDRangeKernel(Reduction_Int_Local, cl::NullRange, cl::NDRange(input_int_elements), cl::NDRange(local_size), NULL, &Integer_mean_sum);
// reads from the buffer object into host memory after kernel processing complete
queue.enqueueReadBuffer(Buffer_Int_Mean_Local, CL_TRUE, 0, output_size, &Int_Mean_Local[0], NULL, &Integer_mean_sum_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Integer_mean_sum_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_mean_sum_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_mean_sum_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Integer_mean_sum.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_mean_sum.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_mean_sum, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Integer_mean_sum_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_mean_sum_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_mean_sum_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_int vector (file converted to integers): " << input_int_size << std::endl;
std::cout << "Int_Mean_Local vector (file converted to integers): " << output_size << std::endl;
std::cout << "Local memory: " << local_size_bytes_integer << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nSum: " << ((Int_Mean_Local[0])) << std::endl;
std::cout << "\nMean: " << ((Int_Mean_Local[0] / 100) / input_int_elements) << std::endl;
//=====================================================================================
// MIN - INTEGERS - ATOMIC
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "MIN - INTEGERS - ATOMIC" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Integer_min_atomic_Read;
cl::Event Integer_min_atomic;
cl::Event Integer_min_atomic_Write;
// stores the number vector of 1 size
std::vector<int> Int_Min_Local(1);
// the output size of the above vector in bytes
output_size = Int_Min_Local.size() * sizeof(int);
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_Int_Min_Local_atomic(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_int, CL_TRUE, 0, input_int_size, &data_int[0], NULL, &Integer_min_atomic_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Minimum_Int_Local = cl::Kernel(program, "Min_Kernel_atomic");
Minimum_Int_Local.setArg(0, buffer_int);
Minimum_Int_Local.setArg(1, Buffer_Int_Min_Local_atomic);
Minimum_Int_Local.setArg(2, cl::Local(local_size * sizeof(int)));
// enques the kernel to be executes on the device
queue.enqueueNDRangeKernel(Minimum_Int_Local, cl::NullRange, cl::NDRange(input_int_elements), cl::NDRange(local_size), NULL, &Integer_min_atomic);
// enques the kernel to be executes on the device
queue.enqueueReadBuffer(Buffer_Int_Min_Local_atomic, CL_TRUE, 0, output_size, &Int_Min_Local[0], NULL, &Integer_min_atomic_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Integer_min_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_min_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_min_atomic_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Integer_min_atomic.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_min_atomic.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_min_atomic, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Integer_min_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_min_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_min_atomic_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_int vector: " << input_int_size << std::endl;
std::cout << "Int_Min_Local vector: " << output_size << std::endl;
std::cout << "Local memory: " << local_size_bytes_integer << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nMinimum: " << ((Int_Min_Local[0] / 100)) << std::endl;
//=====================================================================================
// MIN - INTEGERS - NON - ATOMIC
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "MIN - INTEGERS - NON - ATOMIC" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Integer_min_non_atomic_Write;
cl::Event Integer_min_non_atomic;
cl::Event Integer_min_non_atomic_Read;
// stores the number vector of 1 size
std::vector<int> Int_Min_Local_non_atomic(1);
// the output size of the above vector in bytes
output_size = Int_Min_Local_non_atomic.size() * sizeof(int);
// creates the buffer for the interface for converting data between host and devices
cl::Buffer Buffer_Int_Min_Local_non_atomic(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_int, CL_TRUE, 0, input_int_size, &data_int[0], NULL, &Integer_min_non_atomic_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Minimum_Int_Local_non_atomic = cl::Kernel(program, "Min_Kernel_non_atomic");
Minimum_Int_Local_non_atomic.setArg(0, buffer_int);
Minimum_Int_Local_non_atomic.setArg(1, Buffer_Int_Min_Local_non_atomic);
Minimum_Int_Local_non_atomic.setArg(2, cl::Local(local_size * sizeof(int)));
// enques the kernel to be executes on the device
queue.enqueueNDRangeKernel(Minimum_Int_Local_non_atomic, cl::NullRange, cl::NDRange(input_int_elements), cl::NDRange(local_size), NULL, &Integer_min_non_atomic);
// enques the kernel to be executes on the device
queue.enqueueReadBuffer(Buffer_Int_Min_Local_non_atomic, CL_TRUE, 0, output_size, &Int_Min_Local_non_atomic[0], NULL, &Integer_min_non_atomic_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Integer_min_non_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_min_non_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_min_non_atomic_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Integer_min_non_atomic.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_min_non_atomic.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_min_non_atomic, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Integer_min_non_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_min_non_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_min_non_atomic_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_int vector: " << input_int_size << std::endl;
std::cout << "Int_Min_Local_non_atomic vector: " << output_size << std::endl;
std::cout << "Local memory: " << local_size_bytes_integer << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nMinimum: " << ((Int_Min_Local_non_atomic[0] / 100)) << std::endl;
//=====================================================================================
// MAX - INTEGERS - ATOMIC
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "MAX - INTEGERS - ATOMIC" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Integer_max_atomic_Write;
cl::Event Integer_max_atomic;
cl::Event Integer_max_atomic_Read;
// stores the number vector of 1 size
std::vector<int> Int_Max_Local_Atomic(1);
// the output size of the above vector in bytes
output_size = Int_Max_Local_Atomic.size() * sizeof(int);
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_Int_Max_Local_Atomic(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memorys
queue.enqueueWriteBuffer(buffer_int, CL_TRUE, 0, input_int_size, &data_int[0], NULL, &Integer_max_atomic_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Maximum_Int_Local_atomic = cl::Kernel(program, "Max_Kernel_atomic");
Maximum_Int_Local_atomic.setArg(0, buffer_int);
Maximum_Int_Local_atomic.setArg(1, Buffer_Int_Max_Local_Atomic);
Maximum_Int_Local_atomic.setArg(2, cl::Local(local_size * sizeof(int)));
// enques the kernel to be executes on the device
queue.enqueueNDRangeKernel(Maximum_Int_Local_atomic, cl::NullRange, cl::NDRange(input_int_elements), cl::NDRange(local_size), NULL, &Integer_max_atomic);
// enques the kernel to be executes on the device
queue.enqueueReadBuffer(Buffer_Int_Max_Local_Atomic, CL_TRUE, 0, output_size, &Int_Max_Local_Atomic[0], NULL, &Integer_max_atomic_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Integer_max_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_max_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_max_atomic_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Integer_max_atomic.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_max_atomic.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_max_atomic, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Integer_max_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_max_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_max_atomic_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_int vector: " << input_int_size << std::endl;
std::cout << "Int_Max_Local_Atomic vector: " << output_size << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nMaximum: " << ((Int_Max_Local_Atomic[0] / 100)) << std::endl;
//=====================================================================================
// MAX - INTEGERS - NON - ATOMIC
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "MAX - INTEGERS - NON - ATOMIC" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Integer_max_non_atomic_Write;
cl::Event Integer_max_non_atomic;
cl::Event Integer_max_non_atomic_Read;
// stores the number vector of 1 size
std::vector<int> Int_Max_Local_non_atomic(1);
// the output size of the above vector in bytes
output_size = Int_Max_Local_non_atomic.size() * sizeof(int);
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_Int_Max_Local_non_atomic(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_int, CL_TRUE, 0, input_int_size, &data_int[0], NULL, &Integer_max_non_atomic_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Maximum_Int_Local_non_atomic = cl::Kernel(program, "Max_Kernel_non_atomic");
Maximum_Int_Local_non_atomic.setArg(0, buffer_int);
Maximum_Int_Local_non_atomic.setArg(1, Buffer_Int_Max_Local_non_atomic);
Maximum_Int_Local_non_atomic.setArg(2, cl::Local(local_size * sizeof(int)));
// enques the kernel to be executes on the device
queue.enqueueNDRangeKernel(Maximum_Int_Local_non_atomic, cl::NullRange, cl::NDRange(input_int_elements), cl::NDRange(local_size), NULL, &Integer_max_non_atomic);
// enques the kernel to be executes on the device
queue.enqueueReadBuffer(Buffer_Int_Max_Local_non_atomic, CL_TRUE, 0, output_size, &Int_Max_Local_non_atomic[0], NULL, &Integer_max_non_atomic_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Integer_max_non_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_max_non_atomic_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_max_non_atomic_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Integer_max_non_atomic.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_max_non_atomic.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_max_non_atomic, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Integer_max_non_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Integer_max_non_atomic_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Integer_max_non_atomic_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_int vector: " << input_int_size << std::endl;
std::cout << "Int_Max_Local_non_atomic vector: " << output_size << std::endl;
std::cout << "Local memory: " << local_size_bytes_integer << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nMaximum: " << ((Int_Max_Local_non_atomic[0] / 100)) << std::endl;
//=====================================================================================
//=====================================================================================
//======================================FLOATS=========================================
//=====================================================================================
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "================FLOATS TESTING=================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
// initialisation of the padding size required
size_t padding_size_float = data_float.size() % local_size;
// if the input vector is not a multiple of the local_size
// insert additional neutral elements (0 for addition) so that the total will not be affected
if (padding_size_float) {
// create an extra vector with neutral values
std::vector<float> A_ext(local_size - padding_size_float, 0);
// append that extra vector to our input
data_float.insert(data_float.end(), A_ext.begin(), A_ext.end());
}
// initialises the the sizes, in bytes and outputs
size_t input_float_elements = data_float.size();
size_t input_float_size = data_float.size() * sizeof(float);
size_t nr_groups_float = input_float_elements / local_size * sizeof(float);
// initialises the the sizes, in bytes and outputs
size_t input_float_zero_pad_elements = data_float_Zero_Pad.size();
size_t input_float_zero_pad_size = data_float_Zero_Pad.size() * sizeof(float);
size_t nr_groups_zero_pad_float = input_float_zero_pad_elements / local_size * sizeof(float);
size_t local_size_bytes_float = local_size * sizeof(float);
output_size = 0;
// the buffer used for storing the data set for parsing the memory block to kernel
cl::Buffer buffer_float_zero_pad(context, CL_MEM_READ_ONLY, input_float_zero_pad_size);
cl::Buffer buffer_float(context, CL_MEM_READ_ONLY, input_float_size);
//=====================================================================================
// SUM - MEAN - FLOATS - SINGLE - CALL
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "SUM - MEAN - FLOATS - SINGLE - CALL" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Float_mean_Write;
cl::Event Float_mean;
cl::Event Float_mean_Read;
// stores the number vector of 1 size
std::vector<float> Float_Mean_Local(nr_groups_float);
// the output size of the above vector in bytes
output_size = Float_Mean_Local.size() * sizeof(float);
// local size of the local memory space
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_float_Mean_Local(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_float, CL_TRUE, 0, input_float_size, &data_float[0], NULL, &Float_mean_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Reduction_Float_Local = cl::Kernel(program, "float_Reduction_Kernel");
Reduction_Float_Local.setArg(0, buffer_float);
Reduction_Float_Local.setArg(1, Buffer_float_Mean_Local);
Reduction_Float_Local.setArg(2, cl::Local(local_size_bytes_float));
// enques the kernel to be executes on the devices
queue.enqueueNDRangeKernel(Reduction_Float_Local, cl::NullRange, cl::NDRange(input_float_elements), cl::NDRange(local_size), NULL, &Float_mean);
// enques the kernel to be executes on the device
queue.enqueueReadBuffer(Buffer_float_Mean_Local, CL_TRUE, 0, output_size, &Float_Mean_Local[0], NULL, &Float_mean_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Float_mean_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Float_mean_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Float_mean_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" <<
Float_mean.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Float_mean.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Float_mean, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the read data time, and memory transfer
std::cout << "Read execution time [ns]:" <<
Float_mean_Read.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Float_mean_Read.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Float_mean_Read, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "Size in bytes for vectors: " << std::endl;
std::cout << "data_float vector: " << input_float_size << std::endl;
std::cout << "Float_Mean_Local vector: " << output_size << std::endl;
std::cout << "Local memory: " << local_size_bytes_float << std::endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "\nSum: " << ((Float_Mean_Local[0])) << std::endl;
std::cout << "\nMean: " << ((Float_Mean_Local[0]) / dat_float_original_size) << std::endl;
//=====================================================================================
// SUM - MEAN - FLOATS - MULTI - CALL
//=====================================================================================
std::cout << "" << std::endl;
std::cout << "" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "===============================================" << std::endl;
std::cout << "SUM - MEAN - FLOATS - MULTI - CALL" << std::endl;
std::cout << "" << std::endl;
// used for profilling the Write, Kernel and Read queue
cl::Event Float_mean_multi_Write;
cl::Event Float_mean_multi;
cl::Event Float_mean_multi_Read;
// stores the number vector of 1 size
std::vector<float> Float_Mean_Local_Multi(nr_groups_float);
// the output size of the above vector in bytes
output_size = Float_Mean_Local_Multi.size() * sizeof(float);
// local size of the local memory space
// creates the buffer for the interface for converting data between host and device
cl::Buffer Buffer_float_Mean_Local_Multi(context, CL_MEM_READ_WRITE, output_size);
// allows the buffer object to be written from host memory
queue.enqueueWriteBuffer(buffer_float, CL_TRUE, 0, input_float_size, &data_float[0], NULL, &Float_mean_multi_Write);
// setups a kernel and initialises the arguments for parsing
// parses: buffer used for the data read in, the new buffer for outputting the sum and local memroy
cl::Kernel Reduction_Float_Local_Multi = cl::Kernel(program, "float_Reduction_Kernel_mulitcall");
Reduction_Float_Local_Multi.setArg(0, buffer_float);
Reduction_Float_Local_Multi.setArg(1, Buffer_float_Mean_Local_Multi);
Reduction_Float_Local_Multi.setArg(2, cl::Local(local_size_bytes_float));
// enques the kernel to be executes on the devices
queue.enqueueNDRangeKernel(Reduction_Float_Local_Multi, cl::NullRange, cl::NDRange(input_float_elements), cl::NDRange(local_size), NULL, &Float_mean_multi);
// waits for the event to be ready for storing
Float_mean_multi.wait();
// stores the nano seconds for each call the kernel for profiling
int nano_secs = 0;
// counts the amount of nano seconds needs to complete for each call to the kernel
nano_secs += Float_mean_multi.getProfilingInfo<CL_PROFILING_COMMAND_END>() - Float_mean_multi.getProfilingInfo<CL_PROFILING_COMMAND_START>();
// loops over the remaining workgroups to add those up
for (int i = 0; i < 2; i++)
{
// passes in the buffer output from the above call and assigns the ouput as the input
Reduction_Float_Local_Multi.setArg(0, Buffer_float_Mean_Local_Multi);
Reduction_Float_Local_Multi.setArg(1, Buffer_float_Mean_Local_Multi);
// enques the kernel to be executes on the devices
queue.enqueueNDRangeKernel(Reduction_Float_Local_Multi, cl::NullRange, cl::NDRange(input_float_elements), cl::NDRange(local_size), NULL, &Float_mean_multi);
// waits for the event to be ready for storing
Float_mean_multi.wait();
// counts the amount of nano seconds needs to complete for each call to the kernel
nano_secs += Float_mean_multi.getProfilingInfo<CL_PROFILING_COMMAND_END>() - Float_mean_multi.getProfilingInfo<CL_PROFILING_COMMAND_START>();
}
// enques the kernel to be executes on the device
queue.enqueueReadBuffer(Buffer_float_Mean_Local_Multi, CL_TRUE, 0, output_size, &Float_Mean_Local_Multi[0], NULL, &Float_mean_multi_Read);
// displays the write data time, and memory transfer
std::cout << "Write execution time [ns]:" <<
Float_mean_multi_Write.getProfilingInfo<CL_PROFILING_COMMAND_END>() -
Float_mean_multi_Write.getProfilingInfo<CL_PROFILING_COMMAND_START>() << std::endl;
std::cout << GetFullProfilingInfo(Float_mean_multi_Write, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;
std::cout << "" << std::endl;
// displays the Kernel data time, and memory transfer
std::cout << "Kernel execution time [ns]:" << nano_secs << std::endl;
std::cout << GetFullProfilingInfo(Float_mean_multi, ProfilingResolution::PROF_US) << endl;
std::cout << "" << std::endl;