Question about shared variables

Hi. I’m a newb in programming. So may be the solution is quite simple…

I want to find out if there is some way to share variables within a thread? For example I have some code that is used several times in a kernel, like:

__global__ void procedure ()

{

//define some variables...

for (...)

{

  switch(a)

  {

  case 1:

  //do A

  for (...)

  {

    //do B

  }

  ;

  break;

  case 2:

  //do B

  break;

  case 3:

  //do A

  break;

  }

}

}

Where A and B are about 5 - 10 lines of code and use some common variables, that are loaded at the beginning. The most simple way is to make a function that will do A and a function that will do B. But they need to have about 10 common variables and some more that need to be stored till the next call to A or B. So maybe there is some way to share these variables within a thread (all threads are independent, so the variables have to be shared only within a thread and they shouldn’t be placed in global memory for quicker access). Or maybe there’s a way to make some sort of a substitute variable, use it where i want A and B, so that compiler would insert A code and B code instead of these variables, when compiling?

Thanks.

Not sure I see your problem.
I think,
if you declare your varaibles inside your global
function they will belong to the thread.
Ie each thread gets its own set of variables.
As long as nvcc can find registers to store them,
wont that should do what you want?

Bill

Maybe you want to use a #define statement to define A block code and B block?

#define A_code statement; statement; …

#define B_code statement; statement; …

and so:

__global__ void procedure ()

{

//define some variables...

for (...)

{

  switch(a)

  {

  case 1:

  A_code

  for (...)

  {

    B_code

  }

  ;

  break;

  case 2:

  B_code

  break;

  case 3:

  A_code

  break;

  }

}

}