'\" t .\" Title: __constant .\" Author: The Khronos Group .\" Generator: DocBook XSL Stylesheets v1.79.1 .\" Date: 02/03/2019 .\" Manual: OpenCL Manual .\" Source: The Khronos Group .\" Language: English .\" .TH "__CONSTANT" "3clc" "02/03/2019" "The Khronos Group" "OpenCL Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" __constant \- Address Space Qualifier\&. .SS "" .TS tab(:); l. T{ __constant constant T} .TE .sp 1 .SH "DESCRIPTION" .PP OpenCL implements the following disjoint address spaces: \fB__global\fR, \fB__local\fR, \fB__constant\fR, and \fB__private\fR 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 name; otherwise, the object is allocated in the generic address space\&. .PP The address space names without the __prefix i\&.e\&. \fBglobal\fR, \fBlocal\fR, \fBconstant\fR and \fBprivate\fR may be substituted for the corresponding address space names with the __prefix\&. .PP The generic address space name for arguments to a function in a program, or local variables of a function is \fB__private\fR\&. All function arguments shall be in the \fB__private\fR address space\&. .PP \fBfunctionQualifiers\fR(3clc) function arguments declared to be a pointer of a type can point to one of the following address spaces only: \fB__global\fR, \fB__local\fR or \fB__constant\fR\&. A pointer to address space A can only be assigned to a pointer to the same address space A\&. Casting a pointer to address space A to a pointer to address space B is illegal\&. .PP Function arguments of type \fB\fBotherDataTypes\fR(3clc)\fR, \fB\fBotherDataTypes\fR(3clc)\fR, \fB\fBotherDataTypes\fR(3clc)\fR, \fB\fBotherDataTypes\fR(3clc)\fR, \fB\fBotherDataTypes\fR(3clc)\fR, and \fB\fBotherDataTypes\fR(3clc)\fR refer to image memory objects allocated in the \fB__global\fR address space\&. .SH "NOTES" .PP The \fB__constant\fR or \fBconstant\fR address space name is used to describe variables allocated in global memory and which are accessed inside a kernel(s) as read\-only variables\&. These readonly variables can be accessed by all (global) work\-items of the kernel during its execution\&. Pointers to the \fB__constant\fR address space are allowed as arguments to functions (including kernel functions) and for variables declared inside functions\&. .PP All string literal storage shall be in the \fB__constant\fR address space\&. .PP NOTE: Each argument to a kernel that is a pointer to the \fB__constant\fR address space is counted separately towards the maximum number of such arguments, defined as \fBCL_DEVICE_MAX_CONSTANT_ARGS\fR are described in the table for \fBclGetDeviceInfo\fR(3clc)\&. .PP Variables in the program scope or the outermost scope of kernel functions can be declared in the \fB__constant\fR 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\&. .PP Implementations are not required to aggregate these declarations into the fewest number of constant arguments\&. This behavior is implementation defined\&. .PP Thus portable code must conservatively assume that each variable declared inside a function or in program scope allocated in the \fB__constant\fR address space counts as a separate constant argument\&. .SS "Example" .PP There is no generic address space name for program scope variables\&. All program scope variables must be declared in the \fB__constant\fR address space\&. For example: .TS tab(:); l. T{ // declares a pointer p in the __private address space that // points to an int object in address space __global __global int *p; // declares an array of 4 floats in the __private address space\&. float x[4]; T} .TE .sp 1 .PP There is no address space for function return values\&. Using an address space qualifier in a function return type declaration will generate a compilation error, unless the return type is declared as a pointer type and the qualifier is used on the points\-to address space\&. .PP For example: .TS tab(:); l. T{ __private int f() { \&.\&.\&. } // should generate an error __local int *f() { \&.\&.\&. } // allowed __local int * __private f() { \&.\&.\&. }; // should generate an error\&. T} .TE .sp 1 .SH "SPECIFICATION" .PP \m[blue]\fBOpenCL Specification\fR\m[]\&\s-2\u[1]\d\s+2 .SH "SEE ALSO" .PP \fBglobal\fR(3clc), \fBlocal\fR(3clc), \fBprivate\fR(3clc) .SH "AUTHORS" .PP \fBThe Khronos Group\fR .SH "COPYRIGHT" .br Copyright \(co 2007-2011 The Khronos Group Inc. .br Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials. .sp .SH "NOTES" .IP " 1." 4 OpenCL Specification .RS 4 \%page 222, section 6.5 - Address Space Qualifiers .RE