Fix computations and improve memory usage

Fix a few bugs in the computations performed by the program
(especially with the CUBLAS functions calls) and in function
declarations. Also, improved the memory usage both for the host
and for the device. New version works properly for any arbitrary
subset of the training set.
Fix bug that causes memory problems