thrust scan 的问题

lovezzzzzzzz 2014-06-08 08:58:34
例子里是把啊host上的数组作为scan的输入的。不考虑“统一寻址”的情况下,能直接对device上的数组做 scan 么?我试了一下好像不行啊。总不能每次都先把数据cudaMemcpy到Host,scan以后在copy回device吧?
...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovezzzzzzzz 2014-06-09
  • 打赏
  • 举报
回复
引用 2 楼 sparrow986831 的回复:
[quote=引用 1 楼 sparrow986831 的回复:]

#include <stdlib.h>
#include <stdio.h>

#include <cuda_runtime.h>

#include <thrust/scan.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

int main()
{
	thrust::host_vector<int> H(10, 0);
	thrust::device_vector<int> D(10, 1);
	thrust::inclusive_scan(D.begin(), D.end(), D.begin()); // in-place scan

	thrust::copy(D.begin(), D.end(), H.begin());
	for (int i = 0; i < 10; i++)
	{
		printf("%d, ", H[i]);
	}
	return 0;
	//output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
}
是可以直接操作Device端的数据的,只是要弄清楚scan函数的参数,分别是(InputIterator, InputIterator, OutputIterator),然后按照对应的参数传递就好了。[/quote] 但是我的数据是放在指针里的,怎么把它传给device_vector呢?
_梦魇花葬 2014-06-09
  • 打赏
  • 举报
回复
引用 1 楼 sparrow986831 的回复:

#include <stdlib.h>
#include <stdio.h>

#include <cuda_runtime.h>

#include <thrust/scan.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

int main()
{
	thrust::host_vector<int> H(10, 0);
	thrust::device_vector<int> D(10, 1);
	thrust::inclusive_scan(D.begin(), D.end(), D.begin()); // in-place scan

	thrust::copy(D.begin(), D.end(), H.begin());
	for (int i = 0; i < 10; i++)
	{
		printf("%d, ", H[i]);
	}
	return 0;
	//output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
}
是可以直接操作Device端的数据的,只是要弄清楚scan函数的参数,分别是(InputIterator, InputIterator, OutputIterator),然后按照对应的参数传递就好了。
_梦魇花葬 2014-06-09
  • 打赏
  • 举报
回复

#include <stdlib.h>
#include <stdio.h>

#include <cuda_runtime.h>

#include <thrust/scan.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

int main()
{
	thrust::host_vector<int> H(10, 0);
	thrust::device_vector<int> D(10, 1);
	thrust::inclusive_scan(D.begin(), D.end(), D.begin()); // in-place scan

	thrust::copy(D.begin(), D.end(), H.begin());
	for (int i = 0; i < 10; i++)
	{
		printf("%d, ", H[i]);
	}
	return 0;
	//output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
}
_梦魇花葬 2014-06-09
  • 打赏
  • 举报
回复
引用 3 楼 lovezzzzzzzz 的回复:
[quote=引用 2 楼 sparrow986831 的回复:] [quote=引用 1 楼 sparrow986831 的回复:]

#include <stdlib.h>
#include <stdio.h>

#include <cuda_runtime.h>

#include <thrust/scan.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

int main()
{
	thrust::host_vector<int> H(10, 0);
	thrust::device_vector<int> D(10, 1);
	thrust::inclusive_scan(D.begin(), D.end(), D.begin()); // in-place scan

	thrust::copy(D.begin(), D.end(), H.begin());
	for (int i = 0; i < 10; i++)
	{
		printf("%d, ", H[i]);
	}
	return 0;
	//output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
}
是可以直接操作Device端的数据的,只是要弄清楚scan函数的参数,分别是(InputIterator, InputIterator, OutputIterator),然后按照对应的参数传递就好了。[/quote] 但是我的数据是放在指针里的,怎么把它传给device_vector呢?[/quote] 本人使用thrust库不是很多,也只是大概了解,用最笨的办法就是开辟一个device_vector,然后一个一个赋值。应该会有其它的办法,希望别人能够提出来~

581

社区成员

发帖
与我相关
我的任务
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
  • CUDA编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧