MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
fabrics.cpp File Reference
#include "mxl/fabrics.h"
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <optional>
#include <stdexcept>
#include <mxl-internal/FlowReader.hpp>
#include <mxl-internal/Instance.hpp>
#include <mxl-internal/JsonUtils.hpp>
#include <mxl-internal/Logging.hpp>
#include <picojson/picojson.h>
#include <rdma/fabric.h>
#include <mxl/mxl.h>
#include "internal/Exception.hpp"
#include "internal/FabricInstance.hpp"
#include "internal/FabricInterfaceProbe.hpp"
#include "internal/Initiator.hpp"
#include "internal/Provider.hpp"
#include "internal/Target.hpp"
#include "internal/TargetInfo.hpp"
#include "mxl/platform.h"
#include "VariantUtils.hpp"
Include dependency graph for fabrics.cpp:

Go to the source code of this file.

Namespaces

namespace  mxl
namespace  mxl::lib
namespace  mxl::lib::fabrics
namespace  mxl::lib::fabrics::ofi

Functions

MXL_EXPORT mxlStatus mxlFabricsCreateInitiator (mxlFabricsInstance in_fabricsInstance, mxlFabricsInitiator *out_initiator)
MXL_EXPORT mxlStatus mxlFabricsCreateInstance (mxlInstance in_instance, char const *options, mxlFabricsInstance *out_fabricsInstance)
MXL_EXPORT mxlStatus mxlFabricsCreateTarget (mxlFabricsInstance in_fabricsInstance, mxlFabricsTarget *out_target)
MXL_EXPORT mxlStatus mxlFabricsDestroyInitiator (mxlFabricsInstance in_fabricsInstance, mxlFabricsInitiator in_initiator)
MXL_EXPORT mxlStatus mxlFabricsDestroyInstance (mxlFabricsInstance in_instance)
MXL_EXPORT mxlStatus mxlFabricsDestroyTarget (mxlFabricsInstance in_fabricsInstance, mxlFabricsTarget in_target)
MXL_EXPORT mxlStatus mxlFabricsFreeInterfaceList (mxlFabricsInterfaceList *interfaceList)
MXL_EXPORT mxlStatus mxlFabricsFreeTargetInfo (mxlFabricsTargetInfo in_info)
MXL_EXPORT mxlStatus mxlFabricsGetInterfaces (mxlFabricsInstance in_instance, mxlFabricsInterfaceConfig const *query, mxlFabricsInterfaceList **list)
MXL_EXPORT mxlStatus mxlFabricsInitiatorAddTarget (mxlFabricsInitiator in_initiator, mxlFabricsTargetInfo in_targetInfo)
MXL_EXPORT mxlStatus mxlFabricsInitiatorMakeProgressBlocking (mxlFabricsInitiator in_initiator, uint16_t in_timeoutMs)
MXL_EXPORT mxlStatus mxlFabricsInitiatorMakeProgressNonBlocking (mxlFabricsInitiator in_initiator)
MXL_EXPORT mxlStatus mxlFabricsInitiatorRemoveTarget (mxlFabricsInitiator in_initiator, mxlFabricsTargetInfo in_targetInfo)
MXL_EXPORT mxlStatus mxlFabricsInitiatorSetup (mxlFabricsInitiator in_initiator, mxlFabricsInitiatorConfig const *in_config, char const *options)
MXL_EXPORT mxlStatus mxlFabricsInitiatorTransferGrain (mxlFabricsInitiator in_initiator, uint64_t in_grainIndex, uint16_t in_startSlice, uint16_t in_endSlice)
MXL_EXPORT mxlStatus mxlFabricsInitiatorTransferSamples (mxlFabricsInitiator in_initiator, uint64_t in_headIndex, size_t in_count)
MXL_EXPORT mxlStatus mxlFabricsProviderFromString (char const *in_string, mxlFabricsProvider *out_provider)
MXL_EXPORT mxlStatus mxlFabricsProviderToString (mxlFabricsProvider in_provider, char *out_string, size_t *in_out_stringSize)
MXL_EXPORT mxlStatus mxlFabricsTargetInfoFromString (char const *in_string, mxlFabricsTargetInfo *out_targetInfo)
MXL_EXPORT mxlStatus mxlFabricsTargetInfoToString (mxlFabricsTargetInfo in_targetInfo, char *out_string, size_t *in_stringSize)
MXL_EXPORT mxlStatus mxlFabricsTargetReadGrain (mxlFabricsTarget in_target, uint16_t in_timeoutMs, uint64_t *out_grainIndex)
MXL_EXPORT mxlStatus mxlFabricsTargetReadGrainNonBlocking (mxlFabricsTarget in_target, uint64_t *out_grainIndex)
MXL_EXPORT mxlStatus mxlFabricsTargetReadSamples (mxlFabricsTarget in_target, uint16_t in_timeoutMs, uint64_t *out_headIndex, size_t *out_count)
MXL_EXPORT mxlStatus mxlFabricsTargetReadSamplesNonBlocking (mxlFabricsTarget in_target, uint64_t *out_headIndex, size_t *out_count)
MXL_EXPORT mxlStatus mxlFabricsTargetSetup (mxlFabricsTarget in_target, mxlFabricsTargetConfig const *in_config, char const *options, mxlFabricsTargetInfo *out_info)

Function Documentation

◆ mxlFabricsCreateInitiator()

MXL_EXPORT mxlStatus mxlFabricsCreateInitiator ( mxlFabricsInstance in_fabricsInstance,
mxlFabricsInitiator * out_initiator )

Create a fabrics initiator instance.

Parameters
in_fabricsInstanceA valid mxl fabrics instance
out_initiatorA valid fabrics initiator

Definition at line 376 of file fabrics.cpp.

377{
378 if ((in_fabricsInstance == nullptr) || (out_initiator == nullptr))
379 {
380 return MXL_ERR_INVALID_ARG;
381 }
382
383 return ofi::try_run(
384 [&]()
385 {
386 auto instance = ofi::FabricsInstance::fromAPI(in_fabricsInstance);
387 *out_initiator = instance->createInitiator()->toAPI();
388
389 return MXL_STATUS_OK;
390 },
391 "Failed to create initiator");
392}
static FabricsInstance * fromAPI(mxlFabricsInstance instance) noexcept
Convert an mxlFabricsInstance API object to its underlying FabricsInstance.
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35
@ MXL_STATUS_OK
Definition mxl.h:23

◆ mxlFabricsCreateInstance()

MXL_EXPORT mxlStatus mxlFabricsCreateInstance ( mxlInstance in_instance,
char const * options,
mxlFabricsInstance * out_fabricsInstance )

Create a new mxl-fabrics from an mxl instance. Targets and initiators created from this mxl-fabrics instance will have access to the flows created in the supplied mxl instance.

Parameters
in_instanceAn mxlInstance previously created with mxlCreateInstance().
optionsA json-formatted string with options. Currently not used.
out_fabricsInstanceReturns a pointer to the created mxlFabricsInstance.
Returns
MXL_STATUS_OK if the instance was successfully created

Definition at line 106 of file fabrics.cpp.

107{
108 (void)options;
109 if ((in_instance == nullptr) || (out_fabricsInstance == nullptr))
110 {
111 return MXL_ERR_INVALID_ARG;
112 }
113
114 return ofi::try_run(
115 [&]()
116 {
117 *out_fabricsInstance = reinterpret_cast<mxlFabricsInstance>(
118 new ofi::FabricsInstance(reinterpret_cast<::mxl::lib::Instance*>(in_instance)));
119
120 return MXL_STATUS_OK;
121 },
122 "Failed to create fabrics instance");
123}
The underlying implementation of an mxlFabricsInstance API object.
struct mxlFabricsInstance_t * mxlFabricsInstance
Definition fabrics.h:29

◆ mxlFabricsCreateTarget()

MXL_EXPORT mxlStatus mxlFabricsCreateTarget ( mxlFabricsInstance in_fabricsInstance,
mxlFabricsTarget * out_target )

Create a fabrics target. The target is the receiver of write operations from an initiator.

Parameters
in_fabricsInstanceA valid mxl fabrics instance
out_targetA valid fabrics target

Definition at line 175 of file fabrics.cpp.

176{
177 if ((in_fabricsInstance == nullptr) || (out_target == nullptr))
178 {
179 return MXL_ERR_INVALID_ARG;
180 }
181
182 return ofi::try_run(
183 [&]()
184 {
185 auto instance = ofi::FabricsInstance::fromAPI(in_fabricsInstance);
186 *out_target = instance->createTarget()->toAPI();
187
188 return MXL_STATUS_OK;
189 },
190 "Failed to create target");
191}

◆ mxlFabricsDestroyInitiator()

MXL_EXPORT mxlStatus mxlFabricsDestroyInitiator ( mxlFabricsInstance in_fabricsInstance,
mxlFabricsInitiator in_initiator )

Destroy a fabrics initiator instance.

Parameters
in_fabricsInstanceA valid mxl fabrics instance
in_initiatorA valid fabrics initiator

Definition at line 395 of file fabrics.cpp.

396{
397 if ((in_fabricsInstance == nullptr) || (in_initiator == nullptr))
398 {
399 return MXL_ERR_INVALID_ARG;
400 }
401
402 return ofi::try_run(
403 [&]()
404 {
406
407 return MXL_STATUS_OK;
408 },
409 "Failed to destroy initiator");
410}
void destroyInitiator(InitiatorWrapper *initiator)
Destroy an Initiator associated with this instance.
static InitiatorWrapper * fromAPI(mxlFabricsInitiator api) noexcept
Convert an mxlFabricsInitiator API object to its underlying InitiatorWrapper.
Definition Initiator.cpp:41

◆ mxlFabricsDestroyInstance()

MXL_EXPORT mxlStatus mxlFabricsDestroyInstance ( mxlFabricsInstance in_instance)

Destroy a mxlFabricsInstance.

Parameters
in_instanceThe mxlFabricsInstance to destroy.
Returns
MXL_STATUS_OK if the instances was successfully destroyed.

Definition at line 126 of file fabrics.cpp.

127{
128 if (in_instance == nullptr)
129 {
130 return MXL_ERR_INVALID_ARG;
131 }
132
133 return ofi::try_run(
134 [&]()
135 {
136 delete ofi::FabricsInstance::fromAPI(in_instance);
137
138 return MXL_STATUS_OK;
139 },
140 "Failed to destroy fabrics instance");
141}

◆ mxlFabricsDestroyTarget()

MXL_EXPORT mxlStatus mxlFabricsDestroyTarget ( mxlFabricsInstance in_fabricsInstance,
mxlFabricsTarget in_target )

Destroy a fabrics target instance.

Parameters
in_fabricsInstanceA valid mxl fabrics instance
in_targetA valid fabrics target

Definition at line 194 of file fabrics.cpp.

195{
196 if ((in_fabricsInstance == nullptr) || (in_target == nullptr))
197 {
198 return MXL_ERR_INVALID_ARG;
199 }
200
201 return ofi::try_run(
202 [&]()
203 {
204 auto instance = ofi::FabricsInstance::fromAPI(in_fabricsInstance);
205 auto target = ofi::TargetWrapper::fromAPI(in_target);
206
207 instance->destroyTarget(target);
208
209 return MXL_STATUS_OK;
210 },
211 "Failed to destroy target");
212}
static TargetWrapper * fromAPI(mxlFabricsTarget api) noexcept
Convert an mxlFabricsTarget API object to its underlying TargetWrapper.
Definition Target.cpp:55

◆ mxlFabricsFreeInterfaceList()

MXL_EXPORT mxlStatus mxlFabricsFreeInterfaceList ( mxlFabricsInterfaceList * interfaceList)

Free an interface list previously allocated by mxlFabricsGetInterfaces. This function will also free the character strings in each interface endpoint address struct that is part of the list.

Parameters
interfaceListThe list of interfaces to free.

Definition at line 163 of file fabrics.cpp.

164{
165 if (interfaceList == nullptr)
166 {
167 return MXL_STATUS_OK;
168 }
169
171 return MXL_STATUS_OK;
172}
static void freeRawLinkedList(::mxlFabricsInterfaceList *) noexcept

◆ mxlFabricsFreeTargetInfo()

MXL_EXPORT mxlStatus mxlFabricsFreeTargetInfo ( mxlFabricsTargetInfo in_info)

Free a mxlFabricsTargetInfo object obtained from mxlFabricsTargetSetup() or mxlFabricsTargetInfoFromString().

Parameters
in_infoA mxlFabricsTargetInfo object
Returns
MXL_STATUS_OK if the mxlFabricsTargetInfo object was freed.

Definition at line 669 of file fabrics.cpp.

670{
671 if (in_info == nullptr)
672 {
673 return MXL_ERR_INVALID_ARG;
674 }
675
676 return ofi::try_run(
677 [&]()
678 {
679 delete ofi::TargetInfo::fromAPI(in_info);
680
681 return MXL_STATUS_OK;
682 },
683 "Failed to free target info object");
684}
static TargetInfo * fromAPI(mxlFabricsTargetInfo api) noexcept
Cast an mxlFabricsTargetInfo opaque pointer to a TargetInfo pointer.

◆ mxlFabricsGetInterfaces()

MXL_EXPORT mxlStatus mxlFabricsGetInterfaces ( mxlFabricsInstance in_instance,
mxlFabricsInterfaceConfig const * in_query,
mxlFabricsInterfaceList ** out_list )

Query a list of available providers, interfaces and their capabilities on this system.

Parameters
[in]in_instanceA valid mxlFabricsInstance.
[in]in_query(Optional) Can be used to filter the items returned by this function. Only the provider and address fields are used for filtering; capability flags in the query are ignored. Use MXL_FABRICS_PROVIDER_ANY or NULL to list interfaces for all providers.
[out]out_listA list of interfaces available on the system. Each entry includes the detected capability flags for that interface. The whole list should be freed with mxlFabricsFreeInterfaceList(). This will also free the character arrays returned from this function.

Definition at line 144 of file fabrics.cpp.

145{
146 if ((in_instance == nullptr) || (list == nullptr))
147 {
148 return MXL_ERR_INVALID_ARG;
149 }
150
151 return ofi::try_run(
152 [&]()
153 {
154 auto optQuery =
155 (query == nullptr) ? std::nullopt : std::make_optional<std::reference_wrapper<::mxlFabricsInterfaceConfig const>>(std::cref(*query));
156 *list = ofi::probeInterfaces(optQuery).toRawLinkedList();
157 return MXL_STATUS_OK;
158 },
159 "Failed to get a list of interfaces");
160}
::mxlFabricsInterfaceList * toRawLinkedList() noexcept
struct mxlFabricsInterfaceConfig_t mxlFabricsInterfaceConfig
FabricInterfaceList probeInterfaces(std::optional< std::reference_wrapper<::mxlFabricsInterfaceConfig const > > query)

◆ mxlFabricsInitiatorAddTarget()

MXL_EXPORT mxlStatus mxlFabricsInitiatorAddTarget ( mxlFabricsInitiator in_initiator,
mxlFabricsTargetInfo in_targetInfo )

Add a target to the initiator. This will allow the initiator to send data to the target in subsequent calls to mxlFabricsInitiatorTransferGrain(). This function is always non-blocking. If additional connection setup is required by the underlying implementation, it will only happen during a call to mxlFabricsInitiatorMakeProgress*().

Parameters
in_initiatorA valid fabrics initiator
in_targetInfoThe target information. This should be the same as the one returned from "mxlFabricsTargetSetup".

Definition at line 432 of file fabrics.cpp.

433{
434 if ((in_initiator == nullptr) || (in_targetInfo == nullptr))
435 {
436 return MXL_ERR_INVALID_ARG;
437 }
438
439 return ofi::try_run(
440 [&]()
441 {
442 auto targetInfo = ofi::TargetInfo::fromAPI(in_targetInfo);
443 ofi::InitiatorWrapper::fromAPI(in_initiator)->addTarget(*targetInfo);
444
445 return MXL_STATUS_OK;
446 },
447 "Failed to add target to initiator");
448}
void addTarget(TargetInfo const &targetInfo)
Add a target to the initiator.
Definition Initiator.cpp:64

◆ mxlFabricsInitiatorMakeProgressBlocking()

MXL_EXPORT mxlStatus mxlFabricsInitiatorMakeProgressBlocking ( mxlFabricsInitiator in_initiator,
uint16_t in_timeoutMs )

This function must be called regularly for the initiator to make progress on queued transfer operations, connection establishment operations and connection shutdown operations. If a connection fails, the target is connected again during a later call to this function or to a transfer function.

Parameters
in_initiatorThe initiator that should make progress.
in_timeoutMsThe maximum time to wait for progress to be made (in milliseconds).
Returns
The result code. Returns MXL_ERR_NOT_READY if there is still progress to be made and not all operations have completed before the timeout. Returns MXL_STATUS_OK if no transfer, connection setup or shutdown is pending, which includes the case that no target is added. Some providers return MXL_ERR_INTERRUPTED if the operation is interrupted by the arrival of a POSIX signal.

Definition at line 529 of file fabrics.cpp.

530{
531 if (in_initiator == nullptr)
532 {
533 return MXL_ERR_INVALID_ARG;
534 }
535
536 return ofi::try_run(
537 [&]()
538 {
539 auto const result = ofi::InitiatorWrapper::fromAPI(in_initiator)->makeProgressBlocking(std::chrono::milliseconds(in_timeoutMs));
540 return std::visit(
542 [](ofi::Initiator::Ready) { return MXL_STATUS_OK; },
545 },
546 result);
547 },
548 "Failed to make progress in the initiator");
549}
Initiator::MakeProgressResult makeProgressBlocking(std::chrono::steady_clock::duration)
Attempts to progress execution, including connection management and data operations.
@ MXL_ERR_NOT_READY
Definition mxl.h:49
@ MXL_ERR_INTERRUPTED
Definition mxl.h:45

◆ mxlFabricsInitiatorMakeProgressNonBlocking()

MXL_EXPORT mxlStatus mxlFabricsInitiatorMakeProgressNonBlocking ( mxlFabricsInitiator in_initiator)

This function must be called regularly for the initiator to make progress on queued transfer operations, connection establishment operations and connection shutdown operations. If a connection fails, the target is connected again during a later call to this function or to a mxlFabricsInitiatorTransferGrain or mxlFabricsInitiatorTransferSamples function.

Parameters
in_initiatorThe initiator that should make progress.
Returns
The result code. Returns MXL_ERR_NOT_READY if there is still progress to be made, and not all operations have completed. Returns MXL_STATUS_OK if no transfer, connection setup or shutdown is pending.

Definition at line 506 of file fabrics.cpp.

507{
508 if (in_initiator == nullptr)
509 {
510 return MXL_ERR_INVALID_ARG;
511 }
512
513 return ofi::try_run(
514 [&]()
515 {
516 auto const result = ofi::InitiatorWrapper::fromAPI(in_initiator)->makeProgress();
517 return std::visit(
519 [](ofi::Initiator::Ready) { return MXL_STATUS_OK; },
522 },
523 result);
524 },
525 "Failed to make progress in the initiator");
526}
Initiator::MakeProgressResult makeProgress()
Attempts to progress execution, including connection management and data operations.

◆ mxlFabricsInitiatorRemoveTarget()

MXL_EXPORT mxlStatus mxlFabricsInitiatorRemoveTarget ( mxlFabricsInitiator in_initiator,
mxlFabricsTargetInfo in_targetInfo )

Remove a target from the initiator. This function is always non-blocking. If any additional communication for a graceful shutdown is required it will happend during a call to mxlFabricsInitiatorMakeProgress*(). It is guaranteed that no new grain transfer operations will be queued for this target during calls to mxlFabricsInitiatorTransferGrain() after the target was removed, but it is only guaranteed that the connection shutdown has completed after mxlFabricsInitiatorMakeProgress*() no longer returns MXL_ERR_NOT_READY. If a connection oriented target closes its connection, for example because it was destroyed, it stays added until it is removed with this function. The initiator does not connect to it again, because a new target has new target information with new keys, and potentially a new port. The user needs to remove the old target and add the target information of the new one.

Parameters
in_initiatorA valid fabrics initiator
in_targetInfoThe target information. This should be the same as the one returned from "mxlFabricsTargetSetup".

Definition at line 451 of file fabrics.cpp.

452{
453 if ((in_initiator == nullptr) || (in_targetInfo == nullptr))
454 {
455 return MXL_ERR_INVALID_ARG;
456 }
457
458 return ofi::try_run(
459 [&]()
460 {
461 auto targetInfo = ofi::TargetInfo::fromAPI(in_targetInfo);
462 ofi::InitiatorWrapper::fromAPI(in_initiator)->removeTarget(*targetInfo);
463
464 return MXL_STATUS_OK;
465 },
466 "Failed to remove target from initiator");
467}
void removeTarget(TargetInfo const &targetInfo)
Remove a target from the initiator.
Definition Initiator.cpp:74

◆ mxlFabricsInitiatorSetup()

MXL_EXPORT mxlStatus mxlFabricsInitiatorSetup ( mxlFabricsInitiator in_initiator,
mxlFabricsInitiatorConfig const * in_config,
char const * in_options )

Configure the initiator.

Parameters
in_initiatorA valid fabrics initiator
in_configThe initiator configuration. This will be used to create an endpoint and register a memory region. The memory region corresponds to the one that will be shared with targets.
in_optionsAn optional json-formatted string with options. May be NULL or empty. Recognized fields:
  • "cqDepth" (number >= 1): the depth of the initiator's completion queue. The queue receives one completion per posted write, so increase this when many writes are in flight at once (many targets, many slices per grain). When omitted, an implementation default is used.
Returns
The result code.
See also
mxlStatus

Definition at line 413 of file fabrics.cpp.

414{
415 if ((in_initiator == nullptr) || (in_config == nullptr))
416 {
417 return MXL_ERR_INVALID_ARG;
418 }
419
420 return ofi::try_run(
421 [&]()
422 {
423 auto const setupOptions = ofi::InitiatorSetupOptions{.cqDepth = ofi::parseCqDepthOption(options)};
424 ofi::InitiatorWrapper::fromAPI(in_initiator)->setup(*in_config, setupOptions);
425
426 return MXL_STATUS_OK;
427 },
428 "Failed to set up initiator");
429}
void setup(mxlFabricsInitiatorConfig const &config, InitiatorSetupOptions const &options={})
Set up the initiator with the specified configuration.
Definition Initiator.cpp:51
Provider-independent tuning options for initiator setup.
Definition Initiator.hpp:19

◆ mxlFabricsInitiatorTransferGrain()

MXL_EXPORT mxlStatus mxlFabricsInitiatorTransferGrain ( mxlFabricsInitiator in_initiator,
uint64_t in_grainIndex,
uint16_t in_startSlice,
uint16_t in_endSlice )

Enqueue a transfer operation to all added targets. This function is always non-blocking. The transfer operation might be started right away, but is only guaranteed to have completed after mxlFabricsInitiatorMakeProgress*() no longer returns MXL_ERR_NOT_READY.

Parameters
in_initiatorA valid fabrics initiator
in_grainIndexThe grain index to transfer. The ordering was given when mxlFabricsRegions object were created. This is true for both local and remote memory regions.
in_startSliceThe start slice in the slice range to transfer. This is inclusive.
in_endSliceThe end slice in the slice range to transfer. This is exclusive.
Returns
The result code.
See also
mxlStatus

Definition at line 470 of file fabrics.cpp.

471{
472 if (in_initiator == nullptr)
473 {
474 return MXL_ERR_INVALID_ARG;
475 }
476
477 return ofi::try_run(
478 [&]()
479 {
480 ofi::InitiatorWrapper::fromAPI(in_initiator)->transferGrain(in_grainIndex, in_startSlice, in_endSlice);
481
482 return MXL_STATUS_OK;
483 },
484 "Failed to transfer grain");
485}
void transferGrain(std::uint64_t grainIndex, std::uint16_t startSlice, std::uint16_t endSlice)
Transfer a grain to all targets.
Definition Initiator.cpp:84

◆ mxlFabricsInitiatorTransferSamples()

MXL_EXPORT mxlStatus mxlFabricsInitiatorTransferSamples ( mxlFabricsInitiator in_initiator,
uint64_t in_headIndex,
size_t in_count )

Enqueue a transfer operation to all added targets. This function is always non-blocking. The transfer operation might be started right away, but is only guaranteed to have completed after mxlFabricsInitiatorMakeProgress*() no longer returns MXL_ERR_NOT_READY.

Parameters
in_initiatorA valid fabrics initiator
in_headIndexThe head index to transfer.
in_countThe number of samples per channel to transfer.
Returns
The result code.
See also
mxlStatus

Definition at line 488 of file fabrics.cpp.

489{
490 if (in_initiator == nullptr)
491 {
492 return MXL_ERR_INVALID_ARG;
493 }
494
495 return ofi::try_run(
496 [&]()
497 {
498 ofi::InitiatorWrapper::fromAPI(in_initiator)->transferSamples(in_headIndex, in_count);
499
500 return MXL_STATUS_OK;
501 },
502 "Failed to transfer samples");
503}
void transferSamples(std::uint64_t headIndex, std::size_t count)
Transfer samples to all targets.

◆ mxlFabricsProviderFromString()

MXL_EXPORT mxlStatus mxlFabricsProviderFromString ( char const * in_string,
mxlFabricsProvider * out_provider )

Convert a string to a fabrics provider enum value.

Parameters
in_stringA valid string to convert
out_providerA valid fabrics provider to convert to
Returns
The result code.
See also
mxlStatus

Definition at line 552 of file fabrics.cpp.

553{
554 if ((in_string == nullptr) || (out_provider == nullptr))
555 {
556 return MXL_ERR_INVALID_ARG;
557 }
558
559 return ofi::try_run(
560 [&]()
561 {
562 if (auto provider = ofi::providerFromString(in_string); provider)
563 {
564 *out_provider = ofi::providerToAPI(*provider);
565 return MXL_STATUS_OK;
566 }
567
568 return MXL_ERR_INVALID_ARG;
569 },
570 "Failed to convert string to provider");
571}
std::optional< Provider > providerFromString(std::string const &s) noexcept
Parse a provider name string, and return the enum value.
Definition Provider.cpp:49
mxlFabricsProvider providerToAPI(Provider provider) noexcept
Convert between external and internal versions of this type.
Definition Provider.cpp:21

◆ mxlFabricsProviderToString()

MXL_EXPORT mxlStatus mxlFabricsProviderToString ( mxlFabricsProvider in_provider,
char * out_string,
size_t * in_stringSize )

Convert a fabrics provider enum value to a string.

Parameters
in_providerA valid fabrics provider to convert
out_stringA user supplied buffer of the correct size. Initially you can pass a NULL pointer to obtain the size of the string.
in_stringSizeThe size of the output string.

Definition at line 574 of file fabrics.cpp.

575{
576 if (in_out_stringSize == nullptr)
577 {
578 return MXL_ERR_INVALID_ARG;
579 }
580
581 return ofi::try_run(
582 [&]()
583 {
584 auto providerEnumValueToString = [](char* outString, size_t* inOutStringSize, char const* providerString)
585 {
586 if (outString == nullptr)
587 {
588 *inOutStringSize = ::strlen(providerString) + 1; // Null terminated.
589 }
590 else
591 {
592 if (*inOutStringSize <= ::strlen(providerString))
593 {
594 return MXL_ERR_STRLEN;
595 }
596
597 ::strncpy(outString, providerString, *inOutStringSize);
598 }
599
600 return MXL_STATUS_OK;
601 };
602
603 switch (in_provider)
604 {
605 case MXL_FABRICS_PROVIDER_ANY: return providerEnumValueToString(out_string, in_out_stringSize, "any");
606 case MXL_FABRICS_PROVIDER_TCP: return providerEnumValueToString(out_string, in_out_stringSize, "tcp");
607 case MXL_FABRICS_PROVIDER_EFA: return providerEnumValueToString(out_string, in_out_stringSize, "efa");
608 case MXL_FABRICS_PROVIDER_VERBS: return providerEnumValueToString(out_string, in_out_stringSize, "verbs");
609 case MXL_FABRICS_PROVIDER_SHM: return providerEnumValueToString(out_string, in_out_stringSize, "shm");
610 default: return MXL_ERR_INVALID_ARG;
611 }
612 },
613 "Failed to convert provider to string");
614}
@ MXL_FABRICS_PROVIDER_VERBS
Definition fabrics.h:50
@ MXL_FABRICS_PROVIDER_ANY
Definition fabrics.h:48
@ MXL_FABRICS_PROVIDER_TCP
Definition fabrics.h:49
@ MXL_FABRICS_PROVIDER_SHM
Definition fabrics.h:52
@ MXL_FABRICS_PROVIDER_EFA
Definition fabrics.h:51
@ MXL_ERR_STRLEN
Definition mxl.h:44

◆ mxlFabricsTargetInfoFromString()

MXL_EXPORT mxlStatus mxlFabricsTargetInfoFromString ( char const * in_string,
mxlFabricsTargetInfo * out_targetInfo )

Parse a targetInfo object from its string representation.

Parameters
in_stringA valid string to deserialize
out_targetInfoA valid target info to deserialize to

Definition at line 617 of file fabrics.cpp.

618{
619 if ((in_string == nullptr) || (out_targetInfo == nullptr))
620 {
621 return MXL_ERR_INVALID_ARG;
622 }
623
624 return ofi::try_run(
625 [&]()
626 {
627 *out_targetInfo = std::make_unique<ofi::TargetInfo>(ofi::TargetInfo::fromJSON(in_string)).release()->toAPI();
628
629 return MXL_STATUS_OK;
630 },
631 "Failed to read target info from string");
632}
static TargetInfo fromJSON(std::string const &s)
Construct a TargetInfo instance from a JSON representation.

◆ mxlFabricsTargetInfoToString()

MXL_EXPORT mxlStatus mxlFabricsTargetInfoToString ( mxlFabricsTargetInfo in_targetInfo,
char * out_string,
size_t * in_stringSize )

Serialize a target info object obtained from mxlFabricsTargetSetup() into a string representation.

Parameters
in_targetInfoA valid target info to serialize
out_stringA user supplied buffer of the correct size. Initially you can pass a NULL pointer to obtain the size of the string.
in_stringSizeThe size of the output string.

Definition at line 635 of file fabrics.cpp.

636{
637 if ((in_targetInfo == nullptr) || (in_stringSize == nullptr))
638 {
639 return MXL_ERR_INVALID_ARG;
640 }
641
642 return ofi::try_run(
643 [&]()
644 {
645 auto targetInfoString = ofi::TargetInfo::fromAPI(in_targetInfo)->toJSON();
646
647 if (out_string == nullptr)
648 {
649 *in_stringSize = targetInfoString.length() + 1;
650 }
651 else
652 {
653 if (*in_stringSize <= targetInfoString.length())
654 {
655 return MXL_ERR_STRLEN;
656 }
657 else
658 {
659 std::strncpy(out_string, targetInfoString.c_str(), *in_stringSize);
660 }
661 }
662
663 return MXL_STATUS_OK;
664 },
665 "Failed to serialize target info");
666}
std::string toJSON() const
Serialize a TargetInfo instance to a JSON representation.

◆ mxlFabricsTargetReadGrain()

MXL_EXPORT mxlStatus mxlFabricsTargetReadGrain ( mxlFabricsTarget in_target,
uint16_t in_timeoutMs,
uint64_t * out_entryIndex )

Blocking accessor for a flow grain.

Parameters
in_targetA valid fabrics target
out_grainIndexThe index of the grain that was written, if any.
in_timeoutMsHow long should we wait for the grain (in milliseconds)
Returns
The result code. MXL_ERR_NOT_READY if no grain was available before the timeout. Some providers return MXL_ERR_INTERRUPTED when the blocking read is interrupted by a POSIX signal.
See also
mxlStatus

Definition at line 272 of file fabrics.cpp.

273{
274 if ((in_target == nullptr) || (out_grainIndex == nullptr))
275 {
276 return MXL_ERR_INVALID_ARG;
277 }
278
279 return ofi::try_run(
280 [&]()
281 {
282 auto const result = ofi::TargetWrapper::fromAPI(in_target)->readBlocking(std::chrono::milliseconds(in_timeoutMs));
283 if (!result)
284 {
285 return MXL_ERR_NOT_READY;
286 }
287
288 if (std::holds_alternative<ofi::Target::Interrupted>(*result))
289 {
290 return MXL_ERR_INTERRUPTED;
291 }
292
293 auto const grainResult = std::get_if<ofi::Target::GrainReadResult>(&*result);
294 if (grainResult == nullptr)
295 {
297 }
298
299 *out_grainIndex = grainResult->grainIndex;
300 return MXL_STATUS_OK;
301 },
302 "Failed to wait for new grain");
303}
std::optional< Target::ReadResult > readBlocking(std::chrono::steady_clock::duration timeout)
Definition Target.cpp:75
@ MXL_ERR_INVALID_STATE
Definition mxl.h:47

◆ mxlFabricsTargetReadGrainNonBlocking()

MXL_EXPORT mxlStatus mxlFabricsTargetReadGrainNonBlocking ( mxlFabricsTarget in_target,
uint64_t * out_grainIndex )

Non-blocking accessor for a flow grain.

Parameters
in_targetA valid fabrics target
out_grainIndexThe index of the grain that was written, if any.
Returns
The result code. MXL_ERR_NOT_READY if no grain was available at the time of the call, and the call should be retried.
See also
mxlStatus

Definition at line 238 of file fabrics.cpp.

239{
240 if ((in_target == nullptr) || (out_grainIndex == nullptr))
241 {
242 return MXL_ERR_INVALID_ARG;
243 }
244
245 return ofi::try_run(
246 [&]()
247 {
248 auto const result = ofi::TargetWrapper::fromAPI(in_target)->read();
249 if (!result)
250 {
251 return MXL_ERR_NOT_READY;
252 }
253
254 if (std::holds_alternative<ofi::Target::Interrupted>(*result))
255 {
256 return MXL_ERR_INTERRUPTED;
257 }
258
259 auto const grainResult = std::get_if<ofi::Target::GrainReadResult>(&*result);
260 if (grainResult == nullptr)
261 {
263 }
264
265 *out_grainIndex = grainResult->grainIndex;
266 return MXL_STATUS_OK;
267 },
268 "Failed to try for new grain");
269}
std::optional< Target::ReadResult > read()
Definition Target.cpp:65

◆ mxlFabricsTargetReadSamples()

MXL_EXPORT mxlStatus mxlFabricsTargetReadSamples ( mxlFabricsTarget in_target,
uint16_t in_timeoutMs,
uint64_t * out_headIndex,
size_t * out_count )

Blocking accessor for a flow sample.

Parameters
in_targetA valid fabrics target
out_headIndexThe head index of the samples that were written, if any.
out_countThe number of samples per channel that were written, if any.
in_timeoutMsHow long should we wait for the samples (in milliseconds)
Returns
The result code. MXL_ERR_NOT_READY if no samples were available before the timeout.
See also
mxlStatus
Note
One can simply pass the returned headIndex and count to the flow reader's GetSamples() function to obtain a pointer to the written samples after this call returns MXL_STATUS_OK.

Definition at line 341 of file fabrics.cpp.

342{
343 if ((in_target == nullptr) || (out_headIndex == nullptr) || (out_count == nullptr))
344 {
345 return MXL_ERR_INVALID_ARG;
346 }
347
348 return ofi::try_run(
349 [&]()
350 {
351 auto const result = ofi::TargetWrapper::fromAPI(in_target)->readBlocking(std::chrono::milliseconds(in_timeoutMs));
352 if (!result)
353 {
354 return MXL_ERR_NOT_READY;
355 }
356
357 if (std::holds_alternative<ofi::Target::Interrupted>(*result))
358 {
359 return MXL_ERR_INTERRUPTED;
360 }
361
362 auto const sampleResult = std::get_if<ofi::Target::SampleReadResult>(&*result);
363 if (sampleResult == nullptr)
364 {
366 }
367
368 *out_headIndex = sampleResult->headIndex;
369 *out_count = sampleResult->count;
370 return MXL_STATUS_OK;
371 },
372 "Failed to wait for new samples");
373}

◆ mxlFabricsTargetReadSamplesNonBlocking()

MXL_EXPORT mxlStatus mxlFabricsTargetReadSamplesNonBlocking ( mxlFabricsTarget in_target,
uint64_t * out_headIndex,
size_t * out_count )

Non-blocking accessor for a flow sample.

Parameters
in_targetA valid fabrics target
out_headIndexThe head index of the samples that were written, if any.
out_countThe number of samples per channel that were written, if any.
Returns
The result code. MXL_ERR_NOT_READY if no samples were available at the time of the call, and the call should be retried.
See also
mxlStatus
Note
One can simply pass the returned headIndex and count to the flow reader's GetSamples() function to obtain a pointer to the written samples after this call returns MXL_STATUS_OK.

Definition at line 306 of file fabrics.cpp.

307{
308 if ((in_target == nullptr) || (out_headIndex == nullptr) || (out_count == nullptr))
309 {
310 return MXL_ERR_INVALID_ARG;
311 }
312
313 return ofi::try_run(
314 [&]()
315 {
316 auto const result = ofi::TargetWrapper::fromAPI(in_target)->read();
317 if (!result)
318 {
319 return MXL_ERR_NOT_READY;
320 }
321
322 if (std::holds_alternative<ofi::Target::Interrupted>(*result))
323 {
324 return MXL_ERR_INTERRUPTED;
325 }
326
327 auto const sampleResult = std::get_if<ofi::Target::SampleReadResult>(&*result);
328 if (sampleResult == nullptr)
329 {
331 }
332
333 *out_headIndex = sampleResult->headIndex;
334 *out_count = sampleResult->count;
335 return MXL_STATUS_OK;
336 },
337 "Failed to try for new samples");
338}

◆ mxlFabricsTargetSetup()

MXL_EXPORT mxlStatus mxlFabricsTargetSetup ( mxlFabricsTarget in_target,
mxlFabricsTargetConfig const * in_config,
char const * in_options,
mxlFabricsTargetInfo * out_info )

Configure the target. After the target has been configured, it is ready to receive transfers from an initiator. If additional connection setup is required by the underlying implementation it might not happen during the call to mxlFabricsTargetSetup, but be deferred until the first call to mxlFabricsTargetTryNewGrain().

Parameters
in_targetA valid fabrics target
in_configThe target configuration. This will be used to create an endpoint and register a memory region. The memory region corresponds to the one that will be written to by the initiator.
in_optionsAn optional json-formatted string with options. May be NULL or empty. Recognized fields:
  • "cqDepth" (number >= 1): the depth of the target's completion queue. Increase this for high-frame-rate or many-stream receivers, or when per-completion processing is slow, to avoid completion queue overflow. See the "Receiving grains" section of docs/Fabrics.md. When omitted, an implementation default is used.
out_infoAn mxlFabricsTargetInfo_t object which should be shared to a remote initiator which this target should receive data from. The object must be freed with mxlFabricsFreeTargetInfo().
Returns
The result code.
See also
mxlStatus

Definition at line 215 of file fabrics.cpp.

217{
218 if ((in_target == nullptr) || (in_config == nullptr) || (out_info == nullptr))
219 {
220 return MXL_ERR_INVALID_ARG;
221 }
222
223 return ofi::try_run(
224 [&]()
225 {
226 auto const setupOptions = ofi::TargetSetupOptions{.cqDepth = ofi::parseCqDepthOption(options)};
227
228 // Set up the target, release the returned unique_ptr, convert to external API type, assign the the pointer location
229 // passed by the user.
230 *out_info = ofi::TargetWrapper::fromAPI(in_target)->setup(*in_config, setupOptions).release()->toAPI();
231
232 return MXL_STATUS_OK;
233 },
234 "Failed to set up target");
235}
std::unique_ptr< TargetInfo > setup(mxlFabricsTargetConfig const &config, TargetSetupOptions const &options={})
Set up the target with the specified configuration.
Definition Target.cpp:93
Provider-independent tuning options for target setup.
Definition Target.hpp:23