1 |
|
/** |
2 |
|
* |
3 |
|
* To View the Image |
4 |
|
* ========================= |
5 |
|
* ./unu reshape -i mip.txt -s 200 200 | ./unu quantize -b 8 -o new.png |
6 |
|
*/ |
7 |
#include <OpenCL/OpenCl.h> |
#include <OpenCL/OpenCl.h> |
8 |
#include <assert.h> |
#include <assert.h> |
9 |
#include <stdio.h> |
#include <stdio.h> |
116 |
|
|
117 |
return source; |
return source; |
118 |
} |
} |
119 |
|
void saveResults (float * matrix, int size) |
120 |
|
{ |
121 |
|
int i; |
122 |
|
float max = -INFINITY; |
123 |
|
FILE * out_file; |
124 |
|
out_file = fopen("mip.txt", "w"); |
125 |
|
if (out_file == NULL) { |
126 |
|
fprintf(stderr,"Can not open output file\n"); |
127 |
|
exit (8); |
128 |
|
} |
129 |
|
|
130 |
|
for(i = 0; i < size; i++) |
131 |
|
{ |
132 |
|
if(matrix[i] == -INFINITY || matrix[i] < 0) |
133 |
|
fprintf(out_file,"%f\n",0.0f); |
134 |
|
else |
135 |
|
fprintf(out_file,"%f\n",matrix[i]); |
136 |
|
|
137 |
|
if(matrix[i] > max) |
138 |
|
max = matrix[i]; |
139 |
|
|
140 |
|
} |
141 |
|
printf("Max: %f\n",max); |
142 |
|
fclose(out_file); |
143 |
|
|
144 |
|
|
145 |
|
} |
146 |
float det3x3(float a, float b, float c, float d, float e, float f, float g, float h, float i) |
float det3x3(float a, float b, float c, float d, float e, float f, float g, float h, float i) |
147 |
{ |
{ |
148 |
return ( (a)*(e)*(i) |
return ( (a)*(e)*(i) |
245 |
{ |
{ |
246 |
int index = 0, end = 1, arraySize = rowSize * rowSize; |
int index = 0, end = 1, arraySize = rowSize * rowSize; |
247 |
|
|
248 |
for(index = 0; index < arraySize; index++) |
for(index = 1000; index < 1256; index++) |
249 |
{ |
{ |
250 |
if(end == rowSize) |
if(end == 16) |
251 |
{ |
{ |
252 |
printf(" %.2f\n",matrix[index]); |
printf(" %.2f\n",matrix[index]); |
253 |
end = 1; |
end = 1; |
439 |
err |=clSetKernelArg(kernel,9,sizeof(float), &stepSize); |
err |=clSetKernelArg(kernel,9,sizeof(float), &stepSize); |
440 |
err |=clSetKernelArg(kernel,10,sizeof(int), &nin->axis[1].size); |
err |=clSetKernelArg(kernel,10,sizeof(int), &nin->axis[1].size); |
441 |
err |=clSetKernelArg(kernel,11,sizeof(int), &nin->axis[2].size); |
err |=clSetKernelArg(kernel,11,sizeof(int), &nin->axis[2].size); |
442 |
|
err |=clSetKernelArg(kernel,12,sizeof(int), &nin->axis[0].size); |
443 |
|
|
444 |
|
printf("Error: %d\n",err); |
445 |
assert(err == CL_SUCCESS); |
assert(err == CL_SUCCESS); |
446 |
|
|
447 |
/** Retrieve the Recommend Work Group Size */ |
/** Retrieve the Recommend Work Group Size */ |
460 |
|
|
461 |
err = clEnqueueReadBuffer(queue,out_mem,CL_TRUE,0, sizeof(float) * (SIZE *SIZE),out,0,NULL,NULL); |
err = clEnqueueReadBuffer(queue,out_mem,CL_TRUE,0, sizeof(float) * (SIZE *SIZE),out,0,NULL,NULL); |
462 |
|
|
463 |
printMatrix(out,20); |
saveResults(out,SIZE * SIZE); |
464 |
|
|
465 |
clReleaseKernel(kernel); |
clReleaseKernel(kernel); |
466 |
clReleaseProgram(program); |
clReleaseProgram(program); |