diff --git a/.codespellrc b/.codespellrc index b9251751..8187fdbe 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,2 +1,2 @@ [codespell] -ignore-words-list = crate, trait, dyn, async +ignore-words-list = crate, trait, dyn, async, hsa diff --git a/.gitignore b/.gitignore index d352dd75..31b5895e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ cufile.log .cache/ # Asio -subprojects/asio-* \ No newline at end of file +subprojects/asio-* + +build +subprojects/.wraplock \ No newline at end of file diff --git a/examples/python/expanded_two_peers.py b/examples/python/expanded_two_peers.py index e34a55b9..99c58e56 100755 --- a/examples/python/expanded_two_peers.py +++ b/examples/python/expanded_two_peers.py @@ -11,10 +11,22 @@ import numpy as np import torch -from nixl._api import nixl_agent, nixl_agent_config -from nixl.logging import get_logger +try: + try: + from nixl._api import nixl_agent, nixl_agent_config + from nixl.logging import get_logger + except ImportError: + from rixl._api import nixl_agent, nixl_agent_config + from rixl.logging import get_logger + + logger = get_logger(__name__) + NIXL_AVAILABLE = True +except ImportError: + import logging -logger = get_logger(__name__) + logger = logging.getLogger(__name__) + logger.error("NIXL API missing install NIXL.") + NIXL_AVAILABLE = False def parse_args(): @@ -33,6 +45,10 @@ def parse_args(): if __name__ == "__main__": + if not NIXL_AVAILABLE: + logger.warning("Skipping example - NIXL bindings not available") + sys.exit(0) + args = parse_args() # initiator use default port diff --git a/src/plugins/libfabric/libfabric_backend.cpp b/src/plugins/libfabric/libfabric_backend.cpp index aaad7c3c..4845ee4f 100644 --- a/src/plugins/libfabric/libfabric_backend.cpp +++ b/src/plugins/libfabric/libfabric_backend.cpp @@ -307,11 +307,12 @@ nixlLibfabricEngine::nixlLibfabricEngine(const nixlBackendInitParams *init_param NIXL_INFO << "System runtime: " << (runtime_ == FI_HMEM_CUDA ? "CUDA" : + runtime_ == FI_HMEM_ROCR ? "ROCr" : runtime_ == FI_HMEM_NEURON ? "NEURON" : "SYSTEM"); #ifdef HAVE_CUDA - if (runtime_ == FI_HMEM_CUDA) { + if (runtime_ == FI_HMEM_CUDA || runtime_ == FI_HMEM_ROCR) { // Initialize CUDA context management vramInitCtx(); // CUDA address workaround @@ -673,7 +674,7 @@ nixlLibfabricEngine::getSupportedMems() const { nixl_mem_list_t mems; mems.push_back(DRAM_SEG); #ifdef HAVE_CUDA - if (runtime_ == FI_HMEM_CUDA) { + if (runtime_ == FI_HMEM_CUDA || runtime_ == FI_HMEM_ROCR) { NIXL_DEBUG << "CUDA runtime detected, adding VRAM support"; mems.push_back(VRAM_SEG); } else @@ -708,7 +709,7 @@ nixlLibfabricEngine::registerMem(const nixlBlobDesc &mem, // Use system runtime type to determine device-specific operations if (nixl_mem == VRAM_SEG) { #ifdef HAVE_CUDA - if (runtime_ == FI_HMEM_CUDA) { + if (runtime_ == FI_HMEM_CUDA || runtime_ == FI_HMEM_ROCR) { // CUDA-specific address query // For multi-GPU support, skip CUDA address workaround if (cuda_addr_wa_) { @@ -766,7 +767,7 @@ nixlLibfabricEngine::registerMem(const nixlBlobDesc &mem, #ifdef HAVE_CUDA // Set CUDA context before libfabric operations for VRAM - if (nixl_mem == VRAM_SEG && runtime_ == FI_HMEM_CUDA) { + if (nixl_mem == VRAM_SEG && (runtime_ == FI_HMEM_CUDA || runtime_ == FI_HMEM_ROCR)) { vramApplyCtx(); } #endif diff --git a/src/plugins/libfabric/libfabric_backend.h b/src/plugins/libfabric/libfabric_backend.h index dcb88f91..d1992f20 100644 --- a/src/plugins/libfabric/libfabric_backend.h +++ b/src/plugins/libfabric/libfabric_backend.h @@ -38,9 +38,17 @@ #include "libfabric/libfabric_common.h" #ifdef HAVE_CUDA +#ifdef __HIP_PLATFORM_AMD__ +#include +#include +// Define CUDA types as HIP equivalents for AMD +typedef hipCtx_t CUcontext; +typedef hipDevice_t CUdevice; +#else #include #include #endif +#endif // Forward declarations class nixlLibfabricEngine; diff --git a/src/plugins/libfabric/meson.build b/src/plugins/libfabric/meson.build index 1fdb6fb7..97cfa60f 100644 --- a/src/plugins/libfabric/meson.build +++ b/src/plugins/libfabric/meson.build @@ -16,6 +16,14 @@ # LibFabric plugin configuration +# Hipify sources that include cuda_runtime.h for ROCm/HIP builds +hipify_cmd = find_program('hipify-perl') +hipify_src = generator(hipify_cmd, + output : ['@BASENAME@_hip.cpp'], + arguments : ['@INPUT@', '@EXTRA_ARGS@', '@OUTPUT@']) + +libfabric_backend_hip_src = hipify_src.process('libfabric_backend.cpp', extra_args: '-o') + # Enable libfabric utils layer libfabric_plugin_deps = [ nixl_infra, @@ -38,7 +46,7 @@ endif if 'LIBFABRIC' in static_plugins libfabric_backend_lib = static_library( 'LIBFABRIC', - 'libfabric_backend.cpp', + libfabric_backend_hip_src, 'libfabric_backend.h', 'libfabric_plugin.cpp', dependencies: libfabric_plugin_deps, @@ -50,7 +58,7 @@ if 'LIBFABRIC' in static_plugins else libfabric_backend_lib = shared_library( 'LIBFABRIC', - 'libfabric_backend.cpp', + libfabric_backend_hip_src, 'libfabric_backend.h', 'libfabric_plugin.cpp', dependencies: libfabric_plugin_deps, diff --git a/src/utils/libfabric/libfabric_common.cpp b/src/utils/libfabric/libfabric_common.cpp index 99ab88ea..696efaff 100644 --- a/src/utils/libfabric/libfabric_common.cpp +++ b/src/utils/libfabric/libfabric_common.cpp @@ -102,6 +102,8 @@ getAvailableNetworkDevices() { return {"cxi", provider_device_map["cxi"]}; } else if (provider_device_map.find("efa") != provider_device_map.end()) { return {"efa", provider_device_map["efa"]}; + } else if (provider_device_map.find("verbs;ofi_rxm") != provider_device_map.end()) { + return {"verbs;ofi_rxm", provider_device_map["verbs;ofi_rxm"]}; } else if (provider_device_map.find("tcp") != provider_device_map.end()) { return {"tcp", {provider_device_map["tcp"][0]}}; } else if (provider_device_map.find("sockets") != provider_device_map.end()) { diff --git a/src/utils/libfabric/libfabric_rail.cpp b/src/utils/libfabric/libfabric_rail.cpp index e6080e5a..bcb4639b 100644 --- a/src/utils/libfabric/libfabric_rail.cpp +++ b/src/utils/libfabric/libfabric_rail.cpp @@ -1329,6 +1329,13 @@ nixlLibfabricRail::registerMemory(void *buffer, mr_attr.device.cuda = device_id; NIXL_DEBUG << "CUDA memory registration - iface: FI_HMEM_CUDA, device.cuda: " << device_id; + } else if (iface == FI_HMEM_ROCR) { + // AMD ROCr memory registration + // ROCr uses HSA agent handles for device identification + // The device_id corresponds to the GPU index (0-based) + mr_attr.device.rocr = device_id; + NIXL_DEBUG << "ROCr memory registration - iface: FI_HMEM_ROCR, device.rocr: " + << device_id; } else if (iface == FI_HMEM_NEURON) { /* * Store a sentinel; libfabric requires this to be initialized. diff --git a/src/utils/libfabric/libfabric_rail_manager.cpp b/src/utils/libfabric/libfabric_rail_manager.cpp index d1e3e016..c7c7b8e8 100644 --- a/src/utils/libfabric/libfabric_rail_manager.cpp +++ b/src/utils/libfabric/libfabric_rail_manager.cpp @@ -206,6 +206,9 @@ nixlLibfabricRailManager::nixlLibfabricRailManager(size_t striping_threshold) runtime_ = FI_HMEM_CUDA; NIXL_INFO << "System runtime: CUDA for " << topology->getNumNvidiaAccel() << " NVIDIA GPU(s)"; + } else if (topology->getNumAmdAccel() > 0) { + runtime_ = FI_HMEM_ROCR; + NIXL_INFO << "System runtime: ROCr for " << topology->getNumAmdAccel() << " AMD GPU(s)"; } else if (topology->getNumAwsAccel() > 0) { runtime_ = FI_HMEM_NEURON; NIXL_INFO << "System runtime: NEURON for " << topology->getNumAwsAccel() diff --git a/src/utils/libfabric/libfabric_rail_manager.h b/src/utils/libfabric/libfabric_rail_manager.h index 3e816edc..f30b4e2a 100644 --- a/src/utils/libfabric/libfabric_rail_manager.h +++ b/src/utils/libfabric/libfabric_rail_manager.h @@ -28,9 +28,13 @@ #include "libfabric_rail.h" #ifdef HAVE_CUDA +#ifdef __HIP_PLATFORM_AMD__ +#include +#else #include #include #endif +#endif // Forward declarations class nixlLibfabricTopology; diff --git a/src/utils/libfabric/libfabric_topology.cpp b/src/utils/libfabric/libfabric_topology.cpp index b54fc6c8..ff771410 100644 --- a/src/utils/libfabric/libfabric_topology.cpp +++ b/src/utils/libfabric/libfabric_topology.cpp @@ -30,12 +30,17 @@ #include #ifdef HAVE_CUDA +#ifdef __HIP_PLATFORM_AMD__ +#include +#else #include #endif +#endif nixlLibfabricTopology::nixlLibfabricTopology() : num_aws_accel(0), num_nvidia_accel(0), + num_amd_accel(0), num_numa_nodes(0), num_devices(0), topology_discovered(false), @@ -75,13 +80,13 @@ nixlLibfabricTopology::discoverTopology() { if (status != NIXL_SUCCESS) { return status; } - // For EFA devices, build PCIe to Libfabric device mapping and full topology - if (provider_name == "efa") { + // For EFA and verbs devices, build PCIe to Libfabric device mapping and full topology + if (provider_name == "efa" || provider_name == "verbs;ofi_rxm") { // Build PCIe to Libfabric device mapping status = buildPcieToLibfabricMapping(); if (status != NIXL_SUCCESS) { - NIXL_ERROR << "Failed to build PCIe to Libfabric mapping - this is required for EFA " - "topology discovery"; + NIXL_ERROR << "Failed to build PCIe to Libfabric mapping - this is required for " + << provider_name << " topology discovery"; return status; } // Discover hardware topology using hwloc @@ -95,10 +100,10 @@ nixlLibfabricTopology::discoverTopology() { buildNicInfoMap(); // Build nVidia accelerator to EFA mapping based on PCIe topology - if (num_nvidia_accel > 0) { + if (num_nvidia_accel > 0 || num_amd_accel > 0) { status = buildAccelToEfaMapping(); if (status != NIXL_SUCCESS) { - NIXL_ERROR << "Failed to build accelerator to EFA mapping"; + NIXL_ERROR << "Failed to build accelerator to NIC mapping"; return status; } } @@ -109,6 +114,7 @@ nixlLibfabricTopology::discoverTopology() { // Set basic values without hwloc discovery num_nvidia_accel = 0; // TCP doesn't need accelerator topology + num_amd_accel = 0; // TCP doesn't need accelerator topology num_aws_accel = 0; // TCP doesn't need accelerator topology num_numa_nodes = 1; // Simple fallback @@ -132,6 +138,8 @@ nixlLibfabricTopology::discoverProviderWithDevices() { // Set device type based on discovered provider if (provider_name == "efa") { NIXL_INFO << "Discovered " << num_devices << " EFA devices"; + } else if (provider_name == "verbs;ofi_rxm") { + NIXL_INFO << "Discovered " << num_devices << " InfiniBand (" << provider_name << ") devices"; } else if (provider_name == "tcp" || provider_name == "sockets") { NIXL_INFO << "Discovered " << num_devices << " " << provider_name << " devices (TCP fallback)"; @@ -165,7 +173,7 @@ nixlLibfabricTopology::getEfaDevicesForPci(const std::string &pci_bus_id) const // GPU query, lookup based on GPU BDF if (auto it = pci_to_efa_devices.find(normalized_id); it != pci_to_efa_devices.end()) { - NIXL_DEBUG << "Found EFA devices for PCI " << pci_bus_id << " (normalized to " + NIXL_DEBUG << "Found EFA/IB devices for PCI " << pci_bus_id << " (normalized to " << normalized_id << ")"; return it->second; } @@ -173,14 +181,14 @@ nixlLibfabricTopology::getEfaDevicesForPci(const std::string &pci_bus_id) const // Neuron query, lookup based on EFA BDF if (auto it = pcie_to_libfabric_map.find(normalized_id); it != pcie_to_libfabric_map.end()) { - NIXL_DEBUG << "Found EFA devices for PCI " << pci_bus_id << " (normalized to " + NIXL_DEBUG << "Found EFA/IB devices for PCI " << pci_bus_id << " (normalized to " << normalized_id << ")"; return {it->second}; } // PCI ID parsed successfully but not found in mapping NIXL_WARN << "PCI bus ID " << pci_bus_id << " (normalized to " << normalized_id - << ") not found in accelerator-EFA mapping, returning all devices"; + << ") not found in accelerator-EFA/IB mapping, returning all devices"; } else { // Failed to parse PCI bus ID format NIXL_WARN << "Failed to parse PCI bus ID format: " << pci_bus_id @@ -258,14 +266,16 @@ nixlLibfabricTopology::printTopologyInfo() const { } NIXL_TRACE << "=== Libfabric Topology Information ==="; NIXL_TRACE << "Topology discovered: " << (topology_discovered ? "Yes" : "No"); - NIXL_TRACE << "Number of AWS accelerators: " << num_aws_accel; + NIXL_TRACE << "Number of NVIDIA accelerators: " << num_nvidia_accel; + NIXL_TRACE << "Number of AMD accelerators: " << num_amd_accel; + NIXL_TRACE << "Number of AWS Neuron accelerators: " << num_aws_accel; NIXL_TRACE << "Number of NUMA nodes: " << num_numa_nodes; - NIXL_TRACE << "Number of EFA devices: " << num_devices; - NIXL_TRACE << "EFA devices: "; + NIXL_TRACE << "Number of EFA/IB devices: " << num_devices; + NIXL_TRACE << "EFA/IB devices: "; for (size_t i = 0; i < all_devices.size(); ++i) { NIXL_TRACE << " [" << i << "] " << all_devices[i]; } - NIXL_TRACE << "Accelerator-PCI → EFA mapping:"; + NIXL_TRACE << "Accelerator-PCI → EFA/IB mapping:"; for (const auto &pair : pci_to_efa_devices) { std::stringstream ss; ss << "Accelerator-PCI " << pair.first << " → ["; @@ -276,7 +286,7 @@ nixlLibfabricTopology::printTopologyInfo() const { ss << "]"; NIXL_INFO << ss.str(); } - NIXL_TRACE << "Host memory (DRAM) will limit number of EFA devices used per-NUMA node " + NIXL_TRACE << "Host memory (DRAM) will limit number of EFA/IB devices used per-NUMA node " "according to maximum PCIe switch bandwidth"; NIXL_TRACE << "====================================="; } @@ -285,7 +295,9 @@ std::string nixlLibfabricTopology::getTopologyString() const { std::stringstream ss; ss << "Libfabric Topology: "; - ss << "AWS_Accelerators=" << num_aws_accel << ", "; + ss << "NVIDIA_GPUs=" << num_nvidia_accel << ", "; + ss << "AMD_GPUs=" << num_amd_accel << ", "; + ss << "Neuron_Accelerators=" << num_aws_accel << ", "; ss << "NUMA=" << num_numa_nodes << ", "; ss << "EFA=" << num_devices << ", "; ss << "Discovered=" << (topology_discovered ? "Yes" : "No"); @@ -398,29 +410,39 @@ nixl_status_t nixlLibfabricTopology::discoverAccelWithHwloc() { num_aws_accel = 0; num_nvidia_accel = 0; + num_amd_accel = 0; // Find all PCI devices and log detailed information - static const char *vendor_names[2] = {"NEURON", "NVIDIA"}; hwloc_obj_t pci_obj = nullptr; while ((pci_obj = hwloc_get_next_pcidev(hwloc_topology, pci_obj)) != nullptr) { const bool is_nvidia_accel = isNvidiaAccel(pci_obj); - if (is_nvidia_accel || isNeuronAccel(pci_obj)) { + const bool is_neuron_accel = isNeuronAccel(pci_obj); + const bool is_amd_accel = isAmdAccel(pci_obj); + + if (is_nvidia_accel || is_neuron_accel || is_amd_accel) { std::string pcie_addr = getPcieAddressFromHwlocObj(pci_obj); // Get device and vendor info uint16_t vendor_id = pci_obj->attr->pcidev.vendor_id; uint16_t device_id = pci_obj->attr->pcidev.device_id; uint16_t class_id = pci_obj->attr->pcidev.class_id; - NIXL_TRACE << "Found " << vendor_names[is_nvidia_accel] << " accelerator " - << num_aws_accel << ": " << pcie_addr << " (vendor=" << std::hex << vendor_id - << ", device=" << device_id << ", class=" << class_id << std::dec << ")"; + const char *vendor_name = is_nvidia_accel ? "NVIDIA" : is_amd_accel ? "AMD" : "NEURON"; - num_aws_accel++; - num_nvidia_accel += is_nvidia_accel; + NIXL_TRACE << "Found " << vendor_name << " accelerator: " << pcie_addr + << " (vendor=" << std::hex << vendor_id << ", device=" << device_id + << ", class=" << class_id << std::dec << ")"; + + if (is_nvidia_accel) { + num_nvidia_accel++; + } else if (is_amd_accel) { + num_amd_accel++; + } else { + num_aws_accel++; + } } } - NIXL_TRACE << "Discovered " << num_aws_accel << " " - << vendor_names[num_aws_accel == num_nvidia_accel] << " devices via hwloc"; + NIXL_TRACE << "Discovered " << num_nvidia_accel << " NVIDIA, " << num_amd_accel << " AMD, and " + << num_aws_accel << " Neuron accelerators via hwloc"; // If we found more than 8 NVIDIA accelerators on P5en, investigate further if (num_nvidia_accel > 8) { @@ -447,23 +469,26 @@ nixlLibfabricTopology::discoverAccelWithHwloc() { nixl_status_t nixlLibfabricTopology::discoverEfaDevicesWithHwloc() { - // EFA devices are already discovered via libfabric + // Network devices are already discovered via libfabric // This method validates the hwloc discovery matches libfabric discovery - int hwloc_efa_count = 0; + int hwloc_nic_count = 0; hwloc_obj_t pci_obj = nullptr; while ((pci_obj = hwloc_get_next_pcidev(hwloc_topology, pci_obj)) != nullptr) { - if (isEfaDevice(pci_obj)) { - hwloc_efa_count++; - NIXL_TRACE << "Found EFA device via hwloc: " << getPcieAddressFromHwlocObj(pci_obj); + bool is_target_device = (provider_name == "verbs;ofi_rxm") ? isInfiniBandDevice(pci_obj) + : isEfaDevice(pci_obj); + if (is_target_device) { + hwloc_nic_count++; + NIXL_TRACE << "Found " << provider_name + << " device via hwloc: " << getPcieAddressFromHwlocObj(pci_obj); } } - NIXL_TRACE << "hwloc found " << hwloc_efa_count << " EFA devices, libfabric found " - << num_devices; + NIXL_TRACE << "hwloc found " << hwloc_nic_count << " " << provider_name + << " devices, libfabric found " << num_devices; - if (hwloc_efa_count != num_devices) { - NIXL_DEBUG << "Mismatch between hwloc (" << hwloc_efa_count << ") and libfabric (" - << num_devices << ") EFA device counts"; + if (hwloc_nic_count != num_devices) { + NIXL_DEBUG << "Mismatch between hwloc (" << hwloc_nic_count << ") and libfabric (" + << num_devices << ") " << provider_name << " device counts"; } return NIXL_SUCCESS; @@ -564,10 +589,10 @@ nixlLibfabricTopology::buildTopologyAwareGrouping() { discovered_nics.push_back(entry.second); } - // Step 2: Discover accelerators + // Step 2: Discover accelerators (NVIDIA and AMD) hwloc_obj_t pci_obj = nullptr; while ((pci_obj = hwloc_get_next_pcidev(hwloc_topology, pci_obj)) != nullptr) { - if (isNvidiaAccel(pci_obj)) { + if (isNvidiaAccel(pci_obj) || isAmdAccel(pci_obj)) { AccelInfo accel; accel.hwloc_node = pci_obj; accel.domain_id = pci_obj->attr->pcidev.domain; @@ -747,6 +772,22 @@ nixlLibfabricTopology::isNeuronAccel(hwloc_obj_t obj) const { obj->attr->pcidev.device_id) != std::end(NEURON_DEVICE_IDS); } +bool +nixlLibfabricTopology::isAmdAccel(hwloc_obj_t obj) const { + if (!obj || obj->type != HWLOC_OBJ_PCI_DEVICE) { + return false; + } + // AMD vendor ID is 0x1002 + if (obj->attr->pcidev.vendor_id != 0x1002) { + return false; + } + // Only count devices with GPU class (0x300-0x3ff for display controllers) + // Class 0x302 is 3D controller (GPU), 0x680 is other devices (network, etc.) + // MI300X uses class 0x1200 (Processing accelerators), consumer GPUs use 0x300-0x3ff + uint16_t class_id = obj->attr->pcidev.class_id; + return (class_id >= 0x300 && class_id < 0x400) || (class_id == 0x1200); +} + bool nixlLibfabricTopology::isEfaDevice(hwloc_obj_t obj) const { if (!obj || obj->type != HWLOC_OBJ_PCI_DEVICE) { @@ -760,6 +801,20 @@ nixlLibfabricTopology::isEfaDevice(hwloc_obj_t obj) const { (obj->attr->pcidev.device_id & 0xfff0) == 0xefa0; } +bool +nixlLibfabricTopology::isInfiniBandDevice(hwloc_obj_t obj) const { + if (!obj || obj->type != HWLOC_OBJ_PCI_DEVICE) { + return false; + } + NIXL_TRACE << "Checking isInfiniBandDevice on device " << std::hex << std::showbase + << obj->attr->pcidev.vendor_id << " " << obj->attr->pcidev.device_id; + + // Mellanox/NVIDIA InfiniBand HCA vendor ID is 0x15b3 + // PCI class 0x0c06 identifies InfiniBand controllers + return obj->attr->pcidev.vendor_id == 0x15b3 && + obj->attr->pcidev.class_id == 0x0c06; +} + size_t nixlLibfabricTopology::getPcieDevSpeed(const std::string &pcie_addr) { size_t speed = 0; diff --git a/src/utils/libfabric/libfabric_topology.h b/src/utils/libfabric/libfabric_topology.h index cd846dea..ffecb3d9 100644 --- a/src/utils/libfabric/libfabric_topology.h +++ b/src/utils/libfabric/libfabric_topology.h @@ -44,6 +44,7 @@ class nixlLibfabricTopology { // System information int num_aws_accel; // AWS Trainium accelerators int num_nvidia_accel; // NVIDIA GPU accelerators + int num_amd_accel; // AMD GPU accelerators int num_numa_nodes; int num_devices; @@ -145,7 +146,11 @@ class nixlLibfabricTopology { bool isNeuronAccel(hwloc_obj_t obj) const; bool + isAmdAccel(hwloc_obj_t obj) const; + bool isEfaDevice(hwloc_obj_t obj) const; + bool + isInfiniBandDevice(hwloc_obj_t obj) const; // retrieves line speed of NIC from map size_t @@ -210,6 +215,11 @@ class nixlLibfabricTopology { return num_nvidia_accel; } + int + getNumAmdAccel() const { + return num_amd_accel; + } + const std::vector & getAllDevices() const { return all_devices; @@ -231,7 +241,13 @@ class nixlLibfabricTopology { enum fi_hmem_iface getMrAttrIface(int device_id) const { - return (device_id < num_nvidia_accel) ? FI_HMEM_CUDA : FI_HMEM_NEURON; + if (device_id < num_nvidia_accel) { + return FI_HMEM_CUDA; + } else if (device_id < num_nvidia_accel + num_amd_accel) { + return FI_HMEM_ROCR; + } else { + return FI_HMEM_NEURON; + } } /** @brief Invalid NUMA node id constant. */ diff --git a/src/utils/libfabric/meson.build b/src/utils/libfabric/meson.build index 93c0390e..035ba3b0 100644 --- a/src/utils/libfabric/meson.build +++ b/src/utils/libfabric/meson.build @@ -14,14 +14,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Hipify sources that include cuda_runtime.h for ROCm/HIP builds +hipify_cmd = find_program('hipify-perl') +hipify_src = generator(hipify_cmd, + output : ['@BASENAME@_hip.cpp'], + arguments : ['@INPUT@', '@EXTRA_ARGS@', '@OUTPUT@']) + +libfabric_topology_hip_src = hipify_src.process('libfabric_topology.cpp', extra_args: '-o') +libfabric_rail_manager_hip_src = hipify_src.process('libfabric_rail_manager.cpp', extra_args: '-o') + # Source files -libfabric_utils_sources = files( +libfabric_utils_sources = [ 'libfabric_rail.cpp', - 'libfabric_rail_manager.cpp', 'libfabric_common.cpp', - 'libfabric_topology.cpp', - # More implementation files will be added as we create them -) + libfabric_topology_hip_src, + libfabric_rail_manager_hip_src, +] # Header files libfabric_utils_headers = files( diff --git a/subprojects/.wraplock b/subprojects/.wraplock new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/utils/libfabric/libfabric_topology_test.cpp b/test/unit/utils/libfabric/libfabric_topology_test.cpp index c6cc98d9..d40744a1 100644 --- a/test/unit/utils/libfabric/libfabric_topology_test.cpp +++ b/test/unit/utils/libfabric/libfabric_topology_test.cpp @@ -22,8 +22,12 @@ #include "common/nixl_log.h" #ifdef CUDA_FOUND +#ifdef __HIP_PLATFORM_AMD__ +#include +#else #include #endif +#endif #include #include @@ -40,6 +44,7 @@ struct TopologyInfo { bool enable; const char *instance_type; const char *topo_file; + const char *provider; size_t numa_node_count; size_t nic_count; size_t nic_line_speed; // Gbps 1000^3 @@ -62,6 +67,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "p3dn.24xl", .topo_file = "p3dn.24xl-topo.xml", + .provider = "efa", .numa_node_count = 0, // no NIC is attached to NUMA node, the only NIC is attached to machine .nic_count = 1, .nic_line_speed = 100, @@ -76,6 +82,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "p4d.24xl", .topo_file = "p4d.24xl-topo.xml", + .provider = "efa", .numa_node_count = 2, .nic_count = 4, .nic_line_speed = 100, @@ -92,6 +99,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "p5.48xl", .topo_file = "p5.48xl-topo.xml", + .provider = "efa", .numa_node_count = 2, .nic_count = 32, .nic_line_speed = 100, @@ -114,6 +122,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "p5en.48xl", .topo_file = "p5en.48xl-topo.xml", + .provider = "efa", .numa_node_count = 2, .nic_count = 16, .nic_line_speed = 200, @@ -134,6 +143,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "p6-b200.48xl", .topo_file = "p6-b200.48xl-topo.xml", + .provider = "efa", .numa_node_count = 2, .nic_count = 8, .nic_line_speed = 400, @@ -160,6 +170,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "g5.48xl", .topo_file = "g5.48xl-topo.xml", + .provider = "efa", .numa_node_count = 0, // no NIC is attached to NUMA node, the only NIC is attached to machine .nic_count = 1, .nic_line_speed = 100, @@ -174,6 +185,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "g6.48xl", .topo_file = "g6.48xl-topo.xml", + .provider = "efa", .numa_node_count = 1, // single NIC is attached to a NUMA node .nic_count = 1, .nic_line_speed = 100, @@ -192,6 +204,7 @@ static TopologyInfo topologies[] = { {.enable = true, .instance_type = "c5n.18xl", .topo_file = "c5n.18xl-topo.xml", + .provider = "efa", .numa_node_count = 0, // no NIC is attached to NUMA node, the only NIC is attached to machine .nic_count = 1, .nic_line_speed = 0, // neither fi-info nor hwloc report speed for the NIC @@ -202,6 +215,43 @@ static TopologyInfo topologies[] = { .test_scenarios = {{false, 0}, {true, 50}, {true, 100}, {true, 200}}, .rail_partition = {{{0}}, {{0}}}} // pretending single switch in each node, both using rail 0 + // + // AMD MI300X (verbs;ofi_rxm provider - RoCE) + // + + // MI300X with 8x Broadcom bnxt_re (400Gbps) + 2x Mellanox ConnectX-6 Dx (100Gbps) + // 2 NUMA nodes: NUMA 0 has bnxt_re0-3 + mlx5_0-1, NUMA 1 has bnxt_re4-7 + // Each bnxt_re NIC is behind its own PCIe switch with 63 GB/s upstream link + // bnxt_re1, mlx5_0, and mlx5_1 share a topmost PCIe switch (bus 0x20) + // Topmost switches per NUMA node: 4 (NUMA0: 0x00, 0x20, 0x40, 0x60; + // NUMA1: 0x80, 0xa0, 0xc0, 0xe0) + // Rail assignment (from NicMap iteration order in rail manager): + // 0:bnxt_re5 1:bnxt_re7 2:bnxt_re3 3:bnxt_re6 4:bnxt_re4 5:bnxt_re2 + // 6:mlx5_0 7:mlx5_1 8:bnxt_re1 9:bnxt_re0 + // NOTE: 2000 Gbps (5-rail) scenario skipped because non-uniform NUMA device count + // (6 on NUMA0 vs 4 on NUMA1) breaks test validation's full_node_rail_count assumption + {.enable = true, + .instance_type = "mi300x", + .topo_file = "mi300x-topo.xml", + .provider = "verbs;ofi_rxm", + .numa_node_count = 2, + .nic_count = 10, // 8 bnxt_re + 2 mlx5 + .nic_line_speed = 400, // dominant NIC speed (bnxt_re), mlx5 are 100Gbps + .nic_upstream_link_speed = 56, // average: (8*504 + 2*252)/10 = 453.6 Gbps / 8 = ~56 GB/s + .switch_count = 4, // 4 topmost PCIe switches per NUMA node + .numa_capacity = 252, // 2020 Gbps / 8 = ~252 GB/s per NUMA node + .numa_rail_count = 4, // 2020 Gbps / 453 Gbps avg upstream = ~4 rails per NUMA node + .test_scenarios = {{false, 0}, + {true, 400}, + {true, 800}, + {true, 1200}, + {true, 2400}, + {true, 2800}, + {true, 3200}, + {true, 4000}}, + .rail_partition = {{{9}, {6, 7, 8}, {5}, {2}}, // NUMA 0: bus 0x00, 0x20, 0x40, 0x60 + {{4}, {0}, {3}, {1}}}} + // end of list }; static const size_t topology_count = sizeof(topologies) / sizeof(topologies[0]); @@ -312,7 +362,7 @@ testBasicTopology() { topology.printTopologyInfo(); // Test GPU-specific queries only if GPUs are detected - int num_gpus = topology.getNumNvidiaAccel(); + int num_gpus = topology.getNumNvidiaAccel() + topology.getNumAmdAccel(); if (num_gpus > 0) { NIXL_INFO << "3. Testing GPU-specific queries (detected " << num_gpus << " GPUs)..."; int test_gpus = std::min(num_gpus, 3); // Test up to 3 GPUs or all available @@ -320,7 +370,7 @@ testBasicTopology() { #ifdef CUDA_FOUND // Get PCI bus ID for this GPU cudaDeviceProp prop; - cudaGetDeviceProperties(&prop, gpu_id); + (void)cudaGetDeviceProperties(&prop, gpu_id); char pci_bus_id[32]; snprintf(pci_bus_id, @@ -338,7 +388,7 @@ testBasicTopology() { device_list += device; } NIXL_INFO << " GPU " << gpu_id << " (PCI: " << pci_bus_id << ") mapped to " - << gpu_devices.size() << " EFA devices: " << device_list; + << gpu_devices.size() << " EFA/IB devices: " << device_list; #else NIXL_INFO << " Skipping GPU " << gpu_id << " (CUDA not available)"; #endif @@ -362,6 +412,20 @@ isEfaDevice(hwloc_obj_t obj) { (obj->attr->pcidev.device_id & 0xfff0) == 0xefa0; } +static bool +isVerbsDevice(hwloc_obj_t obj) { + // Match RDMA-capable Ethernet devices that appear as OpenFabrics OS devices: + // - Mellanox/NVIDIA ConnectX (vendor 0x15b3) with Ethernet class (0x0200) + // - Broadcom bnxt_re (vendor 0x14e4) with Ethernet class (0x0200) + if (obj->attr->pcidev.vendor_id == 0x15b3 || + obj->attr->pcidev.vendor_id == 0x14e4) { + return true; + } + // Also match native InfiniBand (class 0x0c06) + return obj->attr->pcidev.vendor_id == 0x15b3 && + obj->attr->pcidev.class_id == 0x0c06; +} + // hwloc helper methods static std::string getPcieAddressFromHwlocPcidev(const hwloc_obj_attr_u::hwloc_pcidev_attr_s &pcidev) { @@ -394,7 +458,7 @@ getNicData(NicData &nic, hwloc_obj_t pci_obj) { } static int -getEfaDeviceNamesFromHwloc(NicMap &nic_map) { +getNicDeviceNamesFromHwloc(NicMap &nic_map) { // when testing we load topologies form XML, so we cannot mix that with local machine info that // comes from libfabric's fi_getinfo() - instead we discover network devices from hwloc, but // that is also missing NIC card line speed that comes in multiples of 1000^3. currently this @@ -437,7 +501,9 @@ getEfaDeviceNamesFromHwloc(NicMap &nic_map) { return 3; } - // get PCI device list, check if EFA, and build map + // get PCI device list, check if target device type, and build map + + bool use_verbs = (strcmp(curr_topology->provider, "verbs;ofi_rxm") == 0); hwloc_obj_t os_obj = nullptr; while ((os_obj = hwloc_get_next_osdev(hwloc_topology, os_obj)) != nullptr) { if (os_obj->attr->osdev.type == HWLOC_OBJ_OSDEV_OPENFABRICS) { @@ -447,7 +513,8 @@ getEfaDeviceNamesFromHwloc(NicMap &nic_map) { << " parent is not a PCI device, skipping"; continue; } - if (isEfaDevice(pci_obj)) { + bool is_target = use_verbs ? isVerbsDevice(pci_obj) : isEfaDevice(pci_obj); + if (is_target) { NicData &nic = nic_map[os_obj->name]; nic.name = os_obj->name; getNicData(nic, pci_obj); @@ -592,7 +659,7 @@ __wrap_fi_getinfo(uint32_t version, // load topology from XML file and feed result into fi_getinfo NicMap nic_map; - int res = getEfaDeviceNamesFromHwloc(nic_map); + int res = getNicDeviceNamesFromHwloc(nic_map); if (res != 0) { return res; } @@ -606,11 +673,11 @@ __wrap_fi_getinfo(uint32_t version, } itr->domain_attr = malloc_zero(); - itr->domain_attr->name = strdup(entry.second.name.c_str()); - itr->fabric_attr = malloc_zero(); - itr->fabric_attr->prov_name = strdup("efa"); - itr->fabric_attr->name = strdup("efa"); + + itr->domain_attr->name = strdup(entry.second.name.c_str()); + itr->fabric_attr->prov_name = strdup(curr_topology->provider); + itr->fabric_attr->name = strdup(curr_topology->provider); itr->ep_attr = malloc_zero(); itr->ep_attr->type = FI_EP_RDM; diff --git a/test/unit/utils/libfabric/meson.build b/test/unit/utils/libfabric/meson.build index 2ce31cd7..5ec906d0 100644 --- a/test/unit/utils/libfabric/meson.build +++ b/test/unit/utils/libfabric/meson.build @@ -14,6 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Hipify sources that include cuda_runtime.h for ROCm/HIP builds +hipify_cmd = find_program('hipify-perl') +hipify_src = generator(hipify_cmd, + output : ['@BASENAME@_hip.cpp'], + arguments : ['@INPUT@', '@EXTRA_ARGS@', '@OUTPUT@']) + +libfabric_topology_test_hip_src = hipify_src.process('libfabric_topology_test.cpp', extra_args: '-o') + libfabric_utils_dep = [ libfabric_dep, nixl_common_deps, serdes_interface ] libfabric_test_cpp_args = [] @@ -34,7 +42,7 @@ if get_option('buildtype') != 'release' '-Wl,--wrap=fi_fabric' ] libfabric_topology_test_bin = executable('libfabric_topology_test', - 'libfabric_topology_test.cpp', + libfabric_topology_test_hip_src, dependencies: libfabric_utils_dep, include_directories: [nixl_inc_dirs, utils_inc_dirs], link_with: libfabric_utils_lib, diff --git a/test/unit/utils/libfabric/topo/mi300x-topo.xml b/test/unit/utils/libfabric/topo/mi300x-topo.xml new file mode 100644 index 00000000..9ddd54ad --- /dev/null +++ b/test/unit/utils/libfabric/topo/mi300x-topo.xml @@ -0,0 +1,2696 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 1 + 10 32 32 10 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file