A Complete Guide to High-Performance Networking for HPC and ML Workloads
An Elastic Fabric Adapter (EFA) is a network device that you can attach to your Amazon EC2 instance to accelerate High Performance Computing (HPC) and machine learning applications. EFA provides lower and more consistent latency and higher throughput than the TCP transport traditionally used in cloud-based HPC systems.
EFA uses a technique called OS-bypass that enables HPC and machine learning applications to bypass the operating system kernel and communicate directly with the EFA device. This reduces overhead and provides similar performance to on-premises HPC clusters.
| Metric | Standard ENI | EFA | Improvement |
|---|---|---|---|
| Latency | 10-20 μs | 3-5 μs | 3-5x lower |
| Message Rate | ~1M messages/sec | ~5M messages/sec | 5x higher |
| Bandwidth | Up to 100 Gbps | Up to 100 Gbps | Similar |
| CPU Overhead | High | Low | Significantly reduced |
| Scalability | Limited | Excellent | Better scaling to thousands of nodes |
EFA is supported on specific high-performance instance types:
EFA requires specific security group rules:
# Inbound and outbound rules for all traffic between instances in the same security group Type: All traffic Protocol: All Port Range: All Source/Destination: The security group itself
This allows all EFA-enabled instances in the same security group to communicate with each other.
# Create a security group for EFA aws ec2 create-security-group \ --group-name efa-sg \ --description "Security group for EFA" \ --vpc-id vpc-12345678 # Add inbound and outbound rules aws ec2 authorize-security-group-ingress \ --group-id sg-12345678 \ --source-group sg-12345678 \ --protocol all aws ec2 authorize-security-group-egress \ --group-id sg-12345678 \ --destination-group sg-12345678 \ --protocol all # Launch an instance with EFA aws ec2 run-instances \ --image-id ami-12345678 \ --count 1 \ --instance-type p4d.24xlarge \ --key-name my-key-pair \ --security-group-ids sg-12345678 \ --subnet-id subnet-12345678 \ --network-interfaces "DeviceIndex=0,InterfaceType=efa,AssociatePublicIpAddress=true,Groups=sg-12345678"
AWS provides EFA-enabled AMIs with all required software pre-installed:
These AMIs are the easiest way to get started with EFA.
If you need to install EFA on a custom AMI:
# Download the EFA installer curl -O https://efa-installer.amazonaws.com/aws-efa-installer-latest.tar.gz # Extract the installer tar -xf aws-efa-installer-latest.tar.gz # Navigate to the extracted directory cd aws-efa-installer # Run the installer sudo ./efa_installer.sh -y # Verify installation fi_info -p efa
After installation, verify that EFA is working correctly:
# Check if EFA device exists ls -la /dev/efa* # Verify EFA module is loaded lsmod | grep efa # Check Libfabric EFA provider fi_info -p efa # Run a simple MPI test cd /opt/amazon/openmpi/bin mpirun -n 2 --host localhost,localhost ./osu_latency
If everything is working correctly, you should see the EFA device, loaded kernel modules, and successful MPI communication.
Use cluster placement groups to minimize latency between instances:
# Create a cluster placement group aws ec2 create-placement-group \ --group-name efa-cluster-pg \ --strategy cluster # Launch instances in the placement group aws ec2 run-instances \ --image-id ami-12345678 \ --count 1 \ --instance-type p4d.24xlarge \ --placement "GroupName=efa-cluster-pg" \ --network-interfaces "DeviceIndex=0,InterfaceType=efa,Groups=sg-12345678"
Optimize MPI parameters for EFA:
# Example mpirun command with optimizations mpirun \ --mca btl ^openib \ --mca pml ^ucx \ --mca opal_warn_on_missing_libcuda 0 \ --mca mtl ofi \ --mca mtl_ofi_provider_include efa \ -x FI_EFA_USE_DEVICE_RDMA=1 \ -x FI_PROVIDER=efa \ -x RDMAV_FORK_SAFE=1 \ -np 64 -npernode 8 \ --hostfile hostfile \ ./my_application
Choose the right instance type for your workload:
Configure a hostfile for multi-node MPI jobs:
# Example hostfile ip-10-0-1-101 slots=8 ip-10-0-1-102 slots=8 ip-10-0-1-103 slots=8 ip-10-0-1-104 slots=8 # Run MPI job across multiple nodes mpirun -n 32 -npernode 8 --hostfile hostfile ./my_application
For large clusters, consider using a cluster management system like AWS ParallelCluster.
Optimize NCCL for distributed machine learning with EFA:
# Set NCCL environment variables export NCCL_DEBUG=INFO export FI_PROVIDER=efa export FI_EFA_USE_DEVICE_RDMA=1 export NCCL_PROTO=simple export NCCL_ALGO=ring # Example PyTorch distributed training python -m torch.distributed.launch \ --nproc_per_node=8 \ --nnodes=4 \ --node_rank=0 \ --master_addr=ip-10-0-1-101 \ --master_port=12345 \ train.py
Combine MPI for inter-node and OpenMP for intra-node parallelism:
# Set OpenMP threads export OMP_NUM_THREADS=4 # Run hybrid MPI+OpenMP job mpirun -n 16 -npernode 4 --hostfile hostfile ./hybrid_application
This approach can reduce MPI communication overhead and improve performance.
Monitor EFA performance using CloudWatch:
Use standard HPC benchmarks to measure performance:
# OSU MPI Benchmarks mpirun -n 2 --host node1,node2 osu_latency mpirun -n 2 --host node1,node2 osu_bw mpirun -n 2 --host node1,node2 osu_allreduce -m 8:1048576 # NCCL Tests for ML workloads ./build/all_reduce_perf -b 8 -e 128M -f 2 -g 8
# Check EFA device and driver ls -la /dev/efa* lsmod | grep efa dmesg | grep -i efa # Verify Libfabric configuration fi_info -p efa FI_LOG_LEVEL=debug fi_info -p efa # Test connectivity between nodes mpirun -n 2 --host node1,node2 hostname # Check security group rules aws ec2 describe-security-groups --group-id sg-12345678
OpenAI uses EFA-enabled instances for training large language models like GPT. The distributed training process requires efficient communication between GPU nodes, and EFA's low-latency, high-throughput networking significantly reduces training time. By using EFA with NCCL, OpenAI can scale their training across hundreds of GPUs while maintaining high efficiency.
Toyota Research Institute uses EFA for computational fluid dynamics (CFD) simulations to optimize vehicle aerodynamics. Their simulations require intensive communication between compute nodes, and EFA's OS-bypass capability allows them to achieve performance similar to on-premises HPC clusters but with the flexibility of the cloud.
Rescale, a cloud HPC platform provider, uses EFA to deliver high-performance computing capabilities to their customers. By leveraging EFA, they can offer near-bare-metal performance for tightly-coupled applications like crash simulations, structural analysis, and weather modeling, enabling their customers to run complex simulations in the cloud.
AstraZeneca uses EFA for molecular dynamics simulations in drug discovery. These simulations model the interactions between proteins and potential drug compounds, requiring intensive communication between compute nodes. EFA enables them to run these simulations faster, accelerating their drug discovery pipeline.
CFD simulations model fluid flow and are used in aerospace, automotive, and weather forecasting:
# Example OpenFOAM run with EFA mpirun -n 256 --hostfile hostfile simpleFoam -parallel
Training large ML models across multiple GPU nodes:
# Example PyTorch distributed training horovodrun -np 32 -H node1:8,node2:8,node3:8,node4:8 \ python train.py --batch-size 64
Simulating the physical movements of atoms and molecules:
# Example GROMACS run with EFA mpirun -n 128 --hostfile hostfile gmx_mpi mdrun -deffnm protein -ntomp 4
Weather forecasting models like the Weather Research and Forecasting (WRF) model are classic examples of applications that benefit from EFA. These models:
A major weather forecasting center migrated their WRF workload from an on-premises HPC cluster to AWS using EFA-enabled instances. They found:
Their AWS architecture included:
Performance optimizations:
| Feature | EFA | Standard EC2 Networking | On-Premises InfiniBand | AWS Enhanced Networking |
|---|---|---|---|---|
| OS-Bypass | Yes | No | Yes | No |
| Latency | 3-5 μs | 10-20 μs | 1-2 μs | 8-15 μs |
| Setup Complexity | Medium | Low | High | Low |
| Cost | Instance cost only | Instance cost only | High (hardware + maintenance) | Instance cost only |
| Scalability | Thousands of nodes | Limited | Thousands of nodes | Moderate |
| Elasticity | High | High | Low | High |