OpenCL implements the following disjoint named address spaces: __global, __local, __constant and __private. The address space qualifier may be used in variable declarations to specify the region of memory that is used to allocate the object. The C syntax for type qualifiers is extended in OpenCL to include an address space name as a valid type qualifier. If the type of an object is qualified by an address space name, the object is allocated in the specified address space name.

The address space names without the __ prefix, i.e. global, local, constant and private, may be substituted for the corresponding address space names with the __ prefix.

The address space name for arguments to a function in a program, or local variables of a function is __private. All function arguments shall be in the __private address space. The address space for a variable at program scope, a static or extern variable inside a function can either be __global or __constant, but defaults to __global if not specified. The address space for all other variables defaults to __private if not specified.


// declares a pointer p in the global address space that
// points to an object in the global address space
global int *p;

void foo (...)
    // declares an array of 4 floats in the private address space
    float x[4];

OpenCL 2.0 adds support for an unnamed generic address space. Pointers that are declared without pointing to a named address space point to the generic address space. Pointer function arguments and return values which do not declare an address space are defined to point to the generic address space.

Kernel function arguments declared to be a pointer or an array of a type must point to one of the named address spaces __global, __local or __constant.

The named address spaces are a subset of the generic address space except for the constant address space.

A pointer to address space A can only be assigned to a pointer to the same address space A or a pointer to the generic address space. Casting a pointer to address space A to a pointer to address space B is illegal if A and B are named address spaces and A is not the same as B.


private int f() { ... }          // should generate an error

local int *f() { ... }           // allowed

local int * private f() { ... }; // should generate an error.

The __global, __constant, __local, __private, global, constant, local, and private names are reserved for use as address space qualifiers and shall not be used otherwise. The __generic and generic names are reserved for future use.

The size of pointers to different address spaces may differ. It is not correct to assume that, for example, sizeof(__global int *) always equals sizeof(__local int *).

See Also

Document Notes

For more information, see the OpenCL C Specification

This page is extracted from the OpenCL C Specification. Fixes and changes should be made to the Specification, not directly.

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.