Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New device type: kDLCPUShared #41

Open
jermainewang opened this issue Jun 10, 2019 · 4 comments
Open

New device type: kDLCPUShared #41

jermainewang opened this issue Jun 10, 2019 · 4 comments

Comments

@jermainewang
Copy link
Member

Similar to kDLCPUPinned, CPU shared memory is allocated and managed quite differently from normal CPU memory. In DGL, we use shared memory to store large graphs so it is quite common to see operation to copy data between CPU memory and shared memory. I guess we could also use the extension type to handle that, but want to bring up this issue to see whether it is better to have a type for that in DLPack.

cc @zheng-da

@tqchen
Copy link
Member

tqchen commented Jun 10, 2019

Can you elaborate what exactly CPU shared is? Is it a DRAM region? Any special support from OS?

@szha
Copy link
Member

szha commented Jun 10, 2019

I think this is referring for example /dev/shm on linux? It's often used in dataloader and multiprocessing for data pipelines

@jermainewang
Copy link
Member Author

The "shared memory" referred here is a RAM region created by one process that can be accessed by other processes. It is mainly used for inter-process communication or a shared data buffer .

One such scenario is on NUMA machine, we want to launch one process for each NUMA core. The processes might share some common data (in our case, a graph structure), so we put it in shared memory.

OS does have special support for shared memory. The most commonly used is the POSIX shared memory APIs: shm_open for create (or open an existing) shared memory buffer, shm_unlink to delete the buffer and so on. Also mmap can map files into memory so a file can also serve as a buffer.

@jermainewang
Copy link
Member Author

Ping to re-active this discussion. It it's hard to add another enum type, I wonder what's the best workaround? For shared memory, I could see two concerns.

  • Each shared memory region has a string name which is given when it is created. However, in current DLPack, the device id is only an integer. The problem could be solved by maintaining a singleton mapping from string name to an integer id outside of DLPack.
  • Shared memory has two different kinds of allocation/deallocation: create and open. Create initializes a new region while open just loads a created region. Again, I feel this could also be handled outside of DLPack.

Thus, I could see two technical routes:

  1. Reuse kDLCPU enum and use device_id for the shared memory name.
  2. Put kDLCPUShared as an extension type. I don't know exactly how this could be done but I do see a kDLExtDev enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants