Your function has the right structure for measuring bandwidth using CUDA events, but there are a couple of issues and suggestions for improvement:
Issues
Hardcoded memcpy direction:
The cudaMemcpyAsync call uses cudaMemcpyHostToDevice unconditionally. You pass the direction string to the function, but you don't use it to select the actual cudaMemcpyKind. This means even if you want to measure device-to-host bandwidth, it will still perform host-to-device copy.
Bandwidth calculation formula:
You calculate bandwidth as bytes * 1e-6 / time. Here:
bytes is in bytes,
time is in milliseconds from cudaEventElapsedTime.
Since time is milliseconds, and bandwidth is usually reported in GB/s, the unit adjustment should be carefully handled:
[
\text{bandwidth} = \frac{\text{bytes} \times 10^{-9}}{\text{time} \times 10^{-3}} = \frac{\text{bytes}}{\text{time}} \times 10^{-6}
]
Your formula bytes * 1e-6 / time gives GB/ms, not GB/s. It should be bytes * 1e-9 / (time * 1e-3) = bytes * 1e-6 / time. So your formula is actually correct if you consider the units correctly. Just clarify in comments if necessary.
Stream synchronization:
You synchronize on the stop event, which should be sufficient, but you might want to be sure the stream itself is idle after this or handle stream synchronization differently. Generally, synchronizing on the event is fine here.
Use of float* for src and dst:
This restricts the function only to float buffers. If you want it to be more generic for any type of data, consider void* for src and dst.