Allocate a symmetric multicast (multimem) buffer over single-node NVLink. Returns the local tensor for this rank plus a :class:`MulticastHandle` that exposes the multicast pointer and the per-rank buffer pointers needed by the fused allreduce kernels. No NVSHMEM dependency.
(
multicomm,
*size: Any,
dtype: Optional[torch.dtype] = None,
device: Optional[torch.device] = None,
)
| 162 | |
| 163 | |
| 164 | def empty_multimem( |
| 165 | multicomm, |
| 166 | *size: Any, |
| 167 | dtype: Optional[torch.dtype] = None, |
| 168 | device: Optional[torch.device] = None, |
| 169 | ) -> Tuple[torch.Tensor, MulticastHandle]: |
| 170 | """Allocate a symmetric multicast (multimem) buffer over single-node NVLink. |
| 171 | |
| 172 | Returns the local tensor for this rank plus a :class:`MulticastHandle` that |
| 173 | exposes the multicast pointer and the per-rank buffer pointers needed by the |
| 174 | fused allreduce kernels. No NVSHMEM dependency. |
| 175 | """ |
| 176 | if len(size) == 1 and isinstance(size[0], Sequence): |
| 177 | size = tuple(size[0]) |
| 178 | else: |
| 179 | size = tuple(size) |
| 180 | |
| 181 | if dtype is None: |
| 182 | dtype = torch.get_default_dtype() |
| 183 | |
| 184 | if device is None: |
| 185 | device = torch.get_default_device() |
| 186 | |
| 187 | def device_to_num(device): |
| 188 | if device.type == "cuda": |
| 189 | return device.index if device.index is not None else 0 |
| 190 | else: |
| 191 | return -1 |
| 192 | |
| 193 | assert device_to_num(device) == multicomm.GetDeviceId(), ( |
| 194 | f"device(got {device_to_num(device)}) of alloc buffer must be same with " |
| 195 | f"multicomm(got {multicomm.GetDeviceId()})" |
| 196 | ) |
| 197 | |
| 198 | hdl = MulticastHandle(multicomm, size, dtype) |
| 199 | |
| 200 | return hdl.get_buffer(hdl.rank, size, dtype=dtype), hdl |
nothing calls this directly
no test coverage detected