简单的opencl内核

问题描述

当我开发一个简单的高斯模糊OpenCL内核时,我发现了这种有趣的效果。 如果我仅将采样器函数的y值增加1,就应该将整个图像移位1,但实际上是将其移位1080px。如果不应用任何移位,则效果很好。输入图像的形状是否可能有问题?

我正在使用PyOpencl运行狗窝。我正在Linux上使用最新的Nvidia驱动程序。

wallpaper = imageio.imread("./w1.jpg")
# insert the alpha channel otherwise the nvidia driver isn't happy
wallpaper = np.insert(wallpaper,3,255,axis=2)
wallpaper.shape = h,w,_ = 1920,1080,4
wallpaper_buffer = cl.image_from_array(ctx,wallpaper.copy(),4,norm_int=True)
result_buffer = cl.Image(ctx,cl.mem_flags.WRITE_ONLY | cl.mem_flags.HOST_READ_ONLY,fmt,shape=(1080,1920))
mask = np.array([0.129001,0.142521,0.151303,0.15435,0.129001],dtype=np.float32)
mask_buffer = cl.Buffer(ctx,mf.READ_ONLY | mf.COPY_HOST_PTR,hostbuf=table)
prg.blur_x(queue,(1080,1920),None,mask_buffer,wallpaper_buffer,result_buffer).wait()
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_LINEAR;

__kernel void blur_y(
    __constant float * mask,read_only image2d_t temp,write_only image2d_t result
) 
{
  float3 res = (float3)(0,0);
  int2 pos = (int2)(get_global_id(0),get_global_id(1));
  for(int y = 0; y <= 6; y ++) {
    float3 image = read_imagef(temp,sampler,(int2)(pos.x,pos.y + (y - 3))).xyz;
    res += mask[p] * image;
  }

  write_imagef(result,pos,(float4)(res,0) );
}

kernel void blur_x(
    __constant float * mask,read_only image2d_t wallpaper,write_only image2d_t result
    )
{  
  int2 pos = (int2)(get_global_id(0),get_global_id(1));

  /*float3 res = (float3)(0,0);
  for(int x = 0; x <= 6; x++) {
    res += mask[x] * read_imagef(wallpaper,(int2)(pos.x + (x - 3),pos.y)).xyz;
  }*/
  
  float4 res = read_imagef(wallpaper,pos.y - 1));
  

  write_imagef(result,(int2)(pos),res); //(float4)(pos.x / 255.0,pos.y / 255.0,0));
}

输入:

Before

输出:

After

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...