在OpenCL中使用CLK_FILTER_LINEAR读取图像时的精度 [英] Precision when reading image with CLK_FILTER_LINEAR in OpenCL

查看:747
本文介绍了在OpenCL中使用CLK_FILTER_LINEAR读取图像时的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的代码来自这个问题 OpenCL image3d linear sampling ,我在2d和3d测试过,两者都有CPU和GPU之间的巨大差异。

The code I used is from this question OpenCL image3d linear sampling , I've tested in 2d and 3d, both with huge diff between CPU and GPU.

这是CPU的结果:

coordinate:0.000000, result: 0.000000
coordinate:0.100000, result: 0.000000
coordinate:0.200000, result: 0.000000
coordinate:0.300000, result: 10.156250
coordinate:0.400000, result: 30.078125
coordinate:0.500000, result: 50.000000
coordinate:0.600000, result: 69.921875
coordinate:0.700000, result: 89.843750
coordinate:0.800000, result: 100.000000
coordinate:0.900000, result: 100.000000
coordinate:1.000000, result: 100.000000

CPU的结果:

coordinate:0.000000, result: 0.000000
coordinate:0.000000, result: 0.000000
coordinate:0.100000, result: 0.000000
coordinate:0.200000, result: 0.000000
coordinate:0.300000, result: 10.000002
coordinate:0.400000, result: 30.000002
coordinate:0.500000, result: 50.000000
coordinate:0.600000, result: 70.000008
coordinate:0.700000, result: 90.000000
coordinate:0.800000, result: 100.000000
coordinate:0.900000, result: 100.000000
coordinate:1.000000, result: 100.000000    

你可能会看到CPU和GPU之间的差异很大,例如10.000002和10.156250。

You may see the diff between CPU and GPU is large, e.g. 10.000002 and 10.156250.

推荐答案

OpenCL规范的相关部分实际上表明它不能保证这些计算的精确度:

The pertinent part of the OpenCL specification that actually states that it doesn't guarantee the precision of these calculations:

If the sampler is specified as using unnormalized coordinates (floating-point or integer
coordinates), filter mode set to CLK_FILTER_NEAREST and addressing mode set to one of the
following modes - CLK_ADDRESS_NONE, CLK_ADDRESS_CLAMP_TO_EDGE or
CLK_ADDRESS_CLAMP, the location of the image element in the image given by (i, j, k) in
section 8.2 will be computed without any loss of precision.

For all other sampler combinations of normalized or unnormalized coordinates, filter and
addressing modes, the relative error or precision of the addressing mode calculations and the
image filter operation are not defined by this revision of the OpenCL specification. To ensure a
minimum precision of image addressing and filter calculations across any OpenCL device, for
these sampler combinations, developers should unnormalize the image coordinate in the kernel
and implement the linear filter in the kernel with appropriate calls to read_image{f|i|ui} with a
sampler that uses unnormalized coordinates, filter mode set to CLK_FILTER_NEAREST,
addressing mode set to CLK_ADDRESS_NONE, CLK_ADDRESS_CLAMP_TO_EDGE or
CLK_ADDRESS_CLAMP and finally performing the interpolation of color values read from the
image to generate the filtered color value. 

我仍然会对供应商造成错误,因为我认为将来锁定它会有所帮助标准。

I would still bug the vendor though, because I think it would be beneficial to lock this down in future standards.

这篇关于在OpenCL中使用CLK_FILTER_LINEAR读取图像时的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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