__PRIVATE(3clc)

πŸ“¦
version 1.0~svn33624 Β· 3 versions
, in ubuntu jammy, ubuntu noble

✨ NAME ✨

__private β€” the Address Space Qualifier πŸ’…

also answers to: __private, private


🌸 DESCRIPTION 🌸

okay so bestie, OpenCL is out here running four disjoint address spaces and you gotta know them: __global, __local, __constant, and __private. the address space qualifier is the little tag you slap on a variable declaration to say which region of memory the object gets allocated in. the C syntax for type qualifiers got extended in OpenCL so an address space name counts as a valid type qualifier. so if the type of an object is qualified by an address space name, the object is allocated in the specified address name β€” and if it's not qualified, the object is allocated in the generic address space. periodt.

the address space names without the __ prefix β€” so global, local, constant and private β€” may be substituted for the corresponding address space names with the __ prefix. iykyk, same vibe, fewer underscores.

the generic address space name for arguments to a function in a program, or for local variables of a function, is __private. and this is the part where you sit up straight: all function arguments shall be in the __private address space. no exceptions, bestie.

functionQualifiers(3clc) β€” function arguments declared to be a pointer of a type can point to one of these address spaces only: __global, __local or __constant. and the rules on assignment are strict-strict:

  • 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 🚫

function arguments of type otherDataTypes(3clc), otherDataTypes(3clc), otherDataTypes(3clc), otherDataTypes(3clc), otherDataTypes(3clc), and otherDataTypes(3clc) refer to image memory objects allocated in the __global address space. (yes that's six of them, all listed, we don't skip entries in this house 🫢)


πŸ’€ NOTES πŸ’€

the tea on defaults, because this trips people up:

  • variables inside a __kernel function that are not declared with an address space qualifier, all variables inside non-kernel functions, and all function arguments are in the __private or private address space.
  • variables declared as pointers are considered to point to the __private address space if an address space qualifier is not specified.

and the big one β€” these names are reserved:

__global, __constant, __local, __private, global, constant, local, and private are reserved for use as address space qualifiers and shall not be used otherwise. do not try it. it's not giving what you think it's giving. 😭

πŸ¦‹ Example πŸ¦‹

there is no generic address space name for program scope variables, bestie. all program scope variables must be declared in the __constant address space. for example:

// 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];

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.

for example:

__private int f() { ... } // should
generate an error __local int *f() {
... } // allowed __local int *
__private f() { ... }; // should
generate an error.

// 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];

🌈 SPECIFICATION 🌈

OpenCL Specification[1]


πŸŽ€ SEE ALSO πŸŽ€

global(3clc), local(3clc), constant(3clc)


πŸ‘‘ AUTHORS πŸ‘‘

The Khronos Group


Copyright Β© 2007-2011 The Khronos Group Inc.

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.


πŸ“ NOTES πŸ“

  1. OpenCL Specification page 222, section 6.5 - Address Space Qualifiers

and that's the whole page, bestie ✨ this one's from the 3clc manual, brought to you by The Khronos Group, dated 01/14/2021, filed under __PRIVATE(3clc). go declare your variables in the right address space, you absolute icon πŸ’…πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from