在OpenCL内核中声明和定义向量的指针审查程序 [英] declaring and defining pointer vetors of vectors in OpenCL Kernel
问题描述
我有一个变量,它是vector的向量,在c ++中,我很容易定义和声明它,但是在OpenCL内核中,我遇到了问题.这是我正在尝试做的一个例子.
I have a variable which is vector of vector, And in c++, I am easily able to define and declare it but in OpenCL Kernel, I am facing the issues. Here is an example of what I am trying to do.
std::vector<vector <double>> filter;
for (int m= 0;m<3;m++)
{
const auto& w = filters[m];
-------sum operation using w
}
现在,在这里,我可以轻松地引用 w 中的 filters [m] 的值,但是我无法执行此OpenCl内核文件.这是我尝试过的方法,但是它给了我错误的输出.
Now Here, I can easily referencing the values of filters[m] in w, but I am not able to do this OpenCl kernel file. Here is what I have tried,but it is giving me wrong output.
在主机代码中:-
filter_dev = cl::Buffer(context,CL_MEM_READ_ONLY|CL_MEM_USE_HOST_PTR,filter_size,(void*)&filters,&err);
filter_dev_buff = cl::Buffer(context,CL_MEM_READ_WRITE,filter_size,NULL,&err);
kernel.setArg(0, filter_dev);
kernel.setArg(1, filter_dev_buff);
在内核代码中:
__kernel void forward_shrink(__global double* filters,__global double* weight)
{
int i = get_global_id[0]; // I have tried to use indiviadual values of i in filters j, just to check the output, but is not giving the same values as in serial c++ implementation
weight = &filters[i];
------ sum operations using weight
}
有人可以帮助我吗?我在哪里错了,或者有什么解决方案?
Can anyone help me? Where I am wrong or what can be the solution?
推荐答案
向量在做很多事情都是错误的.
You are doing multiple things wrong with your vectors.
首先,(void*)&filters
不执行您想要的操作. &filters
不会返回指向实际数据开头的指针.为此,您必须使用filters.data()
.
First of all (void*)&filters
doesn't do what you want it to do. &filters
doesn't return a pointer to the beginning of the actual data. For that you'll have to use filters.data()
.
第二,您不能在OpenCL中使用数组数组(或向量的向量更少).在将数组传递给OpenCL内核之前,您必须先将其扁平化为一维数组.
Second you can't use an array of arrays in OpenCL (or vector of vectors even less). You'll have to flatten the array yourself to a 1D array before you pass it to a OpenCL kernel.
这篇关于在OpenCL内核中声明和定义向量的指针审查程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!