如何减少OpenCL入队时间/其他任何想法? [英] How to reduce OpenCL enqueue time/any other ideas?

查看:80
本文介绍了如何减少OpenCL入队时间/其他任何想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个算法,我一直在尝试在nVidia上使用OpenCL加速它.

I have an algorithm and I've been trying to accelerate it using OpenCL on my nVidia.

它必须处理大量数据(比如说100k到百万),其中每个数据:必须首先更新矩阵(在设备上)(使用数据和两个向量);并且只有在更新整个矩阵之后,两个向量(同样在设备上)才使用相同的数据进行更新.所以,我的主机代码看起来像这样

It has to process a large amount of data (let's say 100k to milions), where for each one datum: a matrix (on the device) has to be updated first (using the datum and two vectors); and only after the whole matrix has been updated, the two vectors (also on the device) are updated using the same datum. So, my host code looks something like this

for (int i = 0; i < milions; i++) {
        clSetKernelArg(kernel_matrixUpdate, 7, sizeof(int), (void *)&i); 
        clSetKernelArg(kernel_vectorsUpdate, 4, sizeof(int), (void *)&i);       
        clEnqueueNDRangeKernel(command_queue, kernel_matrixUpdate, 1, NULL, &global_item_size_Matrix, NULL, 0, NULL, NULL);
        clEnqueueNDRangeKernel(command_queue, kernel_vectorsUpdate, 1, NULL, &global_item_size_Vectors, NULL, 0, NULL, NULL);}

不幸的是,此循环执行时间比内核本身要长.所以我的问题是:

Unfortunately, this loop takes longer to execute than the kernels themselves. So my questions are:

  • 有什么方法可以使N个内核更高效地入队吗?
  • 有没有什么方法可以先更新整个矩阵,然后再更新向量,而无需使用单独的内核?例如.设备是否按顺序运行内核(即,第一个工作组的值为0,1,...,63;第二个工作组的值为64,...)?但是我想那还是个不好的习惯...
  • 还有其他想法吗?:D

所有反馈或意见将不胜感激.谢谢.

Every feedback or opinion will be appreciated. Thank you.

推荐答案

您需要将所有数据上传到GPU,然后调用每个元素具有一个工作项的内核,而不是for循环.

You need to upload all your data to GPU and then call a kernel with one work item per element, instead of the for loop.

通常,当从CPU到GPU时,最外面的"for"循环成为内核调用.

Generally, when going from CPU to GPU, the outermost "for" loop becomes a kernel invocation.

这篇关于如何减少OpenCL入队时间/其他任何想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆