intermediate
The Kernel Is Fast and the Function Is Not
Read the counters before the options. Nothing here is labelled with the answer.
The report
We moved our image filter to the GPU. The kernel benchmarks at 0.8 ms against 11 ms on the CPU — a 14× win. But the endpoint that calls it got slower, not faster. The GPU is clearly doing its job, so we assume the overhead is somewhere in our web framework.
The per-request path
function filter_image(img): // img ≈ 12 MB
d_in = device_alloc(size(img))
copy_to_device(d_in, img) // host -> device
d_out = device_alloc(size(img))
launch(filter_kernel, d_in, d_out)
synchronize()
result = copy_from_device(d_out) // device -> host
device_free(d_in); device_free(d_out)
return resultCountersSIMULATED
| kernel execution time | 0.8 ms | The kernel itself completes in well under a millisecond. |
| host-to-device copy | 2.1 ms | Moving the input to device memory takes over twice the kernel time. |
| device-to-host copy | 2.3 ms | Moving the result back takes a similar amount again. |
| device allocation + free | 3.9 ms per call | Allocating and releasing device buffers is a per-call cost of several milliseconds. |
| launch + synchronize overhead | 0.6 ms | Dispatching the kernel and waiting for completion has a fixed cost. |
| end-to-end GPU path | 9.7 ms (CPU path: 11 ms) | The complete GPU path is marginally faster than the CPU path it replaced. |
What is the hardware doing?