OpenCL函数调用

OpenCL函数调用,opencl,Opencl,我正在开发一个openCL内核,它加载一些点,决定哪个点最高,然后返回它。所有这些都很好,但我想在最高评估之前添加一个计算。这将该点与一对线进行比较。我已将其撰写并工作到一定程度,如下所示: size_t i = group_id * group_stride + local_id; while (i < n){ //load up a pair of points using the index to locate them within a massiv

我正在开发一个
openCL
内核,它加载一些点,决定哪个点最高,然后返回它。所有这些都很好,但我想在最高评估之前添加一个计算。这将该点与一对线进行比较。我已将其撰写并工作到一定程度,如下所示:

    size_t i = group_id * group_stride + local_id;
    while (i < n){
        //load up a pair of points using the index to locate them within a massive dataSet
        int ia = LOAD_GLOBAL_I1(input, i);
        float4 a = LOAD_GLOBAL_F4(dataSet, ia);

        int ib = LOAD_GLOBAL_I1(input, i + group_size);
        float4 b = LOAD_GLOBAL_F4(dataSet, ib);

        //pre-assess the points relative to lines
        if(pass == 0){
            float px = a.x;
            float py = a.y;
            int checkAnswer;
        //want to write this section as a function
            float x1 = tri_input[0].x; float y1 = tri_input[0].y;
            float x2 = tri_input[2].x; float y2 = tri_input[2].y;
            float check = sign((x1-x2) * (py-y1) - (y2-y1) * (px-x1));
            if(check != tri_input[3].x){        //point is outside line 1
                checkAnswer = 1;
            }
            else{
                x1 = tri_input[2].x;  y1 = tri_input[2].y;
                x2 = tri_input[1].x;  y2 = tri_input[1].y;
                check = sign((x1-x2)*(py-y1) - (y2-y1)*(px-x1));
                if(check != tri_input[3].y){    //point is outside line 2
                    checkAnswer = 2;
                }
                else{
                    checkAnswer = 0;            //point is within both lines
        }}}

        //later use the checkAnswer result to change the following
        //find the highest of the pair
        float4 result;
        if(a.z>b.z) result = a;
        else result = b;

        //load up the previous highest result locally
        float4 s = LOAD_LOCAL_F4(shared, local_id);

        //if the previous highest beat this, stick, else twist
        if(s.z>result.z){ STORE_LOCAL_F4(shared, local_id, s);}
        else{ STORE_LOCAL_F4(shared, local_id, result);}
        i += local_stride;
    }
虽然正手版本运行良好并返回正常的“最高点”结果,但函数版本返回错误结果(未检测到我在数据集中隐藏的最高点)。它产生了一个错误的结果,即使该函数还没有整体效果

我做错了什么

[更新]: 此修改后的函数在注释掉的行中工作,然后挂起:

int pointCheck(float4 *P, float2 *testLines){

float2 *l0 = &testLines[0];
float2 *l1 = &testLines[1];
float2 *l2 = &testLines[2];
float2 *l3 = &testLines[3];

float x1 = l0->x; float y1 = l0->y;
float x2 = l2->x; float y2 = l2->y;

float pX = P->x; float pY = P->y;
float c1 = l3->x; float c2 = l3->y;

//float check = sign((x1-x2) * (pY-y1) - (y2-y1) * (pX-x1)); //seems to be a problem with sign
//    if(check != c1){            //point is outside line 1
//        return 1;
//    }
//    else{
//        x1 = l2->x; y1 = l2->y;
//        x2 = l1->x; y2 = l1->y;
//        check = sign((x1-x2) * (pY-y1) - (y2-y1) * (pX-x1));
//        if(check != c2){        //point is outside line 2
//            return 2;
//        }
//        else{
//            return 0;           //point is within both lines
//    }}
}

一个紧迫的问题是如何将参数传递给被调用函数:

int checkA = pointCheck( px,  py, tri_input);
而函数本身需要px和py的指针。您应该改为按以下方式调用函数:

int checkA = pointCheck(&px,  &py, tri_input);
令人惊讶的是,OpenCL没有给出这个内核的构建错误


根据我的经验,一些OpenCL运行时不喜欢在单个函数中使用多个返回语句。尝试将返回值保存到局部变量中,并在函数末尾使用一个return语句。这是因为OpenCL不支持真正的函数调用,而是将所有函数直接内联到内核中。因此,最佳做法是将所有非
\uuu内核
函数标记为
内联
,并将其视为内联函数(即,通过不使用多个返回语句,使编译器更容易内联函数)

叶,这就是诀窍。但愿我现在没有花几个小时把它弄错!我认为我之前得到的非结果是因为内核没有构建/运行。但是是的,没有返回构建错误,这也没有什么帮助!谢谢你的邀请hint@sam_mcelhinney,将
“-I.-Werror”
作为
选项
参数传递到
clBuildProgram
,然后应报告此错误,如果有更多错误,则可能报告其他错误。
int checkA = pointCheck( px,  py, tri_input);
int checkA = pointCheck(&px,  &py, tri_input);