forked from open-mpi/ompi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spml_ikrit.c
1459 lines (1257 loc) · 45.5 KB
/
spml_ikrit.c
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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2013-2015 Mellanox Technologies, Inc.
* All rights reserved.
* Copyright (c) 2014 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include "oshmem_config.h"
#include "opal/datatype/opal_convertor.h"
#include "opal/mca/memchecker/base/base.h"
#include "orte/include/orte/types.h"
#include "orte/runtime/orte_globals.h"
#include "oshmem/mca/spml/ikrit/spml_ikrit.h"
#include "oshmem/include/shmem.h"
#include "oshmem/mca/memheap/memheap.h"
#include "oshmem/mca/memheap/base/base.h"
#include "oshmem/proc/proc.h"
#include "oshmem/mca/spml/base/base.h"
#include "oshmem/mca/spml/base/spml_base_putreq.h"
#include "oshmem/runtime/runtime.h"
#include "orte/util/show_help.h"
#include "oshmem/mca/spml/ikrit/spml_ikrit_component.h"
/* Turn ON/OFF debug output from build (default 0) */
#ifndef SPML_IKRIT_PUT_DEBUG
#define SPML_IKRIT_PUT_DEBUG 0
#endif
#define SPML_IKRIT_MXM_POST_SEND(sreq) \
do { \
mxm_error_t err; \
err = mxm_req_send(&sreq); \
if (MXM_OK != err) { \
SPML_ERROR("mxm_req_send (op=%d) failed: %s - aborting", \
sreq.opcode, \
mxm_error_string(err)); \
oshmem_shmem_abort(-1); \
return OSHMEM_ERROR; \
} \
} while(0)
typedef struct spml_ikrit_am_hdr {
uint64_t va;
} spml_ikrit_am_hdr_t;
struct mca_spml_ikrit_put_request {
mca_spml_base_put_request_t req_put;
mxm_send_req_t mxm_req;
int pe;
mxm_req_buffer_t iov[2];
spml_ikrit_am_hdr_t am_pkt;
};
typedef struct mca_spml_ikrit_put_request mca_spml_ikrit_put_request_t;
OBJ_CLASS_DECLARATION(mca_spml_ikrit_put_request_t);
#if MXM_API < MXM_VERSION(2,0)
static int spml_ikrit_get_ep_address(spml_ikrit_mxm_ep_conn_info_t *ep_info,
mxm_ptl_id_t ptlid)
{
size_t addrlen;
mxm_error_t err;
addrlen = sizeof(ep_info->addr.ptl_addr[ptlid]);
err = mxm_ep_address(mca_spml_ikrit.mxm_ep,
ptlid,
(struct sockaddr *) &ep_info->addr.ptl_addr[ptlid],
&addrlen);
if (MXM_OK != err) {
orte_show_help("help-oshmem-spml-ikrit.txt",
"unable to get endpoint address",
true,
mxm_error_string(err));
return OSHMEM_ERROR;
}
return OSHMEM_SUCCESS;
}
#else
static inline mxm_mem_key_t *to_mxm_mkey(sshmem_mkey_t *mkey) {
if (0 == mkey->len) {
return &mxm_empty_mem_key;
}
return (mxm_mem_key_t *)mkey->u.data;
}
#endif
static inline void mca_spml_irkit_req_wait(mxm_req_base_t *req)
{
do {
/* do at least one progress since
* with some TLs (self, shm) request
* can be completed immediately
*/
opal_progress();
} while (!mxm_req_test(req));
}
static int mca_spml_ikrit_put_request_free(struct oshmem_request_t** request)
{
mca_spml_ikrit_put_request_t *put_req =
*(mca_spml_ikrit_put_request_t **) request;
OPAL_THREAD_LOCK(&oshmem_request_lock);
assert(false == put_req->req_put.req_base.req_free_called);
put_req->req_put.req_base.req_free_called = true;
opal_free_list_return (&mca_spml_base_put_requests,
(opal_free_list_item_t*)put_req);
opal_memchecker_base_mem_noaccess(put_req, sizeof(*put_req));
OPAL_THREAD_UNLOCK(&oshmem_request_lock);
*request = SHMEM_REQUEST_NULL; /*MPI_REQUEST_NULL;*/
return OSHMEM_SUCCESS;
}
static int mca_spml_ikrit_put_request_cancel(struct oshmem_request_t * request,
int complete)
{
return OSHMEM_SUCCESS;
}
static void mca_spml_ikrit_put_request_construct(mca_spml_ikrit_put_request_t* req)
{
req->req_put.req_base.req_type = MCA_SPML_REQUEST_PUT;
req->req_put.req_base.req_oshmem.req_free = mca_spml_ikrit_put_request_free;
req->req_put.req_base.req_oshmem.req_cancel =
mca_spml_ikrit_put_request_cancel;
}
static void mca_spml_ikrit_put_request_destruct(mca_spml_ikrit_put_request_t* req)
{
}
OBJ_CLASS_INSTANCE( mca_spml_ikrit_put_request_t,
mca_spml_base_put_request_t,
mca_spml_ikrit_put_request_construct,
mca_spml_ikrit_put_request_destruct);
struct mca_spml_ikrit_get_request {
mca_spml_base_get_request_t req_get;
mxm_send_req_t mxm_req;
};
typedef struct mca_spml_ikrit_get_request mca_spml_ikrit_get_request_t;
OBJ_CLASS_DECLARATION(mca_spml_ikrit_get_request_t);
static int mca_spml_ikrit_get_request_free(struct oshmem_request_t** request)
{
mca_spml_ikrit_get_request_t *get_req =
*(mca_spml_ikrit_get_request_t **) request;
OPAL_THREAD_LOCK(&oshmem_request_lock);
assert(false == get_req->req_get.req_base.req_free_called);
get_req->req_get.req_base.req_free_called = true;
opal_free_list_return (&mca_spml_base_get_requests,
(opal_free_list_item_t*)get_req);
opal_memchecker_base_mem_noaccess(get_req, sizeof(*get_req));
OPAL_THREAD_UNLOCK(&oshmem_request_lock);
*request = SHMEM_REQUEST_NULL; /*MPI_REQUEST_NULL;*/
return OSHMEM_SUCCESS;
}
static int mca_spml_ikrit_get_request_cancel(struct oshmem_request_t * request,
int complete)
{
return OSHMEM_SUCCESS;
}
static void mca_spml_ikrit_get_request_construct(mca_spml_ikrit_get_request_t* req)
{
req->req_get.req_base.req_type = MCA_SPML_REQUEST_GET;
req->req_get.req_base.req_oshmem.req_free = mca_spml_ikrit_get_request_free;
req->req_get.req_base.req_oshmem.req_cancel =
mca_spml_ikrit_get_request_cancel;
}
static void mca_spml_ikrit_get_request_destruct(mca_spml_ikrit_get_request_t* req)
{
}
OBJ_CLASS_INSTANCE( mca_spml_ikrit_get_request_t,
mca_spml_base_get_request_t,
mca_spml_ikrit_get_request_construct,
mca_spml_ikrit_get_request_destruct);
int mca_spml_ikrit_put_simple(void* dst_addr,
size_t size,
void* src_addr,
int dst);
mca_spml_ikrit_t mca_spml_ikrit = {
{
/* Init mca_spml_base_module_t */
mca_spml_ikrit_add_procs,
mca_spml_ikrit_del_procs,
mca_spml_ikrit_enable,
mca_spml_ikrit_register,
mca_spml_ikrit_deregister,
mca_spml_ikrit_oob_get_mkeys,
mca_spml_ikrit_put,
mca_spml_ikrit_put_nb,
mca_spml_ikrit_get,
mca_spml_ikrit_get_nb,
mca_spml_ikrit_recv,
mca_spml_ikrit_send,
mca_spml_base_wait,
mca_spml_base_wait_nb,
mca_spml_ikrit_fence,
mca_spml_base_rmkey_unpack,
mca_spml_base_rmkey_free,
(void*)&mca_spml_ikrit
}
};
#if MXM_API < MXM_VERSION(2,0)
void mca_spml_ikrit_dump_stats(void);
void mca_spml_ikrit_dump_stats()
{
int num_procs;
int i;
char sbuf[1024];
FILE *fp;
fp = fmemopen(sbuf, sizeof(sbuf), "rw");
num_procs = oshmem_num_procs();
for (i = 0; i < num_procs; i++) {
mxm_print_conn_state(mca_spml_ikrit.mxm_peers[i]->mxm_conn,
MXM_STATE_DETAIL_LEVEL_DATA,
"",
fp);
printf("=========== pe:%d conn:%p stats:\n %s==================\n",
i,
mca_spml_ikrit.mxm_peers[i]->mxm_conn,
sbuf);
rewind(fp);
}
fclose(fp);
}
#endif
static inline mca_spml_ikrit_put_request_t *alloc_put_req(void)
{
mca_spml_ikrit_put_request_t *req;
opal_free_list_item_t* item;
item = opal_free_list_wait (&mca_spml_base_put_requests);
req = (mca_spml_ikrit_put_request_t *) item;
opal_memchecker_base_mem_undefined(req, sizeof(*req));
opal_memchecker_base_mem_defined(&req->req_put.req_base,
sizeof(req->req_put.req_base));
req->req_put.req_base.req_free_called = false;
req->req_put.req_base.req_oshmem.req_complete = false;
return req;
}
static inline mca_spml_ikrit_get_request_t *alloc_get_req(void)
{
mca_spml_ikrit_get_request_t *req;
opal_free_list_item_t* item;
item = opal_free_list_wait (&mca_spml_base_get_requests);
req = (mca_spml_ikrit_get_request_t *) item;
opal_memchecker_base_mem_undefined(req, sizeof(*req));
opal_memchecker_base_mem_defined(&req->req_get.req_base,
sizeof(req->req_get.req_base));
req->req_get.req_base.req_free_called = false;
req->req_get.req_base.req_oshmem.req_complete = false;
return req;
}
int mca_spml_ikrit_enable(bool enable)
{
SPML_VERBOSE(50, "*** ikrit ENABLED ****");
if (false == enable) {
return OSHMEM_SUCCESS;
}
opal_free_list_init (&mca_spml_base_put_requests,
sizeof(mca_spml_ikrit_put_request_t),
opal_cache_line_size,
OBJ_CLASS(mca_spml_ikrit_put_request_t),
0,
opal_cache_line_size,
mca_spml_ikrit.free_list_num,
mca_spml_ikrit.free_list_max,
mca_spml_ikrit.free_list_inc,
NULL, 0, NULL, NULL, NULL);
opal_free_list_init (&mca_spml_base_get_requests,
sizeof(mca_spml_ikrit_get_request_t),
opal_cache_line_size,
OBJ_CLASS(mca_spml_ikrit_get_request_t),
0,
opal_cache_line_size,
mca_spml_ikrit.free_list_num,
mca_spml_ikrit.free_list_max,
mca_spml_ikrit.free_list_inc,
NULL, 0, NULL, NULL, NULL);
mca_spml_ikrit.enabled = true;
return OSHMEM_SUCCESS;
}
static int create_ptl_idx(int dst_pe)
{
oshmem_proc_t *proc;
proc = oshmem_proc_group_find(oshmem_group_all, dst_pe);
proc->transport_ids = (char *) malloc(MXM_PTL_LAST * sizeof(char));
if (!proc->transport_ids)
return OSHMEM_ERROR;
proc->num_transports = 1;
#if MXM_API < MXM_VERSION(2,0)
if (oshmem_my_proc_id() == dst_pe)
proc->transport_ids[0] = MXM_PTL_SELF;
else
#endif
proc->transport_ids[0] = MXM_PTL_RDMA;
return OSHMEM_SUCCESS;
}
static void destroy_ptl_idx(int dst_pe)
{
oshmem_proc_t *proc;
proc = oshmem_proc_group_find(oshmem_group_all, dst_pe);
if (proc->transport_ids)
free(proc->transport_ids);
}
static void mxm_peer_construct(mxm_peer_t *p)
{
p->pe = -1;
p->n_active_puts = 0;
p->need_fence = 0;
}
static void mxm_peer_destruct(mxm_peer_t *p)
{
/* may be we need to remov item from list */
}
OBJ_CLASS_INSTANCE( mxm_peer_t,
opal_list_item_t,
mxm_peer_construct,
mxm_peer_destruct);
int mca_spml_ikrit_del_procs(oshmem_proc_t** procs, size_t nprocs)
{
size_t i, n;
int my_rank = oshmem_my_proc_id();
oshmem_shmem_barrier();
#if MXM_API >= MXM_VERSION(2,0)
if (mca_spml_ikrit.bulk_disconnect) {
mxm_ep_powerdown(mca_spml_ikrit.mxm_ep);
}
#endif
while (NULL != opal_list_remove_first(&mca_spml_ikrit.active_peers)) {
};
OBJ_DESTRUCT(&mca_spml_ikrit.active_peers);
for (n = 0; n < nprocs; n++) {
i = (my_rank + n) % nprocs;
mxm_ep_disconnect(mca_spml_ikrit.mxm_peers[i]->mxm_conn);
if (mca_spml_ikrit.hw_rdma_channel) {
assert(mca_spml_ikrit.mxm_peers[i]->mxm_hw_rdma_conn != mca_spml_ikrit.mxm_peers[i]->mxm_conn);
mxm_ep_disconnect(mca_spml_ikrit.mxm_peers[i]->mxm_hw_rdma_conn);
}
destroy_ptl_idx(i);
OBJ_RELEASE(mca_spml_ikrit.mxm_peers[i]);
}
free(mca_spml_ikrit.mxm_peers);
return OSHMEM_SUCCESS;
}
int mca_spml_ikrit_add_procs(oshmem_proc_t** procs, size_t nprocs)
{
spml_ikrit_mxm_ep_conn_info_t *ep_info = NULL;
spml_ikrit_mxm_ep_conn_info_t *ep_hw_rdma_info = NULL;
spml_ikrit_mxm_ep_conn_info_t my_ep_info = {{0}};
#if MXM_API < MXM_VERSION(2,0)
mxm_conn_req_t *conn_reqs;
int timeout;
#else
size_t mxm_addr_len = MXM_MAX_ADDR_LEN;
#endif
mxm_error_t err;
size_t i, n;
int rc = OSHMEM_ERROR;
oshmem_proc_t *proc_self;
int my_rank = oshmem_my_proc_id();
OBJ_CONSTRUCT(&mca_spml_ikrit.active_peers, opal_list_t);
/* Allocate connection requests */
#if MXM_API < MXM_VERSION(2,0)
conn_reqs = malloc(nprocs * sizeof(mxm_conn_req_t));
if (NULL == conn_reqs) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto bail;
}
memset(conn_reqs, 0x0, sizeof(mxm_conn_req_t));
#endif
ep_info = calloc(sizeof(spml_ikrit_mxm_ep_conn_info_t), nprocs);
if (NULL == ep_info) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto bail;
}
if (mca_spml_ikrit.hw_rdma_channel) {
ep_hw_rdma_info = calloc(sizeof(spml_ikrit_mxm_ep_conn_info_t), nprocs);
if (NULL == ep_hw_rdma_info) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto bail;
}
}
mca_spml_ikrit.mxm_peers = (mxm_peer_t **) malloc(nprocs
* sizeof(*(mca_spml_ikrit.mxm_peers)));
if (NULL == mca_spml_ikrit.mxm_peers) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto bail;
}
#if MXM_API < MXM_VERSION(2,0)
if (OSHMEM_SUCCESS
!= spml_ikrit_get_ep_address(&my_ep_info, MXM_PTL_SELF)) {
rc = OSHMEM_ERROR;
goto bail;
}
if (OSHMEM_SUCCESS
!= spml_ikrit_get_ep_address(&my_ep_info, MXM_PTL_RDMA)) {
rc = OSHMEM_ERROR;
goto bail;
}
#else
if (mca_spml_ikrit.hw_rdma_channel) {
err = mxm_ep_get_address(mca_spml_ikrit.mxm_hw_rdma_ep, &my_ep_info.addr.ep_addr, &mxm_addr_len);
if (MXM_OK != err) {
orte_show_help("help-oshmem-spml-ikrit.txt", "unable to get endpoint address", true,
mxm_error_string(err));
rc = OSHMEM_ERROR;
goto bail;
}
oshmem_shmem_allgather(&my_ep_info, ep_hw_rdma_info,
sizeof(spml_ikrit_mxm_ep_conn_info_t));
}
err = mxm_ep_get_address(mca_spml_ikrit.mxm_ep, &my_ep_info.addr.ep_addr, &mxm_addr_len);
if (MXM_OK != err) {
orte_show_help("help-oshmem-spml-ikrit.txt", "unable to get endpoint address", true,
mxm_error_string(err));
rc = OSHMEM_ERROR;
goto bail;
}
#endif
oshmem_shmem_allgather(&my_ep_info, ep_info,
sizeof(spml_ikrit_mxm_ep_conn_info_t));
opal_progress_register(spml_ikrit_progress);
/* Get the EP connection requests for all the processes from modex */
for (n = 0; n < nprocs; ++n) {
/* mxm 2.0 keeps its connections on a list. Make sure
* that list have different order on every rank */
i = (my_rank + n) % nprocs;
mca_spml_ikrit.mxm_peers[i] = OBJ_NEW(mxm_peer_t);
if (NULL == mca_spml_ikrit.mxm_peers[i]) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto bail;
}
mca_spml_ikrit.mxm_peers[i]->pe = i;
#if MXM_API < MXM_VERSION(2,0)
conn_reqs[i].ptl_addr[MXM_PTL_SELF] =
(struct sockaddr *) &ep_info[i].addr.ptl_addr[MXM_PTL_SELF];
conn_reqs[i].ptl_addr[MXM_PTL_SHM] = NULL;
conn_reqs[i].ptl_addr[MXM_PTL_RDMA] =
(struct sockaddr *) &ep_info[i].addr.ptl_addr[MXM_PTL_RDMA];
#else
err = mxm_ep_connect(mca_spml_ikrit.mxm_ep, ep_info[i].addr.ep_addr, &mca_spml_ikrit.mxm_peers[i]->mxm_conn);
if (MXM_OK != err) {
SPML_ERROR("MXM returned connect error: %s\n", mxm_error_string(err));
goto bail;
}
if (OSHMEM_SUCCESS != create_ptl_idx(i))
goto bail;
mxm_conn_ctx_set(mca_spml_ikrit.mxm_peers[i]->mxm_conn, mca_spml_ikrit.mxm_peers[i]);
if (mca_spml_ikrit.hw_rdma_channel) {
err = mxm_ep_connect(mca_spml_ikrit.mxm_hw_rdma_ep, ep_hw_rdma_info[i].addr.ep_addr, &mca_spml_ikrit.mxm_peers[i]->mxm_hw_rdma_conn);
if (MXM_OK != err) {
SPML_ERROR("MXM returned connect error: %s\n", mxm_error_string(err));
goto bail;
}
} else {
mca_spml_ikrit.mxm_peers[i]->mxm_hw_rdma_conn = mca_spml_ikrit.mxm_peers[i]->mxm_conn;
}
#endif
}
#if MXM_API < MXM_VERSION(2,0)
/* Connect to remote peers */
if (mxm_get_version() < MXM_VERSION(1,5)) {
timeout = 1000;
} else {
timeout = -1;
}
err = mxm_ep_connect(mca_spml_ikrit.mxm_ep, conn_reqs, nprocs, timeout);
if (MXM_OK != err) {
SPML_ERROR("MXM returned connect error: %s\n", mxm_error_string(err));
for (i = 0; i < nprocs; ++i) {
if (MXM_OK != conn_reqs[i].error) {
SPML_ERROR("MXM EP connect to %s error: %s\n",
procs[i]->proc_hostname, mxm_error_string(conn_reqs[i].error));
}
}
rc = OSHMEM_ERR_CONNECTION_FAILED;
goto bail;
}
/* Save returned connections */
for (i = 0; i < nprocs; ++i) {
mca_spml_ikrit.mxm_peers[i]->mxm_conn = conn_reqs[i].conn;
if (OSHMEM_SUCCESS != create_ptl_idx(i)) {
rc = OSHMEM_ERR_CONNECTION_FAILED;
goto bail;
}
mxm_conn_ctx_set(conn_reqs[i].conn, mca_spml_ikrit.mxm_peers[i]);
}
if (conn_reqs)
free(conn_reqs);
#endif
if (ep_info)
free(ep_info);
if (ep_hw_rdma_info)
free(ep_hw_rdma_info);
#if MXM_API >= MXM_VERSION(2,0)
if (mca_spml_ikrit.bulk_connect) {
/* Need a barrier to ensure remote peers already created connection */
oshmem_shmem_barrier();
mxm_ep_wireup(mca_spml_ikrit.mxm_ep);
}
#endif
proc_self = oshmem_proc_group_find(oshmem_group_all, my_rank);
/* identify local processes and change transport to SHM */
for (i = 0; i < nprocs; i++) {
if (procs[i]->super.proc_name.jobid != proc_self->super.proc_name.jobid ||
!OPAL_PROC_ON_LOCAL_NODE(procs[i]->super.proc_flags)) {
continue;
}
if (procs[i] == proc_self)
continue;
/* use zcopy for put/get via sysv shared memory */
procs[i]->transport_ids[0] = MXM_PTL_SHM;
procs[i]->transport_ids[1] = MXM_PTL_RDMA;
procs[i]->num_transports = 2;
}
SPML_VERBOSE(50, "*** ADDED PROCS ***");
return OSHMEM_SUCCESS;
bail:
#if MXM_API < MXM_VERSION(2,0)
if (conn_reqs)
free(conn_reqs);
#endif
if (ep_info)
free(ep_info);
if (ep_hw_rdma_info)
free(ep_hw_rdma_info);
SPML_ERROR("add procs FAILED rc=%d", rc);
return rc;
}
sshmem_mkey_t *mca_spml_ikrit_register(void* addr,
size_t size,
uint64_t shmid,
int *count)
{
int i;
sshmem_mkey_t *mkeys;
#if MXM_API >= MXM_VERSION(2,0)
mxm_error_t err;
mxm_mem_key_t *m_key;
#endif
*count = 0;
mkeys = (sshmem_mkey_t *) calloc(1, MXM_PTL_LAST * sizeof(*mkeys));
if (!mkeys) {
return NULL ;
}
for (i = 0; i < MXM_PTL_LAST; i++) {
mkeys[i].u.key = MAP_SEGMENT_SHM_INVALID;
switch (i) {
case MXM_PTL_SHM:
if ((int)shmid != MAP_SEGMENT_SHM_INVALID) {
mkeys[i].u.key = shmid;
mkeys[i].va_base = 0;
} else {
mkeys[i].len = 0;
mkeys[i].va_base = addr;
}
mkeys[i].spml_context = 0;
break;
#if MXM_API < MXM_VERSION(2,0)
case MXM_PTL_SELF:
mkeys[i].len = 0;
mkeys[i].spml_context = 0;
mkeys[i].va_base = addr;
break;
#endif
case MXM_PTL_RDMA:
mkeys[i].va_base = addr;
mkeys[i].spml_context = 0;
#if MXM_API < MXM_VERSION(2,0)
mkeys[i].len = 0;
#else
if (mca_spml_ikrit.ud_only) {
mkeys[i].len = 0;
break;
}
err = mxm_mem_map(mca_spml_ikrit.mxm_context, &addr, &size, 0, 0, 0);
if (MXM_OK != err) {
SPML_ERROR("Failed to register memory: %s", mxm_error_string(err));
goto error_out;
}
mkeys[i].spml_context = (void *)(unsigned long)size;
m_key = malloc(sizeof(*m_key));
if (NULL == m_key) {
SPML_ERROR("Failed to allocate m_key memory");
goto error_out;
}
mkeys[i].len = sizeof(*m_key);
mkeys[i].u.data = m_key;
err = mxm_mem_get_key(mca_spml_ikrit.mxm_context, addr, m_key);
if (MXM_OK != err) {
SPML_ERROR("Failed to get memory key: %s", mxm_error_string(err));
goto error_out;
}
#endif
break;
default:
SPML_ERROR("unsupported PTL: %d", i);
goto error_out;
}
SPML_VERBOSE(5,
"rank %d ptl %d addr %p size %llu %s",
oshmem_proc_pe(oshmem_proc_local()), i, addr, (unsigned long long)size,
mca_spml_base_mkey2str(&mkeys[i]));
}
*count = MXM_PTL_LAST;
return mkeys;
error_out:
mca_spml_ikrit_deregister(mkeys);
return NULL;
}
int mca_spml_ikrit_deregister(sshmem_mkey_t *mkeys)
{
int i;
MCA_SPML_CALL(fence());
if (!mkeys)
return OSHMEM_SUCCESS;
for (i = 0; i < MXM_PTL_LAST; i++) {
switch (i) {
#if MXM_API < MXM_VERSION(2,0)
case MXM_PTL_SELF:
#endif
case MXM_PTL_SHM:
break;
case MXM_PTL_RDMA:
/* dereg memory */
if (!mkeys[i].spml_context)
break;
#if MXM_API >= MXM_VERSION(2,0)
mxm_mem_unmap(mca_spml_ikrit.mxm_context,
(void *)mkeys[i].va_base,
(unsigned long)mkeys[i].spml_context,
0);
if (0 < mkeys[i].len) {
free(mkeys[i].u.data);
}
#endif
break;
}
}
free(mkeys);
return OSHMEM_SUCCESS;
}
static inline int get_ptl_id(int dst)
{
oshmem_proc_t *proc;
/* get endpoint and btl */
proc = oshmem_proc_group_all(dst);
if (!proc) {
SPML_ERROR("Can not find destination proc for pe=%d", dst);
oshmem_shmem_abort(-1);
return -1;
}
return proc->transport_ids[0];
}
int mca_spml_ikrit_oob_get_mkeys(int pe, uint32_t seg, sshmem_mkey_t *mkeys)
{
int ptl;
ptl = get_ptl_id(pe);
if (ptl < 0)
return OSHMEM_ERROR;
if (ptl != MXM_PTL_RDMA)
return OSHMEM_ERROR;
#if MXM_API < MXM_VERSION(2,0)
if (seg > 1)
return OSHMEM_ERROR;
mkeys[ptl].len = 0;
mkeys[ptl].u.key = MAP_SEGMENT_SHM_INVALID;
return OSHMEM_SUCCESS;
#else
/* we are actually registering memory in 2.0 and later.
* So can only skip mkey exchange when ud is the only transport
*/
if (mca_spml_ikrit.ud_only) {
mkeys[ptl].len = 0;
mkeys[ptl].u.key = MAP_SEGMENT_SHM_INVALID;
return OSHMEM_SUCCESS;
}
return OSHMEM_ERROR;
#endif
}
static int mca_spml_ikrit_get_helper(mxm_send_req_t *sreq,
void *src_addr,
size_t size,
void *dst_addr,
int src)
{
/* shmem spec states that get() operations are blocking. So it is enough
to have single mxm request. Also we count on mxm doing copy */
void *rva;
sshmem_mkey_t *r_mkey;
int ptl_id;
ptl_id = get_ptl_id(src);
/* already tried to send via shm and failed. go via rdma */
if (ptl_id == MXM_PTL_SHM)
ptl_id = MXM_PTL_RDMA;
/**
* Get the address to the remote rkey.
**/
r_mkey = mca_memheap_base_get_cached_mkey(src, src_addr, ptl_id, &rva);
if (!r_mkey) {
SPML_ERROR("pe=%d: %p is not address of shared variable",
src, src_addr);
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
SPML_VERBOSE(100,
"get: pe:%d ptl=%d src=%p -> dst: %p sz=%d. src_rva=%p, %s",
src, ptl_id, src_addr, dst_addr, (int)size, (void *)rva, mca_spml_base_mkey2str(r_mkey));
/* mxm does not really cares for get lkey */
sreq->base.mq = mca_spml_ikrit.mxm_mq;
sreq->base.conn = mca_spml_ikrit.mxm_peers[src]->mxm_conn;
sreq->base.data_type = MXM_REQ_DATA_BUFFER;
sreq->base.data.buffer.ptr = dst_addr;
sreq->base.data.buffer.length = size;
#if MXM_API < MXM_VERSION(2,0)
sreq->base.data.buffer.memh = NULL;
sreq->op.mem.remote_memh = NULL;
#else
sreq->op.mem.remote_mkey = to_mxm_mkey(r_mkey);
#endif
sreq->opcode = MXM_REQ_OP_GET;
sreq->op.mem.remote_vaddr = (intptr_t) rva;
sreq->base.state = MXM_REQ_NEW;
return OSHMEM_SUCCESS;
}
static inline int mca_spml_ikrit_get_shm(void *src_addr,
size_t size,
void *dst_addr,
int src)
{
int ptl_id;
void *rva;
sshmem_mkey_t *r_mkey;
ptl_id = get_ptl_id(src);
/**
* Get the address to the remote rkey.
**/
if (ptl_id != MXM_PTL_SHM)
return OSHMEM_ERROR;
r_mkey = mca_memheap_base_get_cached_mkey(src, src_addr, ptl_id, &rva);
if (!r_mkey) {
SPML_ERROR("pe=%d: %p is not address of shared variable",
src, src_addr);
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
if (!mca_memheap_base_can_local_copy(r_mkey, src_addr))
return OSHMEM_ERROR;
SPML_VERBOSE(100,
"shm get: pe:%d src=%p -> dst: %p sz=%d. src_rva=%p, %s",
src, src_addr, dst_addr, (int)size, (void *)rva, mca_spml_base_mkey2str(r_mkey));
memcpy(dst_addr, (void *) (unsigned long) rva, size);
opal_progress();
return OSHMEM_SUCCESS;
}
int mca_spml_ikrit_get_nb(void* src_addr,
size_t size,
void* dst_addr,
int src,
void **handle)
{
return mca_spml_ikrit_get_async(src_addr, size, dst_addr, src);
}
int mca_spml_ikrit_get(void *src_addr, size_t size, void *dst_addr, int src)
{
mxm_send_req_t sreq;
if (0 >= size) {
return OSHMEM_SUCCESS;
}
if (OSHMEM_SUCCESS == mca_spml_ikrit_get_shm(src_addr, size, dst_addr, src))
return OSHMEM_SUCCESS;
if (OSHMEM_SUCCESS
!= mca_spml_ikrit_get_helper(&sreq,
src_addr,
size,
dst_addr,
src)) {
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
#if MXM_API < MXM_VERSION(2,0)
sreq.base.flags = MXM_REQ_FLAG_BLOCKING;
#else
sreq.flags = MXM_REQ_SEND_FLAG_BLOCKING;
#endif
sreq.base.completed_cb = NULL;
SPML_IKRIT_MXM_POST_SEND(sreq);
mca_spml_irkit_req_wait(&sreq.base);
if (MXM_OK != sreq.base.error) {
SPML_ERROR("get request failed: %s - aborting",
mxm_error_string(sreq.base.error));
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
return OSHMEM_SUCCESS;
}
static inline void get_completion_cb(void *ctx)
{
mca_spml_ikrit_get_request_t *get_req = (mca_spml_ikrit_get_request_t *) ctx;
OPAL_THREAD_ADD32(&mca_spml_ikrit.n_active_gets, -1);
get_req->req_get.req_base.req_spml_complete = true;
get_req->req_get.req_base.req_oshmem.req_status.SHMEM_ERROR =
OSHMEM_SUCCESS;
oshmem_request_complete(&get_req->req_get.req_base.req_oshmem, 1);
oshmem_request_free((oshmem_request_t**) &get_req);
}
/* extension. used 4 fence implementation b4 fence was added to mxm */
int mca_spml_ikrit_get_async(void *src_addr,
size_t size,
void *dst_addr,
int src)
{
mca_spml_ikrit_get_request_t *get_req;
if (OSHMEM_SUCCESS == mca_spml_ikrit_get_shm(src_addr, size, dst_addr, src))
return OSHMEM_SUCCESS;
get_req = alloc_get_req();
if (NULL == get_req) {
SPML_ERROR("out of get requests - aborting");
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
if (OSHMEM_SUCCESS
!= mca_spml_ikrit_get_helper(&get_req->mxm_req,
src_addr,
size,
dst_addr,
src)) {
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
#if MXM_API < MXM_VERSION(2,0)
get_req->mxm_req.base.flags = 0;
#else
get_req->mxm_req.flags = 0;
#endif
get_req->mxm_req.base.completed_cb = get_completion_cb;
get_req->mxm_req.base.context = get_req;
OPAL_THREAD_ADD32(&mca_spml_ikrit.n_active_gets, 1);
SPML_IKRIT_MXM_POST_SEND(get_req->mxm_req);
return OSHMEM_SUCCESS;
}
static inline void fence_completion_cb(void *ctx)
{
mca_spml_ikrit_get_request_t *fence_req =
(mca_spml_ikrit_get_request_t *) ctx;
OPAL_THREAD_ADD32(&mca_spml_ikrit.n_mxm_fences, -1);
fence_req->req_get.req_base.req_spml_complete = true;
fence_req->req_get.req_base.req_oshmem.req_status.SHMEM_ERROR =
OSHMEM_SUCCESS;
oshmem_request_complete(&fence_req->req_get.req_base.req_oshmem, 1);
oshmem_request_free((oshmem_request_t**) &fence_req);
}
static int mca_spml_ikrit_mxm_fence(int dst)
{
mca_spml_ikrit_get_request_t *fence_req;
fence_req = alloc_get_req();
if (NULL == fence_req) {
SPML_ERROR("out of get requests - aborting");
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}