Warning at compilation expression has no effect

Hello,

I’m trying to compile the following cuda kernel:

__global__ void CudaAdamsPreditor(float *fn, float *yn, float h, float *fold, int *iwork ) {

  int bx = blockIdx.x; 

  int tx = threadIdx.x;

  unsigned int stride;

if( bx < iwork[0] && tx < ORDEM ) {

    __device__ __shared__ float FOLD[ORDEM];

    if( tx < ORDEM - 1 ) {

      FOLD[tx] =  fold[bx*ORDEM + tx] = fold[bx*ORDEM + tx + 1];

    }

    FOLD[ORDEM - 1] = fn[bx];

    FOLD[tx] = a[tx] * FOLD[tx];

    for( stride = blockDim.x; stride > 1; stride >> 1 ) {

      __syncthreads();

      if( tx + stride < ORDEM )	FOLD[tx] += FOLD[tx + stride];

    }

    yn[bx] = yn[bx] + h * DIVISOR * FOLD[0];

  }

}

and I get the following compiler message:

adams.cu(49): warning: expression has no effect

where the line 49 is: “for( stride = blockDim.x; stride > 1; stride >> 1 ) {”

the compiler seems to be complaining of the use of the operator >>.

I’m using the following command line in a debian system to compile:

nvcc -c adams.cu

Does anybody knows what this warning is about? As far as I know there is no mistake in the line reported, actually this is an sum algorithm I copied from a cuda tutorial.

Thanks in advance

You need to assign the result of the shift operation to a variable. Otherwise, the result of the expression is not preserved.

You can use either

stride >>= 1

or

stride = stride >> 1

to accomplish what you are trying to do.

Have you tried this?

...

    for( stride = blockDim.x; stride > 1; stride >>= 1 ) {

...

In other words, use “shift equals” instead of “shift.” Or, alternatively,

stride = stride >> 1;

Your expression doesn’t assign the result of the shift to a variable, and the compiler is warning you.

Jeremy

Thanks, now it is working fine! =)