OCL programm without *.cl file

Hello there!

Now i use code like that:


 fp=fopen("mandel.cl", "r"); /*open file with OCL programm*/
 source_str = (char*)malloc(MAX_SOURCE_SIZE);
 source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp);
 fclose(fp);
<some code>
 program = clCreateProgramWithSource(context, 1, (const char **)&source_str, (const size_t *)&source_size, &ret);
 clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
 kernel = clCreateKernel(program, "mandel", &ret); /*"mandel" -- __kernel function in "mandel.cl"*/

I know that CUDA didn’t need for an external file. OpenCL can do without an external source file?

Of course, it can. It is obvious even from the code you supplied. Just initialize source_str the way you wish.

Sorry, i little not understand you.

source_str = “__kernel your_kernel_name(parameters) { code }”;

No, i mean, without source_str, without extend file. I mean something like that:


__kernel void mandel(<some arguments>)
{
 <some code>
}

int main(void)
{
 <some code>
 cl_kernel kernel = clCreateKernel(program, "mandel", &ret);
}

You don’t need external file. Check clBuildProgram: It takes string as parameter.

???, ? ??? ???, ??? ??? ??? ??? ? ??? ??? ?? ???. ? ??? ?? ??? ??? ? ??? ??? ? ??? ??? ??? ??? ???, ??? OpenCL ??? ??? ??? ??? ??? ?? ??? ??? ? “???” ??.

???, ? ??? ???, ??? ??? ??? ??? ? ??? ??? ?? ???. ? ??? ?? ??? ??? ? ??? ??? ? ??? ??? ??? ??? ???, ??? OpenCL ??? ??? ??? ??? ??? ?? ??? ??? ? “???” ??.[/quote]

???, ??? ?? ??? (?? ??? ??? ??? ???-??? ??? ???, ? ??? ??? ? ??? ?? ???).