CuDNN and matcaffe support

Contains:
* Enable CuDNN for Ubuntu 14.04 `Makefile.config`
* Cherry-picked fixes from https://github.com/BVLC/caffe/pull/1310 to allow building matcaffe on OS X