cuda.to_device 是异步的吗?

问题描述 投票:0回答:0

cuda.to_device
使用与内核启动相同的流吗?

似乎 memcpy 是同步的(相对于主机)。

from numba import cuda
import numpy as np

A = np.ones((10000, 10000))
%timeit cuda.to_device(A)
188 ms ± 5.3 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit cuda.synchronize()
14.5 µs ± 7.03 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%%timeit -n1 cuda.to_device(A)
cuda.synchronize()
82.6 µs ± 11.2 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

如果

cuda.to_device
是同步的,为什么同步时间会超过 14.5 µs? (与主机同步≠gpu完成了吗?)


如果我明确提供一个流,结果是相似的。

stream = cuda.stream()
%timeit cuda.to_device(A, stream=stream)
188 ms ± 4.06 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%%timeit -n1 cuda.to_device(A, stream=stream)
cuda.synchronize()

“将传输排队到流”让我觉得传输数据的工作被委托给了流,在这种情况下简单地调用

cuda.to_device
应该更快。

%%timeit -n1 cuda.synchronize()
cuda.to_device(A, stream=stream)
186 ms ± 30 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
cuda numba
© www.soinside.com 2019 - 2024. All rights reserved.