Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:10:13

0001 /**
0002  * Copyright (c) 2018-present, Facebook, Inc.
0003  * All rights reserved.
0004  *
0005  * This source code is licensed under the BSD-style license found in the
0006  * LICENSE file in the root directory of this source tree.
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 // The unbound buffer class represents a chunk of memory.
0023 // It can either be used as a source for send operations or a
0024 // destination for receive operations, or both. There should only be a
0025 // single pending operation against an unbound buffer at any given
0026 // time, or resulting behavior is undefined.
0027 //
0028 // It is called unbound to contrast with the bound buffers that have
0029 // been available since the inception of Gloo. It is unbound in that
0030 // it is not tied to a particular pair.
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   // If specified, the source of this recv is stored in the rank pointer.
0041   // Returns true if it completed, false if it was aborted.
0042   virtual bool waitRecv(int* rank, std::chrono::milliseconds timeout) = 0;
0043 
0044   // If specified, the destination of this send is stored in the rank pointer.
0045   // Returns true if it completed, false if it was aborted.
0046   virtual bool waitSend(int* rank, std::chrono::milliseconds timeout) = 0;
0047 
0048   // Aborts a pending waitRecv call.
0049   virtual void abortWaitRecv() = 0;
0050 
0051   // Aborts a pending waitSend call.
0052   virtual void abortWaitSend() = 0;
0053 
0054   // Default overload.
0055   bool waitRecv() {
0056     return waitRecv(nullptr, kUnsetTimeout);
0057   }
0058 
0059   // Default overload.
0060   bool waitSend() {
0061     return waitSend(nullptr, kUnsetTimeout);
0062   }
0063 
0064   // Rank overload.
0065   bool waitRecv(int* rank) {
0066     return waitRecv(rank, kUnsetTimeout);
0067   }
0068 
0069   // Rank overload.
0070   bool waitSend(int* rank) {
0071     return waitSend(rank, kUnsetTimeout);
0072   }
0073 
0074   // Timeout overload.
0075   bool waitRecv(std::chrono::milliseconds timeout) {
0076     return waitRecv(nullptr, timeout);
0077   }
0078 
0079   // Timeout overload.
0080   bool waitSend(std::chrono::milliseconds timeout) {
0081     return waitSend(nullptr, timeout);
0082   }
0083 
0084   // Deadline overload.
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   // Deadline overload.
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   // If the byte count argument is not specified, it will default the
0099   // number of bytes to be equal to the number of bytes remaining in
0100   // the buffer w.r.t. the offset.
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 } // namespace transport
0123 } // namespace gloo