title: Thrust issue with CUDA 6 managed memory
body: <p>I am running into an issue where when trying to use cudaMallocManaged() and thrust in the same CUDA 6 application thrust fails, even when thrust is not using any of the managed memory. Simply having an unused managed variable is enough to cause thrust to fail. I have created the following reproducer which I am testing on an NVIDIA Jetson TK1 running CUDA 6.0:</p>
  
  <pre><code>#include "thrust/device_ptr.h"
  #include "thrust/sort.h"
  
  __global__ void calculate_hash(uint *hash_values, uint *particle_ids, int length)
  {
      int i = blockIdx.x*blockDim.x + threadIdx.x;
  
      if(i &gt;= length)
          return;
  
      hash_values[i] =  1;
      particle_ids[i] = i;
  }
  
  void hash_particles_gpu(uint *d_hash_values, uint *d_particle_ids, int length)
  {
      int block_size = 256;
      int num_blocks = ceil(length/(float)block_size);
  
      calculate_hash&lt;&lt;&lt;num_blocks, block_size&gt;&gt;&gt;(d_hash_values, d_particle_ids, length);  
  
      cudaDeviceSynchronize();
  
      thrust::device_ptr&lt;uint&gt; keys(d_hash_values);
      thrust::device_ptr&lt;uint&gt; values(d_particle_ids);
      thrust::sort_by_key(keys, keys+length, values);
  }
  
  int main(int argc, char *argv[])
  {
      int length = 15;
      int bytes;
  
      #ifdef BROKE
      int *m_int;
      cudaMallocManaged((void**)&amp;m_int, sizeof(int));
      #endif
  
      // Allocate uint hash value array
      bytes = length*sizeof(unsigned int);
      unsigned int * hash_values;
      cudaMalloc((void**)&amp;hash_values, bytes);    
  
      // Allocate uint particle ID array
      bytes = length*sizeof(unsigned int);
      unsigned int *particle_ids;
      cudaMalloc((void**)&amp;particle_ids, bytes);
  
      hash_particles_gpu(hash_values, particle_ids, length);
  }
  </code></pre>
  
  <p>When I compile and run:</p>
  
  <pre><code>$ nvcc -DBROKE -DTHRUST_DEBUG example.cu -o broke.exe
  $ nvcc -DTHRUST_DEBUG example.cu -o fixed.exe
  $ ./fixed.exe
  $ ./broke.exe
  terminate called after throwing an instance of 'thrust::system::system_error'
    what():  synchronize: RakingReduction: unknown error
  Abort
  </code></pre>
  
  <p>I have checked to make sure I do not have any errors up until this point and everything seems fine until I call sort_by_key. Any idea what is going on?</p>