Some easy, but useful questions

Recently, I am tring to use CUDA to do some job. But some quesitons stop me going further. I’ll appreciate the ones who can answer my question:

1 Does CUDA supports struct? If not, which methods I can adopt to solve the problem?

2 How can I declear and use a var that can be used by the threads in a grid? If the var is very large, for example, 10K bytes, can CUDA still work?

3 Is there any string operations in CUDA API?

  1. support.

  2. read examples in sdk.

  3. it’s ext. C.

Can you speak in more detail?

  1. I have made some experiments, I can’t access structure’s member id device function, even though I have copied them with cudaMalloc.
    Are you sure cuda supports?

  2. Can you give an exact example I can check with?

  3. ext api?

Thank you. What you have answered is too general. Expecting your answer.

To (1) and (3): CUDA is an extension of the C language. You can perform any string operations you can write to code to do in C. Similarly, structs are of course supported. If you are having trouble, post a minimal sample code and we’ll help you find the problem.

If you were referring to the standard library string functions, then the GPU cannot call them. They are host functions and don’t exist on the GPU.

Practically every example in the SDK uses variables in the kernel. The reduction example is simple and easy to understand, it is a good place to start. Oh, and 10k is tiny. You can allocate memory up to the memory limits of your device (~600 MiB on an 8800 GTX or more on Tesla).

Thanks a lot, Mr Anderson. I will try again.

If I still can’t solve these problems, I will really need your help again.

host device int getJulianDate(const char* date) {
int day;

char d[3];

sscanf(d,%d,&day);

strlen(d);
strcmp(d, x);

}

functions sscanf and strlen, strcmp, all of them don’t work here. So I decide to write them myself.

for example:
host device int strlength(char *str)
{
int i;
for(i=0; str[i]!=‘\0’; i++);
return ++i;
}
I use this function to replace strlen. But it doesn’t work. When the program runs, It throws this exception : There are conflicts on accessing i

How can I solve this problem?

  1. Is there any library in CUDA to strlen, strcmp…?
  2. If not, How can I solve this problem?

There is nothing wrong with your device code. The problem is likely in your host code. I’m guessing that you are passing a host pointer into *str.