【问题标题】:opencl auxiliary function just works with int and not with float or float2opencl 辅助函数仅适用于 int 而不适用于 float 或 float2
【发布时间】:2012-12-06 00:49:30
【问题描述】:

我尝试编写一个辅助函数,但在构建程序时总是出现此错误。

:24:7: 错误:'AddVector' 的类型冲突 浮动 AddVector(浮动 a,浮动 b) ^ :19:12: 注意:之前的隐式声明在这里 float a = AddVector(b,c);

我的内核:

__kernel void square(
__global float* input,
__global float* output,
const unsigned int count)
{
//...
float b = 2.f;
float c = 4.f;
float a = AddVector(b,c);
}
float AddVector(float a, float b)
{
return a + b;
}

但是当我对整数类型执行相同操作时,它会起作用:

__kernel void square(
__global float* input,
__global float* output,
const unsigned int count)
{
//...
int b = 2;
int c = 4;
int a = AddVector(b,c);
}
int AddVector(int a, int b)
{
return a + b;
}

我做错了什么?

PS:这个内核什么也没做——它只是为了发现错误

【问题讨论】:

    标签: function kernel opencl


    【解决方案1】:

    您的问题是您在使用 AddVector 函数后声明它。将声明移到用法之上(即内核之上),它会编译得很好。

    要了解有关“隐式函数”位的更多信息 - 请参阅 here。

    另外,使用英特尔离线 OpenCL 编译器 - 我看到两个内核的警告相同。

        :9:9: warning: implicit declaration of function 'AddVector' is invalid in C99
    

    【讨论】:

      猜你喜欢
      • 2012-06-29
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多