将结构中的双指针传递给CUDA [英] Pass double pointer in a struct to CUDA
本文介绍了将结构中的双指针传递给CUDA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下结构:
struct Param
{
double** K_RP;
};
我想在CUDA中对K_RP执行以下操作
And I wanna perform the following operations on "K_RP" in CUDA
__global__ void Test( struct Param prop)
{
int ix = threadIdx.x;
int iy = threadIdx.y;
prop.K_RP[ix][iy]=2.0;
}
如果prop有以下形式,我应该怎么做cudaMalloc 和cudaMemcpy操作?
If "prop" has the following form, how should I do my "cudaMalloc" and "cudaMemcpy" operations?
int main( )
{
Param prop;
Param cuda_prop;
prop.K_RP=alloc2D(Imax,Jmax);
//cudaMalloc cuda_prop ?
//cudaMemcpyH2D prop to cuda_prop ?
Test<<< (1,1), (Imax,Jmax)>>> ( cuda_prop);
//cudaMemcpyD2H cuda_prop to prop ?
return (0);
}
推荐答案
这是时不时问。如果你在cuda标签上搜索,你会发现各种各样的答案的例子。以下是一个示例。
Questions like this get asked from time to time. If you search on the cuda tag, you'll find a variety of examples with answers. Here's one example.
- 一般来说,包含在结构或其他对象中的动态分配数据需要特殊处理。此问题/答案说明了为什么以及如何为单指针(<$处理双指针(
**
)很难,大多数人会推荐展平存储,以便可以通过引用使用单个指针(*
)来处理。如果你真的想看看双指针(**
)如何工作,请查看 this question / answer 。这不是微不足道。
- In general, dynamically allocated data contained within structures or other objects requires special handling. This question/answer explains why and how to do it for the single pointer (
*
) case. - Handling double pointers (
**
) is difficult enough that most people would recommend "flattening" the storage so that it can be handled by reference with a single pointer (*
). If you really want to see how the double pointer (**
) method works, review this question/answer. It's not trivial.
这篇关于将结构中的双指针传递给CUDA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文