14#include "lci_config.hpp"
321 return reinterpret_cast<uintptr_t
>(
p_impl) < 3;
504#if defined(__clang__)
505#pragma clang diagnostic push
506#pragma clang diagnostic ignored "-Wnested-anon-types"
534#if defined(__clang__)
535#pragma clang diagnostic pop
538 data_t(buffer_t buffer_,
bool own_data_ =
false);
540 data_t(
size_t size, allocator_base_t* allocator =
nullptr);
541 data_t(
size_t sizes[],
int count, allocator_base_t* allocator =
nullptr);
579 template <
typename T>
622 template <
typename T>
625 return data.get_scalar<T>();
663 return reinterpret_cast<uintptr_t
>(
p_impl) <= 1;
693using reduce_op_t = void (*)(
const void* left,
const void* right,
void* dst,
746#if __cplusplus >= 201703L
750 auto op =
static_cast<T*
>(value);
751 using result_t = std::invoke_result_t<T>;
753 if constexpr (std::is_same_v<result_t, status_t>) {
754 status_t result = (*op)();
756 }
else if constexpr (std::is_same_v<result_t, errorcode_t>) {
767typename std::enable_if<
768 std::is_same<
typename std::result_of<T()>::type,
status_t>::value,
772 auto op =
static_cast<T*
>(value);
779typename std::enable_if<
780 std::is_same<
typename std::result_of<T()>::type,
errorcode_t>::value,
784 auto op =
static_cast<T*
>(value);
791typename std::enable_if<
792 !std::is_same<
typename std::result_of<T()>::type, status_t>::value &&
793 !std::is_same<
typename std::result_of<T()>::type,
errorcode_t>::value,
797 auto op =
static_cast<T*
>(value);
806 auto op =
static_cast<T*
>(value);
825 .
value(
reinterpret_cast<void*
>(fn))
827 fn->user_context(ret);
838 static_assert(
sizeof(
data_t) == 24,
"data_t size is not 24 bytes");
852 buffers.count = buffers_.size();
854 for (
size_t i = 0; i <
buffers.count; i++) {
855 buffers.buffers[i] = buffers_[i];
876 for (
int i = 0; i <
count; i++) {
880 buffers.buffers[i].base = malloc(sizes[i]);
882 buffers.buffers[i].size = sizes[i];
893 fprintf(stderr,
"Copying buffer with own_data=true is not recommended\n");
906 for (
size_t i = 0; i <
buffers.count; i++) {
921 if (other.is_scalar()) {
922 scalar.size = other.scalar.size;
924 }
else if (other.is_buffer()) {
926 other.set_own_data(
false);
927 }
else if (other.is_buffers()) {
928 buffers.count = other.buffers.count;
929 buffers.buffers = other.buffers.buffers;
930 other.set_own_data(
false);
931 other.buffers.buffers =
nullptr;
943 char* buf = (
char*)malloc(
sizeof(
data_t));
944#if defined(__GNUC__) && !defined(__clang__) && !defined(__NVCC__)
945#pragma GCC diagnostic push
946#pragma GCC diagnostic ignored "-Wclass-memaccess"
948 memcpy(buf, &first,
sizeof(
data_t));
949 memcpy(&first, &second,
sizeof(
data_t));
950 memcpy(&second, buf,
sizeof(
data_t));
951#if defined(__GNUC__) && !defined(__clang__)
952#pragma GCC diagnostic pop
983 buffers.count = buffers_.size();
985 for (
size_t i = 0; i <
buffers.count; i++) {
986 buffers.buffers[i].size = buffers_[i].size;
990 buffers.buffers[i].base = malloc(buffers_[i].
size);
992 memcpy(
buffers.buffers[i].base, buffers_[i].base, buffers_[i].size);
1001 if (
buffer.size !=
sizeof(T)) {
1002 throw std::runtime_error(
"Buffer size does not match scalar size");
1004 return *
reinterpret_cast<const T*
>(
buffer.base);
1006 if (
sizeof(T) >
scalar.size) {
1007 throw std::runtime_error(
"No enough data to fit the scalar.");
1009 return *
reinterpret_cast<const T*
>(
scalar.data);
1011 throw std::runtime_error(
"Cannot convert to a scalar");
1035 throw std::runtime_error(
"Cannot convert to a buffer");
1047 throw std::runtime_error(
"Not a buffers");
1055 throw std::runtime_error(
"Not buffers");
1062 for (
size_t i = 0; i <
buffers.count; i++) {
1070 ret.push_back(
buffers.buffers[i]);
Completion object implementation base type.
Definition lci.hpp:673
comp_impl_t(const attr_t &attr_)
Definition lci.hpp:676
virtual ~comp_impl_t()=default
comp_attr_t attr
Definition lci.hpp:679
comp_attr_t attr_t
Definition lci.hpp:675
virtual void signal(status_t)=0
The actual implementation for RESOURCE comp.
Definition lci_binding_pre.hpp:128
bool is_empty() const
Definition lci.hpp:661
comp_impl_t * p_impl
Definition lci_binding_pre.hpp:139
The actual implementation for graph_add_node.
Definition lci_binding_post.hpp:516
graph_add_node_x && free_cb(graph_node_free_cb_t free_cb_in)
Definition lci_binding_post.hpp:532
graph_add_node_x && value(void *value_in)
Definition lci_binding_post.hpp:531
The actual implementation for RESOURCE mr.
Definition lci_binding_pre.hpp:283
mr_impl_t * p_impl
Definition lci_binding_pre.hpp:289
bool is_empty() const
Definition lci.hpp:319
graph_node_t graph_add_node_op(comp_t graph, const T &op)
Add a functor as a node to the completion graph.
Definition lci.hpp:819
broadcast_algorithm_t
The type of broadcast algorithm.
Definition lci.hpp:229
errorcode_t
The actual error code for LCI API functions.
Definition lci.hpp:119
void(*)(status_t status, void *src_value, void *dst_value) graph_edge_run_cb_t
The function signature for a edge funciton in the completion graph.
Definition lci.hpp:734
const rmr_t RMR_NULL
The NULL value of rkey_t.
Definition lci.hpp:341
uint64_t matching_entry_key_t
The type of matching engine entry key.
Definition lci.hpp:403
const mr_t MR_DEVICE
A special mr_t value for device memory.
Definition lci.hpp:310
const int ANY_SOURCE
Special rank value for any-source receive.
Definition lci.hpp:370
status_t(*)(void *value) graph_node_run_cb_t
The function signature for a node function in the completion graph.
Definition lci.hpp:713
net_opcode_t
The Type of network communication operation codes.
Definition lci.hpp:210
const mr_t MR_HOST
A special mr_t value for host memory.
Definition lci.hpp:304
direction_t
The enum class of comunication direction.
Definition lci.hpp:353
void(*)(void *value) graph_node_free_cb_t
The function signature for a callback that will be triggered when the node was freed.
Definition lci.hpp:728
void(*)(const void *left, const void *right, void *dst, size_t n) reduce_op_t
The user-defined reduction operation.
Definition lci.hpp:693
matching_policy_t
Enum class for matching policy.
Definition lci.hpp:392
void * graph_node_t
The node type for the completion graph.
Definition lci.hpp:699
const tag_t ANY_TAG
Special tag value for any-tag receive.
Definition lci.hpp:376
const graph_node_run_cb_t GRAPH_NODE_DUMMY_CB
A dummy callback function for a graph node.
Definition lci.hpp:721
allreduce_algorithm_t
The type of allreduce algorithm.
Definition lci.hpp:265
reduce_scatter_algorithm_t
The type of reduce scatter algorithm.
Definition lci.hpp:247
const comp_t COMP_NULL_EXPECT_DONE
Deprecated. Same as COMP_NULL.
Definition lci.hpp:644
const mr_t MR_UNKNOWN
A special mr_t value for unknown memory. LCI will detect the memory type automatically.
Definition lci.hpp:317
void * matching_entry_val_t
The type of matching engine entry value.
Definition lci.hpp:408
matching_entry_type_t
The type of matching entry.
Definition lci.hpp:383
uint32_t rcomp_t
The type of remote completion handler.
Definition lci.hpp:364
void(*)(status_t status) comp_handler_t
Function Signature for completion handler.
Definition lci.hpp:686
const graph_node_t GRAPH_START
The start node of the completion graph.
Definition lci.hpp:705
const comp_t COMP_NULL
Special completion object setting allow_posted to false.
Definition lci.hpp:638
const comp_t COMP_NULL_EXPECT_DONE_OR_RETRY
Deprecated. Same as COMP_NULL_RETRY.
Definition lci.hpp:658
uint64_t tag_t
The type of tag.
Definition lci.hpp:347
comp_semantic_t
The enum class of completion semantic.
Definition lci.hpp:418
uint32_t net_imm_data_t
The type of network-layer immediate data field.
Definition lci.hpp:284
const comp_t COMP_NULL_RETRY
Special completion object setting allow_posted and allow_retry to false.
Definition lci.hpp:652
@ ring
Definition lci.hpp:233
@ direct
Definition lci.hpp:231
@ tree
Definition lci.hpp:232
@ retry
Definition lci.hpp:132
@ retry_nopacket
Definition lci.hpp:136
@ done_max
Definition lci.hpp:124
@ posted_backlog
Definition lci.hpp:128
@ done
Definition lci.hpp:121
@ retry_min
Definition lci.hpp:131
@ done_min
Definition lci.hpp:120
@ retry_lock
Definition lci.hpp:135
@ posted_min
Definition lci.hpp:125
@ retry_max
Definition lci.hpp:142
@ posted
Definition lci.hpp:126
@ retry_backlog
Definition lci.hpp:140
@ retry_init
Definition lci.hpp:134
@ done_backlog
Definition lci.hpp:122
@ retry_nomem
Definition lci.hpp:138
@ fatal
Definition lci.hpp:143
@ posted_max
Definition lci.hpp:130
@ READ
Definition lci.hpp:215
@ SEND
Definition lci.hpp:211
@ REMOTE_WRITE
Definition lci.hpp:214
@ RECV
Definition lci.hpp:212
@ WRITE
Definition lci.hpp:213
@ IN
Definition lci.hpp:355
@ OUT
Definition lci.hpp:354
@ max
Definition lci.hpp:397
@ rank_tag
Definition lci.hpp:396
@ tag_only
Definition lci.hpp:395
@ rank_only
Definition lci.hpp:394
@ send
Definition lci.hpp:384
@ recv
Definition lci.hpp:385
@ buffer
Definition lci.hpp:419
@ network
Definition lci.hpp:420
All LCI API functions and classes are defined in this namespace.
const char * get_allreduce_algorithm_str(broadcast_algorithm_t algorithm)
Get the string representation of a collective algorithm.
void swap(data_t &first, data_t &second)
Definition lci.hpp:941
attr_backend_t
Definition lci.hpp:63
@ none
Definition lci.hpp:64
@ ibv
Definition lci.hpp:65
@ ofi
Definition lci.hpp:66
@ ucx
Definition lci.hpp:67
const graph_node_t GRAPH_END
Definition lci.hpp:706
const char * get_reduce_scatter_algorithm_str(broadcast_algorithm_t algorithm)
Get the string representation of a collective algorithm.
@ graph
Definition lci_binding_pre.hpp:32
const char * get_errorcode_str(errorcode_t errorcode)
Get the string representation of an error code.
void graph_free_op_fn(void *value)
Definition lci.hpp:804
std::vector< rbuffer_t > rbuffers_t
Definition lci.hpp:455
attr_net_lock_mode_t
Definition lci.hpp:70
@ LCI_NET_TRYLOCK_POLL
Definition lci.hpp:73
@ LCI_NET_TRYLOCK_SEND
Definition lci.hpp:71
@ LCI_NET_TRYLOCK_RECV
Definition lci.hpp:72
@ LCI_NET_TRYLOCK_MAX
Definition lci.hpp:74
const char * get_net_opcode_str(net_opcode_t opcode)
Get the string representation of a network operation code.
std::enable_if< std::is_same< typenamestd::result_of< T()>::type, status_t >::value, status_t >::type graph_execute_op_fn(void *value)
Definition lci.hpp:770
const char * get_broadcast_algorithm_str(broadcast_algorithm_t algorithm)
Get the string representation of a collective algorithm.
std::vector< buffer_t > buffers_t
Definition lci.hpp:454
The user-defined allocator type.
Definition lci.hpp:461
virtual ~allocator_base_t()=default
virtual void deallocate(void *ptr)=0
virtual void * allocate(size_t size)=0
The type of a local buffer descriptor.
Definition lci.hpp:430
size_t size
Definition lci.hpp:432
void * base
Definition lci.hpp:431
buffer_t(void *base_, size_t size_)
Definition lci.hpp:435
mr_t mr
Definition lci.hpp:433
buffer_t(void *base_, size_t size_, mr_t mr_)
Definition lci.hpp:436
buffer_t()
Definition lci.hpp:434
Definition lci_binding_pre.hpp:99
A generic type for describing or holding data.
Definition lci.hpp:494
static const int MAX_SCALAR_SIZE
Definition lci.hpp:495
get_semantic_t
Enum class of get semantic.
Definition lci.hpp:566
@ copy
Definition lci.hpp:568
@ view
Definition lci.hpp:569
@ move
Definition lci.hpp:567
bool own_data
Definition lci.hpp:512
T get_scalar() const
Get the scalar data from the data object.
Definition lci.hpp:997
type_t
Definition lci.hpp:496
@ LCI_DATA_TYPE_BUFFERS
Definition lci.hpp:500
@ LCI_DATA_TYPE_SCALAR
Definition lci.hpp:498
@ LCI_DATA_TYPE_BUFFER
Definition lci.hpp:499
@ LCI_DATA_TYPE_NONE
Definition lci.hpp:497
void copy_from(const void *data_, size_t size, allocator_base_t *allocator_=nullptr)
Definition lci.hpp:957
buffers_t get_buffers(get_semantic_t semantic=get_semantic_t::move)
Get the buffers from the data object.
Definition lci.hpp:1052
buffer_t * buffers
Definition lci.hpp:531
void * base
Definition lci.hpp:524
void set_type(type_t type_)
Definition lci.hpp:548
struct lci::data_t::@076173265013046342263132075131334126052375112161::@304232263224033304106252124165030274231050146201 buffer
size_t get_buffers_count() const
Get the number of buffers from the data object.
Definition lci.hpp:1044
struct lci::data_t::@076173265013046342263132075131334126052375112161::@363335147013034143035040152023326255073312106017 scalar
char data[MAX_SCALAR_SIZE]
Definition lci.hpp:518
bool is_buffer() const
Definition lci.hpp:553
data_t & operator=(data_t other)
Definition lci.hpp:935
uint8_t size
Definition lci.hpp:517
type_t type
Definition lci.hpp:511
bool is_scalar() const
Definition lci.hpp:552
data_t()
Definition lci.hpp:834
size_t count
Definition lci.hpp:530
buffer_t get_buffer(get_semantic_t semantic=get_semantic_t::move)
Get the buffer from the data object.
Definition lci.hpp:1015
bool is_buffers() const
Definition lci.hpp:554
mr_t mr
Definition lci.hpp:525
struct lci::data_t::@076173265013046342263132075131334126052375112161::@072116374306302151235374307357141054206077020333 common
void set_own_data(bool own_data_)
Definition lci.hpp:550
type_t get_type() const
Definition lci.hpp:547
bool get_own_data() const
Definition lci.hpp:549
friend void swap(data_t &first, data_t &second)
Definition lci.hpp:941
Wrapper class for error code.
Definition lci.hpp:160
bool is_done() const
Check if the error code is in the done category.
Definition lci.hpp:176
error_t()
Definition lci.hpp:162
bool is_posted() const
Check if the error code is in the posted category.
Definition lci.hpp:185
const char * get_str() const
Get the string representation of the error code.
Definition lci.hpp:203
errorcode_t errorcode
Definition lci.hpp:161
void reset_retry()
Reset the error code to retry.
Definition lci.hpp:171
error_t(errorcode_t errorcode_)
Construct an error_t object with a specific error code.
Definition lci.hpp:167
bool is_retry() const
Check if the error code is in the retry category.
Definition lci.hpp:194
The struct for network status.
Definition lci.hpp:292
net_imm_data_t imm_data
Definition lci.hpp:297
int rank
Definition lci.hpp:294
void * user_context
Definition lci.hpp:295
net_opcode_t opcode
Definition lci.hpp:293
size_t length
Definition lci.hpp:296
bool m_is_set
Definition lci.hpp:100
option_t()
Definition lci.hpp:80
T get_value() const
Definition lci.hpp:96
T get_value_or(T default_value) const
Definition lci.hpp:84
bool get_set_value(T *value) const
Definition lci.hpp:88
T m_value
Definition lci.hpp:99
option_t(T value_, bool is_set_)
Definition lci.hpp:82
bool is_set() const
Definition lci.hpp:97
option_t(T value_)
Definition lci.hpp:81
rbuffer_t(uintptr_t disp_, rmr_t rmr_)
Definition lci.hpp:452
uintptr_t disp
Definition lci.hpp:448
rbuffer_t(uintptr_t disp_)
Definition lci.hpp:451
rbuffer_t()
Definition lci.hpp:450
rmr_t rmr
Definition lci.hpp:449
The type of remote memory region.
Definition lci.hpp:330
uintptr_t base
Definition lci.hpp:331
bool is_empty() const
Definition lci.hpp:334
uint64_t opaque_rkey
Definition lci.hpp:332
rmr_t()
Definition lci.hpp:333
The type of the completion desciptor for a posted communication.
Definition lci.hpp:604
bool is_buffer() const
Definition lci.hpp:630
status_t(errorcode_t error_)
Definition lci.hpp:611
bool is_scalar() const
Definition lci.hpp:629
status_t(void *user_context_)
Definition lci.hpp:612
void set_retry()
Definition lci.hpp:618
data_t data
Definition lci.hpp:607
error_t error
Definition lci.hpp:605
void set_done()
Definition lci.hpp:616
tag_t tag
Definition lci.hpp:608
T get_scalar() const
Definition lci.hpp:623
void set_posted()
Definition lci.hpp:617
bool is_done() const
Definition lci.hpp:619
void * user_context
Definition lci.hpp:609
bool is_posted() const
Definition lci.hpp:620
bool is_buffers() const
Definition lci.hpp:631
bool is_retry() const
Definition lci.hpp:621
int rank
Definition lci.hpp:606
buffers_t get_buffers()
Definition lci.hpp:628
buffer_t get_buffer()
Definition lci.hpp:627