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.
Oh, one of the reasons I brought this up is because I think there are some problems mixing cpu memory and gpu memory in this branch, e.g. here:

https://github.com/kloudkl/caffe/blob/math_functions_wrapper/src/caffe/layers/conv_layer.cpp#L104

You did a good job handling this, @kloudkl, for `Blob` objects with the `const_data()`, etc. functions, but I think we'd need to write similar functions for the `SyncedMemory` class (and possibly others?).

The problem I noticed though was that in your `Blob` data functions, the decision about what pointer to return (cpu or gpu) is made based on the *current* mode of operation (i.e. gotten with `Caffe::mode()`), but, e.g. in a layer's `Forward()` and `Backward()` functions, the decision about which device is used to process the data at that pointer is made based on the mode of operation that was current *when the layer was instantiated*, which could be different that the current mode if `Caffe::set_mode()` was called after the layer was instantiated.

If this happens, you could end up passing a cpu pointer to a gpu device function or vice versa.  I think this is what was causing the nasty crashes and bus errors I commented on here yesterday (which I believe stemmed specifically from the code line I noted above, though there, the cpu data is being explicitly fetched always, regardless of which device is being used).

This problem could be mostly fixed by determining the device/mode immediately before getting device-specific pointers and passing them off to device-specific functions (and I say "mostly" because it'd still be possible to cause problems by calling `Caffe::set_mode()` in a different thread between when the device-specific pointers are gotten and when they are passed off to device-specific functions, though if I understand correctly, this is not a concern here).  This would entail not making the device a member of the layer class.