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.
> I think this is what was causing the nasty crashes and bus errors I commented on here yesterday

Yes, bus errors result from handing GPU pointers to CPU code and vice-versa since these addresses are invalid on the host or device respectively.

With regards to the mode, the need to switch back and forth between GPU and CPU seems doubtful. Perhaps the design would be simplest if `device` belonged to `Net` and was set at construction or initialized explicitly for the net making it the same for all layers.

@Yangqing @jeffdonahue thoughts?