Hi,
Lets say that the array chars is within global memory. Thus each thread has access to every array element. The main problem, as I see it, is the changing length of the strings in the array. I can come up with two scenarios solving the problem:
-
Each thread starts processing from the begining of the array. Depending on its ID the actually processed string (by ‘functionA’) starts from the first non-‘\0’ char after ID number of ‘\0’ occurances. It will work, but would be not very efficient.
-
Pad the strings on the right with ‘\0’ (see below) up to the length of the longest one to ensure their length equality. Then each thread would start from the offset given by thread ID times string length (given the thread ids begin from 0). Processing of ‘functionA’ would be done, I suppose, until first ‘\0’ occurance.
const int a={
'h','e','l', 'l', 'o','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
',
'h','o','w','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
',
'A','R','E','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
',
'Y','O','U','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
','
const int a={
‘h’,‘e’,‘l’, ‘l’, ‘o’,‘\0’,
‘h’,‘o’,‘w’,‘\0’,‘\0’,‘\0’,
‘A’,‘R’,‘E’,‘\0’,‘\0’,‘\0’,
‘Y’,‘O’,‘U’,‘\0’,‘\0’,‘\0’
};
'
};
Of cource the mentioned length need to include first ‘\0’ (here 6 chars).
To sum up, when You call the kernel pass mentioned length to it as addtional parameter. The number of threads would be in this case equal to number of strings. For such an example one block would do:
functionA<<<1, 4>>>(6, a);
Hope it helps,
MK