CUDA:将结构指针传递给设备函数可以吗?
在内核内部,可以将内核内部声明的结构体地址传递给设备函数吗?设备函数的参数是一个指向结构的指针。
Inside of a kernel, is it OK to pass the address of a struct, which is declared inside the kernel, to a device function? The device function's argument is a pointer to a struct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,如下程序所示:
结果:
Yes, as the following program demonstrates:
The result:
如果您在设备上分配了内存并且仅在设备内使用它,那么您可以将其传递给您想要的任何设备功能。
唯一需要担心类似问题的情况是当您想要在设备上使用来自主机的地址或来自主机上的设备的地址时。在这些情况下,您必须首先使用适当的内存副本并获取新的设备或主机特定地址。
If you have allocated memory on the device and use it only within the device, then yes you can pass it to whatever device function you want.
The only time you need to worry about anything like that is when you want to use an address from the host on the device or an address from the device on the host. In those cases, you must first use the appropriate memcopy and get a new device or host specific address.