-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssessment1.cpp
More file actions
527 lines (362 loc) · 21.2 KB
/
Copy pathAssessment1.cpp
File metadata and controls
527 lines (362 loc) · 21.2 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
/*
Rishum - CMP3752M Parallel Programming Assessment
All the required statistics has been implemented by this program, including the calculation of the Median, 1st Quartile and 3rd Quartile.
All the statistics are handled and outputted using their exact values (Float). This program as required outputs the Memory Transfer, Kernel
Execution & Total Program execution times.
To sort the Dataset a Bitonic split sorting algorithm has been implemented and performs well on the shorter dataset. On the longer dataset,
the sorting process is incredibly slow and will take significant amounts of time to complete dependent on your hardware and selected platform.
The Mean, Minimum, Maximum and Standard Deviation values are all outputted before the dataset is sorted. The performance values are outputted
at the end of the program and as a result, the sorting process must complete in order to view them.
The program allows you to easily switch datasets and platforms in the initial menus provided and input validation is present to prevent crashes.
All the Kernels (bar sort) implemented, use Atomic Functions (Add, Max, Min, Xchg) to calculate their relevant values. This program has only been tested on Windows; other
operating systems may have issues.
*/
/* Including the required librarys for this program */
#include <iostream>
#include <vector>
#include "Utils.h"
#include <fstream>
#include <algorithm>
/* Declaring a vector to to store the Temperature dataset*/
vector<float> Temperature;
/* Method to allow the user select a dataset and read it in to the program*/
void Read_Dataset() {
bool Loop_Selection = false;
string filename;
//A simple loop to ensure that User's input is valid.
do {
Loop_Selection = false;
string selection;
cout << "Please enter which Dataset you would like to use:\n\n 1. Short Dataset (18732 Entries) \n 2. Long Dataset (1873106 Entries)\n\n";
cout << "Option Number: ";
cin >> selection;
//Clearing the console screen (Windows Only) to improve console readability
system("cls");
if (selection == "1") {
cout << "Loading Small Dataset - This may take a few seconds...\n\n";
filename = "temp_lincolnshire_short.txt";
}
else if (selection == "2") {
cout << "Loading Large Dataset - This may take a bit...\n\n";
filename = "temp_lincolnshire.txt";
}
else {
cout << "Invalid Selection Entered!\n\n";
Loop_Selection = true;
}
} while (Loop_Selection == true);
//Reading in the dataset line by line but ignoring the first five values.
string line;
ifstream infile(filename);
while (getline(infile, line))
{
float space = 0;
for (int i = 0; i < 5; i++) {
space = line.find(' ', space + 1);
}
//Inserting it into the vector
Temperature.push_back(stof(line.substr(space + 1)));
}
system("cls");
cout << "Dataset has finished loading.\n\n";
}
/* A simple Method to check if a string only contains numbers. Used to assist in input validation*/
bool is_number(const std::string& s)
{
//Loop through each value and check if it is a digit.
std::string::const_iterator it = s.begin();
while (it != s.end() && std::isdigit(*it)) ++it;
return !s.empty() && it == s.end();
}
/* A Method that allows the user to select a platform for OpenCL to run on */
int Platform_Select() {
int platform_id;
bool Loop = true;
//Simple do loop for input validation
do {
//Listing all the platforms available on the system.
vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
//Printing these platforms out.
int num_platforms = platforms.size();
for (int i = 0; i < num_platforms; i++)
{
cout << i << ": " << platforms[i].getInfo<CL_PLATFORM_NAME>() << endl;
}
//Allowing the user to select a platform
string User_Selection;
cout << "\nPlease enter the Platform ID you wish to use from above: ";
cin >> User_Selection;
//Some simple input validation to ensure they have only entered a valid platform ID.
if (is_number(User_Selection)){
if ((stoi(User_Selection) >= 0) && (stoi(User_Selection) <= (platforms.size() - 1))) {
platform_id = stoi(User_Selection);
Loop = false;
}
else {
system("cls");
cout << "Invalid Platform ID\n\n";
}
}
else {
system("cls");
cout << "Invalid Value Entered\n\n";
}
} while (Loop);
system("cls");
//Returning the selected platform
return platform_id;
}
/* Main method of this program that contains all the main functionality required. The OpenCL sections
have not been put into their own seperate methods as they will only be invoked once during this program.
*/
int main() {
//Calling the method to read the Dataset into the program.
Read_Dataset();
//Calling the method for the user to select a platform and storing this in a varable.
int platform_id = Platform_Select();
int device_id = 0;
//A try catch to catch any potental OpenCL errors.
try {
//--- Inital Setup - Creating the Context, Command Queue, Getting & Building Kernals and some inital pre-processing ---//
//Creating the context using the platform selected.
cl::Context context = GetContext(platform_id, device_id);
//Outputting to the console the current platform and device
cout << "Currently Platform: " << GetPlatformName(platform_id) << "\nCurrent Device: " << GetDeviceName(platform_id, device_id) << endl;
//Creating the Command Queue with Profiling Enabled
cl::CommandQueue queue(context, CL_QUEUE_PROFILING_ENABLE);
//Creating the program and building the Kernels.
cl::Program::Sources sources;
AddSources(sources, "kernels/my_kernels.cl");
cl::Program program(context, sources);
try {
program.build();
}
catch (const cl::Error& err) {
cout << "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << endl;
cout << "Build Options:\t" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << endl;
cout << "Build Log:\t " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(context.getInfo<CL_CONTEXT_DEVICES>()[0]) << endl;
throw err;
}
//Getting Start time for Profiling
clock_t Start = clock();
//Storing Needed Sizes
size_t InputSize = Temperature.size() * sizeof(float);
size_t OutputSize = Temperature.size() * sizeof(float);
size_t LocalSize = 2; //Change Me
size_t PaddingSize = InputSize % LocalSize;
//Setting up the events for profiling.
cl::Event P_Sum_Input_Buffer_1,P_Sum_Output_Buffer_2,P_Sum_Read_Buffer_3, P_Sum_Kernal;
cl::Event P_Max_Input_Buffer_1,P_Max_Output_Buffer_2,P_Max_Read_Buffer_3, P_Max_Kernal;
cl::Event P_Min_Input_Buffer_1, P_Min_Output_Buffer_2, P_Min_Read_Buffer_3, P_Min_Kernal;
cl::Event P_Var_Input_Buffer_1, P_Var_Output_Buffer_2, P_Var_Read_Buffer_3, P_Var_Kernal;
cl::Event P_Sort_Input_Buffer_1, P_Sort_Output_Buffer_2, P_Sort_Read_Buffer_3, P_Sort_Kernal;
//-- Using OpenCL to calculate the Sum of the dataset and then using it to calculate the datasets mean value. -- //
//Creating a result vector at the same size as the data vector.
vector<float> Sum_Result(Temperature.size());
//Creating the kernel needed.
cl::Kernel Kernal_Sum = cl::Kernel(program, "sum");
//Creating the Buffers which will pass data to and from the Kernal.
cl::Buffer Sum_Input_Buffer(context, CL_MEM_READ_WRITE, InputSize);
cl::Buffer Sum_Output_Buffer(context, CL_MEM_READ_WRITE, OutputSize);
//Passing the temp data into the write buffer.
queue.enqueueWriteBuffer(Sum_Input_Buffer, CL_TRUE, 0, InputSize, Temperature.data(), NULL, &P_Sum_Input_Buffer_1);
//Set the output buffer to values of zero
queue.enqueueFillBuffer(Sum_Output_Buffer, 0, 0, OutputSize, NULL, &P_Sum_Output_Buffer_2);
//Passing the required args.
Kernal_Sum.setArg(0, Sum_Input_Buffer);
Kernal_Sum.setArg(1, Sum_Output_Buffer);
Kernal_Sum.setArg(2, cl::Local(LocalSize * sizeof(float)));
//Running the Kernal
queue.enqueueNDRangeKernel(Kernal_Sum, cl::NullRange, cl::NDRange(Temperature.size()), cl::NDRange(LocalSize), NULL, &P_Sum_Kernal);
//Read the output into the result vector
queue.enqueueReadBuffer(Sum_Output_Buffer, CL_TRUE, 0, OutputSize, &Sum_Result[0], NULL, &P_Sum_Read_Buffer_3);
//Getting Sum & Mean and storing them in a varable.
float Sum = Sum_Result.front();
float Mean = Sum_Result.front() / Temperature.size();
//-- Using OpenCL to calculate the Max value of the dataset -- //
//Creating a result vector at the same size as the data vector.
vector<float> Max_Result(Temperature.size());
//Creating the kernel.
cl::Kernel Kernal_Max = cl::Kernel(program, "max");
//Creating the Buffers which will pass data to and from the Kernal.
cl::Buffer Max_Input_Buffer(context, CL_MEM_READ_WRITE, InputSize);
cl::Buffer Max_Output_Buffer(context, CL_MEM_READ_WRITE, OutputSize);
//Passing the temp data into the write buffer.
queue.enqueueWriteBuffer(Max_Input_Buffer, CL_TRUE, 0, InputSize, Temperature.data() , NULL, &P_Max_Input_Buffer_1);
//Set the output buffer to values of zero
queue.enqueueFillBuffer(Max_Output_Buffer, 0, 0, OutputSize, NULL, &P_Max_Output_Buffer_2);
//Passing the required args.
Kernal_Max.setArg(0, Max_Input_Buffer);
Kernal_Max.setArg(1, Max_Output_Buffer);
Kernal_Max.setArg(2, cl::Local(LocalSize * sizeof(float)));
//Running the Kernal
queue.enqueueNDRangeKernel(Kernal_Max, cl::NullRange, cl::NDRange(Temperature.size()), cl::NDRange(LocalSize), NULL, &P_Max_Kernal);
//Read the output into the result vector
queue.enqueueReadBuffer(Max_Output_Buffer, CL_TRUE, 0, OutputSize, &Max_Result[0], NULL, &P_Max_Read_Buffer_3);
//Storing the Max value in a varable.
float Max_Value = Max_Result.front();
//-- Using OpenCL to calculate the Min value of the dataset -- //
//Creating a result vector at the same size as the data vector.
vector<float> Min_Result(Temperature.size());
//Creating the kernel.
cl::Kernel Kernal_Min = cl::Kernel(program, "min");
//Creating the Buffers which will pass data to and from the Kernal.
cl::Buffer Min_Input_Buffer(context, CL_MEM_READ_WRITE, InputSize);
cl::Buffer Min_Output_Buffer(context, CL_MEM_READ_WRITE, OutputSize);
//Passing the temp data into the write buffer.
queue.enqueueWriteBuffer(Min_Input_Buffer, CL_TRUE, 0, InputSize, Temperature.data(), NULL, &P_Min_Input_Buffer_1);
//Set the output buffer to values of zero
queue.enqueueFillBuffer(Min_Output_Buffer, 0, 0, OutputSize, NULL, &P_Min_Output_Buffer_2);
//Passing the required args.
Kernal_Min.setArg(0, Min_Input_Buffer);
Kernal_Min.setArg(1, Min_Output_Buffer);
Kernal_Min.setArg(2, cl::Local(LocalSize * sizeof(float)));
//Running the Kernal
queue.enqueueNDRangeKernel(Kernal_Min, cl::NullRange, cl::NDRange(Temperature.size()), cl::NDRange(LocalSize), NULL, &P_Min_Kernal);
//Read the output into the result vector
queue.enqueueReadBuffer(Min_Output_Buffer, CL_TRUE, 0, OutputSize, &Min_Result[0], NULL, &P_Min_Read_Buffer_3);
//Storing the Min value in a varable.
float Min_Value = Min_Result.front();
//-- Using OpenCL to calculate the Variance value of the dataset -- //
//Creating a result vector at the same size as the data vector.
vector<float> Variance_Result(Temperature.size());
//Creating the kernel.
cl::Kernel Kernal_Variance = cl::Kernel(program, "variance");
//Creating the Buffers which will pass data to and from the Kernal.
cl::Buffer Variance_Input_Buffer(context, CL_MEM_READ_WRITE, InputSize);
cl::Buffer Variance_Output_Buffer(context, CL_MEM_READ_WRITE, OutputSize);
//Passing the temp data into the write buffer.
queue.enqueueWriteBuffer(Variance_Input_Buffer, CL_TRUE, 0, InputSize, Temperature.data(), NULL, &P_Var_Input_Buffer_1);
//Set the output buffer to values of zero
queue.enqueueFillBuffer(Variance_Output_Buffer, 0, 0, OutputSize, NULL, &P_Var_Output_Buffer_2);
//Passing the required args.
Kernal_Variance.setArg(0, Variance_Input_Buffer);
Kernal_Variance.setArg(1, Variance_Output_Buffer);
Kernal_Variance.setArg(2, cl::Local(LocalSize * sizeof(float)));
Kernal_Variance.setArg(3, sizeof(float), &Mean);
//Running the Kernal
queue.enqueueNDRangeKernel(Kernal_Variance, cl::NullRange, cl::NDRange(Temperature.size()), cl::NDRange(LocalSize), NULL, &P_Var_Kernal);
//Read the output into the result vector
queue.enqueueReadBuffer(Variance_Output_Buffer, CL_TRUE, 0, OutputSize, &Variance_Result[0], NULL, &P_Var_Read_Buffer_3);
//Storing the Std and Variance values in a varable.
float Variance = Variance_Result.front();
float Standard_Deviation = sqrt(Variance_Result.front() / Temperature.size());
//-- Inital printing of the results before sorting the dataset -- //
cout << "\n========================= Statistical Results: =========================";
cout << "\n\nTotal Sum: " << Sum;
cout << "\nMean Value: " << Mean;
cout << "\nMaximium Value: " << Max_Value;
cout << "\nMinimium Value: " << Min_Value;
cout << "\nStandard Deviation: " << Standard_Deviation;
cout << "\n\nDataset is now being sorted for the remaining stats. This may take a very long time on the large dataset";
//-- Using OpenCL to Sort the dataset -- //
//Creating a result vector at the same size as the data vector.
vector<float> Temperature_Sorted(Temperature.size());
//Creating the kernel.
cl::Kernel Kernal_Sort = cl::Kernel(program, "sort");
//Creating the Buffers which will pass data to and from the Kernal.
cl::Buffer Sorting_Input_Buffer(context, CL_MEM_READ_WRITE, InputSize);
cl::Buffer Sorting_Output_Buffer(context, CL_MEM_READ_WRITE, InputSize);
//Passing the temp data into the write buffer.
queue.enqueueWriteBuffer(Sorting_Input_Buffer, CL_TRUE, 0, InputSize, Temperature.data(), NULL, &P_Sort_Input_Buffer_1);
//Set the output buffer to values of zero
queue.enqueueFillBuffer(Sorting_Output_Buffer, 0, 0, OutputSize, NULL, &P_Sort_Output_Buffer_2);
//Passing the required args.
Kernal_Sort.setArg(0, Sorting_Input_Buffer);
Kernal_Sort.setArg(1, Sorting_Output_Buffer);
Kernal_Sort.setArg(2, cl::Local(LocalSize * sizeof(float)));
//Setting inital Merge to 0.
int merge = 0;
Kernal_Sort.setArg(3, merge);
//Running the Kernal
queue.enqueueNDRangeKernel(Kernal_Sort, cl::NullRange, cl::NDRange(Temperature.size()), cl::NDRange(LocalSize), NULL, &P_Sort_Kernal);
//Setting the input arg as the output buffer.
Kernal_Sort.setArg(0, Sorting_Output_Buffer);
//Looping and rerunning Kernal till the dataset is sorted.
bool Sorted = false;
while (Sorted == false)
{
//Flipping merge value
Kernal_Sort.setArg(3, merge);
if (merge == 1){
merge = 0;
} else if (merge == 0) {
merge = 1;
}
//Running the Kernal
queue.enqueueNDRangeKernel(Kernal_Sort, cl::NullRange, cl::NDRange(Temperature.size()), cl::NDRange(LocalSize), NULL, &P_Sort_Kernal);
//Read the output into the result vector
queue.enqueueReadBuffer(Sorting_Output_Buffer, CL_TRUE, 0, OutputSize, &Temperature_Sorted[0],NULL, &P_Sort_Read_Buffer_3);
//Check if data is sorted
if (is_sorted(Temperature_Sorted.begin(), Temperature_Sorted.end()))
{
Sorted = true;
}
}
//Using sorted dataset to get the median and quartiles
float Median = Temperature_Sorted[0.5 * Temperature_Sorted.size()];
float Quartile_1 = Temperature_Sorted[0.25 * Temperature_Sorted.size()];
float Quartile_3 = Temperature_Sorted[0.75 * Temperature_Sorted.size()];
//Outputting these values
cout << "\n\nMedian: " << Median;
cout << "\n1st Quartile: " << Quartile_1;
cout << "\n3rd Quartile: " << Quartile_3;
//-- Performance Result Output Section -- //
cout << "\n\n========================= Performance Results: =========================";
//Calcuating and Outputting the Sum Kernal's performance times
auto R_Sum_Input_Buffer_1 = P_Sum_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sum_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Sum_Output_Buffer_2 = P_Sum_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sum_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Sum_Read_Buffer_3 = P_Sum_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sum_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Sum_Kernal = P_Sum_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sum_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
cout << "\n\nSum Kernal Memory Transfer (Input Buffer): " << R_Sum_Input_Buffer_1 << "ns";
cout << "\nSum Kernal Memory Transfer (Output Buffer): " << R_Sum_Output_Buffer_2 << "ns";
cout << "\nSum Kernal Memory Transfer (Read Buffer): " << R_Sum_Read_Buffer_3 << "ns";
cout << "\nSum Kernal Total Execution Time: " << R_Sum_Kernal << "ns";
//Calcuating and Outputting the Max Kernal's performance times
auto R_Max_Input_Buffer_1 = P_Max_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Max_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Max_Output_Buffer_2 = P_Max_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Max_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Max_Read_Buffer_3 = P_Max_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Max_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Max_Kernal = P_Max_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Max_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
cout << "\n\nMax Kernal Memory Transfer (Input Buffer): " << R_Max_Input_Buffer_1 << "ns";
cout << "\nMax Kernal Memory Transfer (Output Buffer): " << R_Max_Output_Buffer_2 << "ns";
cout << "\nMax Kernal Memory Transfer (Read Buffer): " << R_Max_Read_Buffer_3 << "ns";
cout << "\nMax Kernal Total Execution Time: " << R_Max_Kernal << "ns";
//Calcuating and Outputting the Min Kernal's performance times
auto R_Min_Input_Buffer_1 = P_Min_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Min_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Min_Output_Buffer_2 = P_Min_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Min_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Min_Read_Buffer_3 = P_Min_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Min_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Min_Kernal = P_Min_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Min_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
cout << "\n\nMin Kernal Memory Transfer (Input Buffer): " << R_Min_Input_Buffer_1 << "ns";
cout << "\nMin Kernal Memory Transfer (Output Buffer): " << R_Min_Output_Buffer_2 << "ns";
cout << "\nMin Kernal Memory Transfer (Read Buffer): " << R_Min_Read_Buffer_3 << "ns";
cout << "\nMin Kernal Total Execution Time: " << R_Min_Kernal << "ns";
//Calcuating and Outputting the Variance Kernal's performance times
auto R_Var_Input_Buffer_1 = P_Var_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Var_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Var_Output_Buffer_2 = P_Var_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Var_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Var_Read_Buffer_3 = P_Var_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Var_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Var_Kernal = P_Var_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Var_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
cout << "\n\nVar Kernal Memory Transfer (Input Buffer): " << R_Var_Input_Buffer_1 << "ns";
cout << "\nVar Kernal Memory Transfer (Output Buffer): " << R_Var_Output_Buffer_2 << "ns";
cout << "\nVar Kernal Memory Transfer (Read Buffer): " << R_Var_Read_Buffer_3 << "ns";
cout << "\nVar Kernal Total Execution Time: " << R_Var_Kernal << "ns";
//Calcuating and Outputting the Sorting Kernal's performance times
auto R_Sort_Input_Buffer_1 = P_Sort_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sort_Input_Buffer_1.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Sort_Output_Buffer_2 = P_Sort_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sort_Output_Buffer_2.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Sort_Read_Buffer_3 = P_Sort_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sort_Read_Buffer_3.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
auto R_Sort_Kernal = P_Sort_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_END>() - P_Sort_Kernal.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
cout << "\n\nSort Kernal Memory Transfer (Input Buffer): " << R_Sort_Input_Buffer_1 << "ns";
cout << "\nSort Kernal Memory Transfer (Output Buffer): " << R_Sort_Output_Buffer_2 << "ns";
cout << "\nSort Kernal Memory Transfer (Read Buffer): " << R_Sort_Read_Buffer_3 << "ns";
cout << "\nSort Kernal Total Execution Time: " << R_Sort_Kernal << "ns";
//Calcuating and Outputting the Total Program's performance times
cout << "\n\nTotal Program Execution Time: " << (((float) clock() - Start) / CLOCKS_PER_SEC) << "s";
//Pausing the program once it has finished.
cin.ignore();
cin.get();
}
//Catching the error and outputting it to console.
catch (cl::Error err) {
cerr << "ERROR: " << err.what() << ", " << getErrorString(err.err()) << endl;
}
}