Skip to content

Commit 2c5de3f

Browse files
committed
Clarify backend requirements
Clarify the backend requirements for copying to / from a module scope (global) variable.
1 parent 5461cda commit 2c5de3f

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

sycl/doc/DeviceGlobal.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,22 +557,49 @@ pi_result piextCopyFromDeviceVariable(pi_device Device, const char *name,
557557
In both cases the `name` parameter is the same as the `sycl-unique-id` string
558558
that is associated with the device global variable.
559559

560-
On the Level Zero backend, these PI interfaces are implemented by first calling
561-
[`zeModuleGetGlobalPointer()`][7] to get a device pointer for the variable and
562-
then calling [`zeCommandListAppendMemoryCopy()`][8] to copy to or from that
563-
pointer.
560+
The Level Zero backend has existing APIs that can implement these PI
561+
interfaces. DPC++ first calls [`zeModuleGetGlobalPointer()`][7] to get a
562+
device pointer for the variable and then calls
563+
[`zeCommandListAppendMemoryCopy()`][8] to copy to or from that pointer.
564+
However, the documentation (and implementation) of `zeModuleGetGlobalPointer()`
565+
needs to be extended slightly. The description currently says:
566+
567+
> * The application may query global pointer from any module that either
568+
> exports or imports it.
569+
>
570+
> * The application must dynamically link a module that imports a global before
571+
> the global pointer can be queried from it.
572+
573+
This must be changed to say something along these lines:
574+
575+
> * The interpretation of `pGlobalName` depends on how the module was created.
576+
> If the module was created from SPIR-V that declares the
577+
> **GlobalVariableDecorationsINTEL** capability, the implementation looks
578+
> first for an **OpVariable** that is decorated with **HostAccessINTEL**
579+
> where the *Name* operand is the same as `pGlobalName`. If no such variable
580+
> is found, the implementation then looks for an **OpVariable** that is
581+
> decorated with **LinkageAttributes** where the *Name* operand is the same
582+
> as `pGlobalName`. (The implementation considers both exported and imported
583+
> variables as candidates.)
584+
>
585+
> If the module was created from native code that came from a previous call
586+
> to `zeModuleGetNativeBinary` and that other module was created from SPIR-V,
587+
> then the interpretation of `pGlobalName` is the same as the SPIR-V case.
588+
>
589+
> * If `pGlobalName` identifies an imported SPIR-V variable, the module must be
590+
> dynamically linked before the variable's pointer may be queried.
564591
565592
[7]: <https://spec.oneapi.io/level-zero/latest/core/api.html#zemodulegetglobalpointer>
566593
[8]: <https://spec.oneapi.io/level-zero/latest/core/api.html#zecommandlistappendmemorycopy>
567594

568-
On the OpenCL backend, these PI interfaces are implemented by first calling
569-
`clGetDeviceGlobalVariablePointerINTEL()` to get a device pointer for the
570-
variable. This function is provided by the
571-
[`cl_intel_global_variable_pointers`][9] extension which is not yet
572-
productized. Once we get a pointer, the PI layer calls
573-
`clEnqueueMemcpyINTEL()` to copy to or from that pointer.
595+
The OpenCL backend has a proposed extension
596+
[`cl_intel_global_variable_pointers`][9] that can implement these PI
597+
interfaces. DPC++ first calls `clGetDeviceGlobalVariablePointerINTEL()` to get
598+
a device pointer for the variable and then calls `clEnqueueMemcpyINTEL()` to
599+
copy to or from that pointer. This DPC++ design depends upon implementation of
600+
that OpenCL extension.
574601

575602
[9]: <extensions/DeviceGlobal/cl_intel_global_variable_pointers.asciidoc>
576603

577-
On the CUDA backend, these PI interfaces are implemented on top of
578-
`cudaMemcpyToSymbol()` and `cudaMemcpyFromSymbol()`.
604+
The CUDA backend has existing APIs `cudaMemcpyToSymbol()` and
605+
`cudaMemcpyFromSymbol()` which can be used to implement these PI interfaces.

sycl/doc/extensions/DeviceGlobal/cl_intel_global_variable_pointers.asciidoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ is used to retrieve a pointer to a user-defined global variable
9999
_global_variable_name_ which exists in built _program_. The interpretation of
100100
_global_variable_name_ depends on how the _program_ was created:
101101

102-
* If the _program_ was created with *clCreateProgramWithSource* from OpenCL C
103-
sources, *TODO* (see Issues section below).
104-
105102
* If the _program_ was created with *clCreateProgramWithIL* from SPIR-V, there
106103
are two cases:
107104

0 commit comments

Comments
 (0)