Thank you very much for your reply and help.
Now I was successfully able to compile my sample program with both the OpenCL platforms (FreeOCL as well as with intelocl).
But I observed different results from read_imagef function from both the platforms.
Request you to please let me know if this different results are as expected (which I doubt).
The output from FreeOCL is as follows:
tmp4 = 9466.283203
tmp4 = 9471.979492
tmp4 = 9483.374023
The output from IntelOCL is as follows:
tmp4 = 9460.585938
tmp4 = 9466.283203
tmp4 = 9477.676758
My sample program is as follows:
main.c:
#include <stdio.h>
#include <stdlib.h>
#ifdef APPLE
#include <OpenCL/opencl.h>
#else
#include <OpenCL/cl.h>
#endif
#define MEM_SIZE (5)
#define MAX_SOURCE_SIZE (0x100000)
int main()
{
cl_device_id *device_id = NULL;
cl_context context = NULL;
cl_command_queue command_queue = NULL;
cl_mem memobj = NULL;
cl_program program = NULL;
cl_kernel kernel = NULL;
cl_platform_id *platform_id;
cl_platform_id platform = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_int ret;
float buf[2700];
cl_int status;
char string[MEM_SIZE];
FILE *fp;
char fileName[] = “./kernel.cl”;
char *source_str;
size_t source_size;
int i;
/* Load the source code containing the kernel*/
fp = fopen(fileName, “r”);
if (!fp) {
fprintf(stderr, "Failed to load kernel.
");
exit(1);
}
source_str = (char*)malloc(MAX_SOURCE_SIZE);
source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp);
fclose(fp);
/* Get Platform Info */
ret = clGetPlatformIDs(0, NULL, &ret_num_platforms);
platform_id = (cl_platform_id*) malloc(ret_num_platforms * sizeof(cl_platform_id));
ret = clGetPlatformIDs(ret_num_platforms, platform_id, NULL);
/* select one platform of them */
platform = platform_id[1];
/* Get Device Info */
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 0, NULL, &ret_num_devices);
device_id = (cl_device_id*) malloc(ret_num_devices * sizeof(cl_device_id));
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, ret_num_devices, device_id, NULL);
/* Create OpenCL context */
context = clCreateContext(NULL, 1, device_id, NULL, NULL, &ret);
/Image object/
for (i=0; i<2700; i++)
buf[i] = 9460.5860 + (0.876453*i);
cl_image_desc desc;
desc.image_type = CL_MEM_OBJECT_IMAGE3D;
desc.image_width = 3;
desc.image_height = 3;
desc.image_depth = 3;
desc.image_array_size = 0;
desc.image_row_pitch = 3*4;
desc.image_slice_pitch = 343;
desc.num_mip_levels = 0;
desc.num_samples = 0;
desc.buffer =NULL;
cl_image_format format;
format.image_channel_order = CL_R;
format.image_channel_data_type = CL_FLOAT;
cl_mem d_inputImage = clCreateImage(context, CL_MEM_COPY_HOST_PTR, &format, &desc, (void *)buf, &status);
/* Create Command Queue */
command_queue = clCreateCommandQueue(context, device_id[0], 0, &ret);
/* Create Memory Buffer */
memobj = clCreateBuffer(context, CL_MEM_READ_WRITE,MEM_SIZE * sizeof(char), NULL, &ret);
/* Create Kernel Program from the source */
program = clCreateProgramWithSource(context, 1, (const char **)&source_str,
(const size_t *)&source_size, &ret);
/* Build Kernel Program */
ret = clBuildProgram(program, 1, device_id, NULL, NULL, NULL);
/* Create OpenCL Kernel */
kernel = clCreateKernel(program, “hello”, &ret);
/* Set OpenCL Kernel Parameters */
ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_inputImage);
/* Execute OpenCL Kernel */
ret = clEnqueueTask(command_queue, kernel, 0, NULL,NULL);
/* Finalization */
ret = clFlush(command_queue);
ret = clFinish(command_queue);
ret = clReleaseKernel(kernel);
ret = clReleaseProgram(program);
ret = clReleaseMemObject(memobj);
ret = clReleaseCommandQueue(command_queue);
ret = clReleaseContext(context);
free(source_str);
return 0;
}
kernel.cl:
__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR;
__kernel void hello(__read_only image3d_t img)
{
float4 tmp4;
tmp4 = read_imagef(img,sampler,(float4)(.5f, .5f, .5f, .5f));
printf("tmp4 = %f
",tmp4.x);
tmp4 = read_imagef(img,sampler,(float4)(1,1,1,1));
printf("tmp4 = %f
",tmp4.x);
tmp4 = read_imagef(img,sampler,(float4)(2,2,2,2));
printf("tmp4 = %f
",tmp4.x);
}
Please let us know if I am making any incorrect things.
Thanks & Best Regards,