title: CUDA: --ptxas-options=-v shared memory and cudaFuncAttributes.sharedSizeBytes do not match
body: <p>I'm trying to use <code>reqRegs</code> and <code>sharedSizeBytes</code> in the <code>cudaFuncAttributes</code> struct to dynamically optimise a kernel's block size at runtime. </p>
  
  <p>My current implementation skims the stdout text from <code>nvcc --ptxas-options=-v</code> to discover the register and shared memory usage of the kernel. This method is a little hacky, and is dependent on the exact format of output text from <code>--ptxas-options=-v</code>, which could change without warning. </p>
  
  <p>My problem is that I'm seeing a discrepancy between the 'smem' shared memory value reported in the <code>--ptxas-options=-v</code> output, and <code>sharedSizeBytes</code> in the <code>cudaFuncAttributes</code> struct, which has me worried that either the shared memory estimation I have been using until now is wrong, or that the <code>sharedSizeBytes</code> variable is unreliable, meaning I cannot use it for the purposes of runtime block size optimisation. 
  Here is the output of <code>nvcc --ptxas-options=-v</code> for one such kernel ...</p>
  
  <pre><code>ptxas info    : Used 14 registers, 2088 bytes smem, 48 bytes cmem[1]
  </code></pre>
  
  <p>... compared with the value of <code>cudaFuncAttributes.sharedSizeBytes</code> = 296 at runtime, for the exact same kernel. Does anybody know what could be happening here?</p>
  
  <p>Here is another example with a different kernel: </p>
  
  <pre><code>ptxas info    : Used 18 registers, 2132 bytes smem, 48 bytes cmem[1]
  </code></pre>
  
  <p>where <code>cudaFuncAttributes.sharedSizeBytes</code> = 340 at runtime. </p>
  
  <p>Thanks.</p>