title: Thrust: why always host code is executed in spite of __CUDA_ARCH__
body: <p>I try to define two branches in code: one for CUDA execution and the other - without it (with future OMP in mind). But when I use macro <code>__CUDA_ARCH__</code> it looks as if always the host code is executed. But I supposed that Thrust by default use CUDA (and branch for device code). What's wrong with my code?
  Here it is:</p>
  
  <pre><code>#include &lt;thrust/transform.h&gt;                                 
  #include &lt;thrust/functional.h&gt;                                
  #include &lt;thrust/iterator/counting_iterator.h&gt;                
  #include &lt;stdio.h&gt;                                            
  
  struct my_op                                                  
  {                                                             
      my_op(int init_const) : constanta(init_const) {}      
      __host__ __device__ int operator()(const int &amp;x) const
      {                                                     
          #if defined(__CUDA_ARCH__)                    
              return 2 * x * constanta;    // never executed - why?
          #else                                     
              return x * constanta;        // always executed                 
          #endif                       
      }                                                     
  
  private:                                                      
      int constanta;                                        
  };                                                            
  
  int main()                                                    
  {                                                             
   int data[7] = { 0, 0, 0, 0, 0, 0, 0 };                        
   thrust::counting_iterator&lt;int&gt; first(10);                     
   thrust::counting_iterator&lt;int&gt; last = first + 7;              
  
   int init_value = 1;                                           
   my_op op(init_value);                                         
  
   thrust::transform(first, last, data, op);                     
   for each (int el in data)                                     
      std::cout &lt;&lt; el &lt;&lt; " ";                               
  
   std::cout &lt;&lt; std::endl;                                       
  }                  
  </code></pre>
  
  <p>I expect that "transform" will define vector as multiplied by 2*constanta but I see that host code is used - the output is "10 11 12 13 14 15 16", not "20 22 24 26 28 30 32" (as expected).</p>
  
  <p>Why?</p>