OpenCL程序没有';当从内核调用函数时,不能构建

OpenCL程序没有';当从内核调用函数时,不能构建,opencl,opencl-c,Opencl,Opencl C,这个问题源于问题 我有一个调用常规函数的内核。当我构建并运行代码时,我得到以下输出: Number of devices: 2 building program failed -----COULD NOT CREATE KERNEL!!--- 我的.cl文件中有问题的部分如下所示: #define IDCT_INT_MIN (- IDCT_INT_MAX - 1) #define IDCT_INT_MAX 2147483647 .... ..

这个问题源于问题

我有一个调用常规函数的内核。当我构建并运行代码时,我得到以下输出:

Number of devices: 2
building program failed
-----COULD NOT CREATE KERNEL!!---
我的
.cl
文件中有问题的部分如下所示:

    #define  IDCT_INT_MIN   (- IDCT_INT_MAX - 1)
    #define  IDCT_INT_MAX   2147483647
      ....
      ....
      ....
      ....
      ....
      ....

    #define SCALE(x,n)      ((x) << (n))

    #define but(a,b,x,y)    { x = SUB(a,b); y = ADD(a,b); }

    static  int DESCALE (int x, int n)
    {
        return (x + (1 << (n - 1)) - (x < 0)) >> n;
    }

    static  int ADD(int x, int y)
    {
        int r = x + y;

        return r;       
    }

    static  int SUB(int x, int y)
    {
        int r = x - y;

        return r;        
    }

    static  int CMUL(int c, int x)
    {
        int r = c * x;
        r = (r + (1 << (C_BITS - 1))) >> C_BITS;
        return r;
    }

    static  void rot(int f, int k, int x, int y, int *rx, int *ry) {
        int COS[2][8] = {
            {c0_1, c1_1, c2_1, c3_1, c4_1, c5_1, c6_1, c7_1},
            {c0_s2, c1_s2, c2_s2, c3_s2, c4_s2, c5_s2, c6_s2, c7_s2}
        };

        *rx = SUB(CMUL(COS[f][k], x), CMUL(COS[f][8 - k], y));
        *ry = ADD(CMUL(COS[f][8 - k], x), CMUL(COS[f][k], y));
    }

void idct_1D(__private int *Y);

__kernel void IDCT(__global int *input, __global uchar *output) 
{
    int Y[64];
    int k, l;
    int Yc[8];

    for (k = 0; k < 8; k++)
    {
        for (l = 0; l < 8; l++) Y(k, l) = SCALE(input[(k << 3) + l], S_BITS);
        idct_1d(&Y(k, 0));
    }

    for (l = 0; l < 8; l++)
    {

        for (k = 0; k < 8; k++)
    {
            Yc[k] = Y(k, l);
    }

        idct_1d(Yc);

        for (k = 0; k < 8; k++)
        {
            int r = 128 + DESCALE(Yc[k], S_BITS + 3);
            r = r > 0 ? (r < 255 ? r : 255) : 0;
            X(k, l) = r;
        }

    }
}

void idct_1D(__private int *Y) 
{

int z1[8], z2[8], z3[8];


    but(Y[0], Y[4], z1[1], z1[0]);
    rot(1, 6, Y[2], Y[6], &z1[2], &z1[3]);
    but(Y[1], Y[7], z1[4], z1[7]);
    z1[5] = CMUL(sqrt2, Y[3]);
    z1[6] = CMUL(sqrt2, Y[5]);

    but(z1[0], z1[3], z2[3], z2[0]);
    but(z1[1], z1[2], z2[2], z2[1]);
    but(z1[4], z1[6], z2[6], z2[4]);
    but(z1[7], z1[5], z2[5], z2[7]);

    z3[0] = z2[0];
    z3[1] = z2[1];
    z3[2] = z2[2];
    z3[3] = z2[3];
    rot(0, 3, z2[4], z2[7], &z3[4], &z3[7]);
    rot(0, 1, z2[5], z2[6], &z3[5], &z3[6]);

    but(z3[0], z3[7], Y[7], Y[0]);
    but(z3[1], z3[6], Y[6], Y[1]);
    but(z3[2], z3[5], Y[5], Y[2]);
    but(z3[3], z3[4], Y[4], Y[3]);
}   
Number of devices: 2
building program failed
<kernel>:98:70: error: invalid address space for pointee of pointer argument to __kernel function
__kernel void IDCT(__global int *input, __global uchar *output, int *Yc, int *Yin) 
                                                                     ^
<kernel>:98:79: error: invalid address space for pointee of pointer argument to __kernel function
__kernel void IDCT(__global int *input, __global uchar *output, int *Yc, int *Yin) 
                                                                              ^
<kernel>:105:30: error: called object type '__attribute__((address_space(16776963))) int *' is not a function or function pointer
                for (l = 0; l < 8; l++) Yin(k, l) = SCALE(input[(k << 3) + l], S_BITS);
                                        ~~~^
<kernel>:106:3: warning: implicit declaration of function 'idct_1d' is invalid in C99
                idct_1d(&Yin(k, 0));
                ^
<kernel>:106:15: error: called object type '__attribute__((address_space(16776963))) int *' is not a function or function pointer
                idct_1d(&Yin(k, 0));
                         ~~~^
<kernel>:114:15: error: called object type '__attribute__((address_space(16776963))) int *' is not a function or function pointer
                        Yc[k] = Yin(k, l);
                                ~~~^

-----COULD NOT CREATE KERNEL!!---
void idct_1D(int *Y);


__kernel void IDCT(__global int *input, __global uchar *output);
构建并运行代码后,我得到以下响应:

Number of devices: 2
building program failed
ptxas application ptx input, line 71; error   : Call has wrong number of parameters
ptxas application ptx input, line 112; error   : Call has wrong number of parameters
ptxas application ptx input, line 153; error   : Call has wrong number of parameters
ptxas application ptx input, line 194; error   : Call has wrong number of parameters
ptxas application ptx input, line 235; error   : Call has wrong number of parameters
ptxas application ptx input, line 276; error   : Call has wrong number of parameters
ptxas application ptx input, line 317; error   : Call has wrong number of parameters
ptxas application ptx input, line 358; error   : Call has wrong number of parameters
ptxas application ptx input, line 392; error   : Call has wrong number of parameters
ptxas application ptx input, line 520; error   : Call has wrong number of parameters
ptxas application ptx input, line 648; error   : Call has wrong number of parameters
ptxas application ptx input, line 776; error   : Call has wrong number of parameters
ptxas application ptx input, line 904; error   : Call has wrong number of parameters
ptxas application ptx input, line 1032; error   : Call has wrong number of parameters
ptxas application ptx input, line 1160; error   : Call has wrong number of parameters
ptxas application ptx input, line 1288; error   : Call has wrong number of parameters
ptxas fatal   : Ptx assembly aborted due to errors

-----COULD NOT CREATE KERNEL!!---
我检查了这个,并从我的
.cl
文件中删除了所有注释和printf语句。尽管如此,在构建和运行代码之后,我仍然会遇到同样的错误

编辑:

代码反映了我在遵循pmdj的建议后试图在代码中实现的更改。现在我只得到语法错误

我现在得到的结果如下:

    #define  IDCT_INT_MIN   (- IDCT_INT_MAX - 1)
    #define  IDCT_INT_MAX   2147483647
      ....
      ....
      ....
      ....
      ....
      ....

    #define SCALE(x,n)      ((x) << (n))

    #define but(a,b,x,y)    { x = SUB(a,b); y = ADD(a,b); }

    static  int DESCALE (int x, int n)
    {
        return (x + (1 << (n - 1)) - (x < 0)) >> n;
    }

    static  int ADD(int x, int y)
    {
        int r = x + y;

        return r;       
    }

    static  int SUB(int x, int y)
    {
        int r = x - y;

        return r;        
    }

    static  int CMUL(int c, int x)
    {
        int r = c * x;
        r = (r + (1 << (C_BITS - 1))) >> C_BITS;
        return r;
    }

    static  void rot(int f, int k, int x, int y, int *rx, int *ry) {
        int COS[2][8] = {
            {c0_1, c1_1, c2_1, c3_1, c4_1, c5_1, c6_1, c7_1},
            {c0_s2, c1_s2, c2_s2, c3_s2, c4_s2, c5_s2, c6_s2, c7_s2}
        };

        *rx = SUB(CMUL(COS[f][k], x), CMUL(COS[f][8 - k], y));
        *ry = ADD(CMUL(COS[f][8 - k], x), CMUL(COS[f][k], y));
    }

void idct_1D(__private int *Y);

__kernel void IDCT(__global int *input, __global uchar *output) 
{
    int Y[64];
    int k, l;
    int Yc[8];

    for (k = 0; k < 8; k++)
    {
        for (l = 0; l < 8; l++) Y(k, l) = SCALE(input[(k << 3) + l], S_BITS);
        idct_1d(&Y(k, 0));
    }

    for (l = 0; l < 8; l++)
    {

        for (k = 0; k < 8; k++)
    {
            Yc[k] = Y(k, l);
    }

        idct_1d(Yc);

        for (k = 0; k < 8; k++)
        {
            int r = 128 + DESCALE(Yc[k], S_BITS + 3);
            r = r > 0 ? (r < 255 ? r : 255) : 0;
            X(k, l) = r;
        }

    }
}

void idct_1D(__private int *Y) 
{

int z1[8], z2[8], z3[8];


    but(Y[0], Y[4], z1[1], z1[0]);
    rot(1, 6, Y[2], Y[6], &z1[2], &z1[3]);
    but(Y[1], Y[7], z1[4], z1[7]);
    z1[5] = CMUL(sqrt2, Y[3]);
    z1[6] = CMUL(sqrt2, Y[5]);

    but(z1[0], z1[3], z2[3], z2[0]);
    but(z1[1], z1[2], z2[2], z2[1]);
    but(z1[4], z1[6], z2[6], z2[4]);
    but(z1[7], z1[5], z2[5], z2[7]);

    z3[0] = z2[0];
    z3[1] = z2[1];
    z3[2] = z2[2];
    z3[3] = z2[3];
    rot(0, 3, z2[4], z2[7], &z3[4], &z3[7]);
    rot(0, 1, z2[5], z2[6], &z3[5], &z3[6]);

    but(z3[0], z3[7], Y[7], Y[0]);
    but(z3[1], z3[6], Y[6], Y[1]);
    but(z3[2], z3[5], Y[5], Y[2]);
    but(z3[3], z3[4], Y[4], Y[3]);
}   
Number of devices: 2
building program failed
<kernel>:98:70: error: invalid address space for pointee of pointer argument to __kernel function
__kernel void IDCT(__global int *input, __global uchar *output, int *Yc, int *Yin) 
                                                                     ^
<kernel>:98:79: error: invalid address space for pointee of pointer argument to __kernel function
__kernel void IDCT(__global int *input, __global uchar *output, int *Yc, int *Yin) 
                                                                              ^
<kernel>:105:30: error: called object type '__attribute__((address_space(16776963))) int *' is not a function or function pointer
                for (l = 0; l < 8; l++) Yin(k, l) = SCALE(input[(k << 3) + l], S_BITS);
                                        ~~~^
<kernel>:106:3: warning: implicit declaration of function 'idct_1d' is invalid in C99
                idct_1d(&Yin(k, 0));
                ^
<kernel>:106:15: error: called object type '__attribute__((address_space(16776963))) int *' is not a function or function pointer
                idct_1d(&Yin(k, 0));
                         ~~~^
<kernel>:114:15: error: called object type '__attribute__((address_space(16776963))) int *' is not a function or function pointer
                        Yc[k] = Yin(k, l);
                                ~~~^

-----COULD NOT CREATE KERNEL!!---
void idct_1D(int *Y);


__kernel void IDCT(__global int *input, __global uchar *output);

clBuildProgram()
失败后,您可以使用
clGetProgramBuildInfo()
函数查看详细的编译器输出。大概是这样的:

size_t len;
char buffer[2048];
clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);


顺便说一句,问题很可能是
idct\u 1D
函数获取一个指向
\u全局
内存(默认值)的指针,并且您试图在
\u私有
内存中向其传递一个数组在OpenCL中,始终使用正确的内存空间标记指针。

clBuildProgram()
失败后,您可以使用
clGetProgramBuildInfo()
函数查看详细的编译器输出。大概是这样的:

size_t len;
char buffer[2048];
clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);


顺便说一句,问题很可能是
idct\u 1D
函数获取一个指向
\u全局
内存(默认值)的指针,并且您试图在
\u私有
内存中向其传递一个数组在OpenCL中,始终用正确的内存空间标记指针。

完全无法理解。@WeatherVane我的问题有什么不清楚的地方?我如何改进它?通过问一个具体的问题。没有抛出一堵不完整代码的墙。@WeatherVane我已经删除了我的主机代码,以便将重点放在有问题的内核代码上。Is
int Y[64]。。。Y(k,l)=…
有效的C代码?也许应该去掉C标签?完全不可理解。@WeatherVane我的问题有什么不清楚的?我如何改进它?通过问一个具体的问题。没有抛出一堵不完整代码的墙。@WeatherVane我已经删除了我的主机代码,以便将重点放在有问题的内核代码上。Is
int Y[64]。。。Y(k,l)=…
有效的C代码?也许应该删除C标记?在使用命令
clGetProgramBuildInfo()
并运行我的代码后,我遇到了类型为
ptxas致命的错误:Ptx程序集由于错误而中止。您对解决这些错误有何建议?我从我的.cl文件中删除了注释,但我一直得到相同的输出。一次构建一行内核。然后你知道哪一行引入了问题,你对发生的事情有了更好的了解。如果你被困在某一行,无法找出问题所在,请发布简化代码,我们将尽力帮助你。还要注意的是,你发布的代码不足以帮助你-缩放和除垢功能不可用。我不认为你可以有一个函数(你还没有发布)和一个变量,在C或OpenCL中都命名为Y,并且期望一个不会像其他人所指出的那样影响另一个。您确定您不是在尝试翻译C++代码或其他语言吗?(重命名函数或变量!)一次构建一行内核。你这句话是什么意思?我的内核代码只有一个内核,并且使用命令
clBuildProgram()
不是构建内核代码的唯一方法吗?在使用命令
clgetprogrammbuildinfo()
并运行我的代码之后,我遇到了类错误
ptxas致命:Ptx程序集由于错误而中止。您对解决这些错误有什么建议吗?我从我的.cl文件中删除了注释,但我一直得到相同的输出。一次构建一行内核。然后你知道哪一行引入了问题,你对发生的事情有了更好的了解。如果你被困在某一行,无法找出问题所在,请发布简化代码,我们将尽力帮助你。还要注意的是,你发布的代码不足以帮助你-缩放和除垢功能不可用。我不认为你可以有一个函数(你还没有发布)和一个变量,在C或OpenCL中都命名为Y,并且期望一个不会像其他人所指出的那样影响另一个。您确定您不是在尝试翻译C++代码或其他语言吗?(重命名函数或变量!)一次构建一行内核。你这句话是什么意思?我的内核代码只有一个内核,使用命令
clBuildProgram()
不是构建内核代码的唯一方法吗?