MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Domain.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include "Domain.hpp"
6#include <cstdint>
7#include <memory>
8#include <utility>
9#include <vector>
10#include <rdma/fabric.h>
11#include "Exception.hpp"
12#include "Fabric.hpp"
13#include "MemoryRegion.hpp"
14#include "Region.hpp"
15#include "RegisteredRegion.hpp"
16
18{
19 Domain::Domain(::fid_domain* raw, std::shared_ptr<Fabric> fabric, std::vector<RegisteredRegion> registeredRegions)
20 : _raw(raw)
21 , _fabric(std::move(fabric))
22 , _registeredRegions(std::move(registeredRegions))
23 {}
24
26 {
27 catchAndLogFabricError([this]() { close(); }, "Failed to close domain");
28 }
29
30 std::shared_ptr<Domain> Domain::open(std::shared_ptr<Fabric> fabric)
31 {
32 ::fid_domain* domain;
33
34 fiCall(::fi_domain2, "Failed to open domain", fabric->raw(), fabric->info().raw(), &domain, 0, nullptr);
35
36 struct MakeSharedEnabler : public Domain
37 {
38 MakeSharedEnabler(::fid_domain* domain, std::shared_ptr<Fabric> fabric, std::vector<RegisteredRegion> registerRegions)
39 : Domain(domain, std::move(fabric), std::move(registerRegions))
40 {}
41 };
42
43 return std::make_shared<MakeSharedEnabler>(domain, std::move(fabric), std::vector<RegisteredRegion>{});
44 }
45
46 void Domain::registerRegions(std::vector<Region> const& regions, std::uint64_t access)
47 {
48 std::ranges::transform(
49 regions, std::back_inserter(_registeredRegions), [&](auto const& region) { return registerRegionImpl(region, access); });
50 }
51
52 void Domain::registerRegion(Region const& region, std::uint64_t access)
53 {
54 _registeredRegions.push_back(registerRegionImpl(region, access));
55 }
56
57 std::vector<LocalRegion> Domain::localRegions() const noexcept
58 {
60 }
61
62 std::vector<RemoteRegion> Domain::remoteRegions() const noexcept
63 {
65 }
66
67 bool Domain::usingVirtualAddresses() const noexcept
68 {
69 return (_fabric->info().raw()->domain_attr->mr_mode & FI_MR_VIRT_ADDR) != 0;
70 }
71
72 bool Domain::usingRecvBufForCqData() const noexcept
73 {
74 return (_fabric->info().raw()->rx_attr->mode & FI_RX_CQ_DATA) != 0;
75 }
76
77 std::shared_ptr<Fabric> Domain::fabric() const noexcept
78 {
79 return _fabric;
80 }
81
82 RegisteredRegion Domain::registerRegionImpl(Region const& region, std::uint64_t access)
83 {
84 return RegisteredRegion{MemoryRegion::reg(*this, region, access), region};
85 }
86
88 {
89 _registeredRegions.clear();
90
91 if (_raw != nullptr)
92 {
93 fiCall(::fi_close, "Failed to close domain", &_raw->fid);
94 _raw = nullptr;
95 }
96 }
97
98 Domain::Domain(Domain&& other) noexcept
99 : _raw(other._raw)
100 , _fabric(std::move(other._fabric))
101 , _registeredRegions(std::move(other._registeredRegions))
102 {
103 other._raw = nullptr;
104 }
105
107 {
108 close();
109
110 _raw = other._raw;
111 other._raw = nullptr;
112
113 _fabric = std::move(other._fabric);
114 _registeredRegions = std::move(other._registeredRegions);
115
116 return *this;
117 }
118
119 ::fid_domain* Domain::raw() noexcept
120 {
121 return _raw;
122 }
123
124 ::fid_domain const* Domain::raw() const noexcept
125 {
126 return _raw;
127 }
128}
std::shared_ptr< Fabric > _fabric
Definition Domain.hpp:107
void registerRegion(Region const &region, std::uint64_t access)
Register a single memory region to this domain.
Definition Domain.cpp:52
void registerRegions(std::vector< Region > const &regions, std::uint64_t access)
Register a list of memory regions to this domain.
Definition Domain.cpp:46
bool usingVirtualAddresses() const noexcept
When this returns true, a user should use virtual addresses instead of 0 based addresses when referin...
Definition Domain.cpp:67
std::vector< LocalRegion > localRegions() const noexcept
Get the local regions associated to the registered regions to this domain.
Definition Domain.cpp:57
std::shared_ptr< Fabric > fabric() const noexcept
Accessor for the fabric associated with this domain.
Definition Domain.cpp:77
::fid_domain * raw() noexcept
Accessor for the underlying fi_domain instance.
Definition Domain.cpp:119
void close()
Close this domain and release all associated resources.
Definition Domain.cpp:87
std::vector< RegisteredRegion > _registeredRegions
Definition Domain.hpp:109
static std::shared_ptr< Domain > open(std::shared_ptr< Fabric > fabric)
Open a new domain associated with the specified fabric.
Definition Domain.cpp:30
void operator=(Domain const &)=delete
Domain(Domain const &)=delete
RegisteredRegion registerRegionImpl(Region const &region, std::uint64_t access)
Register a single memory region to this domain.
Definition Domain.cpp:82
bool usingRecvBufForCqData() const noexcept
When this returns true, it means the target must post a fi_recv in order to receive immediate data.
Definition Domain.cpp:72
std::vector< RemoteRegion > remoteRegions() const noexcept
Get the remote regions associated to the registered regions to this domain.
Definition Domain.cpp:62
static MemoryRegion reg(Domain &domain, Region const &region, std::uint64_t access)
Register a memory region with a specified domain and access permissions.
Represent a memory region (unregistered).
Definition Region.hpp:24
Represent a registered memory region.
std::vector< LocalRegion > toLocal(std::vector< RegisteredRegion > const &groups) noexcept
std::vector< RemoteRegion > toRemote(std::vector< RegisteredRegion > const &groups, bool useVirtualAddress) noexcept
void catchAndLogFabricError(F &&fun, std::string_view msg)
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.