Skip to content

Commit

Permalink
Workaround error related to volatile
Browse files Browse the repository at this point in the history
Early exit functors if concurrency does not exist
  • Loading branch information
jaredhoberock committed Apr 1, 2014
1 parent c938407 commit 5511666
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions examples/cuda/simple_cuda_streams.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@

struct ping
{
// XXX nvcc issue prevents us from making ball volatile
//__device__
//void operator()(volatile int &ball)
__device__
void operator()(volatile int &ball)
void operator()(int &ball)
{
// we're not guaranteed concurrency, so only attempt this 1000 times
unsigned int attempt = 0;

ball = 1;

for(unsigned int next_state = 2;
next_state < 25;
next_state < 25 && attempt < 1000;
next_state += 2)
{
while(ball != next_state)
while(ball != next_state && attempt < 1000)
{
#if __CUDA_ARCH__ >= 200
printf("ping waiting for return\n");
#endif
++attempt;
}

ball += 1;
Expand All @@ -42,18 +49,25 @@ struct ping

struct pong
{
// XXX nvcc issue prevents us from making ball volatile
//__device__
//void operator()(volatile int &ball)
__device__
void operator()(volatile int &ball)
void operator()(int &ball)
{
// we're not guaranteed concurrency, so only attempt this 1000 times
unsigned int attempt = 0;

for(unsigned int next_state = 1;
next_state < 25;
next_state < 25 && attempt < 1000;
next_state += 2)
{
while(ball != next_state)
while(ball != next_state && attempt < 1000)
{
#if __CUDA_ARCH__ >= 200
printf("pong waiting for return\n");
#endif
++attempt;
}

ball += 1;
Expand Down

0 comments on commit 5511666

Please sign in to comment.