MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Protocol.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 "Protocol.hpp"
6#include <cassert>
7#include "Exception.hpp"
10
12{
13 std::unique_ptr<IngressProtocol> selectIngressProtocol(DataLayout const& layout, std::vector<Region> regions, std::uint32_t maxSyncBatchSize)
14 {
15 if (layout.isDiscrete())
16 {
17 return std::make_unique<RMAGrainIngressProtocol>(std::move(regions));
18 }
19 else if (layout.isContinuous())
20 {
21 if (regions.size() != 1)
22 {
23 throw Exception::invalidArgument("Expected exactly 1 region for sample protocol.");
24 }
25 return std::make_unique<RMASampleIngressProtocol>(regions.front(), layout.asContinuous(), maxSyncBatchSize);
26 }
27 else
28 {
29 throw Exception::invalidArgument("Unsupported data layout");
30 }
31 }
32
33 std::unique_ptr<EgressProtocolTemplate> selectEgressProtocol(DataLayout const& layout, std::vector<Region> regions)
34 {
35 if (layout.isDiscrete())
36 {
37 return std::make_unique<RMAGrainEgressProtocolTemplate>(layout.asDiscrete(), std::move(regions));
38 }
39 else if (layout.isContinuous())
40 {
41 if (regions.size() != 1)
42 {
43 throw Exception::invalidArgument("Expected exactly 1 region for sample protocol.");
44 }
45 return std::make_unique<RMASampleEgressProtocolTemplate>(layout.asContinuous(), regions.front());
46 }
47 else
48 {
49 throw Exception::invalidArgument("Unsupported data layout");
50 }
51 }
52
53}
Describes the layout of data within memory regions.
Discrete const & asDiscrete() const
Get the DataLayout as Discrete.
bool isContinuous() const noexcept
Check if the DataLayout is of continuous type.
Continuous const & asContinuous() const
Get the DataLayout as Continuous.
bool isDiscrete() const noexcept
Check if the DataLayout is of discrete type.
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
Definition Exception.hpp:43
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