File indexing completed on 2025-01-30 10:10:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <chrono>
0012 #include <cstddef>
0013 #include <cstdint>
0014 #include <limits>
0015 #include <vector>
0016
0017 namespace gloo {
0018 namespace transport {
0019
0020 constexpr auto kUnsetTimeout = std::chrono::milliseconds(-1);
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 class UnboundBuffer {
0033 public:
0034 UnboundBuffer(void* ptr, size_t size) : ptr(ptr), size(size) {}
0035 virtual ~UnboundBuffer() = 0;
0036
0037 void* const ptr;
0038 const size_t size;
0039
0040
0041
0042 virtual bool waitRecv(int* rank, std::chrono::milliseconds timeout) = 0;
0043
0044
0045
0046 virtual bool waitSend(int* rank, std::chrono::milliseconds timeout) = 0;
0047
0048
0049 virtual void abortWaitRecv() = 0;
0050
0051
0052 virtual void abortWaitSend() = 0;
0053
0054
0055 bool waitRecv() {
0056 return waitRecv(nullptr, kUnsetTimeout);
0057 }
0058
0059
0060 bool waitSend() {
0061 return waitSend(nullptr, kUnsetTimeout);
0062 }
0063
0064
0065 bool waitRecv(int* rank) {
0066 return waitRecv(rank, kUnsetTimeout);
0067 }
0068
0069
0070 bool waitSend(int* rank) {
0071 return waitSend(rank, kUnsetTimeout);
0072 }
0073
0074
0075 bool waitRecv(std::chrono::milliseconds timeout) {
0076 return waitRecv(nullptr, timeout);
0077 }
0078
0079
0080 bool waitSend(std::chrono::milliseconds timeout) {
0081 return waitSend(nullptr, timeout);
0082 }
0083
0084
0085 template <typename clock>
0086 bool waitRecv(std::chrono::time_point<clock> deadline) {
0087 return waitRecv(std::chrono::duration_cast<std::chrono::milliseconds>(
0088 deadline - clock::now()));
0089 }
0090
0091
0092 template <typename clock>
0093 bool waitSend(std::chrono::time_point<clock> deadline) {
0094 return waitSend(std::chrono::duration_cast<std::chrono::milliseconds>(
0095 deadline - clock::now()));
0096 }
0097
0098
0099
0100
0101 static constexpr auto kUnspecifiedByteCount = std::numeric_limits<size_t>::max();
0102
0103 virtual void send(
0104 int dstRank,
0105 uint64_t slot,
0106 size_t offset = 0,
0107 size_t nbytes = kUnspecifiedByteCount) = 0;
0108
0109 virtual void recv(
0110 int srcRank,
0111 uint64_t slot,
0112 size_t offset = 0,
0113 size_t nbytes = kUnspecifiedByteCount) = 0;
0114
0115 virtual void recv(
0116 std::vector<int> srcRanks,
0117 uint64_t slot,
0118 size_t offset = 0,
0119 size_t nbytes = kUnspecifiedByteCount) = 0;
0120 };
0121
0122 }
0123 }