ec2: Add GpuInfo to describe_instance_types (#4828)

This commit is contained in:
Edison Gustavo Muenz 2022-02-07 16:13:50 +01:00 committed by GitHub
parent 60e26e5892
commit 32373d2ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 0 deletions

View File

@ -871,6 +871,23 @@ EC2_DESCRIBE_INSTANCE_TYPES = """<?xml version="1.0" encoding="UTF-8"?>
{% endfor %}
</supportedArchitectures>
</processorInfo>
{% if instance_type.get('GpuInfo', {})|length > 0 %}
<gpuInfo>
<gpus>
{% for gpu in instance_type.get('GpuInfo').get('Gpus') %}
<item>
<count>{{ gpu['Count']|int }}</count>
<manufacturer>{{ gpu['Manufacturer'] }}</manufacturer>
<memoryInfo>
<sizeInMiB>{{ gpu['MemoryInfo']['SizeInMiB']|int }}</sizeInMiB>
</memoryInfo>
<name>{{ gpu['Name'] }}</name>
</item>
{% endfor %}
</gpus>
<totalGpuMemoryInMiB>{{ instance_type['GpuInfo']['TotalGpuMemoryInMiB']|int }}</totalGpuMemoryInMiB>
</gpuInfo>
{% endif %}
</item>
{% endfor %}
</instanceTypeSet>

View File

@ -37,6 +37,49 @@ def test_describe_instance_types_filter_by_type():
)
@mock_ec2
def test_describe_instance_types_gpu_instance_types():
client = boto3.client("ec2", "us-east-1")
instance_types = client.describe_instance_types(
InstanceTypes=["p3.2xlarge", "g4ad.8xlarge"]
)
instance_types.should.have.key("InstanceTypes")
instance_types["InstanceTypes"].should_not.be.empty
instance_types["InstanceTypes"].should.have.length_of(2)
instance_types["InstanceTypes"][0]["GpuInfo"].should_not.be.empty
instance_types["InstanceTypes"][1]["GpuInfo"].should_not.be.empty
instance_type_to_gpu_info = {
instance_info["InstanceType"]: instance_info["GpuInfo"]
for instance_info in instance_types["InstanceTypes"]
}
assert instance_type_to_gpu_info == {
"g4ad.8xlarge": {
"Gpus": [
{
"Count": 2,
"Manufacturer": "AMD",
"MemoryInfo": {"SizeInMiB": 8192},
"Name": "Radeon Pro V520",
}
],
"TotalGpuMemoryInMiB": 16384,
},
"p3.2xlarge": {
"Gpus": [
{
"Count": 1,
"Manufacturer": "NVIDIA",
"MemoryInfo": {"SizeInMiB": 16384},
"Name": "V100",
}
],
"TotalGpuMemoryInMiB": 16384,
},
}
@mock_ec2
def test_describe_instance_types_unknown_type():
client = boto3.client("ec2", "us-east-1")