Hardware interview practice
Build a recovery plan from GPU error events
For this exercise, firmware applies a simplified policy to NVIDIA-style Xid events: 94 is treated as contained, 95 as uncontained, and 79 as a lost-bus event. Write the C++ function that validates the batch and produces one deterministic recovery plan.
Starting point
Question code
struct GpuEvent { uint16_t xid; uint8_t job; };
struct Plan { uint64_t kill_jobs; bool reset_gpu, service_host; };
int make_plan(const GpuEvent *e, size_t n, Plan *out);Reviewed example
Work through one case
Input
Events are (xid94,job2) and (xid95,job255).Expected output
kill_jobs=0x4, reset_gpu=true, service_host=false, and make_plan returns 0.The contained event marks job 2 while the uncontained event independently escalates the plan to a GPU reset.
What to cover
Requirements
- Require out; e may be NULL only when n=0. Accept only Xid 79, 94, or 95; Xid 94 requires job<64. Invalid input returns -1 and preserves *out.
- For every Xid 94, set that job bit in kill_jobs; duplicate job events set the bit only once.
- Any Xid 95 sets reset_gpu=true; any Xid 79 sets both reset_gpu=true and service_host=true.
- On success initialize all Plan fields, process the whole batch, write *out once, and return 0.
