Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ECSでGPUを使う 2020年版 / jawsug-container18-lt-using-gpu-on-ecs-2020

Shuichi Ohsawa
November 19, 2020

ECSでGPUを使う 2020年版 / jawsug-container18-lt-using-gpu-on-ecs-2020

Shuichi Ohsawa

November 19, 2020
Tweet

More Decks by Shuichi Ohsawa

Other Decks in Technology

Transcript

  1. ECS GPU-optimized AMI を使おう • ECS で GPU を使うのに最適化された AMI

    • Amazon Linux 2 ベース • AWS CLI で 最新の AMI ID を取得できる aws ssm get-parameters \ --names /aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended \ --output text --query 'Parameters[].Value[]' | jq -r '.image_id'
  2. ECS タスク定義で GPU を指定する { "containerDefinitions": [ { "memory": 80,

    "essential": true, "name": "gpu", "image": "nvidia/cuda:11.0-base", "resourceRequirements": [ { "type":"GPU", "value": "1" } ], "command": [ "sh", "-c", "nvidia-smi" ], "cpu": 100 } ], "family": "example-ecs-gpu" }
  3. GPU 数を指定することの問題点 • 1つの GPU を複数の ECS タスクで共有することができない • 例)g4dn.xlarge

    は GPU 数が 1 なので ECS インスタンス 1 台につき GPU を扱う ECS タスクを 1 つしか配置できない • GPU を使う ECS タスクを同時に実行できない ◦ 例)GPU メトリクス(使用率、メモリ、温度など)を収集、監視するタスク • docker run --gpus=all を ECS タスク定義に渡すことができない ECS Instance Main task GPU Monitoring task
  4. Docker のデフォルトランタイムを変更する • ECS GPU-optimized AMI から EC2 インスタンスを起動 •

    /etc/sysconfig/docker に --default-runtime nvidia を追加 • AMI を作成 # Additional startup options for the Docker daemon, for example: # OPTIONS="--ip-forward=true --iptables=true" # By default we limit the number of open files per container -OPTIONS="--default-ulimit nofile=1024:4096" +OPTIONS="--default-runtime nvidia --default-ulimit nofile=1024:4096" # How many seconds the sysvinit script waits for the pidfile to appear # when starting the daemon.
  5. GPU 使用率に基づいた Auto Scaling がしたい • GPU メトリクスを CloudWatch に投げる

    • https://github.com/ohsawa0515/gpu-cloudwatch-reporting AutoScaling グループ単位 EC2 インスタンス単位