title: Efficient method to check for matrix stability in CUDA
body: <p>A number of algorithms iterate until a certain convergence criterion is reached (e.g. stability of a particular matrix). In many cases, one CUDA kernel must be launched per iteration. My question is: how then does one efficiently and accurately determine whether a matrix has changed over the course of the last kernel call? Here are three possibilities which seem equally unsatisfying:</p>
  
  <ul>
  <li>Writing a global flag each time the matrix is modified inside the kernel. This works, but is highly inefficient and is not technically thread safe.</li>
  <li>Using atomic operations to do the same as above. Again, this seems inefficient since in the worst case scenario one global write per thread occurs.</li>
  <li>Using a reduction kernel to compute some parameter of the matrix (e.g. sum, mean, variance). This might be faster in some cases, but still seems like overkill. Also, it is possible to dream up cases where a matrix has changed but the sum/mean/variance haven't (e.g. two elements are swapped).</li>
  </ul>
  
  <p>Is there any of the three options above, or an alternative, that is considered best practice and/or is generally more efficient?</p>