我正在开发一个对视频帧数据执行一些处理的应用程序。为了加速它,我使用了 2 个图形卡并使用 OpenCL 处理数据。我的想法是将一帧发送到第一张卡,另一帧发送到第二张卡。这些设备使用相同的上下文,但不同的命令队列、内核和内存对象。
但是,在我看来,计算不是并行执行的,因为 2 张卡所需的时间几乎与仅一张显卡所需的时间相同。
有没有人有一个很好的例子,可以同时在独立的数据片段上使用多个设备?
提前致谢。
编辑:
这是切换到 2 个单独的上下文后的结果代码。但是,2 个显卡的执行时间仍然与 1 个显卡相同。
cl::NDRange globalws(imageSize);
cl::NDRange localws;
for (int i = 0; i < numDevices; i++){
// Copy the input data to the device
commandQueues[i].enqueueWriteBuffer(inputDataBuffer[i], CL_TRUE, 0, imageSize*sizeof(float), wt[i].data);
// Set kernel arguments
kernel[i].setArg(0, inputDataBuffer[i]);
kernel[i].setArg(1, modulusBuffer[i]);
kernel[i].setArg(2, imagewidth);
}
for (int i = 0; i < numDevices; i++){
// Run kernel
commandQueues[i].enqueueNDRangeKernel(kernel[i], cl::NullRange, globalws, localws);
}
for (int i = 0; i < numDevices; i++){
// Read the modulus back to the host
float* modulus = new float[imageSize/4];
commandQueues[i].enqueueReadBuffer(modulusBuffer[i], CL_TRUE, 0, imageSize/4*sizeof(float), modulus);
// Do something with the modulus;
}