OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1719 Discussions

Function "ReadSources()" to read .cl source file

kerotankcn_ne_jp
Beginner
450 Views
I read sample programs with Intel OpenCL SDK 1.5. In a sample of "BitonicSort", funtion name"ReadSources()" is used for reading .cl source file. This is the first time to find out this function. Please tell me where this function is defined and described. Is the function included to any API?
0 Kudos
2 Replies
Dmitry_B_Intel1
Employee
450 Views
ReadSources is a helper function which is common for all samples. You can find ReadSources functionimplementation in\\common\\utils.cpp source file. The function declaration is in\\common\\utils.h.This helperfunctionjust opens source .cl file and reads content in a char buffer for furtherOpenCL program creation usingclCreateProgramWithSource.
0 Kudos
kerotankcn_ne_jp
Beginner
450 Views
Dear Sir,
Thank you. I can confirm a description of "ReadSource()" in \\common\\utils.cpp.
Then, does a program of NVIDIA OpenCL work in Intel OpenCL SDK 1.5? Is there the copatiblity between two? Because I find out the different descriptions of a procedure before .cl file reading compared between "BitonicSort" in Intel OpenCL SDK 1.5 sample program and a below program.
Here, I attach a sample program for NVIDIA OpenCL which includes "Hello.cpp" and "Hello.cl". As a result of running this program, a kernel program cannot be loaded.
Regards,
Noriko Etani
----------
Hello.cpp
----------
#include
#include
#ifdef __APPLE__
#include
#else
#include
#endif
#define MEM_SIZE (128)
#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 = NULL;
cl_uint ret_num_devices;
cl_uint ret_num_platforms;
cl_int ret;
char string[MEM_SIZE];
FILE *fp;
char fileName[] = "./hello.cl";
char *source_str;
size_t source_size;
fp = fopen(fileName, "r");
if (!fp) {
fprintf(stderr, "Failed to load kernel.\n");
exit(1);
}
source_str = (char*)malloc(MAX_SOURCE_SIZE);
source_size = fread( source_str, 1, MAX_SOURCE_SIZE, fp);
fclose( fp );
ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
ret = clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, &ret_num_devices);
context = clCreateContext( NULL, 1, &device_id, NULL, NULL, &ret);
command_queue = clCreateCommandQueue(context, device_id, 0, &ret);
memobj = clCreateBuffer(context, CL_MEM_READ_WRITE,MEM_SIZE * sizeof(char), NULL, &ret);
program = clCreateProgramWithSource(context, 1, (const char **)&source_str,
(const size_t *)&source_size, &ret);
ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
kernel = clCreateKernel(program, "hello", &ret);
ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobj);
ret = clEnqueueTask(command_queue, kernel, 0, NULL,NULL);
ret = clEnqueueReadBuffer(command_queue, memobj, CL_TRUE, 0,
MEM_SIZE * sizeof(char),string, 0, NULL, NULL);
puts(string);
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;
}
---------
Hello.cl
---------
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__kernel void hello(__global char* string)
{
string[0] = 'H';
string[1] = 'e';
string[2] = 'l';
string[3] = 'l';
string[4] = 'o';
string[5] = ',';
string[6] = ' ';
string[7] = 'W';
string[8] = 'o';
string[9] = 'r';
string[10] = 'l';
string[11] = 'd';
string[12] = '!';
string[13] = '\0';
}
-----------------------------
0 Kudos
Reply