Unify the CPU, CUDA and OpenCL math functions API in the device wrapper classes

This PR wraps the math functions as suggested by both [Yangqing](https://github.com/BVLC/caffe/issues/382#issuecomment-42465152) in #382 and [jeffdonahue](https://github.com/BVLC/caffe/issues/408#issuecomment-43035934) in #408 to abstract the device type from the algorithms.
In contrast to my earlier comment, fetching the device on the fly according to the mode at the time of the computation is the right choice. Setting the mode should be a method of Net instead of a function of the global Caffe singleton. Further, each layer should have its own mode flag (the Net set mode method suggested would just be a convenience to set all the layers' modes).