Best-Fit GPU Placement Within Single Host NVLink Islands

Last updated: November 29, 2026

Quick Overview

Implement an allocator for a GPU cloud where each VM requests 1 to 8 GPUs that must all come from one host; choose the host that leaves the fewest free GPUs, and support releasing VMs.

Crusoe
Coding & Algorithms
Software Engineer
Crusoe
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Implement an allocator for a GPU cloud where each VM requests 1 to 8 GPUs that must all come from one host; choose the host that leaves the fewest free GPUs, and support releasing VMs.

On Crusoe Cloud a multi-GPU VM needs its GPUs on one NVLink domain, so poor packing leaves hosts with scattered free GPUs that no 8-GPU request can use. The interviewer is checking data structure choice for fast best-fit lookup and reasoning about fragmentation.

What the Interviewer Expects
  • Explains why best fit reduces fragmentation versus first fit
  • Picks a structure that finds the tightest host fast (buckets by free count or a sorted set)
  • Keeps allocate and release consistent, with release restoring buckets
  • Handles invalid requests and duplicate VM ids
  • Discusses complexity and deterministic tie-breaking
Key Topics to Cover
Bin packing
Best fit
Bucketed indexes
Fragmentation
Resource scheduling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Requests for exactly 2 or 4 GPUs must sit on aligned NVLink pairs. How would you model sub-host topology?
  • How would you defragment by live migration, and which VMs would you move?
  • How does this change when hosts have different GPU counts or GPU types?
  • How would you keep the allocator consistent across multiple scheduler replicas?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

allocate(vm_id, gpus) returns a host or None; release(vm_id) frees the GPUs. All GPUs for a VM come from one host. Policy: best fit, meaning among hosts with enough free GPUs choose the one with...

High-Level Design

Since free counts are small integers (0 to 8), keep bucket[f] = set of hosts with exactly f free GPUs. Best fit scans buckets from gpus upward and takes the first non-empty one. This keeps whole...


Submit Your Answer
Markdown supported

Related Questions