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.
If we still rely on the singleton Caffe to set and get the mode, which of the following two decisions do you prefer? First, locking the net and all of its layers in the same mode when instantiated. Second, fetching the device on the fly depending on the current mode?