Forked vladmnih's version of cudamat.