简体   繁体   English

OpenCL 内核参数中的字符***?

[英]Char*** in OpenCL kernel argument?

I need to pass a vector<vector<string>> to a kernel OpenCL.我需要将vector<vector<string>>传递给内核 OpenCL。 What is the easiest way of doing it?最简单的方法是什么? Passing a char*** gives me an error:传递一个char***给我一个错误:

__kernel void vadd(
   __global char*** sets,
   __global int* m,
   __global long* result)
{}

ERROR: clBuildProgram(CL_BUILD_PROGRAM_FAILURE)错误:clBuildProgram(CL_BUILD_PROGRAM_FAILURE)

In OpenCL 1.x, this sort of thing is basically not possible.在 OpenCL 1.x 中,这种事情基本上是不可能的。 You'll need to convert your data such that it fits into a single buffer object, or at least into a fixed number of buffer objects.您需要将数据转换为适合单个缓冲区对象,或至少适合固定数量的缓冲区对象。 Pointers on the host don't make sense on the device.主机上的指针在设备上没有意义。 (With OpenCL 2's SVM feature, you can pass pointer values between host and kernel code, but you'll still need to ensure the memory is allocated in a way that's appropriate for this.) (使用 OpenCL 2 的 SVM 功能,您可以在主机和内核代码之间传递指针值,但您仍然需要确保以适合于此的方式分配内存。)

One option I can think of, bearing in mind I know nothing about the rest of your program, is as follows:我能想到的一种选择是,记住我对程序的其余部分一无所知,如下所示:

  1. Create an OpenCL buffer for all the strings.为所有字符串创建一个 OpenCL 缓冲区。 Add up the number of bytes required for all your strings.将所有字符串所需的字节数相加。 (possibly including nul termination, depending on what you're trying to do) (可能包括 nul 终止,具体取决于您要执行的操作)
  2. Create a buffer for looking up string start offsets (and possibly length).创建一个用于查找字符串起始偏移量(可能还有长度)的缓冲区。 Looks like you have 2 dimensions of lookup (nested vectors) so how you lay this out will depend on whether your inner vectors (second dimension) are all the same size or not.看起来你有 2 个查找维度(嵌套向量),所以你如何布局这将取决于你的内部向量(第二维)是否都是相同的大小。
  3. Write your strings back-to-back into the first buffer, recording start offsets (and length, if necessary) in the second buffer.将您的字符串背靠背写入第一个缓冲区,在第二个缓冲区中记录起始偏移量(和长度,如果需要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM