将交错数组传递给 OpenCL 中的内核
passing a jagged array to a kernel in opencl
所以我知道如何在 CUDA 中做到这一点,但基本上,我想将少量 _global ptrs 传递给函数,然后将这些指针加载到本地或私有中(因为数量很少,而且我已经在内核中有一个本地内存围栏, 我不确定哪个是最快的,我将在让它工作后通过实验确定这一点)。所以我这样写内核:
__kernel foo(
__global int* img,
__global int** img_history,
__private int** private_history,
uint history_length)//could be local
{
for (int i = 0; i < history_length; i++)
private_history[i] = img_history[i];
}
澄清一下,在 cuda 中我是这样做的
__global__ foo(int* img, int** img_history, uint history_length)
{
int* private_history[10];//max values 10
for (int i = 0; i < history_length; i++)
private_history[i] = img_history[i];
}
并加载它
int** host_array = new int*[history_length];
for (int i = 0; i < history_length; i++)
cudaMalloc(host_array+i,size);
int** device_array;
cudaMalloc(&device_array,sizeof(int*)*history_length);
cudaMemcpy(device_array, host_array,sizeof(int*)*history_length,cudaMemcpyHostToDevice)
但是,我收到错误error: invalid address space for pointee of pointer argument to __kernel function
.正确的方法是什么?
我不知道你在 CUDA 中的表现如何。但这完全禁止作为 OpenCL 内核的参数。
不能将指针值复制到设备,然后直接使用它,因为内存地址不同。
为此,您需要:
- 仅复制引用图像表的img_history索引(而不是指针)。
- 随心所欲地使用thouse索引进行操作(整数操作)。
- 使用这些索引访问图像表或执行任何您想要的操作。如果您需要使用这些索引来访问 img,那么它必须是内核的参数。你必须复制所有这些。(全长 img 数组)
例:
__kernel foo(
__global int* img,
__global int* img_history,
__private int* private_history,
uint history_length)//could be local
{
for (int i = 0; i < history_length; i++)
private_history[i] = img_history[i];
/* img[private_history[i]] */ //Use it as you wish
}
相关文章:
- OpenCL 内核参数中的字符***?
- openCL 内核返回垃圾值,尽管没有错误
- OpenCL 内核计时测量 0 秒或导致 SIGABRT
- 将 C++ 库包含在 OpenCL 内核中?
- 在 OpenCL 内核中实现半精度浮点数据类型
- 在 Radeon 卡上并行执行多个 OpenCL 内核
- OpenCL内核是异步执行的吗
- 我可以为nVIDIA GPU编写OpenCL-C++内核吗
- 将 stl 数据结构传递给 opencl 内核
- 将 std::vector 传递给 openCL 内核C++绑定
- OpenCL - 内核方法返回意外结果
- 是否可以在同一设备缓冲区上一个接一个地调用 OpenCL 内核?
- 如何在 OpenCL 内核中包含 C++ 类
- 特定的OpenCL内核在移动和PC上的性能不同
- 监视OpenCL内核中的进度
- 构建 OpenCL 内核时"Compile Server Error."
- 图像如何在OpenCl内核中起作用
- 如何使用 OpenCL 内核制作累加器
- OpenCL 内核执行在调用 clFinish 或 clWaitForEvents 之前不会开始
- 如何将C++向量传递和访问到OpenCL内核