Skip to content

Commit 8ed0146

Browse files
committed
New changes.
Signed-off-by: Garima Gupta <[email protected]>
1 parent b0b8895 commit 8ed0146

File tree

1 file changed

+72
-50
lines changed

1 file changed

+72
-50
lines changed

sycl/doc/PluginInterface.md

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# The DPC++ Runtime Plugin Interface.
22

33
## Overview
4-
The DPC++ Runtime Plugin Interface (PI) is the interface layer between
5-
device-agnostic part of the DPC++ runtime and the device-specific runtime layers
4+
The DPC++ Runtime Plugin Interface (PI) is an interface layer between the
5+
device-agnostic part of DPC++ runtime and the device-specific runtime layers
66
which control execution on devices. It employs the “plugin” mechanism to bind
7-
to the device specific runtime layers similarly to what is used by libomptarget
7+
to the device specific runtime layers similar to what is used by libomptarget
88
or OpenCL.
99

10-
The picture below illustrates the placement of the PI within the overall DPC++
10+
The picture below illustrates the placement of PI within the overall DPC++
1111
runtime stack. Dotted lines show components or paths which are not yet available
1212
in the runtime, but are likely to be developed.
1313
![PI in DPC++ runtime architecture](images/RuntimeArchitecture.svg)
@@ -21,29 +21,30 @@ points implementing the PI interface. The DPC++ runtime collects those function
2121
pointers into a PI interface dispatch table - one per plugin - and uses this
2222
table to dispatch to the device(s) covered by the corresponding plugin.
2323

24-
PI is based on a subset of OpenCL 1.2 runtime specification, it follows its
25-
platform, execution and memory models in all aspects except those explicitly
26-
mentioned in this document. A part of PI API types and functions have exact
24+
PI is based on a subset of OpenCL 1.2 runtime specification, it follows OpenCL's
25+
platform, execution and memory models in all aspects except for those explicitly
26+
mentioned in this document. Some of PI API types and functions have exact
2727
matches in OpenCL. Whenever there is such a match, the semantics also fully
28-
matches unless the differences are explicitly specified in this document. While
28+
match unless the differences are explicitly specified in this document. While
2929
PI has roots in OpenCL, it does have many differences, and the gap is likely
30-
to grow, for example in the areas of memory model and management, program
30+
to grow, for example in areas of memory model and management, program
3131
management.
3232

3333
## Discovery and linkage of PI implementations
3434

3535
![PI implementation discovery](images/PluginDiscovery.svg)
3636

3737
Device discovery phase enumerates all available devices and their features by
38-
querying underlying plugins found in the system. This process is only performed
39-
once before any actual offload is attempted.
38+
querying underlying plugins found in the system. This process is performed when
39+
all attached platforms or devices are queried in an application; for example,
40+
during device selection.
4041

4142
### Plugin discovery
4243

4344
Plugins are physically dynamic libraries or shared objects.
44-
The process to discover plugins will follow the following guidelines.
45+
The process to discover plugins follows the following guidelines.
4546

46-
The SYCL Runtime will read the names of the plugins from a configuration file
47+
The DPC++ Runtime reads the names of the plugins from a configuration file
4748
at a predetermined location (TBD - Add this location). These plugins are
4849
searched at locations in env LD_LIBRARY_PATH on Linux and env PATH on Windows.
4950
(TBD - Extend to search the plugins at a path relative to the SYCL Runtime
@@ -53,44 +54,52 @@ of LD_LIBRARY_PATH.)
5354
To avoid any issues with read-only access, an environment variable SYCL_PI_CONFIG
5455
can be set to point to the configuration file which lists the Plugin names. The
5556
enviroment variable if set overrides the predetermined location's config file.
56-
These Plugins will then be searched in LD_LIBRARY_PATH locations.
57+
These Plugins are then be searched in LD_LIBRARY_PATH locations.
5758
It is the developer's responsibility to include the plugin names from the
5859
predetermined location's config file to enable discovery of all plugins.
5960
(TBD - Extend to support search in DT_RPATH as above.)
60-
A trace mechanism is provided to log the discovery/ binding/ device
61-
enumeration process. Eg: Display all the plugins being discovered, their
62-
information and supported PI version. List attached devices and their properties.
63-
64-
TBD - design and describe the process in detail.
61+
In the current implementation the plugin names are hardcoded in the library.
62+
Configuration file or env SYCL_PI_CONFIG is currently not being considered.
63+
64+
A trace mechanism is provided using env SYCL_PI_TRACE to log the discovery/
65+
binding/ device enumeration process. Different levels of tracing can be achieved
66+
with different values of SYCL_PI_TRACE.
67+
SYCL_PI_TRACE=0x01 provides basic trace of plugins discovered and bound. It also
68+
lists the device selector's selected device information.
69+
SYCL_PI_TRACE=0x02 provides trace of all PI calls made from the DPC++ runtime
70+
with arguments and returned values.
71+
SYCL_PI_TRACE=-1 lists all PI Traces above and more debug messages.
6572

6673
#### Plugin binary interface
6774
Plugins should implement all the Interface APIs required for the PI Version
68-
it supports. It will export a function that will return the function pointer
69-
table that contains the list of implemented Interface Function pointers in a
70-
predetermined order defined in pi.h.
75+
it supports. There is [pi.def](../include/CL/sycl/detail/pi.def)/
76+
[pi.h](../include/CL/sycl/detail/pi.h) file listing all PI API names that can be
77+
called by the specific version of Plugin Interface.
78+
It exports a function - "piPluginInit" that returns the plugin details and function pointer
79+
table containing the list of pointers to implemented Interface Functions defined in pi.h.
7180
In the future, this document will list the minimum set of Interface APIs
7281
to be supported by Plugins. This will also require adding functionality to SYCL
7382
Runtime to work with such limited functionality plugins.
7483

75-
TBD - list and describe the symbols that a plugin must implement in order to
76-
be picked up by the SYCL runtime for offload.
84+
(TBD - list and describe the symbols that a plugin must implement in order to
85+
be picked up by the DPC++ runtime for offload.)
7786

7887
#### Binding a Plugin
79-
Plugins expose the information of supported PI API version.
80-
The Plugin Interface queries the plugins on the supported PI version and checks
81-
for compatibility.(TBD - Extend to support version compatibility checks without
82-
loading the library. Eg: Changing the plugin name to reflect the supported
83-
Plugin Interface version.)
84-
The Plugin Loader then queries each plugin for the Function Pointer Table
85-
and populates a list of the PI API Function Pointers for each plugin.
86-
The user can select/disable a specific plugin with an environment variable,
87-
SYCL_PI_USE. (TBD - Describe the semantics in a separate section for EV and
88-
trace.)
88+
The DPC++ Runtime loads all discovered Plugins and tries to bind them by calling
89+
piPluginInit API for each loaded Plugin. The Plugins return the information of
90+
supported PI version and the list of implemented PI API Function pointers.
91+
(TBD - Use the PI API Version information and check for compatibility.
92+
Extend to support version compatibility checks without loading the library.
93+
Eg:Changing the plugin name to reflect the supported Plugin Interface version.)
8994
The information of compatible plugins (with the Function Pointer Table) is
9095
stored in the associated platforms during platform object construction.
91-
The PI API calls are forwarded using this information.
92-
There is pi.def/pi.h file that lists all PI API names that can be called by the
93-
Plugin Interface.
96+
The PI API calls are later forwarded using this information.
97+
A plugin is said to "bind" after this process completes with no errors.
98+
During device selection, the user can prefer selection of a device from a
99+
specific Plugin or Backend using the env SYCL_BE. The correspondence between
100+
a plugin and a SYCL_BE value is currently hardcoded in the runtime.
101+
( TBD: Make this a part of configuration file).
102+
Eg: SYCL_BE=PI_OPENCL corresponds to OpenCL Plugin.
94103

95104
#### OpenCL plugin
96105

@@ -100,18 +109,16 @@ OpenCL implementations. They can be installed either in the standard Khronos
100109
ICD-compatible way (e.g. listed in files under /etc/OpenCL/vendors on
101110
Linux) or not, and the OpenCL plugin can hook up with both.
102111

103-
TBD - describe the nested OpenCL implementation discovery process performed by
112+
TBD - implement and describe the nested OpenCL implementation discovery process performed by
104113
the OpenCL plugin
105114

106115
### Device enumeration by plugins
107-
After the compatible plugins are loaded, the trace will show all available
108-
devices from each plugin. Similarly, the trace can be extended to show the
109-
underlying API calls that each PI plugin call is being directed to.
110-
111-
TBD - Describe the exact API calls to enable device enumeration feature.
116+
Devices from all bound plugins are queried and listed as and when required, eg: during device selection in device_selector.
117+
The trace shows the PI API calls made when using SYCL_PI_TRACE=-1.
118+
(TBD - Add the trace to list all available devices when plugins are successfully bound.)
112119

113120
### Plugin Unloading
114-
The plugins not chosen to be connected to will be unloaded.
121+
The plugins not chosen to be connected to should be unloaded.
115122

116123
TBD - Unloading a bound plugin.
117124

@@ -123,11 +130,11 @@ able to operate on the corresponding device. The core API further breaks down
123130
into
124131
- **OpenCL-based** APIs which have OpenCL origin and semantics
125132
- **Extension** APIs which don't have counterparts in the OpenCL
126-
- **Interoperability API** which allows interoperability with underlying APIs
133+
- **Interoperability API** which allows interoperability with underlying runtimes
127134
such as OpenCL.
128135

129136
See [pi.h](../include/CL/sycl/detail/pi.h) header for the full list and
130-
descriptions of PI APIs. [TBD: link to pi.h doxygen here]
137+
descriptions of PI APIs.
131138

132139
### The Core OpenCL-based PI APIs
133140

@@ -166,10 +173,10 @@ in a data section.
166173
### The Interoperability PI APIs
167174

168175
These are APIs needed to implement DPC++ runtime interoperability with
169-
underlying "native" device runtimes such as OpenCL. Currently there are only
170-
OpenCL interoperability APIs, which is to be implemented by the OpenCL PI
171-
plugin only. These APIs match semantics of the corresponding OpenCL APIs
172-
exactly.
176+
underlying "native" device runtimes such as OpenCL.
177+
There are some OpenCL interoperability APIs, which are to be implemented
178+
by the OpenCL PI plugin only. These APIs match semantics of the corresponding
179+
OpenCL APIs exactly.
173180
For example:
174181

175182
```
@@ -181,6 +188,21 @@ pi_result piclProgramCreateWithSource(
181188
pi_program * ret_program);
182189
```
183190

191+
Some interoperability extension APIs have been added to get native runtime
192+
handles from the backend-agnostic PI Objects or to create PI Objects using the
193+
native handles. Eg:
194+
195+
```
196+
pi_result piextDeviceGetNativeHandle(
197+
pi_device device,
198+
pi_native_handle *nativeHandle);
199+
200+
pi_result piextDeviceCreateWithNativeHandle(
201+
pi_native_handle nativeHandle,
202+
pi_device *device);
203+
204+
```
205+
184206
### PI Extension mechanism
185207

186208
TBD This section describes a mechanism for DPC++ or other runtimes to detect

0 commit comments

Comments
 (0)