Skip to content

Report per-GPU memory at container instance registration#5061

Open
harishxr wants to merge 1 commit into
aws:devfrom
harishxr:mps-ec2-rci-memory
Open

Report per-GPU memory at container instance registration#5061
harishxr wants to merge 1 commit into
aws:devfrom
harishxr:mps-ec2-rci-memory

Conversation

@harishxr

@harishxr harishxr commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

ecs-init discovers per-GPU usable memory (NVML v2 Total - Reserved) during Setup and persists it as a UUID->MiB map in the GPU info file. The agent loads the map and populates PlatformDevice.GpuInfo.MemoryInMiB when building
the RegisterContainerInstance payload, so the control plane can size GPUs for MPS memory-based placement.

Implementation details

  • ecs-init (ecs-init/gpu/nvidia_gpu_manager.go): new DetectGPUMemory() iterates over each device and computes usable memory with NVML v2 (DeviceGetMemoryInfo_v2), usable = (Total - Reserved) / MiB. Results are stored as GPUMemoryMiB map[string]uint64 (UUID -> MiB) and serialized to the GPU info file. Called from Setup().
  • agent (agent/gpu/nvidia_gpu_manager_unix.go): reads the matching GPUMemoryMiB field from the info file in Initialize(), and SetDevices() sets PlatformDevice.GpuInfo = &GpuPlatformDeviceInfo{MemoryInMiB: ...} when a UUID has a known value. Left nil for GPUs without a value, so legacy hosts are unaffected.

Backward compatible and additive: the field is omitempty on both sides, so older agents/hosts that do not report it send nothing, and the control plane treats it as optional.

Testing

  • On host nvidia-gpu-info.json GPUMemoryMiB = 22563, matching nvidia-smi (23034 total - 471 reserved).
# sudo cat /var/lib/ecs/gpu/nvidia-gpu-info.json
{"DriverVersion":"580.159.03","GPUIDs":["GPU-cc922717-b2bb-b68f-d7da-7e2ac056c6fb"],"GPUMemoryMiB":{"GPU-cc922717-b2bb-b68f-d7da-7e2ac056c6fb":22563},"MpsControlBinaryPresent":true,"MpsServiceEnabled":true,"HasVGPU":false}[root@ip-172-31-37-203 bin]#
  • CloudTrail RegisterContainerInstance requestParameters.platformDevices[0] shows gpuInfo.memoryInMiB = 22563 from this agent build, confirming the field reaches the control plane on the wire.

"platformDevices": [
--
{
"id": "GPU-cc922717-b2bb-b68f-d7da-7e2ac056c6fb",
"type": "GPU",
"gpuInfo": {
"memoryInMiB": 22563
}
}
]


New tests cover the changes: yes

Description for the changelog

Enhancement - Report per-GPU memory at container instance registration for GPU sharing

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions? No

Does this PR include the addition of new environment variables in the README? No

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@harishxr harishxr changed the title Mps ec2 rci memory MPS GPU sharing: report per-GPU memory at container instance registration Jul 24, 2026
@harishxr
harishxr marked this pull request as ready for review July 24, 2026 05:45
@harishxr
harishxr requested a review from a team as a code owner July 24, 2026 05:45
@harishxr
harishxr force-pushed the mps-ec2-rci-memory branch from c6c8dc3 to 5fb5ba5 Compare July 24, 2026 16:55
@harishxr
harishxr enabled auto-merge (rebase) July 24, 2026 17:19
ecs-init discovers per-GPU usable memory via NVML and the agent reports it in the PlatformDevice.gpuInfo field so the control plane can place GPU instances by available memory.
@harishxr
harishxr force-pushed the mps-ec2-rci-memory branch from 5fb5ba5 to cb88dff Compare July 24, 2026 17:23
@harishxr harishxr changed the title MPS GPU sharing: report per-GPU memory at container instance registration Report per-GPU memory at container instance registration Jul 24, 2026
Type: types.PlatformDeviceTypeGpu,
})
}
if memMiB, ok := n.GPUMemoryMiB[gpuID]; ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the case when memory could be missing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential cases:

  • NVML does not return a response due to some reason when we query for memory, memory will be missing in such a case.
  • Agent version is newer than init version, ecs-init will not be able to write the gpuMemory to the gpu info file where agent reads from. In that case, memory will be empty as well.

Comment on lines +250 to +251
seelog.Errorf("Failed to get UUID for device at index %d during memory detection: %v", i, nvml.ErrorString(ret))
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about how we can better surface such errors to customers. Silently registering less capacity is not ideal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this mismatch be caught in DescribeContainerInstances response vs EC2 DescribeInstances or something like that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants