thrust 学习笔记
【摘要】
gather与scatter正好相反:
scatter是顺序输入根据map确定撒点输出位置。
#include <thrust/scatter.h>#include <thrust/device_vector.h>#include <thrust/execution_policy.h>.../...
gather与scatter正好相反:
scatter是顺序输入根据map确定撒点输出位置。
-
#include <thrust/scatter.h>
-
#include <thrust/device_vector.h>
-
#include <thrust/execution_policy.h>
-
...
-
// mark even indices with a 1; odd indices with a 0
-
int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
-
thrust::device_vector<int> d_values(values, values + 10);
-
// scatter all even indices into the first half of the
-
// range, and odd indices vice versa
-
int map[10] = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9};
-
thrust::device_vector<int> d_map(map, map + 10);
-
thrust::device_vector<int> d_output(10);
-
thrust::scatter(thrust::device,
-
d_values.begin(), d_values.end(),
-
d_map.begin(), d_output.begin());
-
// d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
gather是根据map确定输入元素的位置,输出是按顺序的。
-
#include <thrust/gather.h>
-
#include <thrust/device_vector.h>
-
#include <thrust/execution_policy.h>
-
...
-
// mark even indices with a 1; odd indices with a 0
-
int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
-
thrust::device_vector<int> d_values(values, values + 10);
-
// gather all even indices into the first half of the range
-
// and odd indices to the last half of the range
-
int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
-
thrust::device_vector<int> d_map(map, map + 10);
-
thrust::device_vector<int> d_output(10);
-
thrust::gather(thrust::device,
-
d_map.begin(), d_map.end(),
-
d_values.begin(),
-
d_output.begin());
-
// d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
如图:
具体可以查看 https://blog.csdn.net/seamanj/article/details/82976687
————————————————
版权声明:本文为CSDN博主「Scott f」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/shungry/article/details/103079320
文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/123785472
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)