Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a constant address space qualifier in OpenCL?

I'm trying to run the noise OpenCL sample project included in the XCode documentation.

I have one error that I don't understand:

----------------------------------------------------------------------
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);

There is an error on this last line, which involves a const variable. How do you interpret this ? It looks like the compiler is rejecting ZERO_F4 because it's not const, but as you can see, it actually is.

like image 369
alecail Avatar asked Dec 18 '14 13:12

alecail


1 Answers

It looks like the compiler is rejecting ZERO_F4 because it's not const, but as you can see, it actually is.

The compiler is rejecting it because ZERO_F4 is not in __constant address space (this has nothing to do with const). I believe it's a bug in the XCode samples, because the OpenCL C spec clearly says:

Section 6.5 Address space qualifiers:

All program scope variables must be declared in the __constant address space.

Therefore replace this:

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 };

With this:

__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 };

And it should work.

like image 54
user703016 Avatar answered Sep 24 '22 07:09

user703016