opencl kernel的参数类型对应问题,诚心请教

解放牌 2015-11-12 02:27:00
下面这个代码是要写成kernel的函数,
template <typename Out, typename In>
static void filter1D(Out& output, In& data, std::vector<float>& filter,
int height, int width, int channel, bool filterRows)
{
for (int j = 0; j < width; ++j)
{
for (int i = 0; i < height; ++i)
{
float s = 0.0f;
for (int f = 0; f < filter.size(); ++f)
{
int offs = f - filter.size() / 2;
int ioff = filterRows ? (std::min)((int)height - 1, (std::max)(0, i + offs)) : i;
int joff = filterRows ? j : (std::min)((int)width - 1, (std::max)(0, j + offs));

// conv2 style boundary handling
//int ioff = filterRows ? i + offs : i;
//int joff = filterRows ? j : j + offs;
//if (ioff >= height || ioff < 0 || joff >= width || joff < 0) continue;
s += data[height*width*channel + height*joff + ioff] * filter[f];
}
output[height*width*channel + height*j + i] = s;
}
}

在这个函数中第一个参数是一个Out类型, 而Out是一个模板

以下这个是调用上面这个函数(在case0 : 处调用,在下面这个函数中,第一个参数是std::vector<float> 类型
std::vector<float> pass1(height * width * nchannels);
std::vector<float> gradIm(height * width * nchannels);
for (int c = 0; c < nchannels; ++c)
{
for (int histIdx = 0; histIdx < nHists / 2; ++histIdx)
{
switch (histIdx)
{
case 0:
// Y dir
filter1D(pass1, image, gaussianDeriv, height, width, c, true);
filter1D(gradIm, pass1, gaussian, height, width, c, false);


那么我的问题是,我该怎么杨来写kernel的参数类型?float * 不行,提示报错信息:
error C2440: 'initializing' : cannot convert from 'std::vector<float,std::allocator<_Ty>> *' to 'float *'
那么我的kernel第一个参数类型怎么写呢?
...全文
512 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tech_otaku0512 2019-04-23
  • 打赏
  • 举报
回复
我现在也遇到了一个问题,需要将STL容器中的Point_类(Point)和Rect_类(Rect)的数据类型传入到Kernel中,我需要重新写这两个stl模板对应的方法吗?
百灵工作室 2015-12-04
  • 打赏
  • 举报
回复
不要使用stl模板,使用基本类型,将计算结果传出,再使用stl
wcblem4ak 2015-11-19
  • 打赏
  • 举报
回复
好像opencl内核中是无法使用c++的stl库的,所以,解决方案应该是你根据代码中对这个vector的用法,自己定义一个数据结构来实现这些操作,然后在kernel端也定义一下,就可以用了

602

社区成员

发帖
与我相关
我的任务
社区描述
异构开发技术
社区管理员
  • OpenCL和异构编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧