NVIDIA's Multi-Instance GPU (MIG) technology allows a single physical GPU to be partitioned into multiple isolated instances, each with dedicated compute slices and memory. This enables efficient sharing of expensive GPU hardware across multiple inference or training workloads.
Implement a function mig_resource_allocation that allocates MIG instances to a set of workloads on a single GPU.
gpu_config (dict): GPU specifications with keys 'total_compute_slices' (int) and 'total_memory_gb' (float)mig_profiles (list of dicts): Available MIG partition profiles. Each dict has keys 'name' (str), 'compute_slices' (int), 'memory_gb' (float). Multiple workloads can use the same profile type.workloads (list of dicts): Workloads requesting GPU resources. Each dict has keys 'name' (str), 'min_compute_slices' (int), 'min_memory_gb' (float)Use a greedy approach:
Return a dictionary with:
'allocations': list of dicts, each with 'workload' (str), 'profile' (str), 'compute_slices' (int), 'memory_gb' (float)'total_compute_used': int, total compute slices allocated'total_memory_used': float, total memory allocated (rounded to 2 decimals)'compute_utilization': float, percentage of compute used (rounded to 2 decimals)'memory_utilization': float, percentage of memory used (rounded to 2 decimals)'workloads_served': int, number of successfully allocated workloads'workloads_rejected': list of workload name strings that could not be allocated