Fix memory pool implementation
Fix memory pool implementation

Summary:
The memory pool implementation was written back in the days when I only had
one GPU, and as a result I overlooked the fact that:

(1) CNMEM needs to have the same current device for the allocation and
deallocation to take place correctly.
(2) cub needs the device id of the pointer passed in for proper deallocation.

As a result, since C2 right now switches contexts very frequently, I added a
global map to keep record of the pointer affiliations, and use that for
deallocation when we are at another context.

I have not tested the speed but assuming that std::unordered_map is not too bad
this should be fairly fast.

Differential Revision: D4617300

fbshipit-source-id: e8bb366616cd93504e7d68b7f999011cd49caba5

davinwang/caffe2,pietern/caffe2,davinwang/caffe2,Yangqing/caffe2,xzturn/caffe2,bwasti/caffe2,davinwang/caffe2,sf-wind/caffe2,davinwang/caffe2,pietern/caffe2,Yangqing/caffe2,davinwang/caffe2,xzturn/caffe2,pietern/caffe2,bwasti/caffe2,sf-wind/caffe2,xzturn/caffe2,Yangqing/caffe2,pietern/caffe2,caffe2/caffe2,sf-wind/caffe2,pietern/caffe2,sf-wind/caffe2,sf-wind/caffe2,Yangqing/caffe2,bwasti/caffe2,xzturn/caffe2,bwasti/caffe2,Yangqing/caffe2,xzturn/caffe2,bwasti/caffe2