title: Misaligned address in CUDA
body: <p>Can anyone tell me whats wrong with the following code inside a CUDA kernel:</p>
  
  <pre><code>__constant__ unsigned char MT[256] = {
      0xde, 0x6f, 0x6f, 0xb1, 0xde, 0x6f, 0x6f, 0xb1, 0x91, 0xc5, 0xc5, 0x54, 0x91, 0xc5, 0xc5, 0x54,....};
  
  typedef unsinged int U32;
  
  __global__ void Kernel (unsigned int  *PT, unsigned int  *CT, unsigned int  *rk)
  {
  
      long int i;
      __shared__ unsigned char sh_MT[256];    
  
      for (i = 0; i &lt; 64; i += 4)
          ((U32*)sh_MT)[threadIdx.x + i] = ((U32*)MT)[threadIdx.x + i];
  
      __shared__ unsigned int sh_rkey[4];
      __shared__ unsigned int sh_state_pl[4];
      __shared__ unsigned int sh_state_ct[4];
  
      sh_state_pl[threadIdx.x] = PT[threadIdx.x];
      sh_rkey[threadIdx.x] = rk[threadIdx.x];
      __syncthreads();
  
  
      sh_state_ct[threadIdx.x] = ((U32*)sh_MT)[sh_state_pl[threadIdx.x]]^\
      ((U32*)(sh_MT+3))[((sh_state_pl[(1 + threadIdx.x) % 4] &gt;&gt; 8) &amp; 0xff)] ^ \
      ((U32*)(sh_MT+2))[((sh_state_pl[(2 + threadIdx.x) % 4] &gt;&gt; 16) &amp; 0xff)] ^\
      ((U32*)(sh_MT+1))[((sh_state_pl[(3 + threadIdx.x) % 4] &gt;&gt; 24) &amp; 0xff )];
  
  
      CT[threadIdx.x] = sh_state_ct[threadIdx.x];
  }
  </code></pre>
  
  <p>At This line of code , </p>
  
  <pre><code>((U32*)(sh_MT+3))......
  </code></pre>
  
  <p>The CUDA debugger gives me the error message :
  <strong><em>misaligned address</em></strong></p>
  
  <p>How can I fix this error? </p>
  
  <p>I am using CUDA 7 in MVSC  and i use 1 Block and 4 threads for executing the Kernel Function as follow:</p>
  
  <pre><code>__device__ unsigned int *state;
  __device__ unsigned int *key;
  __device__ unsigned int *ct;
  .
  .
  main()
  {
  cudaMalloc((void**)&amp;state, 16);
  cudaMalloc((void**)&amp;ct, 16);
  cudaMalloc((void**)&amp;key, 16);
  //cudamemcpy(copy some values to =&gt; state , ct, key);   
  Kernel &lt;&lt; &lt;1, 4 &gt;&gt; &gt;(state, ct, key); 
  }
  </code></pre>
  
  <p>Remember please, I can't change my "MT Table" type.
  Thanks in advance for any advice or answer .</p>