title: Sum over an axis using matrix multiplication
body: <p>Given a 4D matrix A of shape NxCxHxW, I want to calculate 4D matrix B of shape Nx1xHxW where b is the sum of a over the 2nd dimension.</p>
  
  <pre><code>for n in range(N):
    for h in range(H):
      for w in range(W):
        b[n][0][h][w] = 0
        for c in range(C):
          b[n][0][h][w] += a[n][c][h][w]
  </code></pre>
  
  <p>Since the code is on GPU, I can only use the 4D matrix multiplication function gemm, i.e. B = A * C. What should be the matrix C?</p>