Char*** in OpenCL kernel argument?

纵然是瞬间 提交于 2021-02-04 06:25:29

问题


I need to pass a vector<vector<string>> to a kernel OpenCL. What is the easiest way of doing it? Passing a char*** gives me an error:

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

ERROR: clBuildProgram(CL_BUILD_PROGRAM_FAILURE)


回答1:


In OpenCL 1.x, this sort of thing is basically not possible. 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.)

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. Add up the number of bytes required for all your strings. (possibly including nul termination, depending on what you're trying to do)
  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.
  3. Write your strings back-to-back into the first buffer, recording start offsets (and length, if necessary) in the second buffer.


来源:https://stackoverflow.com/questions/59992140/char-in-opencl-kernel-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!