Hi
sorry for the late reply.
there are some mistakes in your code
1. You allocated memory as 1D and trying to access it as 2D. thats good but you are using the expression y * Hieght + x is wrong. always it should be (y * width + x)
2. change fread(kernel_src,1,filelen,fp); to fread(kernel_src,filelen,1,fp);
I think rest will be fine.
try these changes and compile your code.
First, check if you insert the kernel code in vs 2010 project with correct way. If you already do that ant the host still can't read kernel file then try change your code:
#define MAX_SOURCE_SIZE (0x100000)
int main(int argc, char **argv)
{
///Your host code
//Load Kernel Source
FILE *fp;
const char fileName[] = "./parallel.cl";
fp = fopen(fileName, "r");
if (!fp)
{
fprintf(stderr, "Failed to load kernel.\n");
exit(1);
}
char *source_str = source_str = (char *)malloc(MAX_SOURCE_SIZE);
size_t source_size = source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp);
fclose(fp);
program = clCreateProgramWithSource(context, 1, (const char **) &source_str, (const size_t *) &source_size, &err);
err = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
///Your host code
return 0;
}
Hope it works.......
Hi arvin,
Thank you for reply,
now its reading the kernel file and when it compiles its displaying the value of Matrix A and Matrix B but output is wrong.
this is the portion of the code i am referring to:
/* Display Results */
printf("\n Matrix A\n");
for ( y=0; y< height; y++)
{
for ( x=0; x< width; x++)
{
printf("%.2f,",inputMatrix1[y*height+x]);
}
printf("\n");
}
printf("\n Matrix B\n");
for ( y=0; y< height; y++)
{
for ( x=0; x< width; x++)
{
printf("%.2f,",inputMatrix2[y*width+x]);
}
printf("\n");
}
printf("\n Matrix A + Mattrix B\n");
for ( y=0; y< height; y++)
{
for ( x=0; x< width; x++)
{
printf("%.2f,",results[y*height+x]);
}
printf("\n");
}
Assume your kernel is correct, looks like you make a mistake when print matrixB
Your code (print Matrix B) is weird because your matrixB d is printed differently with other matrix (matrix A and C) .
printf("\n Matrix B\n");
for ( y=0; y< height; y++)
{
for ( x=0; x< width; x++)
{
printf("%.2f,",inputMatrix2[y*width+x]);
}
printf("\n");
}
Try to change the code (bold) with this:
printf("%.2f,",inputMatrix2[y*height+x]);
If the program still not show the correct result, you can show me the output of matrix A, B, and C
Hi arvin,
I made the change as you said but output is still null matrix and i have attached matrix output to original post.
please post your vs project complete here. Lets see whats going wrong.
Thanks arvin,now i am getting output.
Congratulations and keep trying more stuffs in OpenCL.