__GLOBAL(3clc)

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

πŸ’– NAME πŸ’–

__global β€” the address space qualifier, bestie. Also answers to __global global.


✨ DESCRIPTION ✨

okay so first things first: OpenCL is out here implementing disjoint address spaces, and there are exactly four of them:

  • __global
  • __local
  • __constant
  • __private

The address space qualifier is what you slap into a variable declaration when you wanna say exactly which region of memory that object gets allocated in. OpenCL took the C syntax for type qualifiers and extended it so an address space name counts as a valid type qualifier. So if your object's type is qualified by an address space name, it gets allocated in that address space. If you don't qualify it? It goes in the generic address space. no cap.

Also cute detail: the address space names without the __ prefix β€” like global, local, constant, private β€” can be substituted for the corresponding names with the __ prefix. same energy, less underscore.

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 non-negotiable: all function arguments shall be in the __private address space.

Now, functionQualifiers(3clc) β€” function arguments declared to be a pointer of a type can only point to one of these address spaces: __global, __local, or __constant. And a pointer to address space A can only be assigned to a pointer to the same address space A. Trying to cast a pointer to address space A into a pointer to address space B? 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. six of them, all otherDataTypes(3clc), don't ask, that's just how the page wrote it πŸ’…


🌸 NOTES 🌸

The __global (or global) address space name is how you refer to memory objects β€” buffer objects or image objects β€” that got allocated from the global memory pool. it's giving main character storage ✨

A buffer memory object can be declared as a pointer to a scalar, a vector, or a user-defined struct. Which means your kernel can read and/or write any location in that buffer. go off.

The actual size of the array memory object? That gets determined when the memory object is allocated via the appropriate API calls in the host code. not your kernel's business, fr fr.

If an image object is attached to an argument declared with this qualifier, the argument must be declared as:

And heads up: the elements of an image object cannot be directly accessed. Built-in functions to read from and write to an image object are provided instead. use those, bestie.

The const qualifier can also be used alongside the __global qualifier to specify a read-only buffer memory object. cute and locked πŸ”’

πŸŽ€ Examples πŸŽ€

There is no generic address space name for program scope variables. All program scope variables must be declared in the __constant address space. like, all of them. 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. tricky little loophole, iykyk.

For example:

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

And the struct moment:

__global float4  *color;      // An array of float4 elements
typedef struct {
  float a[3];
  int   b[2];
} foo_t;
__global foo_t   *my_info;    // An array of foo_t elements.

obsessed with my_info actually. iconic name. πŸ‘‘


⭐ SPECIFICATION ⭐

OpenCL Specification[1]


πŸ¦‹ SEE ALSO πŸ¦‹

local(3clc), constant(3clc), private(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 following condition: the above copyright notice and this 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 was brought to you by The Khronos Group, dated 01/14/2021, from the __GLOBAL(3clc) era of the OpenCL Manual. slay, stay in your address space, and never cast between them. periodt. πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from