Utils.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. #pragma once
  2. #include <ATen/ATen.h>
  3. #include <c10/util/accumulate.h>
  4. #include <c10/util/irange.h>
  5. #include <c10d/Types.hpp>
  6. #ifdef _WIN32
  7. #include <winsock2.h>
  8. #include <ws2tcpip.h>
  9. typedef SSIZE_T ssize_t;
  10. #pragma comment(lib, "Ws2_32.lib")
  11. #else
  12. #include <fcntl.h>
  13. #include <netdb.h>
  14. #include <sys/poll.h>
  15. #include <sys/socket.h>
  16. #include <unistd.h>
  17. #endif
  18. #include <sys/types.h>
  19. #include <chrono>
  20. #include <cstdint>
  21. #include <cstdlib>
  22. #include <functional>
  23. #include <limits>
  24. #include <string>
  25. #include <system_error>
  26. #include <tuple>
  27. #include <vector>
  28. namespace c10d {
  29. TORCH_API std::string parse_env(const char* env_var_name);
  30. // Retrieve tensor shapes from a given tensor.
  31. TORCH_API std::vector<at::Tensor> getTensorShapes(const std::vector<at::Tensor>& tensors);
  32. // Turns at::IntArrayRef into "(1, 2, 3, 4)".
  33. inline std::string toString(at::IntArrayRef l) {
  34. std::stringstream ss;
  35. ss << "(";
  36. for (const auto i : c10::irange(l.size())) {
  37. if (i > 0) {
  38. ss << ", ";
  39. }
  40. ss << l[i];
  41. }
  42. ss << ")";
  43. return ss.str();
  44. }
  45. inline std::string toString(const c10::Layout& layout) {
  46. std::stringstream ss;
  47. ss << layout;
  48. return ss.str();
  49. }
  50. inline void assertSameType(
  51. const at::DeprecatedTypeProperties& type,
  52. const std::vector<at::Tensor>& tensors) {
  53. for (const auto i : c10::irange(tensors.size())) {
  54. if (!tensors[i].options().type_equal(type.options())) {
  55. const std::string expected = type.toString();
  56. const std::string actual = tensors[i].toString();
  57. throw std::invalid_argument(
  58. "mixed types (" + expected + " and " + actual + ")");
  59. }
  60. }
  61. }
  62. inline bool parseEnvVarFlag(const char* envVarName) {
  63. char* stringValue = std::getenv(envVarName);
  64. if (stringValue != nullptr) {
  65. int val;
  66. try {
  67. val = std::stoi(stringValue);
  68. } catch (std::exception& e) {
  69. TORCH_CHECK(false,
  70. "Invalid value for environment variable: " + std::string(envVarName));
  71. }
  72. if (val == 1) {
  73. return true;
  74. } else if (val == 0) {
  75. return false;
  76. } else {
  77. TORCH_CHECK(false,
  78. "Invalid value for environment variable: " + std::string(envVarName));
  79. }
  80. }
  81. return false;
  82. }
  83. inline void assertSameSizes(
  84. const at::IntArrayRef& sizes,
  85. const std::vector<at::Tensor>& tensors) {
  86. for (const auto i : c10::irange(tensors.size())) {
  87. if (!tensors[i].sizes().equals(sizes)) {
  88. const auto expected = toString(sizes);
  89. const auto actual = toString(tensors[i].sizes());
  90. throw std::invalid_argument(
  91. "mixed sizes (" + expected + " and " + actual + ")");
  92. }
  93. }
  94. }
  95. inline void assertSameSizeAndType(const std::vector<at::Tensor>& tensors) {
  96. // Ensure we have at least one tensor
  97. if (tensors.size() == 0) {
  98. throw std::invalid_argument("argument is empty");
  99. }
  100. // Ensure all tensors have identical type and shape
  101. auto options = tensors[0].options();
  102. auto sizes = tensors[0].sizes();
  103. for (const auto i : c10::irange(1, tensors.size())) {
  104. if (!tensors[i].options().type_equal(options)) {
  105. const auto expected = toString(options);
  106. const auto actual = toString(tensors[i].options());
  107. throw std::invalid_argument(
  108. "argument contains mixed types (" + expected + " and " + actual +
  109. ")");
  110. }
  111. if (!tensors[i].sizes().equals(sizes)) {
  112. const auto expected = toString(sizes);
  113. const auto actual = toString(tensors[i].sizes());
  114. throw std::invalid_argument(
  115. "argument contains mixed sizes (" + expected + " and " + actual +
  116. ")");
  117. }
  118. }
  119. }
  120. inline void assertTypeMatch(
  121. std::function<void(const std::string&)> fn,
  122. const at::DeprecatedTypeProperties& type,
  123. const at::ArrayRef<at::Tensor> tensors,
  124. size_t index) {
  125. if (!tensors[index].options().type_equal(type.options())) {
  126. fn("invalid tensor type at index " + std::to_string(index) + " (expected " +
  127. type.toString() + ", got " + tensors[index].toString() + ")");
  128. }
  129. }
  130. inline void assertTypeMatch(
  131. std::function<void(const std::string&)> fn,
  132. const at::TensorOptions& options,
  133. const at::ArrayRef<at::Tensor> tensors,
  134. size_t index) {
  135. if (!tensors[index].options().type_equal(options)) {
  136. fn("invalid tensor type at index " + std::to_string(index) + " (expected " +
  137. toString(options) + ", got " + toString(tensors[index].options()) + ")");
  138. }
  139. }
  140. inline void assertSizesMatch(
  141. std::function<void(const std::string&)> fn,
  142. const at::IntArrayRef& sizes,
  143. const at::ArrayRef<at::Tensor> tensors,
  144. size_t index) {
  145. if (tensors[index].sizes() != sizes) {
  146. fn("invalid tensor size at index " + std::to_string(index) + " (expected " +
  147. toString(sizes) + ", got " + toString(tensors[index].sizes()) + ")");
  148. }
  149. }
  150. inline void assertLayoutMatch(
  151. std::function<void(const std::string&)> fn,
  152. const c10::Layout& expected,
  153. const at::ArrayRef<at::Tensor> tensors,
  154. size_t index) {
  155. const auto& actual = tensors[index].layout();
  156. if (actual != expected) {
  157. fn("invalid tensor layout at index " + std::to_string(index) +
  158. " (expected " + toString(expected) + ", got " + toString(actual) + ")");
  159. }
  160. }
  161. inline void assertLayoutMatch(
  162. std::function<void(const std::string&)> fn,
  163. const at::ArrayRef<at::Tensor> tensors) {
  164. const auto& layout = tensors[0].layout();
  165. for (const auto i : c10::irange(1, tensors.size())) {
  166. assertLayoutMatch(fn, layout, tensors, i);
  167. }
  168. }
  169. inline void assertNonEmpty(
  170. std::function<void(const std::string&)> fn,
  171. const at::ArrayRef<at::Tensor> tensors) {
  172. if (tensors.size() == 0) {
  173. fn("requires non-empty tensor list");
  174. }
  175. }
  176. inline void assertSingleElement(
  177. std::function<void(const std::string&)> fn,
  178. const at::ArrayRef<at::Tensor> tensors) {
  179. if (tensors.size() != 1) {
  180. fn("requires a single-element tensor list");
  181. }
  182. }
  183. inline void assertSingleElementInput(
  184. std::function<void(const std::string&)> fn,
  185. const at::ArrayRef<at::Tensor> tensors) {
  186. if (tensors.size() != 1) {
  187. fn("requires a single-element input tensor list");
  188. }
  189. }
  190. inline void assertSingleElementOutput(
  191. std::function<void(const std::string&)> fn,
  192. const at::ArrayRef<at::Tensor> tensors) {
  193. if (tensors.size() != 1) {
  194. fn("requires a single-element output tensor list");
  195. }
  196. }
  197. inline void assertRootRank(
  198. std::function<void(const std::string&)> fn,
  199. int rank,
  200. int size) {
  201. if (rank < 0 || rank >= size) {
  202. fn("invalid root rank: " + std::to_string(rank));
  203. }
  204. }
  205. inline void assertRootTensor(
  206. std::function<void(const std::string&)> fn,
  207. int rank,
  208. int size) {
  209. if (rank < 0 || rank >= size) {
  210. fn("invalid root tensor: " + std::to_string(rank));
  211. }
  212. }
  213. inline void assertDense(
  214. std::function<void(const std::string&)> fn,
  215. const at::ArrayRef<at::Tensor> tensors) {
  216. const auto& layout = tensors[0].layout();
  217. if (layout != at::kStrided) {
  218. fn("only supports dense tensors");
  219. }
  220. }
  221. inline void assertCPU(
  222. std::function<void(const std::string&)> fn,
  223. const at::ArrayRef<at::Tensor> tensors) {
  224. const auto& device = tensors[0].device();
  225. if (device.type() != at::kCPU) {
  226. fn("only supports CPU tensors");
  227. }
  228. }
  229. inline void assertSameDevice(
  230. std::function<void(const std::string&)> fn,
  231. const at::ArrayRef<at::Tensor> tensors) {
  232. if (tensors.size() < 2) {
  233. return;
  234. }
  235. const auto& device = tensors[0].device();
  236. for (const auto i : c10::irange(1, tensors.size())) {
  237. if (tensors[i].device() != device) {
  238. fn("tensors should be on the same device");
  239. }
  240. }
  241. }
  242. inline void assertTypeAndSizesMatch(
  243. std::function<void(const std::string&)> fn,
  244. const at::ArrayRef<at::Tensor> tensors,
  245. const at::DeprecatedTypeProperties& type,
  246. const at::IntArrayRef& sizes) {
  247. for (const auto i : c10::irange(tensors.size())) {
  248. assertTypeMatch(fn, type, tensors, i);
  249. assertSizesMatch(fn, sizes, tensors, i);
  250. }
  251. }
  252. inline void assertTypeAndSizesMatch(
  253. std::function<void(const std::string&)> fn,
  254. const at::ArrayRef<at::Tensor> tensors,
  255. const at::TensorOptions& options,
  256. const at::IntArrayRef& sizes) {
  257. for (const auto i : c10::irange(tensors.size())) {
  258. assertTypeMatch(fn, options, tensors, i);
  259. assertSizesMatch(fn, sizes, tensors, i);
  260. }
  261. }
  262. inline void assertTypeAndSizesMatch(
  263. std::function<void(const std::string&)> fn,
  264. const at::ArrayRef<at::Tensor> tensors) {
  265. const auto& options = tensors[0].options();
  266. const auto sizes = tensors[0].sizes();
  267. assertTypeAndSizesMatch(fn, tensors.slice(1), options, sizes);
  268. }
  269. // Copied from ATen/core/functional.h.
  270. template <typename F, typename T>
  271. inline auto fmap(T& inputs, const F& fn)
  272. -> std::vector<decltype(fn(*inputs.begin()))> {
  273. std::vector<decltype(fn(*inputs.begin()))> r;
  274. r.reserve(inputs.size());
  275. for (auto& input : inputs) {
  276. r.push_back(fn(input));
  277. }
  278. return r;
  279. }
  280. // Copied from torch/csrc/utils/tensor_flatten.h.
  281. inline at::Tensor flattenDenseTensors(at::TensorList tensors) {
  282. static const auto flatten = [](const at::Tensor& t) {
  283. return t.contiguous().view({-1});
  284. };
  285. if (tensors.size() == 1) {
  286. return flatten(tensors[0]);
  287. }
  288. return at::cat(::c10d::fmap(tensors, flatten));
  289. }
  290. inline at::Tensor newLikeFlat(
  291. std::vector<std::vector<at::Tensor>>& tensors,
  292. size_t deviceIdx) {
  293. if (tensors.size() == 0 || tensors[0].size() == 0) {
  294. TORCH_CHECK(false, "Received an empty list");
  295. }
  296. if (deviceIdx >= tensors.size()) {
  297. TORCH_CHECK(false, "Invalid device index");
  298. }
  299. auto& t = tensors[deviceIdx][0];
  300. auto device = t.device();
  301. for (const auto i : c10::irange(1, tensors[deviceIdx].size())) {
  302. if (tensors[deviceIdx][i].device() != device) {
  303. TORCH_CHECK(false, "Expecting all tensors on the same device");
  304. }
  305. }
  306. at::DeviceGuard gpuGuard(device);
  307. std::vector<int64_t> sizes{static_cast<int64_t>(tensors[deviceIdx].size())};
  308. std::vector<int64_t> strides{static_cast<int64_t>(t.numel())};
  309. sizes.insert(sizes.end(), t.sizes().begin(), t.sizes().end());
  310. strides.insert(strides.end(), t.strides().begin(), t.strides().end());
  311. return at::empty_strided(
  312. sizes, strides, t.options().memory_format(c10::nullopt));
  313. }
  314. inline at::Tensor newLikeFlat(std::vector<at::Tensor>& tensors) {
  315. if (tensors.size() == 0) {
  316. TORCH_CHECK(false, "Received an empty list");
  317. }
  318. auto& t = tensors[0];
  319. at::DeviceGuard gpuGuard(t.device());
  320. std::vector<int64_t> sizes{static_cast<int64_t>(tensors.size())};
  321. sizes.insert(sizes.end(), t.sizes().begin(), t.sizes().end());
  322. return at::empty(sizes, t.options());
  323. }
  324. inline std::vector<std::vector<int64_t>> getSizes(
  325. const std::vector<at::Tensor>& tensors) {
  326. std::vector<std::vector<int64_t>> sizes(tensors.size());
  327. for (const auto i : c10::irange(tensors.size())) {
  328. sizes[i] = tensors[i].sizes().vec();
  329. }
  330. return sizes;
  331. }
  332. inline std::vector<int> getDevices(const std::vector<at::Tensor>& tensors) {
  333. std::vector<int> devices(tensors.size(), -1);
  334. if (tensors[0].device().is_cuda()) {
  335. for (const auto i : c10::irange(tensors.size())) {
  336. devices[i] = tensors[i].storage().device().index();
  337. }
  338. }
  339. return devices;
  340. }
  341. template <typename T>
  342. inline T* getDataPointer(const at::Tensor& tensor) {
  343. // This method is only used in ProcessGroupGloo for now. Call sites must make
  344. // sure that the input tensor is contiguous. It is OK if the tensor does not
  345. // start from the beginning of the storage. For example, it could come from
  346. // chunk(..., dim=0)[1]. Hence, we need to use data_ptr() instead of
  347. // tensor.storage().data()
  348. // NB: not using tensor.data<T>() because tensor is not aware of gloo::TYPE
  349. return static_cast<T*>(tensor.data_ptr());
  350. }
  351. template <typename T>
  352. std::vector<T*> getDataPointers(const std::vector<at::Tensor>& tensors) {
  353. std::vector<T*> ptrs(tensors.size());
  354. for (const auto i : c10::irange(tensors.size())) {
  355. ptrs[i] = getDataPointer<T>(tensors[i]);
  356. }
  357. return ptrs;
  358. }
  359. // For alltoall split size sanity check
  360. inline void checkSplitSizes(
  361. const std::vector<int64_t>& split_sizes,
  362. const at::Tensor& tensor,
  363. int group_size) {
  364. if (split_sizes.size() == 0) {
  365. TORCH_CHECK(
  366. tensor.size(0) % group_size == 0,
  367. "Tensor's dim 0 does not divide equally across group size");
  368. } else {
  369. TORCH_CHECK(
  370. split_sizes.size() == static_cast<size_t>(group_size),
  371. "Number of tensor splits not equal to group size");
  372. const auto sum = c10::sum_integers(split_sizes);
  373. TORCH_CHECK(
  374. sum == tensor.size(0), "Split sizes doesn't match total dim 0 size");
  375. }
  376. }
  377. // Compute alltoall lengths and offsets, handling multi-dimension tensors
  378. template <typename T>
  379. size_t computeLengthsAndOffsets(
  380. const std::vector<int64_t>& split_sizes,
  381. const at::Tensor& tensor,
  382. std::vector<T>* lengths,
  383. std::vector<T>* offsets) {
  384. size_t group_size = lengths->size();
  385. bool equal_splits = false;
  386. size_t dim0_size = tensor.size(0);
  387. size_t row_size = (dim0_size ? tensor.numel() / dim0_size : 1);
  388. size_t split_size = 0;
  389. size_t offset = 0;
  390. if (split_sizes.size() == 0) {
  391. equal_splits = true;
  392. split_size = tensor.size(0) / group_size;
  393. }
  394. for(const auto i : c10::irange(group_size)) {
  395. size_t length = row_size * (equal_splits ? split_size : split_sizes[i]);
  396. TORCH_INTERNAL_ASSERT(
  397. length <= std::numeric_limits<int>::max() &&
  398. offset <= std::numeric_limits<int>::max(),
  399. "Length or offset larger than INT_MAX not supported");
  400. (*lengths)[i] = length;
  401. (*offsets)[i] = offset;
  402. offset += length;
  403. }
  404. return offset;
  405. }
  406. template <typename T>
  407. size_t computeLengthsAndOffsets(
  408. const std::vector<at::Tensor>& tensors,
  409. std::vector<T>* lengths,
  410. std::vector<T>* offsets) {
  411. size_t group_size = lengths->size();
  412. size_t offset = 0;
  413. for(const auto i : c10::irange(group_size)) {
  414. size_t length = tensors[i].numel();
  415. TORCH_INTERNAL_ASSERT(
  416. length <= std::numeric_limits<int>::max() &&
  417. offset <= std::numeric_limits<int>::max(),
  418. "Length or offset larger than INT_MAX not supported");
  419. (*lengths)[i] = length;
  420. (*offsets)[i] = offset;
  421. offset += length;
  422. }
  423. return offset;
  424. }
  425. using RankType = uint32_t;
  426. using SizeType = uint64_t;
  427. // `errno` is only meaningful when it fails. E.g., a successful `fork()` sets
  428. // `errno` to `EINVAL` in child process on some macos
  429. // (https://stackoverflow.com/a/20295079), and thus `errno` should really only
  430. // be inspected if an error occurred.
  431. //
  432. // `success_cond` is an expression used to check if an error has happend. So for
  433. // `fork()`, we can use `SYSCHECK(pid = fork(), pid != -1)`. The function output
  434. // is stored in variable `__output` and may be used in `success_cond`.
  435. #ifdef _WIN32
  436. #define SYSCHECK(expr, success_cond) \
  437. while (true) { \
  438. auto __output = (expr); \
  439. auto errno_local = WSAGetLastError(); \
  440. (void)__output; \
  441. if (!(success_cond)) { \
  442. if (errno == EINTR) { \
  443. continue; \
  444. } else if ( \
  445. errno_local == WSAETIMEDOUT || errno_local == WSAEWOULDBLOCK) { \
  446. TORCH_CHECK(false, "Socket Timeout"); \
  447. } else { \
  448. throw std::system_error(errno_local, std::system_category()); \
  449. } \
  450. } else { \
  451. break; \
  452. } \
  453. }
  454. #else
  455. #define SYSCHECK(expr, success_cond) \
  456. while (true) { \
  457. auto __output = (expr); \
  458. (void)__output; \
  459. if (!(success_cond)) { \
  460. if (errno == EINTR) { \
  461. continue; \
  462. } else if (errno == EAGAIN || errno == EWOULDBLOCK) { \
  463. TORCH_CHECK(false, "Socket Timeout"); \
  464. } else { \
  465. throw std::system_error(errno, std::system_category()); \
  466. } \
  467. } else { \
  468. break; \
  469. } \
  470. }
  471. #endif
  472. // Most functions indicate error by returning `-1`. This is a helper macro for
  473. // this common case with `SYSCHECK`.
  474. // Since SOCKET_ERROR = -1 in MSVC, so also leverage SYSCHECK_ERR_RETURN_NEG1
  475. #define SYSCHECK_ERR_RETURN_NEG1(expr) SYSCHECK(expr, __output != -1)
  476. namespace tcputil {
  477. // Send and receive
  478. template <typename T>
  479. void sendBytes(
  480. int socket,
  481. const T* buffer,
  482. size_t length,
  483. bool moreData = false) {
  484. size_t bytesToSend = sizeof(T) * length;
  485. if (bytesToSend == 0) {
  486. return;
  487. }
  488. auto bytes = reinterpret_cast<const uint8_t*>(buffer);
  489. uint8_t* currentBytes = const_cast<uint8_t*>(bytes);
  490. int flags = 0;
  491. #ifdef MSG_MORE
  492. if (moreData) { // there is more data to send
  493. flags |= MSG_MORE;
  494. }
  495. #endif
  496. // Ignore SIGPIPE as the send() return value is always checked for error
  497. #ifdef MSG_NOSIGNAL
  498. flags |= MSG_NOSIGNAL;
  499. #endif
  500. while (bytesToSend > 0) {
  501. ssize_t bytesSent;
  502. SYSCHECK_ERR_RETURN_NEG1(
  503. bytesSent =
  504. ::send(socket, (const char*)currentBytes, bytesToSend, flags))
  505. if (bytesSent == 0) {
  506. throw std::system_error(ECONNRESET, std::system_category());
  507. }
  508. bytesToSend -= bytesSent;
  509. currentBytes += bytesSent;
  510. }
  511. }
  512. template <typename T>
  513. void recvBytes(int socket, T* buffer, size_t length) {
  514. size_t bytesToReceive = sizeof(T) * length;
  515. if (bytesToReceive == 0) {
  516. return;
  517. }
  518. auto bytes = reinterpret_cast<uint8_t*>(buffer);
  519. uint8_t* currentBytes = bytes;
  520. while (bytesToReceive > 0) {
  521. ssize_t bytesReceived;
  522. SYSCHECK_ERR_RETURN_NEG1(
  523. bytesReceived = recv(socket, (char*)currentBytes, bytesToReceive, 0))
  524. if (bytesReceived == 0) {
  525. throw std::system_error(ECONNRESET, std::system_category());
  526. }
  527. bytesToReceive -= bytesReceived;
  528. currentBytes += bytesReceived;
  529. }
  530. }
  531. // send a vector's length and data
  532. template <typename T>
  533. void sendVector(int socket, const std::vector<T>& vec, bool moreData = false) {
  534. SizeType size = vec.size();
  535. sendBytes<SizeType>(socket, &size, 1, true);
  536. sendBytes<T>(socket, vec.data(), size, moreData);
  537. }
  538. // receive a vector as sent in sendVector
  539. template <typename T>
  540. std::vector<T> recvVector(int socket) {
  541. SizeType valueSize;
  542. recvBytes<SizeType>(socket, &valueSize, 1);
  543. std::vector<T> value(valueSize);
  544. recvBytes<T>(socket, value.data(), value.size());
  545. return value;
  546. }
  547. // this is only for convenience when sending rvalues
  548. template <typename T>
  549. void sendValue(int socket, const T& value, bool moreData = false) {
  550. sendBytes<T>(socket, &value, 1, moreData);
  551. }
  552. template <typename T>
  553. T recvValue(int socket) {
  554. T value;
  555. recvBytes<T>(socket, &value, 1);
  556. return value;
  557. }
  558. // send a string's length and data
  559. inline void sendString(
  560. int socket,
  561. const std::string& str,
  562. bool moreData = false) {
  563. SizeType size = str.size();
  564. sendBytes<SizeType>(socket, &size, 1, true);
  565. sendBytes<char>(socket, str.data(), size, moreData);
  566. }
  567. // receive a string as sent in sendString
  568. inline std::string recvString(int socket) {
  569. SizeType valueSize;
  570. recvBytes<SizeType>(socket, &valueSize, 1);
  571. std::vector<char> value(valueSize);
  572. recvBytes<char>(socket, value.data(), value.size());
  573. return std::string(value.data(), value.size());
  574. }
  575. } // namespace tcputil
  576. } // namespace c10d