cuda-python icon indicating copy to clipboard operation
cuda-python copied to clipboard

Support IPC handle in `cuda.core`

Open leofang opened this issue 1 year ago • 4 comments

leofang avatar Sep 11 '24 22:09 leofang

Tentatively assign to myself to complete the design.

leofang avatar Sep 19 '24 02:09 leofang

need to decide if we want to commit to it, this seems a lot harder than I thought:

  • https://developer.nvidia.com/blog/introducing-low-level-gpu-virtual-memory-management/
  • https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__VA.html

leofang avatar Jan 16 '25 20:01 leofang

[CUresult](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1gc6c391505e117393cc2558fff6bfc2e9) [cuIpcCloseMemHandle](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1gd6f5d5bcf6376c6853b64635b0157b9e) ( [CUdeviceptr](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1g183f7b0d8ad008ea2a5fd552537ace4e) dptr )
Attempts to close memory mapped with cuIpcOpenMemHandle.
[CUresult](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1gc6c391505e117393cc2558fff6bfc2e9) [cuIpcGetEventHandle](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1gea02eadd12483de5305878b13288a86c) ( [CUipcEventHandle](https://docs.nvidia.com/cuda/cuda-driver-api/structCUipcEventHandle__v1.html#structCUipcEventHandle__v1)* pHandle, [CUevent](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1g6d740185cf0953636d4ae37f68d7559b) event )
Gets an interprocess handle for a previously allocated event.
[CUresult](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1gc6c391505e117393cc2558fff6bfc2e9) [cuIpcGetMemHandle](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1g6f1b5be767b275f016523b2ac49ebec1) ( [CUipcMemHandle](https://docs.nvidia.com/cuda/cuda-driver-api/structCUipcMemHandle__v1.html#structCUipcMemHandle__v1)* pHandle, [CUdeviceptr](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1g183f7b0d8ad008ea2a5fd552537ace4e) dptr )
Gets an interprocess memory handle for an existing device memory allocation.
[CUresult](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1gc6c391505e117393cc2558fff6bfc2e9) [cuIpcOpenEventHandle](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1gf1d525918b6c643b99ca8c8e42e36c2e) ( [CUevent](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1g6d740185cf0953636d4ae37f68d7559b)* phEvent, [CUipcEventHandle](https://docs.nvidia.com/cuda/cuda-driver-api/structCUipcEventHandle__v1.html#structCUipcEventHandle__v1) handle )
Opens an interprocess event handle for use in the current process.
[CUresult](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1gc6c391505e117393cc2558fff6bfc2e9) [cuIpcOpenMemHandle](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1ga8bd126fcff919a0c996b7640f197b79) ( [CUdeviceptr](https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1g183f7b0d8ad008ea2a5fd552537ace4e)* pdptr, [CUipcMemHandle](https://docs.nvidia.com/cuda/cuda-driver-api/structCUipcMemHandle__v1.html#structCUipcMemHandle__v1) handle, unsigned int  Flags )
Opens an interprocess memory handle exported from another process and returns a device pointer usable in the local process.

leofang avatar Jan 16 '25 20:01 leofang

Per discussion with Raphael:

We should avoid using the legacy IPC handle API for 2 reasons: - It is not secure - on Windows, it is not performant because a copy of the block is made at allocation time

We should instead use mempool create with IPC enabled. Some considerations / requirements are: - user must provide a size argument at creation time for the mempool for windows IPC

I will look into the best way to fit this into the existing object model.

keenan-simpson avatar Feb 04 '25 18:02 keenan-simpson

@leofang

is CUDA IPC communication currently possible? I'm using cu.cuIpcGetMemHandle, and while it seems like it should take two parameters, passing two results in the following error:

TypeError: cuIpcGetMemHandle() takes exactly 1 positional argument (2 given)

kimud6003 avatar Jul 18 '25 07:07 kimud6003

Hi @kimud6003, sorry that your question fell through the cracks. The cuIpcGetMemHandle API from the driver module takes only 1 argument: https://nvidia.github.io/cuda-python/cuda-bindings/latest/module/driver.html#cuda.bindings.driver.cuIpcGetMemHandle I believe the confusion comes from the fact that we perform aggressive argument transform in cuda.bindings, so unlike the raw C APIs the output-only args are returned directly as part of the return value.

This issue is not about cuda.bindings, though. It's about pythonic exposure of IPC support in cuda.core, and very soon we'll enable it for Linux users 🙂

leofang avatar Sep 26 '25 02:09 leofang