OpenCL是否支持随机访问的全局队列缓冲区?

我正在编写一个处理组合数据的内核。 因为这些问题通常都有很大的问题空间,大多数处理过的数据都是垃圾,有没有办法可以做到以下几点:

(1)如果计算的数据通过某种条件,则将其置于全局输出缓冲区。

(2)输出缓冲区满后,数据将被发送回主机

(3)主机从缓冲区中获取数据的副本并清除它

(4)然后创建一个由GPU填充的新缓冲区

为简单起见,这个例子可以说是一个选择性的内在产品,我的意思是

__global int buffer_counter; // Counts void put_onto_output_buffer(float value, __global float *buffer, int size) { // Put this value onto the global buffer or send a signal to the host } __kernel void inner_product( __global const float *threshold, // threshold __global const float *first_vector, // 10000 float vector __global const float *second_vector, // 10000 float vector __global float *output_buffer, // 100 float vector __global const int *output_buffer_size // size of the output buffer -- 100 { int id = get_global_id(0); float value = first_vector[id] * second_vector[id]; if (value >= threshold[0]) put_onto_output_buffer(value, output_buffer, output_buffer_size[0]); } 

这取决于输出的频率。 如果它是高频率(工作项经常写输出),那么buffer_counter将成为争用的来源并且会导致减速(顺便说一下,它需要使用primefaces方法更新,这就是为什么它的原因慢)。 在这种情况下,你最好总是在后面编写输出并对真实的输出进行排序。

另一方面,如果写入输出相当罕见,那么使用primefaces位置指示器就很有意义。 大多数工作项目将进行计算,确定它们没有输出,并退休。 只有那些有输出的不频繁的人才会争夺primefaces输出位置索引,然后连续递增它,并将它们的输出写在它们的唯一位置。 您的输出内存将紧凑地包含结果(没有特定的顺序,因此如果您愿意,请存储工作项ID)。

再次,请阅读primefaces,因为索引需要是primefaces的。