From 9ddf0e06498d4b85082f767e616a8ca4d3aaec9b Mon Sep 17 00:00:00 2001 From: Wenkai Du <43822138+wenkaidu@users.noreply.github.com> Date: Mon, 17 Oct 2022 10:24:59 -0700 Subject: [PATCH] Support P2P with invisible devices (#636) * Support P2P with invisible devices * Update copyright year --- src/graph/xml.cc | 29 ++++++++++++----------------- src/include/rocm_smi_wrap.h | 4 +++- src/misc/rocm_smi_wrap.cc | 34 ++++++++++++++++++++++++---------- src/transport/p2p.cc | 2 +- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/graph/xml.cc b/src/graph/xml.cc index 9b4a610aed..99dd5ab9f7 100644 --- a/src/graph/xml.cc +++ b/src/graph/xml.cc @@ -602,7 +602,7 @@ ncclResult_t ncclTopoGetXmlFromSys(struct ncclXmlNode* pciNode, struct ncclXml* return ncclSuccess; } -ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvmlDev, struct ncclXml* xml, struct ncclXmlNode** gpuNodeRet) { +ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, uint32_t rocmDev, struct ncclXml* xml, struct ncclXmlNode** gpuNodeRet) { struct ncclXmlNode* gpuNode = NULL; NCCLCHECK(xmlGetSub(pciNode, "gpu", &gpuNode)); if (gpuNode == NULL) NCCLCHECK(xmlAddNode(xml, pciNode, "gpu", &gpuNode)); @@ -612,12 +612,12 @@ ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvm int dev = -1; NCCLCHECK(xmlGetAttrIndex(gpuNode, "dev", &index)); if (index == -1) { - if (nvmlDev == NULL) { + if (rocmDev == -1) { const char* busId; NCCLCHECK(xmlGetAttr(pciNode, "busid", &busId)); if (busId == NULL || hipDeviceGetByPCIBusId(&dev, busId) != hipSuccess) dev = -1; } else { - NCCLCHECK(ncclNvmlDeviceGetIndex(nvmlDev, (unsigned int*)&dev)); + dev = rocmDev; } NCCLCHECK(xmlSetAttrInt(gpuNode, "dev", dev)); } @@ -627,13 +627,9 @@ ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvm NCCLCHECK(xmlGetAttrIndex(gpuNode, "sm", &index)); if (index == -1) { int cudaMajor, cudaMinor; - if (nvmlDev == NULL) { - hipDeviceProp_t devProp; - CUDACHECK(hipGetDeviceProperties(&devProp, dev)); - cudaMajor = devProp.major; cudaMinor = devProp.minor; - } else { - NCCLCHECK(ncclNvmlDeviceGetCudaComputeCapability(nvmlDev, &cudaMajor, &cudaMinor)); - } + hipDeviceProp_t devProp; + CUDACHECK(hipGetDeviceProperties(&devProp, 0)); + cudaMajor = devProp.major; cudaMinor = devProp.minor; NCCLCHECK(xmlSetAttrInt(gpuNode, "sm", cudaMajor*10+cudaMinor)); } int sm; @@ -643,7 +639,7 @@ ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvm NCCLCHECK(xmlGetAttrIndex(gpuNode, "gcn", &index)); if (index == -1) { hipDeviceProp_t devProp; - CUDACHECK(hipGetDeviceProperties(&devProp, dev)); + CUDACHECK(hipGetDeviceProperties(&devProp, 0)); gcn = devProp.gcnArch; NCCLCHECK(xmlSetAttrInt(gpuNode, "gcn", gcn)); } @@ -653,7 +649,7 @@ ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvm NCCLCHECK(xmlGetAttrIndex(gpuNode, "arch", &index)); if (index == -1) { hipDeviceProp_t devProp; - CUDACHECK(hipGetDeviceProperties(&devProp, dev)); + CUDACHECK(hipGetDeviceProperties(&devProp, 0)); memcpy(&arch.arch, &devProp.arch, sizeof(hipDeviceArch_t)); NCCLCHECK(xmlSetAttrInt(gpuNode, "arch", arch.value)); } @@ -665,9 +661,8 @@ ncclResult_t ncclTopoGetXmlFromGpu(struct ncclXmlNode* pciNode, nvmlDevice_t nvm #if defined(__HIP_PLATFORM_HCC__) || defined(__HCC__) || defined(__HIPCC__) const char* busId; NCCLCHECK(xmlGetAttr(pciNode, "busid", &busId)); - if (busId == NULL || hipDeviceGetByPCIBusId(&dev, busId) != hipSuccess) return ncclInternalError; - int deviceCnt; - CUDACHECK(hipGetDeviceCount(&deviceCnt)); + uint32_t deviceCnt; + NCCLCHECK(rocm_smi_getNumDevice(&deviceCnt)); for (int i=0; i> 32, (id & 0xff00) >> 8, (id & 0xf0) >> 4, (id & 0x3)); + return ncclSuccess; +} + + ncclResult_t rocm_smi_getDeviceIndexByPciBusId(const char* pciBusId, uint32_t* deviceIndex) { uint32_t i, num_devs = 0; int64_t busid; @@ -74,15 +96,7 @@ ncclResult_t rocm_smi_getDeviceIndexByPciBusId(const char* pciBusId, uint32_t* d } } -ncclResult_t rocm_smi_getLinkInfo(int srcDev, int dstDev, RSMI_IO_LINK_TYPE* rsmi_type, int *hops, int *count) { - char srcStr[] = "00000000:00:00.0", dstStr[] = "00000000:00:00.0"; - uint32_t srcIndex, dstIndex; - - CUDACHECK(hipDeviceGetPCIBusId(srcStr, sizeof(srcStr), srcDev)); - CUDACHECK(hipDeviceGetPCIBusId(dstStr, sizeof(dstStr), dstDev)); - NCCLCHECK(rocm_smi_getDeviceIndexByPciBusId(srcStr, &srcIndex)); - NCCLCHECK(rocm_smi_getDeviceIndexByPciBusId(dstStr, &dstIndex)); - +ncclResult_t rocm_smi_getLinkInfo(int srcIndex, int dstIndex, RSMI_IO_LINK_TYPE* rsmi_type, int *hops, int *count) { uint64_t rsmi_hops, rsmi_weight; ROCMSMICHECK(rsmi_topo_get_link_type(srcIndex, dstIndex, &rsmi_hops, rsmi_type)); ROCMSMICHECK(rsmi_topo_get_link_weight(srcIndex, dstIndex, &rsmi_weight)); diff --git a/src/transport/p2p.cc b/src/transport/p2p.cc index d6bfaf29c8..ff092d2a43 100644 --- a/src/transport/p2p.cc +++ b/src/transport/p2p.cc @@ -121,7 +121,7 @@ ncclResult_t p2pCanConnect(int* ret, struct ncclTopoSystem* topo, struct ncclTop int cudaDev1 = busIdToCudaDev(info1->busId); int cudaDev2 = busIdToCudaDev(info2->busId); if (cudaDev1 == -1 || cudaDev2 == -1) { -#if CUDART_VERSION >= 10010 +#if defined(__HIP_PLATFORM_HCC__) || defined(__HCC__) || defined(__HIPCC__) || CUDART_VERSION >= 10010 // CUDA 10.1 and later can use P2P with invisible devices. return ncclSuccess; #else