MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Protocol.hpp
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#pragma once
6
7#include <cstddef>
8#include <cstdint>
9#include <memory>
10#include <rdma/fabric.h>
11#include "DataLayout.hpp"
12#include "Endpoint.hpp"
13#include "Region.hpp"
14#include "SliceRange.hpp"
15#include "Target.hpp"
16#include "TargetInfo.hpp"
17
19{
24 {
25 public:
26 virtual ~IngressProtocol() = default;
27
32 [[nodiscard]]
33 virtual std::vector<RemoteRegion> registerMemory(std::shared_ptr<Domain> domain) = 0;
34
35 [[nodiscard]]
36 virtual std::optional<TargetInfoBounceBufferInfo> bounceBufferInfo() const = 0;
37
40 virtual void start(Endpoint const& endpoint) = 0;
41
46 [[nodiscard]]
47 virtual std::optional<Target::ReadResult> read(Endpoint const& endpoint, Completion const& completion) = 0;
48
51 [[nodiscard]]
52 virtual bool canReadGrains() const noexcept = 0;
53
56 [[nodiscard]]
57 virtual bool canReadSamples() const noexcept = 0;
58
61 virtual void reset() = 0;
62 };
63
69 {
70 public:
71 virtual ~EgressProtocol() = default;
72
80 virtual void registerMemory(std::shared_ptr<Domain> domain) = 0;
81
89 virtual void transferGrain(Endpoint const& ep, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint32_t payloadOffset,
90 SliceRange const& sliceRange, ::fi_addr_t destAddr = FI_ADDR_UNSPEC) = 0;
91
97 virtual void transferSamples(Endpoint const& ep, std::uint64_t headIndex, std::size_t count, ::fi_addr_t destAddr = FI_ADDR_UNSPEC) = 0;
98
101 virtual void processCompletion(Completion const& completion) = 0;
102
105 [[nodiscard]]
106 virtual bool hasPendingWork() const = 0;
107
111 virtual std::size_t reset() = 0;
112 };
113
119 {
120 public:
121 virtual ~EgressProtocolTemplate() = default;
122
125 virtual void registerMemory(std::shared_ptr<Domain> domain) = 0;
126
129 [[nodiscard]]
130 virtual std::unique_ptr<EgressProtocol> createInstance(Completion::Token token, TargetInfo remoteInfo) = 0;
131 };
132
139 [[nodiscard]]
140 std::unique_ptr<IngressProtocol> selectIngressProtocol(DataLayout const& layout, std::vector<Region> regions, std::uint32_t maxSyncBatchSize);
141
147 [[nodiscard]]
148 std::unique_ptr<EgressProtocolTemplate> selectEgressProtocol(DataLayout const& layout, std::vector<Region> regions);
149}
Type to represent a completion entry from a CompletionQueue.
std::uintptr_t Token
A token used to associate a completion entry with an endpoint.
Describes the layout of data within memory regions.
virtual std::unique_ptr< EgressProtocol > createInstance(Completion::Token token, TargetInfo remoteInfo)=0
Create a new instance of the protocol for a remote target.
virtual void registerMemory(std::shared_ptr< Domain > domain)=0
Register memory required by the protocol.
Interface for transfer operations.
Definition Protocol.hpp:69
virtual void processCompletion(Completion const &completion)=0
Process a completion event. Any post-processing after a transfer should be done here.
virtual bool hasPendingWork() const =0
Check if there is uncompleted requests.
virtual std::size_t reset()=0
Destroy the protocol object.
virtual void transferGrain(Endpoint const &ep, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint32_t payloadOffset, SliceRange const &sliceRange, ::fi_addr_t destAddr=FI_ADDR_UNSPEC)=0
Transfer a grain to a remote target.
virtual void transferSamples(Endpoint const &ep, std::uint64_t headIndex, std::size_t count, ::fi_addr_t destAddr=FI_ADDR_UNSPEC)=0
Transfer samples to a remote target.
virtual void registerMemory(std::shared_ptr< Domain > domain)=0
Register local memory regions used in this protocol.
RAII Wrapper around a libfabric endpoint (fi_ep).
Definition Endpoint.hpp:29
Interface for post-processing on transfer reception.
Definition Protocol.hpp:24
virtual std::optional< Target::ReadResult > read(Endpoint const &endpoint, Completion const &completion)=0
Process a completion with the given immediate data.
virtual bool canReadGrains() const noexcept=0
Check if this protocol can read grains.
virtual void start(Endpoint const &endpoint)=0
Start receiving.
virtual void reset()=0
Destroy the protocol object.
virtual bool canReadSamples() const noexcept=0
Check if this protocol can read samples.
virtual std::optional< TargetInfoBounceBufferInfo > bounceBufferInfo() const =0
virtual std::vector< RemoteRegion > registerMemory(std::shared_ptr< Domain > domain)=0
Register local memory regions used in this protocol.
A SliceRange represents a range of slices within a grain.
std::unique_ptr< IngressProtocol > selectIngressProtocol(DataLayout const &layout, std::vector< Region > regions, std::uint32_t maxSyncBatchSize)
Select an appropriate ingress protocol based on the data layout.
Definition Protocol.cpp:13
std::unique_ptr< EgressProtocolTemplate > selectEgressProtocol(DataLayout const &layout, std::vector< Region > regions)
Select an appropriate egress protocol based on the data layout.
Definition Protocol.cpp:33
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
TargetInfo contains all the information required by an initiator to operate transfers to the given ta...