-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathipc_utils.h
More file actions
67 lines (54 loc) · 2.02 KB
/
ipc_utils.h
File metadata and controls
67 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// clang-format off
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*/
// clang-format on
#pragma once
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
namespace nvfuser {
// Helper functions for serializing data to bytes for TCP store
template <typename T>
std::vector<uint8_t> toBytes(const T& data) {
return std::vector<uint8_t>(
reinterpret_cast<const uint8_t*>(&data),
reinterpret_cast<const uint8_t*>(&data) + sizeof(T));
}
template <typename T>
const T& fromBytes(const std::vector<uint8_t>& bytes) {
return *reinterpret_cast<const T*>(bytes.data());
}
// IPC Utils for sharing file descriptors
enum class MulticastProtocol { Memcpy, Multimem, BatchMemcpy };
MulticastProtocol getMulticastProtocol();
// Backend for symmetric memory allocation and rendezvous.
// Native: Fuser's own CUDA VMM + IPC implementation (default, maintained).
// PyTorch*: Use PyTorch's symmetric memory (torch.distributed._symmetric_memory)
// with the given transport backend (Nccl, Nvshmem, or Cuda).
enum class SymmetricMemoryBackend {
Native,
PyTorchNccl,
PyTorchNvshmem,
PyTorchCuda,
};
SymmetricMemoryBackend getSymmetricMemoryBackend();
// Creates a listening Unix domain socket bound to path.
// If path starts with '@', it uses the abstract namespace (replaced with \0).
// Returns the socket file descriptor.
int createIpcSocket(const std::string& path);
// Connects to the Unix domain socket at path and sends the file descriptor fd.
// Optionally sends header_data of size header_len along with the FD.
void sendFd(
const std::string& path,
int fd,
const void* header_data = nullptr,
size_t header_len = 0);
// Accepts a connection on the listening socket_fd and receives a file
// descriptor. Optionally receives header_data of size header_len. Returns the
// received file descriptor.
int recvFd(int socket_fd, void* header_data = nullptr, size_t header_len = 0);
} // namespace nvfuser