boost :: compute流压缩 [英] boost::compute stream compaction

查看:81
本文介绍了boost :: compute流压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用boost :: compute进行流压缩?

例如如果只想对数组中的某些元素执行繁重的操作.首先,使用与您要对其执行操作的元素相对应的掩码数组生成掩码数组:

E.g. if you want to perform heavy operation only on certain elements in the array. First you generate mask array with ones corresponding to elements for which you want to perform operation:

mask = [0 0 0 1 1 0 1 0 1]

然后对掩码数组执行互斥扫描(前缀和)以获取:

Then perform exclusive scan (prefix sum) of mask array to get:

scan = [0 0 0 0 1 2 2 3 3]

然后使用以下方法压缩该数组:

Then compact this array with:

if (mask[i])
    inds[scan[i]] = i;

要获取压缩索引(索引)的最终数组:

To get final array of compacted indices (inds):

[3 4 6 8]

最终数组的大小为scan.last() + mask.last()

推荐答案

#include <boost/compute/algorithm/copy_if.hpp>

using namespace boost::compute;

detail::copy_index_if(mask.begin(), mask.end(), inds.begin(), _1 == 1, queue);

这篇关于boost :: compute流压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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