3 Replies Latest reply on Apr 14, 2011 5:12 AM by himanshu.gautam

    Issues with building kernel code and malloc

    krishnan

      Hi folks

      I've been trying to build this kernel code for a few days now, and I have seen some very peculiar errors. (the host side code for loading and building the code are given below.)

      When the last line of my `blob1_kernel.cl' is `}', I get the error:

      `blob1: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
      Aborted'

      (I get the same error when I remove some of the #defines at the top of `blob1_kernel.cl').

      When the last line of `blob1_kernel.cl' is blank and I preserve all the #defines, I get the error:

      `Build failed. Error Code=-11
      --- Build Log -- '

      Presumably, this error is coming from clBuildProgram. The Build Log is empty. Even when I deliberately break the code, and I know the errors that should be reported, the Build Log remains empty.

      I have attached the code I have used to load and build kernel source. I wonder if anyone can tell me what I'm doing wrong. Please let me know if a better description of the problem is needed.

      //Relevant CL declarations cl_context context; cl_program program; cl_int err; cl_device_id device_id; //Variables to read kernel source FILE *fp; long filelen; long readlen; char *kernel_src; // char string to hold kernel source //Read the kernel fp = fopen("blob1_kernel.cl","r"); fseek(fp,0L, SEEK_END); filelen = ftell(fp); rewind(fp); kernel_src = malloc(sizeof(char)*(filelen+1)); readlen = fread(kernel_src,1,filelen,fp); if(readlen!=filelen) { printf("error reading file\n"); exit(1); } //ensure that the string is NULL terminated kernel_src[filelen+1]='\0'; //Basic OpenCL setup of context, command queue etc. // create program object from source. kernel_src contains // source read from file earlier program = clCreateProgramWithSource(context, 1 , (const char **) &kernel_src, NULL, &err); if (err != CL_SUCCESS) { printf("Unable to create program object. Error Code=%d\n",err); exit(1); } err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); if (err != CL_SUCCESS) { printf("Build failed. Error Code=%d\n", err); size_t len; char buffer[4096]; // get the build log clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len); printf("--- Build Log -- \n %s\n",buffer); exit(1); }