Offline Binary Kernel Generation

Hi, I read document by AMD which describes how to create Offline Binary Kernel Generation. There is this written:

Setup the OpenCL™ platform with the CL_CONTEXT_OFFLINE_DEVICES_AMD property set to 1. This gives you the ability to build OpenCL™ C kernels for OpenCL™ devices which may not necessarily be installed or accessible in your build system.

Example:

#define CL_CONTEXT_OFFLINE_DEVICES_AMD 0x403F

cl_platform_id platform; /* you must find the appropriate platform. */
cl_context_properties cprops[5];

cprops[0] = CL_CONTEXT_PLATFORM;
cprops[1] = (cl_context_properties)platform;
cprops[2] = CL_CONTEXT_OFFLINE_DEVICES_AMD;
cprops[3] = (cl_context_properties)1;
cprops[4] = (cl_context_properties)NULL;

Problem is that I dont know what is cprops.

In my code, this is what I have:

char pna_blur_gpu(char* imgname,uint32_t size,float sigma)
{
    uint32_t imgSize;
    float* matrix;
    cl_int ret;//the openCL error code/s
    //get the image
    ME_ImageBMP bmp;
    meImageBMP_Init(&bmp,imgname);
    imgSize = bmp.imgWidth*bmp.imgHeight*3;
    //create the gaussian kernel
    matrix = createGaussianKernel(size,sigma);
    //create the pointer that will hold the new (blurred) image data
    unsigned char* newData;
    newData = malloc(imgSize);
    // Read in the kernel code into a c string
    FILE* f;
    char* kernelSource;
    size_t kernelSrcSize;
    if( (f = fopen("kernel.cl", "r")) == NULL)
    {
        fprintf(stderr, "Failed to load OpenCL kernel code.
");
        return false;
    }
    kernelSource = malloc(MAX_SOURCE_SIZE);
    kernelSrcSize = fread( kernelSource, 1, MAX_SOURCE_SIZE, f);
    fclose(f);

    //Get platform and device information
    cl_platform_id platformID;//will hold the ID of the openCL available platform
    cl_uint platformsN;//will hold the number of openCL available platforms on the machine
    cl_device_id deviceID;//will hold the ID of the openCL device
    cl_uint devicesN; //will hold the number of OpenCL devices in the system
    if(clGetPlatformIDs(1, &platformID, &platformsN) != CL_SUCCESS)
    {
        printf("Could not get the OpenCL Platform IDs
");
        return false;
    }
    if(clGetDeviceIDs(platformID, CL_DEVICE_TYPE_DEFAULT, 1,&deviceID, &devicesN) != CL_SUCCESS)
    {
        printf("Could not get the system's OpenCL device
");
        return false;
    }

 /** Offline Binary Kernel Generation **/
 #define CL_CONTEXT_OFFLINE_DEVICES_AMD    0x403F
 cprops[0] = CL_CONTEXT_PLATFORM;
 cprops[1] = (cl_context_properties)platformID;
 cprops[2] = CL_CONTEXT_OFFLINE_DEVICES_AMD;
 cprops[3] = (cl_context_properties)1;
 cprops[4] = (cl_context_properties)NULL;
 /*********************************************/


    // Create an OpenCL context
    cl_context context = clCreateContext( NULL, 1, &deviceID, NULL, NULL, &ret);
    if(ret != CL_SUCCESS)
    {
        printf("Could not create a valid OpenCL context
");
        return false;
    }

I have the cprops undeclared, can you explain how to declare it?

In the AMD sample code, it is declared thusly: “cl_context_properties cprops[5];”. The type “cl_context_properties” is defined in the cl.h header.

Hi, I had to be blind that I have missed the line.

In the manual they written: “build the OpenCL program for all of the OpenCLdevices you need to support.”. How to understand this? If I have only one device, it will not support more then one device? Or possibly if I have ATI and compile program for ATI so NVIDIA will not be supported by the program? That should not make sense because the algorithm is general.

Also, is there difference between:

ret = clBuildProgram(program, 1, &deviceID, NULL, NULL, NULL))

and

ret = clBuildProgram(program, 1, NULL, NULL, NULL, NULL))

?

One more question. In step 6 I have found this piece of code:
err = clGetProgramInfo( program, CL_PROGRAM_BINARIEIS, sizeof(char *)*nDevices, binaries, NULL );


But I have CL_PROGRAM_BINARIEIS undeclared and I cannot  find it in CL.h, how to declare it?

[QUOTE=barracuda;30637]Hi, I had to be blind that I have missed the line.

In the manual they written: “build the OpenCL program for all of the OpenCLdevices you need to support.”. How to understand this? If I have only one device, it will not support more then one device? Or possibly if I have ATI and compile program for ATI so NVIDIA will not be supported by the program? That should not make sense because the algorithm is general.[/QUOTE]

They are correct. You can’t ship this binary and expect it to work on all their hardware.

What you want it SPIR, but nobody is shipping support yet since it is new.

I have noticed that the program which I generated begins on string ELF.
This is what I see in kernelBinary: 0x1590020 “\177ELF\001\001\001”
See it in hexa editor:

I looked on internet what could it mean and I found some link which found text “Compilation error”. So could this mean that the binary program was not successfully generated? It has size 11000 bytes. It looks like everything is fine, but when I looked on the program string in code::blocks, so I could watch only cca 7 characters and there was the ELF. I ask this because I have some proglem when I try to load the binary, the pointer returned by

program = clCreateProgramWithBinary( context, 1, &deviceID, &kernelBinarySize, &(*kernelBinary), NULL, &err );

return NULL pointer 0x0.
Please,Can you check my program if I have something wrong?

Line 112