You are given a correct but slow kernel for an unfamiliar accelerator with explicitly managed memory and vector units. How do you make it much faster within a few hours?
Answer
Model answer, written in a candidate's voice
In short
- Study the accelerator model first: memory hierarchy, vector width, cores, DMA/async copy, alignment, latency and throughput limits.
- Measure baseline and build trace/visualisation early: timing, counters, memory traffic, stalls, and a simple heat map or timeline.
- Classify the bottleneck with arithmetic intensity/roofline: memory-bound versus compute-bound versus latency/dependency-bound.
- Apply high-value fixes in order: vectorise, tile into fast memory, pack independent work, overlap loads with compute, then use multiple cores.
- Keep correctness tests running throughout: golden outputs, randomised inputs, invariants, and before/after comparison.
- Rank ideas by expected gain and effort, timebox each change, and keep only changes that improve measured performance without breaking tests.
In full
I would start by reading the machine model rather than guessing: vector width, number of cores, fast-memory size and access rules, DMA or async-copy capabilities, alignment and bank constraints, and the latency/throughput balance. In parallel I would measure the baseline and build a small trace or visualisation early, so I can see where time goes and whether the kernel is memory-bound, compute-bound, or dependency/latency-bound; I would use arithmetic intensity or a roofline-style check to decide whether to attack traffic, vector throughput, or overlap. Then I would rank fixes by expected gain: first vectorise and remove scalar bottlenecks, tile into fast memory, pack independent instructions, overlap loads with compute with prefetch or double buffering, and only then partition across cores if the work is truly parallel and contention is controlled. Throughout, correctness tests stay running with golden outputs, randomised inputs and invariants, and I would keep a change only if it improves the measured baseline without breaking them. In a few hours I would timebox each experiment, prefer cheap high-impact changes, and stop when the remaining ideas are unlikely to beat the measured gain.
What a strong answer covers
- Study the machine model.
- Measure the baseline, and build trace or visualisation tools early.
- Find whether memory traffic or compute is the bottleneck.
- Vectorise, tile into fast memory, pack independent instructions, overlap loads with compute, use multiple cores.
- Keep correctness tests running.
- Rank ideas by expected gain.
Common mistakes
- Micro-optimising before profiling.
- Breaking correctness without tests.