您如何重用GPU内存中的相同数据但内存位置不同? [英] How do you re-use the same data in the GPU memory but a different memory location?

查看:77
本文介绍了您如何重用GPU内存中的相同数据但内存位置不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有非常大的数据.我只想将此数据复制到GPU内存一次.由于无法使用指针访问GPU内存中此数据的不同部分,那么如何重用GPU内存中的相同数据但使用不同的内存位置?

I have a very large data. I only want to copy this data to GPU memory once. Since using pointers to access different parts of this data in GPU memory cannot be used then how do you re-use the same data in the GPU memory but a different memory location?

注意:我希望除非有其他方法,否则不要使用复制方法.

简单示例:

int data[100000]; int output[1000];

array< int> in(100000,数据); 一会儿(计数< 100000) { 程度1. ext(1000); array_view< int> out(1000,输出);

array<int> in(100000, data); while(count < 100000) { extent<1> ext(1000); array_view<int> out(1000, output);

out.discard_data();

out.discard_data();

parallel_for_each(ext,[=,& in](index< 1> idx)limit(amp) { out [idx] = in [idx]; }); out.synchronize();

parallel_for_each(ext, [=, &in](index<1> idx) restrict(amp) { out[idx] = in[idx]; }); out.synchronize();

/**由CPU完成的一些其他代码**/ /**由CPU完成的一些其他代码**/ 数++; }

/** some other code done by CPU **/ /** some other code done by CPU **/ count++; }

您可以在p_f_e内部看到, in [idx]从位置[0]开始并复制下10个元素

As you can see inside the p_f_e,  in[idx] starts at location in[0] and copies next 10 elements

对于下一个"while"迭代,我希望in [idx]从[1]中的位置开始并复制下10个元素

For the next 'while' iteration, I want in[idx] to start at location in[1] and copies next 10 elements

对于下一个"while"迭代,我希望in [idx]从in [2]的位置开始并复制下10个元素,依此类推.

For the next 'while' iteration, I want in[idx] to start at location in[2] and copies next 10 elements and so on.

这对我来说只是一个学习项目.

This is just a learning project for me.

注意:我希望除非您没有其他方法,否则不要使用复制方法.

谢谢.

推荐答案

您好,

可能是这样的:

#include <amp.h>


int main()
{
	const uint32_t data_size = 100000;
	const uint32_t step = 1000;
	
	int data[data_size];
    int output[step];

	concurrency::array<int> in(data_size, data);  
	
	uint32_t count = 0;
	while(count < data_size)
	{
		concurrency::extent<1> ext(step);     
		concurrency::array_view<int> out(ext, output); 

		out.discard_data();

		concurrency::parallel_for_each(ext, [=, &in](concurrency::index<1> idx) restrict(amp) 
		{
			out[idx] = in[idx + count];
		});
		
		out.synchronize();

		/** some other code done by CPU **/
		
		/** some other code done by CPU **/
		
		count += step;
	}

	return 0;
}


除非我误解了您的问题,否则这可能是继续阅读的解决方案 中,从p_f_e先前停止的位置开始.


Unless I misunderstood your question, this can be a solution to continue reading from in starting from where the p_f_e stopped previously.


这篇关于您如何重用GPU内存中的相同数据但内存位置不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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