向设备发送 char ** 数据类型
我有一个字符指针数组,我想将其发送到设备。有人可以告诉我怎么做吗?
这是我到目前为止所尝试过的:
char **a;
char **b;
*a[0]="Foo1";
*a[1]=="Foo2";
cudaMalloc(void**)?,sizeof(?);
cudamemcpy(b,a,sizeof(?),cudaMemcpyHostToDevice);
如何将参数传递给上述两个函数? 最后应该如何调用内核? (我只是传递 b 或 *b 还是什么?)
I have an array of character pointers which I want to send to device. Can somebody tell me how?
Here is what I have tried so far:
char **a;
char **b;
*a[0]="Foo1";
*a[1]=="Foo2";
cudaMalloc(void**)?,sizeof(?);
cudamemcpy(b,a,sizeof(?),cudaMemcpyHostToDevice);
How do I pass in the parameters to the above two functions?
And finally how should the kernel be called? (Do I just pass b or *b or something?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将字符指针发送到设备,您将在设备上拥有一个 CPU 内存地址数组,这可能不是您想要的。
如果要将整个数据结构发送到那里,请为每个字符串分配
sizeof(char) * string_length
字节,然后将生成的 device 指针存储在 <代码>char*。然后,完成后,将设备指针数组发送到设备,为其分配sizeof(char*) * number_of_strings
字节。当你调用内核时,给它设备端的设备指针数组。
If you send the character pointers to the device, you will have an array of CPU memory addresses on the device, which is probably not what you want.
If you want to send the whole data structure there, allocate
sizeof(char) * string_length
bytes for each string, and then store the resulting device pointers in a CPU array ofchar*
s. Then, once it's complete, send the array of device pointers to the device, allocatingsizeof(char*) * number_of_strings
bytes for it.When you call the kernel, give it the device-side array of device pointers.
要分配,请使用 array[0] = "stringliteral"
不需要明星。
要获取长度,请使用 strlen()。 siezeof 无关紧要。
切勿将其复制到此字符串矩阵中,或将其作为输出参数传递。
你必须为此分配内存。
to assign, use
array[0] = "string literal"
No need for stars.
To get length, use strlen(). siezeof is irrelevant.
Never copy into this string matrix, or pass it as out parameter.
You have to allocate memory for that.