C ++ AMP函数参数 [英] C++ AMP function argument

查看:64
本文介绍了C ++ AMP函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试在main的for循环内调用函数.  我的AMP代码可以正常工作,但是我不确定那是怎么回事.  在以下代码中,我是否在循环的每个步骤中两次将数据从主机复制到GPU?数组A和 B真的很大.我正在努力避免尽可能多地进行复制.如果可以在GPU(由funcX创建)上传递数组作为funcY参数,那就太好了.是否可以通过任何方法将GPU上已经存在的数组传递给funcY?  我使用的数组 在CPU上被定义为1维,在GPU上被视为2维.预先感谢您的帮助.   

Hello,  I am trying to call functions inside a for loop in main.  My AMP code works fine, but I am not really sure what is going on.  In the following code, am I copying data from host to GPU twice every step of the loop? Both array A and B are really large. I'm trying to avoid copying as much as I can.  It would be very nice if I can pass arrays on GPU (created by funcX) as funcY arguments.  Is there any way I can pass the array already exist on GPU to funcY?  The arrays I use are defined as 1-Dimensional on CPU and it is treated as 2-Dimensional on GPU. Thank you in advance for your help.   


推荐答案

您可以这样更改funcX和funcY的声明:

You can change the declaration of funcX and funcY like this:

void funcX(array_view< int,2& Aamp,array_view< int,2& Bamp)

void funcX(array_view<int,2> Aamp, array_view<int,2> Bamp)

void funcY(array_view< int,2& Aamp,array_view< int,2& Bamp)

void funcY(array_view<int,2> Aamp, array_view<int,2> Bamp)

然后,您可以在main()函数中声明Aamp和Bamp array_views并将它们传递给funcX和funcY.

Then you can declare the Aamp and Bamp array_views in the main() function and pass them to funcX and funcY.

这应该最大程度地减少CPU和GPU之间的复制.

This should minimize copying between CPU and GPU.


这篇关于C ++ AMP函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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