【问题标题】:What is a constant address space qualifier in OpenCL?OpenCL 中的常量地址空间限定符是什么?
【发布时间】:2015-02-17 07:44:35
【问题描述】:

我正在尝试运行 XCode 文档中包含的噪声 OpenCL 示例项目。

我有一个我不明白的错误:

----------------------------------------------------------------------
Using active OpenGL context...
----------------------------------------------------------------------
Connecting to NVIDIA GeForce 320M...
----------------------------------------------------------------------
Loading kernel source from file 'noise_kernel.cl'...
----------------------------------------------------------------------
Building compute program...
[CL_DEVICE_NOT_AVAILABLE] : OpenCL Error : Error: Build Program driver returned (10007)
Break on OpenCLErrorBreak to debug.
OpenCL Warning : clBuildProgram failed: could not build program for 0x1022600 (GeForce 320M) (err:-2)
Break on OpenCLWarningBreak to debug.
[CL_BUILD_ERROR] : OpenCL Build Error : Compiler build log:
<program source>:58:21: error: global variables must have a constant address space qualifier
static const float4 ZERO_F4 = (float4)(0.0f, 0.0f, 0.0f, 0.0f);

最后一行有一个错误,涉及一个 const 变量。你如何解释这个?看起来编译器拒绝 ZERO_F4 因为它不是 const,但正如您所见,它实际上是。

【问题讨论】:

    标签: c opencl osx-yosemite


    【解决方案1】:

    编译器似乎拒绝 ZERO_F4,因为它不是 const,但正如你所看到的,它实际上是。

    编译器拒绝它,因为ZERO_F4 不在__constant 地址空间中(这与const 无关)。我相信这是 XCode 示例中的一个错误,因为 OpenCL C 规范明确指出:

    第 6.5 节地址空间限定符:

    所有程序范围变量都必须在__constant 地址空间中声明。

    因此替换这个:

    static const float4 ZERO_F4 = (float4){ 0.0f, 0.0f, 0.0f, 0.0f };
    static const float4 ONE_F4  = (float4){ 1.0f, 1.0f, 1.0f, 1.0f };
    

    有了这个:

    __constant float4 ZERO_F4 = (float4){ 0.0f, 0.0f, 0.0f, 0.0f };
    __constant float4 ONE_F4  = (float4){ 1.0f, 1.0f, 1.0f, 1.0f };
    

    它应该可以工作。

    【讨论】:

    • 编译器是否有一些改变破坏了以前的(据说可以工作?)代码?我目前正在修复另一个具有相同问题的代码示例(Grass..)
    • 我想这是一个错误,自编写示例以来可能已修复,是的。规范本身一直声明全局范围的变量必须是__constant
    猜你喜欢
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 2019-02-19
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多