context.h
1 
5 #pragma once
6 
7 #include <cstdint>
8 #include <cstring>
9 #include <memory>
10 #include <string>
11 
12 #include <ucp/api/ucp.h>
13 
14 #include <ucxx/component.h>
15 #include <ucxx/config.h>
16 #include <ucxx/constructors.h>
17 
18 namespace ucxx {
19 
20 namespace experimental {
21 class ContextBuilder;
22 } // namespace experimental
23 
24 class MemoryHandle;
25 class Worker;
26 
35 class Context : public Component {
36  private:
37  ucp_context_h _handle{nullptr};
38  Config _config{{}};
39  uint64_t _featureFlags{0};
40  bool _cudaSupport{false};
41 
52  Context(const ConfigMap ucxConfig, const uint64_t featureFlags);
53 
54  public:
55  static constexpr uint64_t defaultFeatureFlags =
56  UCP_FEATURE_TAG | UCP_FEATURE_WAKEUP | UCP_FEATURE_STREAM | UCP_FEATURE_AM |
57  UCP_FEATURE_RMA;
58 
59  Context() = delete;
60  Context(const Context&) = delete;
61  Context& operator=(Context const&) = delete;
62  Context(Context&& o) = delete;
63  Context& operator=(Context&& o) = delete;
64 
71  friend std::shared_ptr<Context> createContext(ConfigMap ucxConfig, const uint64_t featureFlags);
72 
77 
82 
96  [[nodiscard]] ConfigMap getConfig();
97 
113  [[nodiscard]] ucp_context_h getHandle();
114 
129  [[nodiscard]] std::string getInfo();
130 
145  [[nodiscard]] uint64_t getFeatureFlags() const;
146 
161  [[nodiscard]] bool hasCudaSupport() const;
162 
181  [[nodiscard]] std::shared_ptr<Worker> createWorker(const bool enableDelayedSubmission = false,
182  const bool enableFuture = false);
183 
221  [[nodiscard]] std::shared_ptr<MemoryHandle> createMemoryHandle(
222  const size_t size, void* buffer, const ucs_memory_type_t memoryType = UCS_MEMORY_TYPE_HOST);
223 };
224 
240 std::shared_ptr<Context> createContext(ConfigMap ucxConfig, const uint64_t featureFlags);
241 
242 } // namespace ucxx
243 
244 // Include experimental features
245 #include <ucxx/experimental/context_builder.h>
A UCXX component class to prevent early destruction of parent object.
Definition: component.h:17
Component encapsulating the UCP configuration.
Definition: config.h:19
Component encapsulating the UCP context.
Definition: context.h:35
std::string getInfo()
Get information from UCP context.
friend std::shared_ptr< Context > createContext(ConfigMap ucxConfig, const uint64_t featureFlags)
Friend declaration for ucxx::createContext with parameters.
std::shared_ptr< MemoryHandle > createMemoryHandle(const size_t size, void *buffer, const ucs_memory_type_t memoryType=UCS_MEMORY_TYPE_HOST)
Create a new std::shared_ptr<ucxx::memoryHandle>.
ConfigMap getConfig()
Get the context configuration.
bool hasCudaSupport() const
Query whether CUDA support is available.
~Context()
ucxx::Context destructor
ucp_context_h getHandle()
Get the underlying ucp_context_h handle.
uint64_t getFeatureFlags() const
Get feature flags that were used to construct the UCP context.
static constexpr uint64_t defaultFeatureFlags
Suggested default context feature flags to use.
Definition: context.h:55
std::shared_ptr< Worker > createWorker(const bool enableDelayedSubmission=false, const bool enableFuture=false)
Create a new ucxx::Worker.
Builder class for constructing std::shared_ptr<ucxx::Context> objects.
Definition: context_builder.h:42
Definition: address.h:15
std::unordered_map< std::string, std::string > ConfigMap
A UCP configuration map.
Definition: typedefs.h:83
std::shared_ptr< Context > createContext(const ConfigMap ucxConfig, const uint64_t featureFlags)
Constructor of shared_ptr<ucxx::Context> with parameters.