Amazon ECS タスク定義での GPU の指定 - Amazon Elastic Container Service

Amazon ECS タスク定義での GPU の指定

コンテナインスタンス上の GPU と Docker GPU ランタイムを利用するには、コンテナに必要な GPU の数をタスク定義内で必ず指定します。GPU をサポートするコンテナが配置されると、Amazon ECS コンテナエージェントは必要な数の物理 GPU を適切なコンテナに固定します。タスク内でコンテナ用に予約されている、すべての GPU の数は、タスクが起動されたコンテナインスタンスで使用できる GPU の数を超えることはできません。詳細については、「コンソールを使用した Amazon ECS タスク定義の作成」を参照してください。

重要

GPU 要件をタスク定義で指定していない場合、タスクではデフォルトの Docker ランタイムが使用されます。

タスク定義での GPU 要件の JSON 形式は以下のとおりです。

{ "containerDefinitions": [ { ... "resourceRequirements" : [ { "type" : "GPU", "value" : "2" } ], }, ... }

以下の例では、GPU 要件を指定する Docker コンテナの構文を示しています。このコンテナは 2 つの GPU を使用しており、nvidia-smi ユーティリティを実行した後に終了します。

{ "containerDefinitions": [ { "memory": 80, "essential": true, "name": "gpu", "image": "nvidia/cuda:11.0.3-base", "resourceRequirements": [ { "type":"GPU", "value": "2" } ], "command": [ "sh", "-c", "nvidia-smi" ], "cpu": 100 } ], "family": "example-ecs-gpu" }

次のタスク定義の例は、使用可能な GPU 数を出力する TensorFlow コンテナを示しています。タスクは Amazon ECS マネージドインスタンスで実行され、1 つの GPU が必要で、g4dn.xlarge インスタンスを使用します。

{ "family": "tensorflow-gpu", "networkMode": "awsvpc", "executionRoleArn": "arn:aws:iam::account-id:role/ecsTaskExecutionRole", "containerDefinitions": [ { "name": "tensorflow", "image": "tensorflow/tensorflow:latest-gpu", "essential": true, "command": [ "python", "-c", "import tensorflow as tf; print('Num GPUs Available: ', len(tf.config.list_physical_devices('GPU')))" ], "resourceRequirements": [ { "type": "GPU", "value": "1" } ], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/tensorflow-gpu", "awslogs-region": "region", "awslogs-stream-prefix": "ecs" } } } ], "requiresCompatibilities": [ "MANAGED_INSTANCES" ], "cpu": "4096", "memory": "8192", }