Results 1 to 2 of 2

Thread: Error Reading Kernel Source

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    8

    Error Reading Kernel Source

    Hello. I am just beginning to learn OpenCL and I am going through the exercises from the Introduction_to_OpenCL_Programming (exercise files can be found here: http://developer.amd.com/zones/openclzo ... -2010.aspx ). I am having trouble getting the code from the multiply matrix problem to run. It compiles, but when I run the program it gives me the message that there was an error reading file.

    This is the portion of code I am referring to:
    Code :
    // read the kernel
    	fp = fopen("multMatrix_kernel.cl","r");
    	fseek(fp,0L, SEEK_END);
    	filelen = ftell(fp);
    	rewind(fp);
     
    	kernel_src = (char*) malloc(sizeof(char)*(filelen+1));
    	readlen = fread(kernel_src,1,filelen,fp);
    	if(readlen!= filelen)
    	{
    	   printf("error reading file\n");
    	   printf(kernel_src);
    	   std::cin.get();
    	   exit(1);
    	}

    Anyway, I began printing out the kernel source and it seems there is a bunch of characters at the end.


    Anyway, if anyone has run into a similar problem I would greatly appreciate any pointers you might have. I am using VS2010. Thank you for your time.

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Error Reading Kernel Source

    It's possible that was corrupted and that caused the text-mode read operation to return less amount of data. Try opening the kernel file with notepad, see if it looks odd, and then save it again anyway. Notepad may automatically correct some simple issues.

    Just in case, how did you print the kernel source? If you printed it with printf(), what you see at the end was simply caused because the string is not null-terminated.

    Try this instead:

    Code :
       // read the kernel
       const char* filename = "multMatrix_kernel.cl";
       fp = fopen(filename,"rb");
       if(!fp)
       {
           printf("Error: could not open %s for reading\n", filename);
           exit(1);
       }
       fseek(fp,0L, SEEK_END);
       filelen = ftell(fp);
       rewind(fp);
     
       kernel_src = (char*) calloc(sizeof(char), filelen+1);
       if(!kernel_src)
       {
          printf("Error: Out of memory");
          exit(-1);
       }
     
       readlen = fread(kernel_src, 1, filelen, fp);
       if(readlen != filelen)
       {
          printf("Error reading file\n");
          printf("%*s", readlen, kernel_src);
          std::cin.get();
          exit(1);
       }

    Opening files in text mode only produces headaches in my experience.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Similar Threads

  1. Replies: 6
    Last Post: 02-27-2011, 02:49 AM
  2. Kernel's source code protection
    By pelotoescogorciao in forum Suggestions for next release
    Replies: 3
    Last Post: 01-17-2011, 08:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •