|
@@ -82,17 +82,20 @@ double sum = 0;
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Initialize the bucketsort algorithm
|
|
// Initialize the bucketsort algorithm
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
-void init_bucketsort(int listsize)
|
|
|
|
|
|
+void init_bucketsort(int listsize, int platform_id, int device_id, int use_gpu)
|
|
{
|
|
{
|
|
cl_uint num = 0;
|
|
cl_uint num = 0;
|
|
clGetPlatformIDs(0, NULL, &num);
|
|
clGetPlatformIDs(0, NULL, &num);
|
|
cl_platform_id platformID[num];
|
|
cl_platform_id platformID[num];
|
|
clGetPlatformIDs(num, platformID, NULL);
|
|
clGetPlatformIDs(num, platformID, NULL);
|
|
|
|
|
|
- clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,0,NULL,&num);
|
|
|
|
|
|
+ // Selector for CPU/GPU
|
|
|
|
+ cl_device_type device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
|
|
|
|
+
|
|
|
|
+ clGetDeviceIDs(platformID[platform_id],device_type,0,NULL,&num);
|
|
|
|
|
|
cl_device_id devices[num];
|
|
cl_device_id devices[num];
|
|
- err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,num,devices,NULL);
|
|
|
|
|
|
+ err = clGetDeviceIDs(platformID[platform_id],device_type,num,devices,NULL);
|
|
// int gpu = 1;
|
|
// int gpu = 1;
|
|
// err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 2, &device_id, NULL);
|
|
// err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 2, &device_id, NULL);
|
|
|
|
|
|
@@ -104,12 +107,12 @@ void init_bucketsort(int listsize)
|
|
char name[128];
|
|
char name[128];
|
|
|
|
|
|
|
|
|
|
- clGetDeviceInfo(devices[0],CL_DEVICE_NAME,128,name,NULL);
|
|
|
|
|
|
+ clGetDeviceInfo(devices[device_id],CL_DEVICE_NAME,128,name,NULL);
|
|
|
|
|
|
|
|
|
|
- bucketContext = clCreateContext(0, 1, &devices[0], NULL, NULL, &err);
|
|
|
|
|
|
+ bucketContext = clCreateContext(0, 1, &devices[device_id], NULL, NULL, &err);
|
|
|
|
|
|
- bucketCommands = clCreateCommandQueue(bucketContext, devices[0], CL_QUEUE_PROFILING_ENABLE, &err);
|
|
|
|
|
|
+ bucketCommands = clCreateCommandQueue(bucketContext, devices[device_id], CL_QUEUE_PROFILING_ENABLE, &err);
|
|
|
|
|
|
h_offsets = (unsigned int *) malloc(DIVISIONS * sizeof(unsigned int));
|
|
h_offsets = (unsigned int *) malloc(DIVISIONS * sizeof(unsigned int));
|
|
for(int i = 0; i < DIVISIONS; i++){
|
|
for(int i = 0; i < DIVISIONS; i++){
|
|
@@ -162,7 +165,7 @@ void init_bucketsort(int listsize)
|
|
char buffer[2048];
|
|
char buffer[2048];
|
|
|
|
|
|
printf("Error: Failed to build bucket program executable!\n");
|
|
printf("Error: Failed to build bucket program executable!\n");
|
|
- clGetProgramBuildInfo(bucketProgram, devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
|
|
|
|
|
|
+ clGetProgramBuildInfo(bucketProgram, devices[device_id], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
|
|
printf("%s\n", buffer);
|
|
printf("%s\n", buffer);
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
@@ -193,22 +196,25 @@ void finish_bucketsort()
|
|
free(historesult);
|
|
free(historesult);
|
|
}
|
|
}
|
|
|
|
|
|
-void histogramInit(int listsize) {
|
|
|
|
|
|
+void histogramInit(int listsize, int platform_id, int device_id, int use_gpu) {
|
|
cl_uint num = 0;
|
|
cl_uint num = 0;
|
|
clGetPlatformIDs(0, NULL, &num);
|
|
clGetPlatformIDs(0, NULL, &num);
|
|
cl_platform_id platformID[num];
|
|
cl_platform_id platformID[num];
|
|
clGetPlatformIDs(num, platformID, NULL);
|
|
clGetPlatformIDs(num, platformID, NULL);
|
|
|
|
|
|
- clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,0,NULL,&num);
|
|
|
|
|
|
+ // Selector for CPU/GPU
|
|
|
|
+ cl_device_type device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
|
|
|
|
+
|
|
|
|
+ clGetDeviceIDs(platformID[platform_id],device_type,0,NULL,&num);
|
|
|
|
|
|
num = 2;
|
|
num = 2;
|
|
char name[128];
|
|
char name[128];
|
|
|
|
|
|
- clGetPlatformInfo(platformID[1], CL_PLATFORM_PROFILE,128,name,NULL);
|
|
|
|
|
|
+ clGetPlatformInfo(platformID[platform_id], CL_PLATFORM_PROFILE,128,name,NULL);
|
|
|
|
|
|
|
|
|
|
cl_device_id devices[num];
|
|
cl_device_id devices[num];
|
|
- err = clGetDeviceIDs(platformID[1],CL_DEVICE_TYPE_CPU,num,devices,NULL);
|
|
|
|
|
|
+ err = clGetDeviceIDs(platformID[1],device_type,num,devices,NULL);
|
|
// int gpu = 1;
|
|
// int gpu = 1;
|
|
// err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 2, &device_id, NULL);
|
|
// err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 2, &device_id, NULL);
|
|
|
|
|
|
@@ -218,7 +224,7 @@ void histogramInit(int listsize) {
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
|
|
- clGetDeviceInfo(devices[0],CL_DEVICE_NAME,128,name,NULL);
|
|
|
|
|
|
+ clGetDeviceInfo(devices[device_id],CL_DEVICE_NAME,128,name,NULL);
|
|
|
|
|
|
printf("%s \n", name);
|
|
printf("%s \n", name);
|
|
|
|
|
|
@@ -229,9 +235,9 @@ void histogramInit(int listsize) {
|
|
0
|
|
0
|
|
};
|
|
};
|
|
|
|
|
|
- histoContext = clCreateContext(0, 1, &devices[0], NULL, NULL, &err);
|
|
|
|
|
|
+ histoContext = clCreateContext(0, 1, &devices[device_id], NULL, NULL, &err);
|
|
|
|
|
|
- histoCommands = clCreateCommandQueue(histoContext, devices[0], CL_QUEUE_PROFILING_ENABLE, &err);
|
|
|
|
|
|
+ histoCommands = clCreateCommandQueue(histoContext, devices[device_id], CL_QUEUE_PROFILING_ENABLE, &err);
|
|
histoInput = clCreateBuffer(histoContext, CL_MEM_READ_ONLY, listsize*(sizeof(float)), NULL, NULL);
|
|
histoInput = clCreateBuffer(histoContext, CL_MEM_READ_ONLY, listsize*(sizeof(float)), NULL, NULL);
|
|
histoOutput = clCreateBuffer(histoContext, CL_MEM_READ_WRITE, 1024 * sizeof(unsigned int), NULL, NULL);
|
|
histoOutput = clCreateBuffer(histoContext, CL_MEM_READ_WRITE, 1024 * sizeof(unsigned int), NULL, NULL);
|
|
FILE *fp;
|
|
FILE *fp;
|
|
@@ -264,7 +270,7 @@ void histogramInit(int listsize) {
|
|
char buffer[2048];
|
|
char buffer[2048];
|
|
|
|
|
|
printf("Error: Failed to build program executable!\n");
|
|
printf("Error: Failed to build program executable!\n");
|
|
- clGetProgramBuildInfo(histoProgram, devices[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
|
|
|
|
|
|
+ clGetProgramBuildInfo(histoProgram, devices[device_id], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
|
|
printf("%s\n", buffer);
|
|
printf("%s\n", buffer);
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
@@ -349,13 +355,13 @@ void finish_histogram() {
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void bucketSort(float *d_input, float *d_output, int listsize,
|
|
void bucketSort(float *d_input, float *d_output, int listsize,
|
|
int *sizes, int *nullElements, float minimum, float maximum,
|
|
int *sizes, int *nullElements, float minimum, float maximum,
|
|
- unsigned int *origOffsets)
|
|
|
|
|
|
+ unsigned int *origOffsets, int platform_id, int device_id, int use_gpu)
|
|
{
|
|
{
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
// // First pass - Create 1024 bin histogram
|
|
// // First pass - Create 1024 bin histogram
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
// ////////////////////////////////////////////////////////////////////////////
|
|
- histogramInit(listsize);
|
|
|
|
- histogram1024GPU(h_offsets, d_input, minimum, maximum, listsize);
|
|
|
|
|
|
+ histogramInit(listsize, platform_id, device_id, use_gpu);
|
|
|
|
+ histogram1024GPU(h_offsets, d_input, minimum, maximum, listsize);
|
|
finish_histogram();
|
|
finish_histogram();
|
|
for(int i=0; i<histosize; i++) historesult[i] = (float)h_offsets[i];
|
|
for(int i=0; i<histosize; i++) historesult[i] = (float)h_offsets[i];
|
|
|
|
|