Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/nccl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/topo.cc')
-rw-r--r--src/misc/topo.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/misc/topo.cc b/src/misc/topo.cc
new file mode 100644
index 0000000..6364978
--- /dev/null
+++ b/src/misc/topo.cc
@@ -0,0 +1,51 @@
+/*************************************************************************
+ * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
+ *
+ * See LICENSE.txt for license information
+ ************************************************************************/
+
+#include "core.h"
+#include "topo.h"
+
+#define BUSID_SIZE (sizeof("0000:00:00.0"))
+#define BUSID_REDUCED_SIZE (sizeof("0000:00"))
+
+ncclResult_t getCudaPath(int cudaDev, char** path) {
+ char busId[BUSID_SIZE];
+ CUDACHECK(cudaDeviceGetPCIBusId(busId, BUSID_SIZE, cudaDev));
+ for (int i=0; i<BUSID_SIZE; i++) busId[i] = tolower(busId[i]);
+ char busPath[] = "/sys/class/pci_bus/0000:00/../../0000:00:00.0";
+ memcpy(busPath+sizeof("/sys/class/pci_bus/")-1, busId, BUSID_REDUCED_SIZE-1);
+ memcpy(busPath+sizeof("/sys/class/pci_bus/0000:00/../../")-1, busId, BUSID_SIZE-1);
+ *path = realpath(busPath, NULL);
+ if (*path == NULL) {
+ WARN("Could not find real path of %s", busPath);
+ return ncclSystemError;
+ }
+ return ncclSuccess;
+}
+
+const char* pathDists[] = { "PIX", "PXB", "PHB", "NODE", "SYS" };
+
+int pciDistance(char* path1, char* path2) {
+ int score = 0;
+ int depth = 0;
+ int same = 1;
+ for (int i=0; i<strlen(path1); i++) {
+ if (path1[i] != path2[i]) same = 0;
+ if (path1[i] == '/') {
+ depth++;
+ if (same == 1) score++;
+ }
+ }
+ if (score <= 3) {
+ /* Split the former PATH_SOC distance into PATH_NODE and PATH_SYS based on numaId */
+ int numaId1 = getNumaId(path1);
+ int numaId2 = getNumaId(path2);
+ TRACE(NCCL_INIT, "depth %d score %d path1 %s numaId %d path2 %s numaId %d", depth, score, path1, numaId1, path2, numaId2);
+ return ((numaId1 == numaId2) ? PATH_NODE : PATH_SYS);
+ }
+ if (score == 4) return PATH_PHB;
+ if (score == depth-1) return PATH_PIX;
+ return PATH_PXB;
+}