@@ -2884,6 +2884,50 @@ between the host and device is known to be compatible.
28842884 );
28852885 #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
28862886
2887+ ``__cl_clang_function_scope_local_variables ``
2888+ ----------------------------------------------
2889+
2890+ This extension allows declaring variables in the local address space within
2891+ function scope, including non-kernel functions or nested scopes within a kernel,
2892+ using regular OpenCL extension pragma mechanism detailed in `the OpenCL
2893+ Extension Specification, section 1.2
2894+ <https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#extensions-overview> `_.
2895+
2896+ This relaxes the `Declaration Scopes and Variable Types
2897+ <https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#_usage_for_declaration_scopes_and_variable_types> `_
2898+ rule that limits local-address-space variable declarations to the outermost
2899+ compound statement inside the body of the kernel function.
2900+
2901+ To expose static local allocations at kernel scope, targets can either force-
2902+ inline non-kernel functions that declare local memory or pass a kernel-allocated
2903+ local buffer to those functions via an implicit argument.
2904+
2905+ .. code-block :: c++
2906+
2907+ #pragma OPENCL EXTENSION __cl_clang_function_scope_local_variables : enable
2908+ kernel void kernel1 (...)
2909+ {
2910+ {
2911+ local float a; // compiled - no diagnostic generated
2912+ }
2913+ }
2914+ void foo ()
2915+ {
2916+ local float c; // compiled - no diagnostic generated
2917+ }
2918+
2919+ #pragma OPENCL EXTENSION __cl_clang_function_scope_local_variables : disable
2920+ kernel void kernel2 (...)
2921+ {
2922+ {
2923+ local float a; // error - variables in the local address space can only be declared in the outermost scope of a kernel function
2924+ }
2925+ }
2926+ void bar ()
2927+ {
2928+ local float c; // error - non-kernel function variable cannot be declared in local address space
2929+ }
2930+
28872931Remove address space builtin function
28882932-------------------------------------
28892933
0 commit comments