Skip to content

Commit a0c4f63

Browse files
committed
Update SPV and OCL specs w.r.t. variable name
We decided that we need some alternate way for the host to reference a global variable in the kernel other than using the exported SPIR-V name. Extend the `HostAccessINTEL` decoration to take a new `Name` parameter. This allows the host to access even a non-exported `OpVariable`. Changes are still needed to the "DeviceGlobal.md" spec to explain how this new field will be set by the compiler. Those changes will be made in a separate commit.
1 parent eda8c3e commit a0c4f63

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

sycl/doc/extensions/DeviceGlobal/SPV_INTEL_global_variable_decorations.asciidoc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ This extension requires SPIR-V 1.0.
6161
== Overview
6262

6363
This extension adds decorations that can be applied to global (module scope)
64-
variables. These decorations are intended to help code generation for FPGA
65-
devices, but they must be recognized by any consumer that supports this
64+
variables. These decorations are mostly intended to help code generation for
65+
FPGA devices, but they must be recognized by any consumer that supports this
6666
extension.
6767

6868
== Extension Name
@@ -103,7 +103,7 @@ Modify Section 3.20, Decoration, adding these rows to the Decoration table:
103103
--
104104
[options="header"]
105105
|====
106-
2+^| Decoration | Extra Operands | Enabling Capabilities
106+
2+^| Decoration 2+^| Extra Operands | Enabling Capabilities
107107

108108
// --- ROW BREAK ---
109109
| 6147
@@ -113,8 +113,10 @@ Only valid on global (module scope) *OpVariable*.
113113

114114
The client API's execution environment may provide a way to access a global
115115
variable's value from the host system. If it does, this decoration provides
116-
an assertion by the producer about the types of these accesses. This may allow
117-
the consumer to perform certain optimizations, especially for FPGA devices.
116+
two pieces of information. _Access_ is an assertion by the producer about the
117+
types of these accesses, which may allow the consumer to perform certain
118+
optimizations, especially for FPGA devices. _Name_ is a name which the client
119+
API's execution environment may use to identify this variable.
118120

119121
Legal values of _Access_:
120122

@@ -135,6 +137,8 @@ If a global *OpVariable* is not decorated with *HostAccessINTEL*, the default
135137
behavior is [Read/Write].
136138
| Literal Number +
137139
_Access_
140+
| Literal String +
141+
_Name_
138142
| *GlobalVariableDecorationsINTEL*
139143

140144
// --- ROW BREAK ---
@@ -154,7 +158,7 @@ Legal values of _Trigger_:
154158
* 1 [init on device reset] - Initialization is performed when a reset signal is
155159
sent to the device.
156160

157-
| Literal Number +
161+
2+| Literal Number +
158162
_Trigger_
159163
| *GlobalVariableDecorationsINTEL*
160164

@@ -174,7 +178,7 @@ Legal values of _Value_:
174178
* 1 [True] - Access to this memory is through a CSR interface shared with the
175179
kernel arguments.
176180

177-
| Literal Number +
181+
2+| Literal Number +
178182
_Value_
179183
| *GlobalVariableDecorationsINTEL*
180184

sycl/doc/extensions/DeviceGlobal/cl_intel_global_variable_pointers.asciidoc

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,26 @@ cl_int clGetDeviceGlobalVariablePointerINTEL(
9696
void **global_variable_pointer_ret );
9797
----
9898
is used to retrieve a pointer to a user-defined global variable
99-
_global_variable_name_ which exists in built _program_.
99+
_global_variable_name_ which exists in built _program_. The interpretation of
100+
_global_variable_name_ depends on how the _program_ was created:
101+
102+
* If the _program_ was created with *clCreateProgramWithSource* from OpenCL C
103+
sources, *TODO* (see Issues section below).
104+
105+
* If the _program_ was created with *clCreateProgramWithIL* from SPIR-V, there
106+
are two cases:
107+
108+
- If the SPIR-V module declares the *GlobalVariableDecorationsINTEL*
109+
capability, the implementation looks first for an *OpVariable* that is
110+
decorated with *HostAccessINTEL* where the _Name_ operand is the same as
111+
_global_variable_name_.
112+
113+
- The implementation next looks for an *OpVariable* that is decorated with
114+
*LinkageAttributes* where the _Linkage Type_ is *Export* and the _Name_
115+
operand is the same as _global_variable_name_.
116+
117+
* If the _program_ was created in any other way, the interpretation of
118+
_global_variable_name_ is implementation-defined.
100119

101120
The returned pointer is a Unified Shared Memory pointer to the requested global
102121
variable and is specific to given _device_.
@@ -150,21 +169,12 @@ cl_intel_global_variable_pointers ...
150169

151170
== Issues
152171

153-
. Can this extension be used to query the address of any global variable in the program?
172+
. Exactly what is the interpretation of _global_variable_name_ for a _program_
173+
that was created from OpenCL C sources? Must the variable be declared
174+
"extern"? Are "constant" variables allowed?
154175
+
155176
--
156177
*UNRESOLVED*
157-
158-
It is not possible to obtain address of *any* arbitrary global variable using
159-
`clGetDeviceGlobalVariablePointerINTEL`, and the mechanism to identify that the
160-
global variable may have it's address taken is dependent on how program object
161-
is created:
162-
163-
* for programs created from source, *TODO* (extern?)
164-
165-
* for programs created from SPIR-V IL, *TODO* (global variable needs to have *export* linkage?)
166-
167-
* for programs created from a binary, the mechanism is implementation defined.
168178
--
169179

170180
. Can a queried global variable pointer be used by a kernel from another program object?
@@ -185,4 +195,5 @@ Currently this is disallowed.
185195
|Rev|Date|Author|Changes
186196
|0.9.0|2019-09-14|Jaroslaw Chodor|*Initial revision*
187197
|0.9.0|2021-09-22|Ben Ashbaugh|Added preview disclaimer, general cleanup.
198+
|0.9.0|2021-10-18|Greg Lueck|Clarify variable name for SPIR-V case.
188199
|========================================

0 commit comments

Comments
 (0)