title: Calculate squared Euclidean distance matrix on GPU
body: <p>Let <code>p</code> be a matrix of first set of locations where each row gives the coordinates of a particular point. Similarly, let <code>q</code> be a matrix of second set of locations where each row gives the coordinates of a particular point. </p>
  
  <p>Then formula for pairwise squared Euclidean distance is:</p>
  
  <pre><code>k(i,j) = (p(i,:) - q(j,:))*(p(i,:) - q(j,:))', 
  </code></pre>
  
  <p>where <code>p(i,:)</code> denotes <code>i</code>-th row of matrix <code>p</code>, and <code>p'</code> denotes the transpose of <code>p</code>.</p>
  
  <p>I would like to compute matrix <code>k</code> on CUDA-enabled GPU (NVidia Tesla) in C++. I have OpenCV v.2.4.1 with GPU support but I'm open to other alternatives, like Thrust library. However, I'm not too familiar with GPU programming. Can you suggest an efficient way to accomplish this task? What C++ libraries should I use? </p>