

# SUS05-BP04 优化基于硬件的计算加速器的使用
<a name="sus_sus_hardware_a5"></a>

优化加速型计算实例的使用，以减少工作负载的物理基础架构需求。

 **常见反模式：**
+  不监控 GPU 使用情况。
+  将通用实例用于工作负载，而专用实例可以提供更高的性能、更低的成本和更高的性能功耗比。
+  使用基于硬件的计算加速器来完成任务，而使用基于 CPU 的替代方案能更高效地完成任务。

 **建立此最佳实践的好处：**通过优化基于硬件的加速器的使用，您能够减少工作负载对物理基础设施的需求。

 **在未建立这种最佳实践的情况下暴露的风险等级：**中 

## 实施指导
<a name="implementation-guidance"></a>

 如果需要高处理能力，可以受益于使用加速型计算实例，这些实例提供对基于硬件的计算加速器的访问，例如图形处理单元（GPU）和现场可编程门阵列（FPGA）。这些硬件加速器能够比基于 CPU 的替代方案更有效地执行某些功能，例如图形处理或数据模式匹配。许多加速工作负载（如渲染、转码和机器学习）在资源使用方面变化很大。仅在需要时运行此硬件，并在不需要时自动停用它们，以最大限度地减少资源消耗。

## 实施步骤
<a name="implementation-steps"></a>
+  **探索计算加速器：**确定可以满足要求的[加速型计算实例](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html)。
+  **使用专用硬件：**对于机器学习工作负载，利用特定于工作负载的专用硬件，例如 [AWS Trainium](https://aws.amazon.com/machine-learning/trainium/)、[AWS Inferentia](https://aws.amazon.com/machine-learning/inferentia/) 和 [Amazon EC2 DL1](https://aws.amazon.com/ec2/instance-types/dl1/)。AWSInf2 实例等 Inferentia 实例[相比同类 Amazon EC2 实例，性能功耗比提升了 50%](https://aws.amazon.com/machine-learning/inferentia/)。
+  **监控使用情况指标：**收集加速型计算实例的使用情况指标。例如，按照[使用 Amazon CloudWatch 收集 NVIDIA GPU 指标](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-NVIDIA-GPU.html)所述，使用 CloudWatch 代理收集 GPU 的 `utilization_gpu` 和 `utilization_memory` 等指标。
+  **规模适中：**优化硬件加速器的代码、网络运营和设置，来确保底层硬件得到充分利用。
  +  [优化 GPU 设置](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/optimize_gpu.html) 
  +  [GPU Monitoring and Optimization in the Deep Learning AMI](https://docs.aws.amazon.com/dlami/latest/devguide/tutorial-gpu.html) 
  +  [Optimizing I/O for GPU performance tuning of deep learning training in Amazon SageMaker AI](https://aws.amazon.com/blogs/machine-learning/optimizing-i-o-for-gpu-performance-tuning-of-deep-learning-training-in-amazon-sagemaker/) 
+  **保持最新：**使用最新的高性能库和 GPU 驱动程序。
+  **释放不需要的实例：**使用自动化功能在不使用 GPU 实例时将其释放。

## 资源
<a name="resources"></a>

 **相关文档：**
+  [加速计算](https://aws.amazon.com/ec2/instance-types/#Accelerated_Computing) 
+ [Let's Architect\$1 Architecting with custom chips and accelerators ](https://aws.amazon.com/blogs/architecture/lets-architect-custom-chips-and-accelerators/)
+ [如何为我的工作负载选择适当的 Amazon EC2 实例类型？](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-choose-type-for-workload/)
+  [Amazon EC2 VT1 Instances](https://aws.amazon.com/ec2/instance-types/vt1/) 
+ [ Choose the best AI accelerator and model compilation for computer vision inference with Amazon SageMaker AI ](https://aws.amazon.com/blogs/machine-learning/choose-the-best-ai-accelerator-and-model-compilation-for-computer-vision-inference-with-amazon-sagemaker/)

 **相关视频：**
+ [AWS re:Invent 2021 - How to select Amazon EC2 GPU instances for deep learning ](https://www.youtube.com/watch?v=4bVrIbgGWEA)
+  [AWS 在线技术讲座 – 部署经济高效的深度学习推理](https://www.youtube.com/watch?v=WiCougIDRsw) 
+ [AWS re:Invent 2023 - Cutting-edge AI with AWS and NVIDIA](https://www.youtube.com/watch?v=ud4-z_sb_ps)
+ [AWS re:Invent 2022 - [NEW LAUNCH\$1] Introducing AWS Inferentia2-based Amazon EC2 Inf2 instances](https://www.youtube.com/watch?v=jpqiG02Y2H4)
+ [AWS re:Invent 2022 - Accelerate deep learning and innovate faster with AWS Trainium](https://www.youtube.com/watch?v=YRqvfNwqUIA)
+ [AWS re:Invent 2022 - Deep learning on AWS with NVIDIA: From training to deployment](https://www.youtube.com/watch?v=l8AFfaCkp0E)