Opencl-关系函数

时间:2015-08-18 15:12:47

标签: opencl vectorization

我曾尝试在程序中使用关系函数,但有些东西很奇怪。

有些vector A有每个值;

如果我尝试打印此vector A,它就能正常运行。

但是,如果我在vector A的代码中添加一些关系函数,

它返回所有;

如果 vector 元素之一具有NAN值,那么它是否为全零?

有什么问题?请帮忙。

////////////////////////////////////// 我尝试了简单的示例代码,然后看起来像是以错误的方式工作。

主机代码

float *array;
        array = (float *) malloc(sizeof(float) * 16);

        array[0] = 1;
        array[1] = 0.5;
        array[2] = 0;
        array[3] = -0.5;
        array[4] = -1;
        array[5] = 1;
        array[6] = 0.5;
        array[7] = 0;
        array[8] = -0.5;
        array[9] = -1;
        array[10] = 1;
        array[11] = 0.5;
        array[12] = 0;
        array[13] = -0.5;
        array[14] = -1;
        array[15] = -1;

        int *array2;
        array2 = (int *) malloc(sizeof(int) * 16);
        test_buffer1 = cl::Buffer(gContext,
                CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR, 16 * sizeof(cl_float), &array,
                NULL);
        test_buffer2 = cl::Buffer(gContext,
                CL_MEM_READ_WRITE , 16 * sizeof(cl_int), NULL,
                        NULL);

        test_func.setArg(0, test_buffer1);
        test_func.setArg(1, test_buffer2);
        gQueue.enqueueNDRangeKernel(test_func, cl::NDRange(0, 0),
                cl::NDRange(1, 1), cl::NDRange(1, 1), NULL, NULL);
        gQueue.enqueueReadBuffer(test_buffer2, CL_TRUE, 0,
                16 * sizeof(cl_int), array2);
        LOGV("----test arr----");
        LOGV("element 0 : %d", array2[0]);
        LOGV("element 1 : %d", array2[1]);
        LOGV("element 2 : %d", array2[2]);
        LOGV("element 3 : %d", array2[3]);
        LOGV("element 4 : %d", array2[4]);
        LOGV("element 5 : %d", array2[5]);
        LOGV("element 6 : %d", array2[6]);
        LOGV("element 7 : %d", array2[7]);
        LOGV("element 8 : %d", array2[8]);
                LOGV("element 9 : %d", array2[9]);
                LOGV("element 10 : %d", array2[10]);
                LOGV("element 11: %d", array2[11]);
                LOGV("element 12: %d", array2[12]);
                LOGV("element 13: %d", array2[13]);
                LOGV("element 14: %d", array2[14]);
                LOGV("element 15: %d", array2[15]);
        LOGV("----test end----");

kerenel代码

 __kernel void Test_func1(
        __global float* datatin,
        __global int* dataout)
        {

        float16 inputdata;
        int16 iszero;
          float16 result;
        inputdata=vload16(0,datatin);


        iszero=isequal(inputdata,(float16)0);

       // result=convert_float16(iszero);
        vstore16(iszero,0,dataout);

    }

上述代码的结果

08-19 01:30:06.064: V/FBIA_JNI(17250): element 0 : 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 1 : -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 2 : 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 3 : -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 4 : -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 5 : -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 6 : -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 7 : 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 8 : 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 9 : 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 10 : 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 11: 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 12: -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 13: -1
08-19 01:30:06.064: V/FBIA_JNI(17250): element 14: 0
08-19 01:30:06.064: V/FBIA_JNI(17250): element 15: -1

0 个答案:

没有答案