uint期间在OpenCL上对CPU和GPU进行uchar转换时的结果不同

时间:2018-01-01 16:29:38

标签: opencl

以下是正在进行的示例:

__kernel void test( __global uint* input, __global uchar* output)
{
    uint t[10];
    t[0] = 63782405;

    uint t1[10];
    doSomeCalculations(t1);
    doSomeOtherStuff(t1);//after calculations t1[0] is also 63782405;

    output[0] = uchar(t[0]);
    output[1] = uchar(t1[0]);
}

在我的主机上,我看到输出[0]为5,但是当我在GPU上运行时,输出[1]为102。当我在CPU上运行时,输出[0]为5,输出[1]为5.因此它在CPU上运行正确,在GPU上运行错误。 另外,如果我将输出声明为uint,那么在CPU和GPU上输出[0]和输出[1]也是5。 任何想法,它怎么可能?

更新: 为了更清楚, 当:

__kernel void test( __global uint* input, __global uint* output)
    {
        uint t[10];
        t[0] = 63782405;

        uint t1[10];
        doSomeCalculations(t1);
        doSomeOtherStuff(t1);//after calculations t1[0] is also 63782405;

        output[0] = t[0];
        output[1] = t1[0];
    }

输出[0]是63782405, 输出[1]是63782405

当:

__kernel void test( __global uint* input, __global uint* output)
    {
        uint t[10];
        t[0] = 63782405;

        uint t1[10];
        doSomeCalculations(t1);
        doSomeOtherStuff(t1);//after calculations t1[0] is also 63782405;

        output[0] = uchar(t[0]);
        output[1] = uchar(t1[0]);
    }

输出[0]是5, 输出[1]为5

以及何时:

__kernel void test( __global uint* input, __global uchar* output)
    {
        uint t[10];
        t[0] = 63782405;

        uint t1[10];
        doSomeCalculations(t1);
        doSomeOtherStuff(t1);//after calculations t1[0] is also 63782405;

        output[0] = uchar(t[0]);
        output[1] = uchar(t1[0]);
    }

输出[0]是5, 输出[1]是102

1 个答案:

答案 0 :(得分:0)

我不确定OpenCL中是否有uchar(value)这样的东西,如果有任何编译器支持它,它可能是非官方的。

首先,标量之间的转换是隐含的(所以你实际上并不需要任何东西,只需要一个简单的作业output[0] = t[0])。禁止对向量进行隐式转换。

其次,转换标量和向量的官方显式方式为convert_type{,_sat,_round_mode}(value),因此对于您的情况output[0] = convert_uchar(t[0])投射值(重新解释位)的官方方式是as_type()(仅供参考)。

相关问题