cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

savage309
Adept I

OpenCL constant memory

Hi there,

I need to write code that runs both in OpenCL and CUDA.

I am having some trouble with the constant memory however.

In CUDA constant memory is file scope only (and transferred with the special API call cudaMemcpytoSymbol).

In OpenCL constant memory is function scope only (transferred as regular data).

Is there a way to declare constant memory in OpenCL in file scope, that could be set prior kerne launch (or if anybody knows how to do the opposite in CUDA) ?

Thanks.

0 Likes
1 Solution
dipak
Big Boss

Hi,

You can declare constant variables at program scope or file scope in OpenCL 1.2. As per this page  __constant :

Variables in the program scope or the outermost scope of kernel functions can be declared in the __constant address space. These variables are required to be initialized and the values used to initialize these variables must be a compile time constant. Writing to such a variable results in a compile-time error.

OpenCL 2.0, on the other hand, allows you to declare variables in the global address space at program scope. For details, you may check "Program-Scope Global Variables Overview" section of this blog http://developer.amd.com/community/blog/2014/12/11/opencl-2-0-generic-address-space-program-scope-va... .

You can aslo find few examples here __global .

Regards,

View solution in original post

2 Replies
dipak
Big Boss

Hi,

You can declare constant variables at program scope or file scope in OpenCL 1.2. As per this page  __constant :

Variables in the program scope or the outermost scope of kernel functions can be declared in the __constant address space. These variables are required to be initialized and the values used to initialize these variables must be a compile time constant. Writing to such a variable results in a compile-time error.

OpenCL 2.0, on the other hand, allows you to declare variables in the global address space at program scope. For details, you may check "Program-Scope Global Variables Overview" section of this blog http://developer.amd.com/community/blog/2014/12/11/opencl-2-0-generic-address-space-program-scope-va... .

You can aslo find few examples here __global .

Regards,

Thanks.

0 Likes