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

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

Аватар пользователя kerotankcn.ne.jp

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?

3 posts / 0 новое
Последнее сообщение
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.
Аватар пользователя Dmitry Budnikov (Intel)

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.

Аватар пользователя kerotankcn.ne.jp
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'; } -----------------------------

Зарегистрируйтесь, чтобы оставить комментарий.