cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

amdkid
Adept I

How to use clCreateProgramWithSource function with not single string?[CLOSED]

Hi to all.

I try to use clCreateProgramWithSource function with  strings parameter equivalent not single string.

I equate count parameter to number of strings in strings parameter

then as strings parameter I use pointer to an array of PChar strings

as lengths parameter I use NULL

In that case function  clCreateProgramWithSource not returns an error, but function clBuildProgram return error code -11 (CL_BUILD_PROGRAM_FAILURE)

which is not arises if in function  clCreateProgramWithSource i use single PChar string as strings parameter and count=1  lengths=NULL.

Below I show my cl code:

inline void Work0()

{

return;

}

inline void Work1(__global const float4 * a1, __global const float4 * b1, __global float4 * c1, int i1)

{

     float4 bufa;             

     float4 bufb;

     bufa=a1[i1];                 

     bufb=b1[i1];

     bufa += bufb;        

     c1[i1]=bufa;                  

}

__kernel void VectorAdd( __global const float4 * a, __global const float4 * b, __global float4 * c, int N)

{

     int i = get_global_id(0);   // Получаем номер потока

     if(i>N-1)

     {

          Work0();

     }

     else

     {

          Work1(a, b, c, i);

     }

}

Somebody please help me to solve that's problem.

Answer find in post Sep 10, 2012 7:32 AM

0 Likes
8 Replies
binying
Challenger

Something like this would work...

-----------------

...

status = convertToString(filename, sourceStr);

          const char *source = sourceStr.c_str();

          size_t sourceSize[] = {strlen(source)};

          cl_program program = clCreateProgramWithSource(context, 1, &source, sourceSize, NULL);

...

--------------

0 Likes

binying:

I know that will work

status = convertToString(filename, sourceStr);

const char *source = sourceStr.c_str();

size_t sourceSize[] = {strlen(source)};

cl_program program = clCreateProgramWithSource(context, 1, &source, NULL, NULL);

but I ned somthing like that

char *src[];                 // Array of pointers to strings

int NumStrings;          // Number of pointers in src (!=1)

cl_program program = clCreateProgramWithSource(context, NumStrings, &src[0],  NULL, NULL);

And I don't know how must be arranged strings in src, and what values ned to be in all parameters of function for case when NumStrings>1.

0 Likes

if strings are null terminated then just

char *src[];                 // Array of pointers to strings

int NumStrings;          // Number of pointers in src (!=1)

cl_program program = clCreateProgramWithSource(context, NumStrings, src,  NULL, NULL);

that is all.

0 Likes

Thanks Nou but it's not work.

May be I misunderstand concept of null terminated strings.

I program in delphi &I think it tried all possible, when strings are pchar strings, when strings is string with 0 char in the end of all strings and when 0 char in the end of the last string. In all cses does not work, clBuildProgram everytime showing me error code -11. But if i use single pchar string it's working. I don't understand where I do mistake.

0 Likes

Probably I understend how it must be

char *src[];                 // Array of pointers to strings

int NumStrings;          // Number of pointers in src (!=1)

cl_program program = clCreateProgramWithSource(context, NumStrings, src,  NULL, NULL);

It's will work if we use PChar strings and in every string we write whole function code(earlier I wrote in every string single string from function source code).

So if we have two files with one function in each, then we have two strings,each of which consists from functions from that's files.

0 Likes
amdkid
Adept I

Sorry, but does anybody know,  cl_program object have limitation to source code size?

0 Likes

Have you check the openCL 1.2 specification about this?

0 Likes

Thanks Binying

I've just watched description of functions  clCreateProgramWithSource and ClBuildProgram in OpenCL specification 1.2, but not find useful information about it.

I think if program size is too large, in function clBuildProgram arises error CL_BUILD_PROGRAM_FAILURE, but I not sure about it .

0 Likes