-
Notifications
You must be signed in to change notification settings - Fork 29
/
psm_ep.c
1579 lines (1378 loc) · 43.5 KB
/
psm_ep.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
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2021 Cornelis Networks.
Copyright(c) 2016 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Cornelis Networks, www.cornelisnetworks.com
BSD LICENSE
Copyright(c) 2021 Cornelis Networks.
Copyright(c) 2016 Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 2003-2016 Intel Corporation. All rights reserved. */
#include <sys/types.h>
#include <sys/stat.h>
#include <sched.h> /* cpu_set */
#include <ctype.h> /* isalpha */
#include <stdbool.h>
#include "psm_user.h"
#include "psm2_hal.h"
#include "psm_mq_internal.h"
#include "psm_am_internal.h"
#ifdef PSM_CUDA
#include "psm_gdrcpy.h"
#endif
/*
* Endpoint management
*/
psm2_ep_t psmi_opened_endpoint = NULL;
int psmi_opened_endpoint_count = 0;
static uint16_t *hfi_lids;
static uint32_t nlids;
static psm2_error_t psmi_ep_open_device(const psm2_ep_t ep,
const struct psm2_ep_open_opts *opts,
const psm2_uuid_t unique_job_key,
struct psmi_context *context,
psm2_epid_t *epid);
/*
* Device management
*
* PSM uses "devices" as components to manage communication to self, to peers
* reachable via shared memory and finally to peers reachable only through
* hfi.
*/
int psmi_ep_device_is_enabled(const psm2_ep_t ep, int devid);
psm2_error_t __psm2_ep_num_devunits(uint32_t *num_units_o)
{
static int num_units = -1;
PSM2_LOG_MSG("entering");
PSMI_ERR_UNLESS_INITIALIZED(NULL);
if (num_units == -1) {
num_units = psmi_hal_get_num_units();
if (num_units == -1)
num_units = 0;
}
*num_units_o = (uint32_t) num_units;
PSM2_LOG_MSG("leaving");
return PSM2_OK;
}
PSMI_API_DECL(psm2_ep_num_devunits)
static int cmpfunc(const void *p1, const void *p2)
{
uint64_t a = ((uint64_t *) p1)[0];
uint64_t b = ((uint64_t *) p2)[0];
if (a < b)
return -1;
if (a == b)
return 0;
return 1;
}
static psm2_error_t
psmi_ep_multirail(int *num_rails, uint32_t *unit, uint16_t *port)
{
uint32_t num_units;
uint64_t gid_hi, gid_lo;
int i, j, ret, count = 0;
char *env;
psm2_error_t err = PSM2_OK;
uint64_t gidh[HFI_MAX_RAILS][3];
union psmi_envvar_val env_multirail;
int multirail_within_socket_used = 0;
int node_id = -1, found = 0;
psmi_getenv("PSM2_MULTIRAIL",
"Use all available HFIs in the system for communication.\n"
"0: Disabled (default),\n"
"1: Enable multirail across all available HFIs,\n"
"2: Enable multirail within socket.\n"
"\t For multirail within a socket, we try to find at\n"
"\t least one HFI on the same socket as current task.\n"
"\t If none found, we continue to use other HFIs within\n"
"\t the system.",
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_INT,
(union psmi_envvar_val)0,
&env_multirail);
if (!env_multirail.e_int) {
*num_rails = 0;
return err;
}
if (env_multirail.e_int == 2)
multirail_within_socket_used = 1;
/*
* map is in format: unit:port,unit:port,...
*/
if ((env = getenv("PSM2_MULTIRAIL_MAP"))) {
if (sscanf(env, "%d:%d", &i, &j) == 2) {
char *comma = strchr(env, ',');
unit[count] = i;
port[count] = j;
count++;
while (comma) {
if (sscanf(comma, ",%d:%d", &i, &j) != 2) {
break;
}
unit[count] = i;
port[count] = j;
count++;
if (count == HFI_MAX_RAILS)
break;
comma = strchr(comma + 1, ',');
}
}
*num_rails = count;
/*
* Check if any of the port is not usable.
*/
for (i = 0; i < count; i++) {
ret = psmi_hal_get_port_active(unit[i], port[i]);
if (ret <= 0) {
err =
psmi_handle_error(NULL,
PSM2_EP_DEVICE_FAILURE,
"Unit/port: %d:%d is not active.",
unit[i], port[i]);
return err;
}
ret = psmi_hal_get_port_lid(unit[i], port[i]);
if (ret <= 0) {
err =
psmi_handle_error(NULL,
PSM2_EP_DEVICE_FAILURE,
"Couldn't get lid for unit %d:%d",
unit[i], port[i]);
return err;
}
ret =
psmi_hal_get_port_gid(unit[i], port[i], &gid_hi,
&gid_lo);
if (ret == -1) {
err =
psmi_handle_error(NULL,
PSM2_EP_DEVICE_FAILURE,
"Couldn't get gid for unit %d:%d",
unit[i], port[i]);
return err;
}
}
return err;
}
if ((err = psm2_ep_num_devunits(&num_units))) {
return err;
}
if (num_units > HFI_MAX_RAILS) {
_HFI_INFO
("Found %d units, max %d units are supported, use %d\n",
num_units, HFI_MAX_RAILS, HFI_MAX_RAILS);
num_units = HFI_MAX_RAILS;
}
/*
* PSM2_MULTIRAIL=2 functionality-
* - Try to find at least find one HFI in the same root
* complex. If none found, continue to run and
* use remaining HFIs in the system.
* - If we do find at least one HFI in same root complex, we
* go ahead and add to list.
*/
if (multirail_within_socket_used) {
node_id = psmi_get_current_proc_location();
for (i = 0; i < num_units; i++) {
if (psmi_hal_get_unit_active(i) <= 0)
continue;
int node_id_i;
if (!psmi_hal_get_node_id(i, &node_id_i)) {
if (node_id_i == node_id) {
found = 1;
break;
}
}
}
}
/*
* Get all the ports with a valid lid and gid, one per unit.
*/
for (i = 0; i < num_units; i++) {
int node_id_i;
if (!psmi_hal_get_node_id(i, &node_id_i))
{
if (multirail_within_socket_used &&
found && (node_id_i != node_id))
continue;
}
for (j = HFI_MIN_PORT; j <= HFI_MAX_PORT; j++) {
ret = psmi_hal_get_port_lid(i, j);
if (ret <= 0)
continue;
ret = psmi_hal_get_port_gid(i, j, &gid_hi, &gid_lo);
if (ret == -1)
continue;
gidh[count][0] = gid_hi;
gidh[count][1] = i;
gidh[count][2] = j;
count++;
break;
}
}
/*
* Sort all the ports with gidh from small to big.
* This is for multiple fabrics, and we use fabric with the
* smallest gid to make the master connection.
*/
qsort(gidh, count, sizeof(uint64_t) * 3, cmpfunc);
for (i = 0; i < count; i++) {
unit[i] = (uint32_t) gidh[i][1];
port[i] = (uint16_t) (uint32_t) gidh[i][2];
}
*num_rails = count;
return err;
}
static psm2_error_t
psmi_ep_devlids(uint16_t **lids, uint32_t *num_lids_o,
uint64_t my_gid_hi, uint64_t my_gid_lo)
{
uint32_t num_units;
int i;
psm2_error_t err = PSM2_OK;
PSMI_ERR_UNLESS_INITIALIZED(NULL);
if (hfi_lids == NULL) {
if ((err = psm2_ep_num_devunits(&num_units)))
goto fail;
hfi_lids = (uint16_t *)
psmi_calloc(PSMI_EP_NONE, UNDEFINED,
num_units * psmi_hal_get_num_ports(), sizeof(uint16_t));
if (hfi_lids == NULL) {
err = psmi_handle_error(NULL, PSM2_NO_MEMORY,
"Couldn't allocate memory for dev_lids structure");
goto fail;
}
for (i = 0; i < num_units; i++) {
int j;
for (j = HFI_MIN_PORT; j <= HFI_MAX_PORT; j++) {
int lid = psmi_hal_get_port_lid(i, j);
int ret;
uint64_t gid_hi = 0, gid_lo = 0;
if (lid <= 0)
continue;
ret = psmi_hal_get_port_gid(i, j, &gid_hi, &gid_lo);
if (ret == -1)
continue;
else if (my_gid_hi != gid_hi) {
_HFI_VDBG("LID %d, unit %d, port %d, "
"mismatched GID %llx:%llx and "
"%llx:%llx\n",
lid, i, j,
(unsigned long long)gid_hi,
(unsigned long long)gid_lo,
(unsigned long long)my_gid_hi,
(unsigned long long)
my_gid_lo);
continue;
}
_HFI_VDBG("LID %d, unit %d, port %d, "
"matching GID %llx:%llx and "
"%llx:%llx\n", lid, i, j,
(unsigned long long)gid_hi,
(unsigned long long)gid_lo,
(unsigned long long)my_gid_hi,
(unsigned long long)my_gid_lo);
hfi_lids[nlids++] = (uint16_t) lid;
}
}
if (nlids == 0) {
err = psmi_handle_error(NULL, PSM2_EP_DEVICE_FAILURE,
"Couldn't get lid&gid from any unit/port");
goto fail;
}
}
*lids = hfi_lids;
*num_lids_o = nlids;
fail:
return err;
}
static psm2_error_t
psmi_ep_verify_pkey(psm2_ep_t ep, uint16_t pkey, uint16_t *opkey)
{
int i, ret;
psm2_error_t err;
for (i = 0; i < 16; i++) {
ret = psmi_hal_get_port_index2pkey(ep->unit_id, ep->portnum, i);
if (ret < 0) {
err = psmi_handle_error(NULL, PSM2_EP_DEVICE_FAILURE,
"Can't get a valid pkey value from pkey table\n");
return err;
} else if ((ret & 0x7fff) == 0x7fff) {
continue; /* management pkey, not for app traffic. */
}
if ((pkey & 0x7fff) == (uint16_t)(ret & 0x7fff)) {
break;
}
}
/* if pkey does not match */
if (i == 16) {
err = psmi_handle_error(NULL, PSM2_EP_DEVICE_FAILURE,
"Wrong pkey 0x%x, please use PSM2_PKEY to specify a valid pkey\n",
pkey);
return err;
}
if (((uint16_t)ret & 0x8000) == 0) {
err = psmi_handle_error(NULL, PSM2_EP_DEVICE_FAILURE,
"Limited Member pkey 0x%x, please use PSM2_PKEY to specify a valid pkey\n",
(uint16_t)ret);
return err;
}
/* return the final pkey */
*opkey = (uint16_t)ret;
return PSM2_OK;
}
uint64_t __psm2_epid_nid(psm2_epid_t epid)
{
uint64_t rv;
PSM2_LOG_MSG("entering");
rv = (uint64_t) PSMI_EPID_GET_LID(epid);
PSM2_LOG_MSG("leaving");
return rv;
}
PSMI_API_DECL(psm2_epid_nid)
/* Currently not exposed to users, we don't acknowledge the existence of
* subcontexts */
uint64_t psmi_epid_subcontext(psm2_epid_t epid)
{
return (uint64_t) PSMI_EPID_GET_SUBCONTEXT(epid);
}
/* Currently not exposed to users, we don't acknowledge the existence of
* service levels encoding within epids. This may require
* changing to expose SLs
*/
uint64_t psmi_epid_version(psm2_epid_t epid)
{
return (uint64_t) PSMI_EPID_GET_EPID_VERSION(epid);
}
uint64_t __psm2_epid_context(psm2_epid_t epid)
{
uint64_t rv;
PSM2_LOG_MSG("entering");
rv = (uint64_t) PSMI_EPID_GET_CONTEXT(epid);
PSM2_LOG_MSG("leaving");
return rv;
}
PSMI_API_DECL(psm2_epid_context)
uint64_t __psm2_epid_port(psm2_epid_t epid)
{
uint64_t rv;
PSM2_LOG_MSG("entering");
rv = __psm2_epid_context(epid);
PSM2_LOG_MSG("leaving");
return rv;
}
PSMI_API_DECL(psm2_epid_port)
psm2_error_t __psm2_ep_query(int *num_of_epinfo, psm2_epinfo_t *array_of_epinfo)
{
psm2_error_t err = PSM2_OK;
int i;
psm2_ep_t ep;
PSM2_LOG_MSG("entering");
PSMI_ERR_UNLESS_INITIALIZED(NULL);
if (*num_of_epinfo <= 0) {
err = psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid psm2_ep_query parameters");
PSM2_LOG_MSG("leaving");
return err;
}
if (psmi_opened_endpoint == NULL) {
err = psmi_handle_error(NULL, PSM2_EP_WAS_CLOSED,
"PSM Endpoint is closed or does not exist");
PSM2_LOG_MSG("leaving");
return err;
}
ep = psmi_opened_endpoint;
for (i = 0; i < *num_of_epinfo; i++) {
if (ep == NULL)
break;
array_of_epinfo[i].ep = ep;
array_of_epinfo[i].epid = ep->epid;
array_of_epinfo[i].jkey = ep->jkey;
memcpy(array_of_epinfo[i].uuid,
(void *)ep->uuid, sizeof(psm2_uuid_t));
psmi_uuid_unparse(ep->uuid, array_of_epinfo[i].uuid_str);
ep = ep->user_ep_next;
}
*num_of_epinfo = i;
PSM2_LOG_MSG("leaving");
return err;
}
PSMI_API_DECL(psm2_ep_query)
psm2_error_t __psm2_ep_epid_lookup(psm2_epid_t epid, psm2_epconn_t *epconn)
{
psm2_error_t err = PSM2_OK;
psm2_epaddr_t epaddr;
psm2_ep_t ep;
PSM2_LOG_MSG("entering");
PSMI_ERR_UNLESS_INITIALIZED(NULL);
/* Need to have an opened endpoint before we can resolve epids */
if (psmi_opened_endpoint == NULL) {
err = psmi_handle_error(NULL, PSM2_EP_WAS_CLOSED,
"PSM Endpoint is closed or does not exist");
PSM2_LOG_MSG("leaving");
return err;
}
ep = psmi_opened_endpoint;
while (ep) {
epaddr = psmi_epid_lookup(ep, epid);
if (!epaddr) {
ep = ep->user_ep_next;
continue;
}
/* Found connection for epid. Return info about endpoint to caller. */
psmi_assert_always(epaddr->ptlctl->ep == ep);
epconn->addr = epaddr;
epconn->ep = ep;
epconn->mq = ep->mq;
PSM2_LOG_MSG("leaving");
return err;
}
err = psmi_handle_error(NULL, PSM2_EPID_UNKNOWN,
"Endpoint connection status unknown");
PSM2_LOG_MSG("leaving");
return err;
}
PSMI_API_DECL(psm2_ep_epid_lookup);
psm2_error_t __psm2_ep_epid_lookup2(psm2_ep_t ep, psm2_epid_t epid, psm2_epconn_t *epconn)
{
psm2_error_t err = PSM2_OK;
PSM2_LOG_MSG("entering");
PSMI_ERR_UNLESS_INITIALIZED(NULL);
/* Need to have an opened endpoint before we can resolve epids */
if (ep == NULL) {
err = psmi_handle_error(NULL, PSM2_EP_WAS_CLOSED,
"PSM Endpoint is closed or does not exist");
PSM2_LOG_MSG("leaving");
return err;
}
if (epconn == NULL) {
err = psmi_handle_error(ep, PSM2_PARAM_ERR,
"Invalid output parameter");
PSM2_LOG_MSG("leaving");
return err;
}
psm2_epaddr_t epaddr = psmi_epid_lookup(ep, epid);
if (epaddr) {
/* Found connection for epid. Return info about endpoint to caller. */
psmi_assert_always(epaddr->ptlctl->ep == ep);
epconn->addr = epaddr;
epconn->ep = ep;
epconn->mq = ep->mq;
PSM2_LOG_MSG("leaving");
return err;
}
err = psmi_handle_error(ep, PSM2_EPID_UNKNOWN,
"Endpoint connection status unknown");
PSM2_LOG_MSG("leaving");
return err;
}
PSMI_API_DECL(psm2_ep_epid_lookup2);
psm2_error_t __psm2_epaddr_to_epid(psm2_epaddr_t epaddr, psm2_epid_t *epid)
{
psm2_error_t err = PSM2_OK;
PSM2_LOG_MSG("entering");
if (epaddr && epid) {
*epid = epaddr->epid;
}
else {
err = psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid input epaddr or output epid parameter");
}
PSM2_LOG_MSG("leaving");
return err;
}
PSMI_API_DECL(psm2_epaddr_to_epid);
psm2_error_t
__psm2_ep_epid_share_memory(psm2_ep_t ep, psm2_epid_t epid, int *result_o)
{
uint32_t num_lids = 0;
uint16_t *lids = NULL;
int i;
uint16_t epid_lid;
int result = 0;
psm2_error_t err;
PSM2_LOG_MSG("entering");
psmi_assert_always(ep != NULL);
PSMI_ERR_UNLESS_INITIALIZED(ep);
if ((!psmi_ep_device_is_enabled(ep, PTL_DEVID_IPS)) ||
(psmi_epid_version(epid) == PSMI_EPID_VERSION_SHM)) {
/* If we are in the no hfi-mode, or the other process is,
* the epid doesn't help us - so assume both we're on the same
* machine and try to connect.
*/
result = 1;
} else {
epid_lid = (uint16_t) psm2_epid_nid(epid);
err = psmi_ep_devlids(&lids, &num_lids, ep->gid_hi, ep->gid_lo);
if (err) {
PSM2_LOG_MSG("leaving");
return err;
}
for (i = 0; i < num_lids; i++) {
if (epid_lid == lids[i]) {
/* we share memory if the lid is the same. */
result = 1;
break;
}
}
}
*result_o = result;
PSM2_LOG_MSG("leaving");
return PSM2_OK;
}
PSMI_API_DECL(psm2_ep_epid_share_memory)
psm2_error_t __psm2_ep_open_opts_get_defaults(struct psm2_ep_open_opts *opts)
{
PSM2_LOG_MSG("entering");
PSMI_ERR_UNLESS_INITIALIZED(NULL);
if (!opts)
return PSM2_PARAM_ERR;
/* Set in order in the structure. */
opts->timeout = 30000000000LL; /* 30 sec */
opts->unit = HFI_UNIT_ID_ANY;
opts->affinity = PSM2_EP_OPEN_AFFINITY_SET;
opts->shm_mbytes = 0; /* deprecated in psm2.h */
opts->sendbufs_num = 1024;
opts->network_pkey = psmi_hal_get_default_pkey();
opts->port = HFI_PORT_NUM_ANY;
opts->outsl = PSMI_SL_DEFAULT;
opts->service_id = HFI_DEFAULT_SERVICE_ID;
opts->path_res_type = PSM2_PATH_RES_NONE;
opts->senddesc_num = 4096;
opts->imm_size = 128;
PSM2_LOG_MSG("leaving");
return PSM2_OK;
}
PSMI_API_DECL(psm2_ep_open_opts_get_defaults)
psm2_error_t psmi_poll_noop(ptl_t *ptl, int replyonly);
psm2_error_t
__psm2_ep_open_internal(psm2_uuid_t const unique_job_key, int *devid_enabled,
struct psm2_ep_open_opts const *opts_i, psm2_mq_t mq,
psm2_ep_t *epo, psm2_epid_t *epido)
{
psm2_ep_t ep = NULL;
uint32_t num_units;
size_t len;
psm2_error_t err;
psm2_epaddr_t epaddr = NULL;
char buf[128], *p, *e;
union psmi_envvar_val envvar_val;
size_t ptl_sizes;
struct psm2_ep_open_opts opts;
ptl_t *amsh_ptl, *ips_ptl, *self_ptl;
int i;
/* First get the set of default options, we overwrite with the user's
* desired values afterwards */
if ((err = psm2_ep_open_opts_get_defaults(&opts)))
goto fail;
if (opts_i != NULL) {
if (opts_i->timeout != -1)
opts.timeout = opts_i->timeout;
if (opts_i->unit != -1)
opts.unit = opts_i->unit;
if (opts_i->affinity != -1)
opts.affinity = opts_i->affinity;
if (opts_i->sendbufs_num != -1)
opts.sendbufs_num = opts_i->sendbufs_num;
if (opts_i->network_pkey != psmi_hal_get_default_pkey())
opts.network_pkey = opts_i->network_pkey;
if (opts_i->port != 0)
opts.port = opts_i->port;
if (opts_i->outsl != -1)
opts.outsl = opts_i->outsl;
if (opts_i->service_id)
opts.service_id = (uint64_t) opts_i->service_id;
if (opts_i->path_res_type != PSM2_PATH_RES_NONE)
opts.path_res_type = opts_i->path_res_type;
if (opts_i->senddesc_num)
opts.senddesc_num = opts_i->senddesc_num;
if (opts_i->imm_size)
opts.imm_size = opts_i->imm_size;
}
/* Get Service ID from environment */
if (!psmi_getenv("PSM2_IB_SERVICE_ID",
"HFI Service ID for path resolution",
PSMI_ENVVAR_LEVEL_USER,
PSMI_ENVVAR_TYPE_ULONG_ULONG,
(union psmi_envvar_val)HFI_DEFAULT_SERVICE_ID,
&envvar_val)) {
opts.service_id = (uint64_t) envvar_val.e_ulonglong;
}
/* Get Path resolution type from environment Possible choices are:
*
* NONE : Default same as previous instances. Utilizes static data.
* OPP : Use OFED Plus Plus library to do path record queries.
* UMAD : Use raw libibumad interface to form and process path records.
*/
if (!psmi_getenv("PSM2_PATH_REC",
"Mechanism to query HFI path record (default is no path query)",
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_STR,
(union psmi_envvar_val)"none", &envvar_val)) {
if (!strcasecmp(envvar_val.e_str, "none"))
opts.path_res_type = PSM2_PATH_RES_NONE;
else if (!strcasecmp(envvar_val.e_str, "opp"))
opts.path_res_type = PSM2_PATH_RES_OPP;
else if (!strcasecmp(envvar_val.e_str, "umad"))
opts.path_res_type = PSM2_PATH_RES_UMAD;
else {
_HFI_ERROR("Unknown path resolution type %s. "
"Disabling use of path record query.\n",
envvar_val.e_str);
opts.path_res_type = PSM2_PATH_RES_NONE;
}
}
/* If a specific unit is set in the environment, use that one. */
if (!psmi_getenv("HFI_UNIT", "Device Unit number (-1 autodetects)",
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_LONG,
(union psmi_envvar_val)HFI_UNIT_ID_ANY, &envvar_val)) {
opts.unit = envvar_val.e_long;
}
/* Get user specified port number to use. */
if (!psmi_getenv("HFI_PORT", "IB Port number (0 autodetects)",
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_LONG,
(union psmi_envvar_val)HFI_PORT_NUM_ANY,
&envvar_val)) {
opts.port = envvar_val.e_long;
}
/* Get service level from environment, path-query overrides it */
if (!psmi_getenv
("HFI_SL", "HFI outging ServiceLevel number (default 0)",
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_LONG,
(union psmi_envvar_val)PSMI_SL_DEFAULT, &envvar_val)) {
opts.outsl = envvar_val.e_long;
}
/* Get network key from environment. MVAPICH and other vendor MPIs do not
* specify it on ep open and we may require it for vFabrics.
* path-query will override it.
*/
if (!psmi_getenv("PSM2_PKEY",
"HFI PKey to use for endpoint",
PSMI_ENVVAR_LEVEL_USER,
PSMI_ENVVAR_TYPE_ULONG,
(union psmi_envvar_val)((unsigned int)(psmi_hal_get_default_pkey())),
&envvar_val)) {
opts.network_pkey = (uint64_t) envvar_val.e_ulong;
}
/* BACKWARDS COMPATIBILITY: Open MPI likes to choose its own PKEY of
0x7FFF. That's no longer a valid default, so override it if the
client was compiled against PSM v1 */
if (PSMI_VERNO_GET_MAJOR(psmi_verno_client()) < 2 &&
opts.network_pkey == 0x7FFF) {
opts.network_pkey = psmi_hal_get_default_pkey();;
}
/* Get number of default send buffers from environment */
if (!psmi_getenv("PSM2_NUM_SEND_BUFFERS",
"Number of send buffers to allocate [1024]",
PSMI_ENVVAR_LEVEL_USER,
PSMI_ENVVAR_TYPE_UINT,
(union psmi_envvar_val)1024, &envvar_val)) {
opts.sendbufs_num = envvar_val.e_uint;
}
/* Get immediate data size - transfers less than immediate data size do
* not consume a send buffer and require just a send descriptor.
*/
if (!psmi_getenv("PSM2_SEND_IMMEDIATE_SIZE",
"Immediate data send size not requiring a buffer [128]",
PSMI_ENVVAR_LEVEL_USER,
PSMI_ENVVAR_TYPE_UINT,
(union psmi_envvar_val)128, &envvar_val)) {
opts.imm_size = envvar_val.e_uint;
}
/* Get number of send descriptors - by default this is 4 times the number
* of send buffers - mainly used for short/inlined messages.
*/
if (!psmi_getenv("PSM2_NUM_SEND_DESCRIPTORS",
"Number of send descriptors to allocate [4096]",
PSMI_ENVVAR_LEVEL_USER,
PSMI_ENVVAR_TYPE_UINT,
(union psmi_envvar_val)4096, &envvar_val)) {
opts.senddesc_num = envvar_val.e_uint;
}
if (psmi_device_is_enabled(devid_enabled, PTL_DEVID_IPS)) {
if ((err = psm2_ep_num_devunits(&num_units)) != PSM2_OK)
goto fail;
} else
num_units = 0;
/* do some error checking */
if (opts.timeout < -1) {
err = psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid timeout value %lld",
(long long)opts.timeout);
goto fail;
} else if (num_units && (opts.unit < -1 || opts.unit >= (int)num_units)) {
err = psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid Device Unit ID %d (%d units found)",
opts.unit, num_units);
goto fail;
} else if ((opts.port < HFI_MIN_PORT || opts.port > HFI_MAX_PORT) &&
opts.port != HFI_PORT_NUM_ANY) {
err = psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid Device port number %d",
opts.port);
goto fail;
} else if (opts.affinity < 0
|| opts.affinity > PSM2_EP_OPEN_AFFINITY_FORCE) {
err =
psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid Affinity option: %d",
opts.affinity);
goto fail;
} else if (opts.outsl < PSMI_SL_MIN || opts.outsl > PSMI_SL_MAX) {
err = psmi_handle_error(NULL, PSM2_PARAM_ERR,
"Invalid SL number: %lld",
(unsigned long long)opts.outsl);
goto fail;
}
/* Allocate end point structure storage */
ptl_sizes =
(psmi_device_is_enabled(devid_enabled, PTL_DEVID_SELF) ?
psmi_ptl_self.sizeof_ptl() : 0) +
(psmi_device_is_enabled(devid_enabled, PTL_DEVID_IPS) ?
psmi_ptl_ips.sizeof_ptl() : 0) +
(psmi_device_is_enabled(devid_enabled, PTL_DEVID_AMSH) ?
psmi_ptl_amsh.sizeof_ptl() : 0);
if (ptl_sizes == 0)
return PSM2_EP_NO_DEVICE;
ep = (psm2_ep_t) psmi_memalign(PSMI_EP_NONE, UNDEFINED, 64,
sizeof(struct psm2_ep) + ptl_sizes);
epaddr = (psm2_epaddr_t) psmi_calloc(PSMI_EP_NONE, PER_PEER_ENDPOINT,
1, sizeof(struct psm2_epaddr));
if (ep == NULL || epaddr == NULL) {
err = psmi_handle_error(NULL, PSM2_NO_MEMORY,
"Couldn't allocate memory for %s structure",
ep == NULL ? "psm2_ep" : "psm2_epaddr");
goto fail;
}
memset(ep, 0, sizeof(struct psm2_ep) + ptl_sizes);
/* Copy PTL enabled status */
for (i = 0; i < PTL_MAX_INIT; i++)
ep->devid_enabled[i] = devid_enabled[i];
/* Matched Queue initialization. We do this early because we have to
* make sure ep->mq exists and is valid before calling ips_do_work.
*/
ep->mq = mq;
/* Get ready for PTL initialization */
memcpy(&ep->uuid, (void *)unique_job_key, sizeof(psm2_uuid_t));
ep->epaddr = epaddr;
ep->memmode = mq->memmode;
ep->hfi_num_sendbufs = opts.sendbufs_num;
ep->service_id = opts.service_id;
ep->path_res_type = opts.path_res_type;
ep->hfi_num_descriptors = opts.senddesc_num;
ep->hfi_imm_size = opts.imm_size;
ep->errh = psmi_errhandler_global; /* by default use the global one */
ep->ptl_amsh.ep_poll = psmi_poll_noop;
ep->ptl_ips.ep_poll = psmi_poll_noop;
ep->connections = 0;
/* See how many iterations we want to spin before yielding */
psmi_getenv("PSM2_YIELD_SPIN_COUNT",
"Spin poll iterations before yield",
PSMI_ENVVAR_LEVEL_HIDDEN,
PSMI_ENVVAR_TYPE_UINT,
(union psmi_envvar_val)PSMI_BLOCKUNTIL_POLLS_BEFORE_YIELD,
&envvar_val);
ep->yield_spin_cnt = envvar_val.e_uint;
/* Set skip_affinity flag if PSM is not allowed to set affinity */
if (opts.affinity == PSM2_EP_OPEN_AFFINITY_SKIP)
ep->skip_affinity = true;
ptl_sizes = 0;
amsh_ptl = ips_ptl = self_ptl = NULL;
if (psmi_ep_device_is_enabled(ep, PTL_DEVID_AMSH)) {
amsh_ptl = (ptl_t *) (ep->ptl_base_data + ptl_sizes);
ptl_sizes += psmi_ptl_amsh.sizeof_ptl();
}
if (psmi_ep_device_is_enabled(ep, PTL_DEVID_IPS)) {
ips_ptl = (ptl_t *) (ep->ptl_base_data + ptl_sizes);
ptl_sizes += psmi_ptl_ips.sizeof_ptl();
}
if (psmi_ep_device_is_enabled(ep, PTL_DEVID_SELF)) {
self_ptl = (ptl_t *) (ep->ptl_base_data + ptl_sizes);
ptl_sizes += psmi_ptl_self.sizeof_ptl();
}
if ((err = psmi_ep_open_device(ep, &opts, unique_job_key,
&(ep->context), &ep->epid)))
goto fail;
psmi_assert_always(ep->epid != 0);
ep->epaddr->epid = ep->epid;
_HFI_VDBG("psmi_ep_open_device() passed\n");
/* Set our new label as soon as we know what it is */
strncpy(buf, psmi_gethostname(), sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
p = buf + strlen(buf);
/* If our rank is set, use it. If not, use context.subcontext notation */
if (((e = getenv("MPI_RANKID")) != NULL && *e) ||
((e = getenv("PSC_MPI_RANK")) != NULL && *e))
len = snprintf(p, sizeof(buf) - strlen(buf), ":%d.", atoi(e));
else
len = snprintf(p, sizeof(buf) - strlen(buf), ":%d.%d.",
(uint32_t) psm2_epid_context(ep->epid),
(uint32_t) psmi_epid_subcontext(ep->epid));
*(p + len) = '\0';
ep->context_mylabel = psmi_strdup(ep, buf);
if (ep->context_mylabel == NULL) {
err = PSM2_NO_MEMORY;
goto fail;
}
/* hfi_set_mylabel(ep->context_mylabel); */
if ((err = psmi_epid_set_hostname(psm2_epid_nid(ep->epid), buf, 0)))
goto fail;
_HFI_VDBG("start ptl device init...\n");
if (psmi_ep_device_is_enabled(ep, PTL_DEVID_SELF)) {
if ((err = psmi_ptl_self.init(ep, self_ptl, &ep->ptl_self)))
goto fail;
}
if (psmi_ep_device_is_enabled(ep, PTL_DEVID_IPS)) {
if ((err = psmi_ptl_ips.init(ep, ips_ptl, &ep->ptl_ips)))
goto fail;
}
/* If we're shm-only, this device is enabled above */
if (psmi_ep_device_is_enabled(ep, PTL_DEVID_AMSH)) {
if ((err = psmi_ptl_amsh.init(ep, amsh_ptl, &ep->ptl_amsh)))
goto fail;
} else {
/* We may have pre-attached as part of getting our rank for enabling
* shared contexts. */
}
_HFI_VDBG("finish ptl device init...\n");
/*
* Keep only IPS since only IPS support multi-rail, other devices
* are only setup once. IPS device can come to this function again.
*/
for (i = 0; i < PTL_MAX_INIT; i++) {
if (devid_enabled[i] != PTL_DEVID_IPS) {
devid_enabled[i] = -1;