1
1
# The DPC++ Runtime Plugin Interface.
2
2
3
3
## 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
6
6
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
8
8
or OpenCL.
9
9
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++
11
11
runtime stack. Dotted lines show components or paths which are not yet available
12
12
in the runtime, but are likely to be developed.
13
13
![ PI in DPC++ runtime architecture] ( images/RuntimeArchitecture.svg )
@@ -21,29 +21,30 @@ points implementing the PI interface. The DPC++ runtime collects those function
21
21
pointers into a PI interface dispatch table - one per plugin - and uses this
22
22
table to dispatch to the device(s) covered by the corresponding plugin.
23
23
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
27
27
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
29
29
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
31
31
management.
32
32
33
33
## Discovery and linkage of PI implementations
34
34
35
35
![ PI implementation discovery] ( images/PluginDiscovery.svg )
36
36
37
37
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.
40
41
41
42
### Plugin discovery
42
43
43
44
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.
45
46
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
47
48
at a predetermined location (TBD - Add this location). These plugins are
48
49
searched at locations in env LD_LIBRARY_PATH on Linux and env PATH on Windows.
49
50
(TBD - Extend to search the plugins at a path relative to the SYCL Runtime
@@ -53,44 +54,52 @@ of LD_LIBRARY_PATH.)
53
54
To avoid any issues with read-only access, an environment variable SYCL_PI_CONFIG
54
55
can be set to point to the configuration file which lists the Plugin names. The
55
56
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.
57
58
It is the developer's responsibility to include the plugin names from the
58
59
predetermined location's config file to enable discovery of all plugins.
59
60
(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.
65
72
66
73
#### Plugin binary interface
67
74
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.
71
80
In the future, this document will list the minimum set of Interface APIs
72
81
to be supported by Plugins. This will also require adding functionality to SYCL
73
82
Runtime to work with such limited functionality plugins.
74
83
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.)
77
86
78
87
#### 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.)
89
94
The information of compatible plugins (with the Function Pointer Table) is
90
95
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.
94
103
95
104
#### OpenCL plugin
96
105
@@ -100,18 +109,16 @@ OpenCL implementations. They can be installed either in the standard Khronos
100
109
ICD-compatible way (e.g. listed in files under /etc/OpenCL/vendors on
101
110
Linux) or not, and the OpenCL plugin can hook up with both.
102
111
103
- TBD - describe the nested OpenCL implementation discovery process performed by
112
+ TBD - implement and describe the nested OpenCL implementation discovery process performed by
104
113
the OpenCL plugin
105
114
106
115
### 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.)
112
119
113
120
### 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.
115
122
116
123
TBD - Unloading a bound plugin.
117
124
@@ -123,11 +130,11 @@ able to operate on the corresponding device. The core API further breaks down
123
130
into
124
131
- ** OpenCL-based** APIs which have OpenCL origin and semantics
125
132
- ** 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
127
134
such as OpenCL.
128
135
129
136
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.
131
138
132
139
### The Core OpenCL-based PI APIs
133
140
@@ -166,10 +173,10 @@ in a data section.
166
173
### The Interoperability PI APIs
167
174
168
175
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.
173
180
For example:
174
181
175
182
```
@@ -181,6 +188,21 @@ pi_result piclProgramCreateWithSource(
181
188
pi_program * ret_program);
182
189
```
183
190
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
+
184
206
### PI Extension mechanism
185
207
186
208
TBD This section describes a mechanism for DPC++ or other runtimes to detect
0 commit comments