OpenCL 内核参数中的字符***? [英] Char*** in OpenCL kernel argument?

查看:95
本文介绍了OpenCL 内核参数中的字符***?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 vector> 传递给内核 OpenCL.最简单的方法是什么?传递 char*** 给我一个错误:

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)
{}

错误:clBuildProgram(CL_BUILD_PROGRAM_FAILURE)

ERROR: clBuildProgram(CL_BUILD_PROGRAM_FAILURE)

推荐答案

在 OpenCL 1.x 中,这种事情基本上是不可能的.您需要将数据转换为适合单个缓冲区对象,或至少适合固定数量的缓冲区对象.主机上的指针在设备上没有意义.(使用 OpenCL 2 的 SVM 功能,您可以在主机和内核代码之间传递指针值,但您仍需要确保以适合于此的方式分配内存.)

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. 为所有字符串创建一个 OpenCL 缓冲区.将所有字符串所需的字节数相加.(可能包括 nul 终止,具体取决于您要执行的操作)
  2. 创建一个用于查找字符串起始偏移量(可能还有长度)的缓冲区.看起来您有 2 个查找维度(嵌套向量),因此您如何布局将取决于您的内部向量(第二维)的大小是否相同.
  3. 将您的字符串背靠背写入第一个缓冲区,并在第二个缓冲区中记录起始偏移量(以及长度,如有必要).

这篇关于OpenCL 内核参数中的字符***?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆