cudamat/cudamat — pull request #2 by f0k (2013-08-22 18:21:21+00:00)
Title: Replace kernels for add_row and add_col by a dot product call

When working with a centered DBM, I noticed that a large fraction of computation time was spent in add_col_vec. I replaced it with a dot product, improving speed quite a bit.
Now when I benchmarked the change again, it seems to be dependent on the matrix size (or shape?) whether it gives an improvement or not. The following benchmarks the speed in ipython:
```python
import cudamat as cmt
cmt.init()
cmt.CUDAMatrix.init_random()
X = cmt.empty((400, 256)).fill_with_randn()
Y = cmt.empty(X.shape)
col = cmt.empty((X.shape[0], 1)).fill_with_randn()
row = cmt.empty((1, X.shape[1])).fill_with_randn()
%timeit X.add_col_vec(col, target=Y)
%timeit X.add_col_mult(col, mult=2, target=Y)
%timeit X.add_row_vec(row, target=Y)
```
With this shape, the dot product is faster than the old kernel, but for a 4096x512 matrix the dot product is slower -- either because the matrix is larger, or because it is more nicely aligned. This needs some more benchmarking, maybe we could select the code path dynamically depending on the matrix shape, or decide that it's not that important after all.