编辑:如果工作负载对于硬件来说太轻,多个并发命令队列可以实现更好的总带宽。
与 opengl 一样,opencl 需要将多个缓冲区批处理为单个缓冲区以获得更快的速度,即使使用单个 opencl 内核参数与多个参数相比也更快。因为每个操作都有操作系统/api开销。移动更大但更少的块更好。
您可以购买两个组合起来相当于 gtx 750 的显卡,以使用多个 pci-e 带宽(如果您的主板可以分别提供两个 16x 通道)
Pcie 通道有两种方式,因此您可以尝试并行写入和读取或并行化可视化和计算或并行计算和写入或并行计算和读取或并行计算+写入+读取(当然,如果它们不相互依赖,如图 1-a 所示)如果你的算法中有这样的,如果你的显卡可以的。
一旦我尝试在一个大数组上分而治之来计算每个部分并将其发送到 gpu,它需要几秒钟。现在我只用一次调用来计算写入一次计算调用。只需几毫秒。
图 1-a:
write iteration --- compute iteration ---- read iteration --- parallels
1 - - 1
2 1 - 2
3 2 1 3
4 3 2 3
5 4 3 3
6 5 4 3
如果迭代之间没有依赖关系。如果有依赖,那么:
图1-b:
write iteration --- compute iteration ---- read iteration --- parallels
half of 1 - - 1
other half of 1 half of 1 - 2
half of 2 other half of 1 half of 1 3
other half of 2 half of 2 other half of 1 3
half of 3 other half of 2 half of 2 3
other half of 3 half of 3 other half of 2 3
如果您需要在大小不定的图像批次之间进行并行化:
cpu to gpu -------- gpu to gpu ----- compute ----- gpu to cpu
1,2,3,4,5 - - -
- 1,2,3 - -
- 4,5 1,2,3 -
- - 4,5 1,2,3
6,7,8,9 - - 4,5
10,11,12 6,7,8 - -
13,14 9,10,11 6,7 -
15,16,17,18 12,13,14 8,9,10 6