-
Notifications
You must be signed in to change notification settings - Fork 8
/
libibverbscpp.h
executable file
·3537 lines (2741 loc) · 113 KB
/
libibverbscpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef LIBIBVERBSCPP_LIBRARY_H
#define LIBIBVERBSCPP_LIBRARY_H
#include <fcntl.h>
#include <infiniband/verbs.h>
#include <iostream>
#include <memory>
#include <sstream>
namespace ibv {
namespace internal {
[[nodiscard]] inline std::runtime_error exception(const char *function, int errnum);
constexpr void check(const char *function, bool ok);
constexpr void checkStatus(const char *function, int status);
constexpr void checkPtr(const char *function, const void *ptr);
constexpr void checkStatusNoThrow(const char *function, int status) noexcept;
struct PointerOnly {
PointerOnly() = delete;
PointerOnly(const PointerOnly &) = delete;
PointerOnly &operator=(const PointerOnly &) = delete;
PointerOnly(PointerOnly &&) = delete;
PointerOnly &operator=(PointerOnly &&) = delete;
~PointerOnly() = default;
};
} // namespace internal
enum class NodeType : std::underlying_type_t<ibv_node_type> {
UNKNOWN = IBV_NODE_UNKNOWN,
CA = IBV_NODE_CA,
SWITCH = IBV_NODE_SWITCH,
ROUTER = IBV_NODE_ROUTER,
RNIC = IBV_NODE_RNIC,
USNIC = IBV_NODE_USNIC,
USNIC_UDP = IBV_NODE_USNIC_UDP
};
enum class TransportType : std::underlying_type_t<ibv_transport_type> {
UNKNOWN = IBV_TRANSPORT_UNKNOWN,
IB = IBV_TRANSPORT_IB,
IWARP = IBV_TRANSPORT_IWARP,
USNIC = IBV_TRANSPORT_USNIC,
USNIC_UDP = IBV_TRANSPORT_USNIC_UDP
};
enum class AccessFlag : std::underlying_type_t<ibv_access_flags> {
LOCAL_WRITE = IBV_ACCESS_LOCAL_WRITE,
REMOTE_WRITE = IBV_ACCESS_REMOTE_WRITE, /// Enable Remote Write Access. Requires local write access to the MR
REMOTE_READ = IBV_ACCESS_REMOTE_READ, /// Enable Remote Read Access
REMOTE_ATOMIC = IBV_ACCESS_REMOTE_ATOMIC, /// Enable Remote Atomic Operation Access (if supported). Requires local write access to the MR
MW_BIND = IBV_ACCESS_MW_BIND,
ZERO_BASED = IBV_ACCESS_ZERO_BASED, /// If set, the address set on the 'remote_addr' field on the WR will be an offset from the MW's start address.
ON_DEMAND = IBV_ACCESS_ON_DEMAND
};
struct Gid {
ibv_gid underlying;
[[nodiscard]] constexpr uint64_t getSubnetPrefix() const;
[[nodiscard]] constexpr uint64_t getInterfaceId() const;
};
class GlobalRoutingHeader : public ibv_grh {
using ibv_grh::dgid;
using ibv_grh::hop_limit;
using ibv_grh::next_hdr;
using ibv_grh::paylen;
using ibv_grh::sgid;
using ibv_grh::version_tclass_flow;
public:
[[nodiscard]] constexpr uint32_t getVersionTclassFlow() const;
[[nodiscard]] constexpr uint16_t getPaylen() const;
[[nodiscard]] constexpr uint8_t getNextHdr() const;
[[nodiscard]] constexpr uint8_t getHopLimit() const;
[[nodiscard]] const Gid &getSgid() const;
[[nodiscard]] const Gid &getDgid() const;
};
static_assert(sizeof(GlobalRoutingHeader) == sizeof(ibv_grh), "");
class GlobalRoute : public ibv_global_route {
using ibv_global_route::dgid;
using ibv_global_route::flow_label;
using ibv_global_route::hop_limit;
using ibv_global_route::sgid_index;
using ibv_global_route::traffic_class;
public:
/// Destination GID or MGID
[[nodiscard]] const Gid &getDgid() const;
/// Destination GID or MGID
void setDgid(const Gid &dGid);
/// Flow label
[[nodiscard]] constexpr uint32_t getFlowLabel() const;
/// Flow label
constexpr void setFlowLabel(uint32_t flowLabel);
/// Source GID index
[[nodiscard]] constexpr uint8_t getSgidIndex() const;
/// Source GID index
constexpr void getSgidIndex(uint8_t sgidIndex);
/// Hop limit
[[nodiscard]] constexpr uint8_t getHopLimit() const;
/// Hop limit
constexpr void setHopLimit(uint8_t hopLimit);
/// Traffic class
[[nodiscard]] constexpr uint8_t getTrafficClass() const;
/// Traffic class
constexpr void setTrafficClass(uint8_t trafficClass);
};
static_assert(sizeof(GlobalRoute) == sizeof(ibv_global_route), "");
namespace flow {
enum class Flags : std::underlying_type_t<ibv_flow_flags> {
DONT_TRAP = IBV_FLOW_ATTR_FLAGS_DONT_TRAP
};
enum class AttributeType : std::underlying_type_t<ibv_flow_attr_type> {
NORMAL = IBV_FLOW_ATTR_NORMAL,
ALL_DEFAULT = IBV_FLOW_ATTR_ALL_DEFAULT,
MC_DEFAULT = IBV_FLOW_ATTR_MC_DEFAULT
};
enum class SpecType : std::underlying_type_t<ibv_flow_spec_type> {
ETH = IBV_FLOW_SPEC_ETH,
IPV4 = IBV_FLOW_SPEC_IPV4,
TCP = IBV_FLOW_SPEC_TCP,
UDP = IBV_FLOW_SPEC_UDP
};
struct Spec : ibv_flow_spec {
constexpr SpecType getType() const;
constexpr uint16_t getSize() const;
};
struct EthFilter : ibv_flow_eth_filter {
};
struct IPv4Filter : ibv_flow_ipv4_filter {
};
struct TcpUdpFilter : ibv_flow_tcp_udp_filter {
};
struct Attributes : ibv_flow_attr {
};
class Flow : public ibv_flow, public internal::PointerOnly {
using ibv_flow::comp_mask;
using ibv_flow::context;
using ibv_flow::handle;
public:
static void *operator new(std::size_t) noexcept = delete;
static void operator delete(void *ptr) noexcept;
};
} // namespace flow
namespace context {
class Context;
} // namespace context
namespace protectiondomain {
class ProtectionDomain;
} // namespace protectiondomain
namespace workcompletion {
enum class Status : std::underlying_type_t<ibv_wc_status> {
SUCCESS = IBV_WC_SUCCESS,
LOC_LEN_ERR = IBV_WC_LOC_LEN_ERR,
LOC_QP_OP_ERR = IBV_WC_LOC_QP_OP_ERR,
LOC_EEC_OP_ERR = IBV_WC_LOC_EEC_OP_ERR,
LOC_PROT_ERR = IBV_WC_LOC_PROT_ERR,
WR_FLUSH_ERR = IBV_WC_WR_FLUSH_ERR,
MW_BIND_ERR = IBV_WC_MW_BIND_ERR,
BAD_RESP_ERR = IBV_WC_BAD_RESP_ERR,
LOC_ACCESS_ERR = IBV_WC_LOC_ACCESS_ERR,
REM_INV_REQ_ERR = IBV_WC_REM_INV_REQ_ERR,
REM_ACCESS_ERR = IBV_WC_REM_ACCESS_ERR,
REM_OP_ERR = IBV_WC_REM_OP_ERR,
RETRY_EXC_ERR = IBV_WC_RETRY_EXC_ERR,
RNR_RETRY_EXC_ERR = IBV_WC_RNR_RETRY_EXC_ERR,
LOC_RDD_VIOL_ERR = IBV_WC_LOC_RDD_VIOL_ERR,
REM_INV_RD_REQ_ERR = IBV_WC_REM_INV_RD_REQ_ERR,
REM_ABORT_ERR = IBV_WC_REM_ABORT_ERR,
INV_EECN_ERR = IBV_WC_INV_EECN_ERR,
INV_EEC_STATE_ERR = IBV_WC_INV_EEC_STATE_ERR,
FATAL_ERR = IBV_WC_FATAL_ERR,
RESP_TIMEOUT_ERR = IBV_WC_RESP_TIMEOUT_ERR,
GENERAL_ERR = IBV_WC_GENERAL_ERR
};
/// Opcode for work completions
enum class Opcode : std::underlying_type_t<ibv_wc_opcode> {
/// Either workrequest::Send or workrequest::SendWithImm
SEND = IBV_WC_SEND,
/// Either workrequest::Write or workrequest::WriteWithImm
RDMA_WRITE = IBV_WC_RDMA_WRITE,
/// workrequest::Read
RDMA_READ = IBV_WC_RDMA_READ,
/// workrequest::AtomicCompareSwap
COMP_SWAP = IBV_WC_COMP_SWAP,
/// workrequest::AtomicFetchAdd
FETCH_ADD = IBV_WC_FETCH_ADD,
/// Currently not supported. Should match IBV_WR_BIND_MW
BIND_MW = IBV_WC_BIND_MW,
/// Currently not supported. Should match IBV_WR_LOCAL_INV
LOCAL_INV = IBV_WC_LOCAL_INV,
/// workrequest::Recv
RECV = IBV_WC_RECV,
/// workrequest::Recv, but additionally has immediate data
RECV_RDMA_WITH_IMM = IBV_WC_RECV_RDMA_WITH_IMM
};
enum class Flag : std::underlying_type_t<ibv_wc_flags> {
GRH = IBV_WC_GRH,
WITH_IMM = IBV_WC_WITH_IMM,
IP_CSUM_OK = IBV_WC_IP_CSUM_OK,
WITH_INV = IBV_WC_WITH_INV
};
class WorkCompletion : public ibv_wc {
using ibv_wc::byte_len;
using ibv_wc::imm_data;
using ibv_wc::opcode;
using ibv_wc::status;
using ibv_wc::vendor_err;
using ibv_wc::wr_id;
// using ibv_wc::invalidated_rkey;
using ibv_wc::dlid_path_bits;
using ibv_wc::pkey_index;
using ibv_wc::qp_num;
using ibv_wc::sl;
using ibv_wc::slid;
using ibv_wc::src_qp;
using ibv_wc::wc_flags;
public:
[[nodiscard]] constexpr uint64_t getId() const;
[[nodiscard]] constexpr Status getStatus() const;
[[nodiscard]] constexpr bool isSuccessful() const;
[[nodiscard]] explicit constexpr operator bool() const;
[[nodiscard]] constexpr Opcode getOpcode() const;
[[nodiscard]] constexpr bool hasImmData() const;
[[nodiscard]] constexpr bool hasInvRkey() const;
[[nodiscard]] constexpr uint32_t getImmData() const;
[[nodiscard]] constexpr uint32_t getInvRkey() const;
[[nodiscard]] constexpr uint32_t getQueuePairNumber() const;
[[nodiscard]] constexpr uint32_t getSourceQueuePair() const;
[[nodiscard]] constexpr bool testFlag(Flag flag) const;
[[nodiscard]] constexpr uint16_t getPkeyIndex() const;
[[nodiscard]] constexpr uint16_t getSlid() const;
[[nodiscard]] constexpr uint8_t getSl() const;
[[nodiscard]] constexpr uint8_t getDlidPathBits() const;
private:
constexpr static void checkCondition(bool condition);
};
static_assert(sizeof(WorkCompletion) == sizeof(ibv_wc), "");
[[nodiscard]] inline std::string to_string(Opcode opcode);
[[nodiscard]] inline std::string to_string(Status status);
} // namespace workcompletion
namespace ah {
class Attributes : public ibv_ah_attr {
using ibv_ah_attr::dlid;
using ibv_ah_attr::grh;
using ibv_ah_attr::is_global;
using ibv_ah_attr::port_num;
using ibv_ah_attr::sl;
using ibv_ah_attr::src_path_bits;
using ibv_ah_attr::static_rate;
public:
/// Global Routing Header (GRH) attributes
[[nodiscard]] const GlobalRoute &getGrh() const;
/// Global Routing Header (GRH) attributes
constexpr void setGrh(const GlobalRoute &grh);
/// Destination LID
[[nodiscard]] constexpr uint16_t getDlid() const;
/// Destination LID
constexpr void setDlid(uint16_t dlid);
/// Service Level
[[nodiscard]] constexpr uint8_t getSl() const;
/// Service Level
constexpr void setSl(uint8_t sl);
/// Source path bits
[[nodiscard]] constexpr uint8_t getSrcPathBits() const;
/// Source path bits
constexpr void setSrcPathBits(uint8_t src_path_bits);
/// Maximum static rate
[[nodiscard]] constexpr uint8_t getStaticRate() const;
/// Maximum static rate
constexpr void setStaticRate(uint8_t static_rate);
/// GRH attributes are valid
[[nodiscard]] constexpr bool getIsGlobal() const;
/// GRH attributes are valid
constexpr void setIsGlobal(bool is_global);
/// Physical port number
[[nodiscard]] constexpr uint8_t getPortNum() const;
/// Physical port number
constexpr void setPortNum(uint8_t port_num);
};
static_assert(sizeof(Attributes) == sizeof(ibv_ah_attr), "");
class AddressHandle : public ibv_ah, public internal::PointerOnly {
using ibv_ah::context;
using ibv_ah::handle;
using ibv_ah::pd;
public:
static void *operator new(std::size_t) noexcept = delete;
static void operator delete(void *ptr) noexcept;
};
static_assert(sizeof(AddressHandle) == sizeof(ibv_ah), "");
} // namespace ah
namespace completions {
class CompletionQueue : public ibv_cq, public internal::PointerOnly {
using ibv_cq::async_events_completed;
using ibv_cq::channel;
using ibv_cq::comp_events_completed;
using ibv_cq::cond;
using ibv_cq::context;
using ibv_cq::cq_context;
using ibv_cq::cqe;
using ibv_cq::handle;
using ibv_cq::mutex;
public:
static void *operator new(std::size_t) noexcept = delete;
static void operator delete(void *ptr) noexcept;
/// Resize the CompletionQueue to have at last newCqe entries
void resize(int newCqe);
/// Acknowledge nEvents events on the CompletionQueue
void ackEvents(unsigned int nEvents);
/// Poll the CompletionQueue for the next numEntries WorkCompletions and put them into resultArray
/// @returns the number of completions found
[[nodiscard]] int poll(int numEntries, workcompletion::WorkCompletion *resultArray);
/// Request completion notification event on this CompletionQueue for the associated CompletionEventChannel
/// @param solicitedOnly if the events should only be produced for workrequests with Flags::SOLICITED
void requestNotify(bool solicitedOnly);
};
static_assert(sizeof(CompletionQueue) == sizeof(ibv_cq), "");
class CompletionEventChannel : public ibv_comp_channel, public internal::PointerOnly {
using ibv_comp_channel::context;
using ibv_comp_channel::fd;
using ibv_comp_channel::refcnt;
public:
static void *operator new(std::size_t) noexcept = delete;
static void operator delete(void *ptr) noexcept;
/// Wait for the next completion event in this CompletionEventChannel
/// @returns the CompletionQueue, that got the event and the CompletionQueues QP context @see setQpContext
[[nodiscard]] std::tuple<CompletionQueue *, void *> getEvent();
};
static_assert(sizeof(CompletionEventChannel) == sizeof(ibv_comp_channel), "");
} // namespace completions
enum class Mtu : std::underlying_type_t<ibv_mtu> {
_256 = IBV_MTU_256,
_512 = IBV_MTU_512,
_1024 = IBV_MTU_1024,
_2048 = IBV_MTU_2048,
_4096 = IBV_MTU_4096
};
[[nodiscard]] inline std::string to_string(Mtu mtu);
namespace port {
enum class State : std::underlying_type_t<ibv_port_state> {
NOP = IBV_PORT_NOP,
DOWN = IBV_PORT_DOWN,
INIT = IBV_PORT_INIT,
ARMED = IBV_PORT_ARMED,
ACTIVE = IBV_PORT_ACTIVE,
ACTIVE_DEFER = IBV_PORT_ACTIVE_DEFER
};
enum class CapabilityFlag : std::underlying_type_t<ibv_port_cap_flags> {
SM = IBV_PORT_SM,
NOTICE_SUP = IBV_PORT_NOTICE_SUP,
TRAP_SUP = IBV_PORT_TRAP_SUP,
OPT_IPD_SUP = IBV_PORT_OPT_IPD_SUP,
AUTO_MIGR_SUP = IBV_PORT_AUTO_MIGR_SUP,
SL_MAP_SUP = IBV_PORT_SL_MAP_SUP,
MKEY_NVRAM = IBV_PORT_MKEY_NVRAM,
PKEY_NVRAM = IBV_PORT_PKEY_NVRAM,
LED_INFO_SUP = IBV_PORT_LED_INFO_SUP,
SYS_IMAGE_GUID_SUP = IBV_PORT_SYS_IMAGE_GUID_SUP,
PKEY_SW_EXT_PORT_TRAP_SUP = IBV_PORT_PKEY_SW_EXT_PORT_TRAP_SUP,
EXTENDED_SPEEDS_SUP = IBV_PORT_EXTENDED_SPEEDS_SUP,
CM_SUP = IBV_PORT_CM_SUP,
SNMP_TUNNEL_SUP = IBV_PORT_SNMP_TUNNEL_SUP,
REINIT_SUP = IBV_PORT_REINIT_SUP,
DEVICE_MGMT_SUP = IBV_PORT_DEVICE_MGMT_SUP,
VENDOR_CLASS_SUP = IBV_PORT_VENDOR_CLASS_SUP,
DR_NOTICE_SUP = IBV_PORT_DR_NOTICE_SUP,
CAP_MASK_NOTICE_SUP = IBV_PORT_CAP_MASK_NOTICE_SUP,
BOOT_MGMT_SUP = IBV_PORT_BOOT_MGMT_SUP,
LINK_LATENCY_SUP = IBV_PORT_LINK_LATENCY_SUP,
CLIENT_REG_SUP = IBV_PORT_CLIENT_REG_SUP,
IP_BASED_GIDS = IBV_PORT_IP_BASED_GIDS
};
class Attributes : public ibv_port_attr {
using ibv_port_attr::active_mtu;
using ibv_port_attr::active_speed;
using ibv_port_attr::active_width;
using ibv_port_attr::bad_pkey_cntr;
using ibv_port_attr::gid_tbl_len;
using ibv_port_attr::init_type_reply;
using ibv_port_attr::lid;
using ibv_port_attr::link_layer;
using ibv_port_attr::lmc;
using ibv_port_attr::max_msg_sz;
using ibv_port_attr::max_mtu;
using ibv_port_attr::max_vl_num;
using ibv_port_attr::phys_state;
using ibv_port_attr::pkey_tbl_len;
using ibv_port_attr::port_cap_flags;
using ibv_port_attr::qkey_viol_cntr;
using ibv_port_attr::sm_lid;
using ibv_port_attr::sm_sl;
using ibv_port_attr::state;
using ibv_port_attr::subnet_timeout;
public:
/// Logical port state
[[nodiscard]] constexpr State getState() const;
/// Max MTU supported by port
[[nodiscard]] constexpr Mtu getMaxMtu() const;
/// Actual MTU
[[nodiscard]] constexpr Mtu getActiveMtu() const;
/// Length of source GID table
[[nodiscard]] constexpr int getGidTblLen() const;
/// test port capabilities
[[nodiscard]] constexpr bool hasCapability(CapabilityFlag flag);
/// Maximum message size
[[nodiscard]] constexpr uint32_t getMaxMsgSize() const;
/// Bad P_Key counter
[[nodiscard]] constexpr uint32_t getBadPkeyCntr() const;
/// Q_Key violation counter
[[nodiscard]] constexpr uint32_t getQkeyViolCntr() const;
/// Length of partition table
[[nodiscard]] constexpr uint16_t getPkeyTblLen() const;
/// Base port LID
[[nodiscard]] constexpr uint16_t getLid() const;
/// SM LID
[[nodiscard]] constexpr uint16_t getSmLid() const;
/// LMC of LID
[[nodiscard]] constexpr uint8_t getLmc() const;
/// Maximum number of VLs
[[nodiscard]] constexpr uint8_t getMaxVlNum() const;
/// SM service level
[[nodiscard]] constexpr uint8_t getSmSl() const;
/// Subnet propagation delay
[[nodiscard]] constexpr uint8_t getSubnetTimeout() const;
/// Type of initialization performed by SM
[[nodiscard]] constexpr uint8_t getInitTypeReply() const;
/// Currently active link width
[[nodiscard]] constexpr uint8_t getActiveWidth() const;
/// Currently active link speed
[[nodiscard]] constexpr uint8_t getActiveSpeed() const;
/// Physical port state
[[nodiscard]] constexpr uint8_t getPhysState() const;
/// link layer protocol of the port
[[nodiscard]] constexpr uint8_t getLinkLayer() const;
};
static_assert(sizeof(Attributes) == sizeof(ibv_port_attr), "");
} // namespace port
namespace device {
enum class CapabilityFlag : std::underlying_type_t<ibv_device_cap_flags> {
RESIZE_MAX_WR = IBV_DEVICE_RESIZE_MAX_WR,
BAD_PKEY_CNTR = IBV_DEVICE_BAD_PKEY_CNTR,
BAD_QKEY_CNTR = IBV_DEVICE_BAD_QKEY_CNTR,
RAW_MULTI = IBV_DEVICE_RAW_MULTI,
AUTO_PATH_MIG = IBV_DEVICE_AUTO_PATH_MIG,
CHANGE_PHY_PORT = IBV_DEVICE_CHANGE_PHY_PORT,
UD_AV_PORT_ENFORCE = IBV_DEVICE_UD_AV_PORT_ENFORCE,
CURR_QP_STATE_MOD = IBV_DEVICE_CURR_QP_STATE_MOD,
SHUTDOWN_PORT = IBV_DEVICE_SHUTDOWN_PORT,
INIT_TYPE = IBV_DEVICE_INIT_TYPE,
PORT_ACTIVE_EVENT = IBV_DEVICE_PORT_ACTIVE_EVENT,
SYS_IMAGE_GUID = IBV_DEVICE_SYS_IMAGE_GUID,
RC_RNR_NAK_GEN = IBV_DEVICE_RC_RNR_NAK_GEN,
SRQ_RESIZE = IBV_DEVICE_SRQ_RESIZE,
N_NOTIFY_CQ = IBV_DEVICE_N_NOTIFY_CQ,
MEM_WINDOW = IBV_DEVICE_MEM_WINDOW,
UD_IP_CSUM = IBV_DEVICE_UD_IP_CSUM,
XRC = IBV_DEVICE_XRC,
MEM_MGT_EXTENSIONS = IBV_DEVICE_MEM_MGT_EXTENSIONS,
MEM_WINDOW_TYPE_2A = IBV_DEVICE_MEM_WINDOW_TYPE_2A,
MEM_WINDOW_TYPE_2B = IBV_DEVICE_MEM_WINDOW_TYPE_2B,
RC_IP_CSUM = IBV_DEVICE_RC_IP_CSUM,
RAW_IP_CSUM = IBV_DEVICE_RAW_IP_CSUM,
MANAGED_FLOW_STEERING = IBV_DEVICE_MANAGED_FLOW_STEERING
};
enum class AtomicCapabilities : std::underlying_type_t<ibv_atomic_cap> {
NONE = IBV_ATOMIC_NONE,
HCA = IBV_ATOMIC_HCA,
GLOB = IBV_ATOMIC_GLOB
};
class Attributes : public ibv_device_attr {
using ibv_device_attr::atomic_cap;
using ibv_device_attr::device_cap_flags;
using ibv_device_attr::fw_ver;
using ibv_device_attr::hw_ver;
using ibv_device_attr::local_ca_ack_delay;
using ibv_device_attr::max_ah;
using ibv_device_attr::max_cq;
using ibv_device_attr::max_cqe;
using ibv_device_attr::max_ee;
using ibv_device_attr::max_ee_init_rd_atom;
using ibv_device_attr::max_ee_rd_atom;
using ibv_device_attr::max_fmr;
using ibv_device_attr::max_map_per_fmr;
using ibv_device_attr::max_mcast_grp;
using ibv_device_attr::max_mcast_qp_attach;
using ibv_device_attr::max_mr;
using ibv_device_attr::max_mr_size;
using ibv_device_attr::max_mw;
using ibv_device_attr::max_pd;
using ibv_device_attr::max_pkeys;
using ibv_device_attr::max_qp;
using ibv_device_attr::max_qp_init_rd_atom;
using ibv_device_attr::max_qp_rd_atom;
using ibv_device_attr::max_qp_wr;
using ibv_device_attr::max_raw_ethy_qp;
using ibv_device_attr::max_raw_ipv6_qp;
using ibv_device_attr::max_rdd;
using ibv_device_attr::max_res_rd_atom;
using ibv_device_attr::max_sge;
using ibv_device_attr::max_sge_rd;
using ibv_device_attr::max_srq;
using ibv_device_attr::max_srq_sge;
using ibv_device_attr::max_srq_wr;
using ibv_device_attr::max_total_mcast_qp_attach;
using ibv_device_attr::node_guid;
using ibv_device_attr::page_size_cap;
using ibv_device_attr::phys_port_cnt;
using ibv_device_attr::sys_image_guid;
using ibv_device_attr::vendor_id;
using ibv_device_attr::vendor_part_id;
public:
/// The Firmware verssion
[[nodiscard]] constexpr const char *getFwVer() const;
/// Node GUID (in network byte order)
[[nodiscard]] constexpr uint64_t getNodeGuid() const;
/// System image GUID (in network byte order)
[[nodiscard]] constexpr uint64_t getSysImageGuid() const;
/// Largest contiguous block that can be registered
[[nodiscard]] constexpr uint64_t getMaxMrSize() const;
/// Supported memory shift sizes
[[nodiscard]] constexpr uint64_t getPageSizeCap() const;
/// Vendor ID, per IEEE
[[nodiscard]] constexpr uint32_t getVendorId() const;
/// Vendor supplied part ID
[[nodiscard]] constexpr uint32_t getVendorPartId() const;
/// Hardware version
[[nodiscard]] constexpr uint32_t getHwVer() const;
/// Maximum number of supported QPs
[[nodiscard]] constexpr int getMaxQp() const;
/// Maximum number of outstanding WR on any work queue
[[nodiscard]] constexpr int getMaxQpWr() const;
/// Check for a capability
[[nodiscard]] constexpr bool hasCapability(CapabilityFlag flag) const;
/// Maximum number of s/g per WR for SQ & RQ of QP for non RDMA Read operations
[[nodiscard]] constexpr int getMaxSge() const;
/// Maximum number of s/g per WR for RDMA Read operations
[[nodiscard]] constexpr int getMaxSgeRd() const;
/// Maximum number of supported CQs
[[nodiscard]] constexpr int getMaxCq() const;
/// Maximum number of CQE capacity per CQ
[[nodiscard]] constexpr int getMaxCqe() const;
/// Maximum number of supported MRs
[[nodiscard]] constexpr int getMaxMr() const;
/// Maximum number of supported PDs
[[nodiscard]] constexpr int getMaxPd() const;
/// Maximum number of RDMA Read & Atomic operations that can be outstanding per QP
[[nodiscard]] constexpr int getMaxQpRdAtom() const;
/// Maximum number of RDMA Read & Atomic operations that can be outstanding per EEC
[[nodiscard]] constexpr int getMaxEeRdAtom() const;
/// Maximum number of resources used for RDMA Read & Atomic operations by this HCA as the Target
[[nodiscard]] constexpr int getMaxResRdAtom() const;
/// Maximum depth per QP for initiation of RDMA Read & Atomic operations
[[nodiscard]] constexpr int getMaxQpInitRdAtom() const;
/// Maximum depth per EEC for initiation of RDMA Read & Atomic operations
[[nodiscard]] constexpr int getMaxEeInitRdAtom() const;
/// Atomic operations support level
[[nodiscard]] constexpr AtomicCapabilities getAtomicCap() const;
/// Maximum number of supported EE contexts
[[nodiscard]] constexpr int getMaxEe() const;
/// Maximum number of supported RD domains
[[nodiscard]] constexpr int getMaxRdd() const;
/// Maximum number of supported MWs
[[nodiscard]] constexpr int getMaxMw() const;
/// Maximum number of supported raw IPv6 datagram QPs
[[nodiscard]] constexpr int getMaxRawIpv6Qp() const;
/// Maximum number of supported Ethertype datagram QPs
[[nodiscard]] constexpr int getMaxRawEthyQp() const;
/// Maximum number of supported multicast groups
[[nodiscard]] constexpr int getMaxMcastGrp() const;
/// Maximum number of QPs per multicast group which can be attached
[[nodiscard]] constexpr int getMaxMcastQpAttach() const;
/// Maximum number of QPs which can be attached to multicast groups
[[nodiscard]] constexpr int getMaxTotalMcastQpAttach() const;
/// Maximum number of supported address handles
[[nodiscard]] constexpr int getMaxAh() const;
/// Maximum number of supported FMRs
[[nodiscard]] constexpr int getMaxFmr() const;
/// Maximum number of (re)maps per FMR before an unmap operation in required
[[nodiscard]] constexpr int getMaxMapPerFmr() const;
/// Maximum number of supported SRQs
[[nodiscard]] constexpr int getMaxSrq() const;
/// Maximum number of WRs per SRQ
[[nodiscard]] constexpr int getMaxSrqWr() const;
/// Maximum number of s/g per SRQ
[[nodiscard]] constexpr int getMaxSrqSge() const;
/// Maximum number of partitions
[[nodiscard]] constexpr uint16_t getMaxPkeys() const;
/// Local CA ack delay
[[nodiscard]] constexpr uint8_t getLocalCaAckDelay() const;
/// Number of physical ports
[[nodiscard]] constexpr uint8_t getPhysPortCnt() const;
};
static_assert(sizeof(Attributes) == sizeof(ibv_device_attr), "");
class Device : public ibv_device, public internal::PointerOnly {
// using ibv_device::_ops;
using ibv_device::dev_name;
using ibv_device::dev_path;
using ibv_device::ibdev_path;
using ibv_device::name;
using ibv_device::node_type;
using ibv_device::transport_type;
public:
/// A human-readable name associated with the RDMA device
[[nodiscard]] const char *getName();
/// Global Unique IDentifier (GUID) of the RDMA device
[[nodiscard]] uint64_t getGUID();
/// Open a RDMA device context
[[nodiscard]] std::unique_ptr<context::Context> open();
};
static_assert(sizeof(Device) == sizeof(ibv_device), "");
class DeviceList {
int num_devices = 0; // needs to be initialized first
Device **devices = nullptr;
public:
/// Get a list of available RDMA devices
DeviceList();
~DeviceList();
DeviceList(const DeviceList &) = delete;
DeviceList &operator=(const DeviceList &) = delete;
DeviceList(DeviceList &&other) noexcept;
constexpr DeviceList &operator=(DeviceList &&other) noexcept;
[[nodiscard]] constexpr Device **begin();
[[nodiscard]] constexpr Device **end();
[[nodiscard]] constexpr size_t size() const;
[[nodiscard]] constexpr Device *&operator[](int idx);
};
} // namespace device
namespace memoryregion {
enum class ReregFlag : std::underlying_type_t<ibv_rereg_mr_flags> {
CHANGE_TRANSLATION = IBV_REREG_MR_CHANGE_TRANSLATION,
CHANGE_PD = IBV_REREG_MR_CHANGE_PD,
CHANGE_ACCESS = IBV_REREG_MR_CHANGE_ACCESS,
FLAGS_SUPPORTED = IBV_REREG_MR_FLAGS_SUPPORTED
};
enum class ReregErrorCode : std::underlying_type_t<ibv_rereg_mr_err_code> {
INPUT = IBV_REREG_MR_ERR_INPUT,
DONT_FORK_NEW = IBV_REREG_MR_ERR_DONT_FORK_NEW,
DO_FORK_OLD = IBV_REREG_MR_ERR_DO_FORK_OLD,
CMD = IBV_REREG_MR_ERR_CMD,
CMD_AND_DO_FORK_NEW = IBV_REREG_MR_ERR_CMD_AND_DO_FORK_NEW
};
[[nodiscard]] inline std::string to_string(ReregErrorCode ec);
struct Slice : public ibv_sge {
Slice() = default;
Slice(uint64_t addr, uint32_t length, uint32_t lkey) : ibv_sge{addr, length, lkey} {}
};
struct RemoteAddress {
uint64_t address;
uint32_t rkey;
[[nodiscard]] constexpr RemoteAddress offset(uint64_t offset) const noexcept;
};
class MemoryRegion : public ibv_mr, public internal::PointerOnly {
using ibv_mr::addr;
using ibv_mr::context;
using ibv_mr::handle;
using ibv_mr::length;
using ibv_mr::lkey;
using ibv_mr::pd;
using ibv_mr::rkey;
public:
static void *operator new(std::size_t) noexcept = delete;
static void operator delete(void *ptr) noexcept;
[[nodiscard]] context::Context *getContext() const;
[[nodiscard]] protectiondomain::ProtectionDomain *getPd() const;
[[nodiscard]] constexpr void *getAddr() const;
[[nodiscard]] constexpr size_t getLength() const;
[[nodiscard]] constexpr uint32_t getHandle() const;
[[nodiscard]] constexpr uint32_t getLkey() const;
[[nodiscard]] constexpr uint32_t getRkey() const;
[[nodiscard]] Slice getSlice();
[[nodiscard]] Slice getSlice(uint32_t offset, uint32_t sliceLength);
[[nodiscard]] RemoteAddress getRemoteAddress();
/// Reregister the MemoryRegion to modify the attribotes of an existing MemoryRegion,
/// reusing resources whenever possible
void reRegister(std::initializer_list<ReregFlag> changeFlags, protectiondomain::ProtectionDomain *newPd,
void *newAddr, size_t newLength, std::initializer_list<AccessFlag> accessFlags);
};
static_assert(sizeof(MemoryRegion) == sizeof(ibv_mr), "");
[[nodiscard]] inline std::string to_string(const MemoryRegion &mr);
} // namespace memoryregion
namespace workrequest {
// internal
enum class Opcode : std::underlying_type_t<ibv_wr_opcode> {
RDMA_WRITE = IBV_WR_RDMA_WRITE,
RDMA_WRITE_WITH_IMM = IBV_WR_RDMA_WRITE_WITH_IMM,
SEND = IBV_WR_SEND,
SEND_WITH_IMM = IBV_WR_SEND_WITH_IMM,
RDMA_READ = IBV_WR_RDMA_READ,
ATOMIC_CMP_AND_SWP = IBV_WR_ATOMIC_CMP_AND_SWP,
ATOMIC_FETCH_AND_ADD = IBV_WR_ATOMIC_FETCH_AND_ADD,
LOCAL_INV = IBV_WR_LOCAL_INV,
BIND_MW = IBV_WR_BIND_MW,
SEND_WITH_INV = IBV_WR_SEND_WITH_INV
};
enum class Flags : std::underlying_type_t<ibv_send_flags> {
FENCE = IBV_SEND_FENCE, /// The fence Indicator (valid for RC)
SIGNALED = IBV_SEND_SIGNALED, /// The completion notification indicator. Relevant only if QP was created with setSignalAll(true)
SOLICITED = IBV_SEND_SOLICITED, /// The solocited event indicator. Valid for Send / Write with immediate
INLINE = IBV_SEND_INLINE, /// Send data as inline data. Valid for Send / Write
IP_CSUM = IBV_SEND_IP_CSUM /// Offload the IBv4 and TCP/UDP checksum calculation. Valid when the device supports checksum offload (see Context.queryAttributes())
};
struct SendWr : public ibv_send_wr {
private:
using ibv_send_wr::imm_data;
using ibv_send_wr::next;
using ibv_send_wr::num_sge;
using ibv_send_wr::opcode;
using ibv_send_wr::send_flags;
using ibv_send_wr::sg_list;
using ibv_send_wr::wr_id;
// using ibv_send_wr::invalidate_rkey;
using ibv_send_wr::bind_mw;
using ibv_send_wr::qp_type;
using ibv_send_wr::wr;
// using ibv_send_wr::tso;
public:
constexpr SendWr();
/// A user defined Identifier
constexpr void setId(uint64_t id);
/// A user defined Identifier
[[nodiscard]] constexpr uint64_t getId() const;
/// Pointer to the next WorkRequest. nullptr if last
constexpr void setNext(SendWr *wrList);
/// Set the scatter / gather array
constexpr void setSge(memoryregion::Slice *scatterGatherArray, int size);
/// Set a single flag specifying the work request properties
constexpr void setFlag(Flags flag);
constexpr void setFence();
constexpr void setSignaled();
constexpr void setSolicited();
constexpr void setInline();
constexpr void setIpCsum();
/// Set multiple flags specifying the work request properties
constexpr void setFlags(std::initializer_list<Flags> flags);
protected:
constexpr void setOpcode(Opcode opcode);
/// Set Immediate data for this workrequest
constexpr void setImmData(uint32_t data);
[[nodiscard]] constexpr decltype(wr) &getWr();
};
static_assert(sizeof(SendWr) == sizeof(ibv_send_wr), "");
// internal
struct Rdma : SendWr {
/// Set the RemoteAddress, this operation should work on
constexpr void setRemoteAddress(memoryregion::RemoteAddress remoteAddress);
[[deprecated]] constexpr void setRemoteAddress(uint64_t remote_addr, uint32_t rkey);
};
struct Write : Rdma {
constexpr Write();
};
struct WriteWithImm : Write {
constexpr WriteWithImm();
using SendWr::setImmData;
};
struct Send : SendWr {
constexpr Send();
/// Address handle for the remote node address
constexpr void setUDAddressHandle(ah::AddressHandle &ah);
/// QueuePair number and QKey of the destination QueuePair
constexpr void setUDRemoteQueue(uint32_t qpn, uint32_t qkey);
};
struct SendWithImm : SendWr {
constexpr SendWithImm();
using SendWr::setImmData;
};