title: Can __shared__ variables be encapsulated in __device__ __host__ functions?
body: <p>I would like to encapsulate the following cuda code:</p>
  
  <pre><code>__device__ __host__ 
  void myFunction()
  {
  #ifdef __CUDA_ARCH__
      __shared__ float sharedVar[3];
  #else
      float sharedVar[3];
  #endif
  
      ...
  }
  </code></pre>
  
  <p>into something more streamlined such as:</p>
  
  <pre><code>__device__ __host__ 
  void myFunction()
  {
      SHARED_MEMORY float sharedVar[3];
      ...
  }
  </code></pre>
  
  <p>Where SHARED_MEMORY evaluates to __shared__ if __CUDA_ARCH__ is defined, or nothing otherwise.  The following is the obvious approach:</p>
  
  <pre><code>#define SHARED_MEMORY \
  #ifdef __CUDA_ARCH__ \
      __shared__ \
  #endif
  </code></pre>
  
  <p>However, this doesn't compile because other c-preprocessor directives can not be used in a macro.  Is there any way to encapsulate this code?</p>