-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathconnection.hpp
More file actions
117 lines (88 loc) · 3.72 KB
/
connection.hpp
File metadata and controls
117 lines (88 loc) · 3.72 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#ifndef MSCCLPP_CONNECTION_HPP_
#define MSCCLPP_CONNECTION_HPP_
#include <mscclpp/core.hpp>
#include <mscclpp/gpu_utils.hpp>
#include "communicator.hpp"
#include "context.hpp"
#include "ib.hpp"
#include "registered_memory.hpp"
#include "socket.h"
namespace mscclpp {
class ConnectionFactory {
private:
using ConnectionCreator = std::function<std::shared_ptr<Connection>(std::shared_ptr<Context>, Endpoint, Endpoint)>;
static std::unordered_map<std::string, ConnectionCreator>& getRegistry() {
static std::unordered_map<std::string, ConnectionCreator> registry;
return registry;
}
public:
static void registerConnection(const std::string& connName, ConnectionCreator creator) {
getRegistry()[connName] = creator;
}
static std::shared_ptr<Connection> createConnection(const std::string& connName, std::shared_ptr<Context> context,
Endpoint localEndpoint, Endpoint remoteEndpoint) {
auto& registry = getRegistry();
auto it = registry.find(connName);
if (it != registry.end()) {
return it->second(context, localEndpoint, remoteEndpoint);
}
throw std::runtime_error("Unknown connection type: " + connName);
}
};
class CudaIpcConnection : public Connection {
private:
std::shared_ptr<CudaIpcStream> stream_;
public:
CudaIpcConnection(std::shared_ptr<Context> context, Endpoint localEndpoint, Endpoint remoteEndpoint,
std::shared_ptr<CudaIpcStream> stream);
Transport transport() const override;
Transport remoteTransport() const override;
void write(RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset,
uint64_t size) override;
void updateAndSync(RegisteredMemory dst, uint64_t dstOffset, uint64_t* src, uint64_t newValue) override;
void flush(int64_t timeoutUsec) override;
};
class IBConnection : public Connection {
private:
Transport transport_;
Transport remoteTransport_;
IbQp* qp_;
std::unique_ptr<uint64_t> dummyAtomicSource_; // not used anywhere but IB needs a source
RegisteredMemory dummyAtomicSourceMem_;
mscclpp::TransportInfo dstTransportInfo_;
public:
IBConnection(std::shared_ptr<Context> context, Endpoint localEndpoint, Endpoint remoteEndpoint);
Transport transport() const override;
Transport remoteTransport() const override;
void write(RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset,
uint64_t size) override;
void updateAndSync(RegisteredMemory dst, uint64_t dstOffset, uint64_t* src, uint64_t newValue) override;
void flush(int64_t timeoutUsec) override;
};
class EthernetConnection : public Connection {
private:
std::unique_ptr<Socket> sendSocket_;
std::unique_ptr<Socket> recvSocket_;
std::thread threadRecvMessages_;
volatile uint32_t* abortFlag_;
const uint64_t sendBufferSize_;
const uint64_t recvBufferSize_;
std::vector<char> sendBuffer_;
std::vector<char> recvBuffer_;
void recvMessages();
void sendMessage();
public:
EthernetConnection(std::shared_ptr<Context> context, Endpoint localEndpoint, Endpoint remoteEndpoint,
uint64_t sendBufferSize = 256 * 1024 * 1024, uint64_t recvBufferSize = 256 * 1024 * 1024);
~EthernetConnection();
Transport transport() const override;
Transport remoteTransport() const override;
void write(RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset,
uint64_t size) override;
void updateAndSync(RegisteredMemory dst, uint64_t dstOffset, uint64_t* src, uint64_t newValue) override;
void flush(int64_t timeoutUsec) override;
};
} // namespace mscclpp
#endif // MSCCLPP_CONNECTION_HPP_