1
1
# The DPC++ Runtime Plugin Interface.
2
2
3
-
4
3
## Overview
5
- The DPC++ Runtime Plugin Interface (PI) is the interface layer between
6
- 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
7
6
which control execution on devices. It employs the “plugin” mechanism to bind
8
- 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
9
8
or OpenCL.
10
9
11
- 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++
12
11
runtime stack. Dotted lines show components or paths which are not yet available
13
12
in the runtime, but are likely to be developed.
14
13
![ PI in DPC++ runtime architecture] ( images/RuntimeArchitecture.svg )
@@ -22,31 +21,85 @@ points implementing the PI interface. The DPC++ runtime collects those function
22
21
pointers into a PI interface dispatch table - one per plugin - and uses this
23
22
table to dispatch to the device(s) covered by the corresponding plugin.
24
23
25
- PI is based on a subset of OpenCL 1.2 runtime specification, it follows its
26
- platform, execution and memory models in all aspects except those explicitly
27
- 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
28
27
matches in OpenCL. Whenever there is such a match, the semantics also fully
29
- matches unless the differences are explicitly specified in this document. While
28
+ match unless the differences are explicitly specified in this document. While
30
29
PI has roots in OpenCL, it does have many differences, and the gap is likely
31
- 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
32
31
management.
33
32
34
33
## Discovery and linkage of PI implementations
35
34
36
35
![ PI implementation discovery] ( images/PluginDiscovery.svg )
37
36
38
37
Device discovery phase enumerates all available devices and their features by
39
- querying underlying plugins found in the system. This process is only performed
40
- 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.
41
41
42
42
### Plugin discovery
43
43
44
- Plugins are physically dynamic libraries stored somewhere in the system where
45
- the DPC++ runtime runs. TBD - design and describe the process in details.
44
+ Plugins are physically dynamic libraries or shared objects.
45
+ The process to discover plugins follows the following guidelines.
46
+
47
+ The DPC++ Runtime reads the names of the plugins from a configuration file
48
+ at a predetermined location (TBD - Add this location). These plugins are
49
+ searched at locations in env LD_LIBRARY_PATH on Linux and env PATH on Windows.
50
+ (TBD - Extend to search the plugins at a path relative to the SYCL Runtime
51
+ installation directory by using DT_RPATH on Linux. Similar functionality can be
52
+ achieved on Windows using SetDllDirectory. This will help avoiding extra setting
53
+ of LD_LIBRARY_PATH.)
54
+ To avoid any issues with read-only access, an environment variable SYCL_PI_CONFIG
55
+ can be set to point to the configuration file which lists the Plugin names. The
56
+ enviroment variable if set overrides the predetermined location's config file.
57
+ These Plugins are then be searched in LD_LIBRARY_PATH locations.
58
+ It is the developer's responsibility to include the plugin names from the
59
+ predetermined location's config file to enable discovery of all plugins.
60
+ (TBD - Extend to support search in DT_RPATH as above.)
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.
46
72
47
73
#### Plugin binary interface
48
- TBD - list and describe all the symbols plugin must export in order to be picked
49
- up by the DPC++ runtime for offload.
74
+ Plugins should implement all the Interface APIs required for the PI Version
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.
80
+ In the future, this document will list the minimum set of Interface APIs
81
+ to be supported by Plugins. This will also require adding functionality to SYCL
82
+ Runtime to work with such limited functionality plugins.
83
+
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.)
86
+
87
+ #### Binding a Plugin
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.)
94
+ The information of compatible plugins (with the Function Pointer Table) is
95
+ stored in the associated platforms during platform object construction.
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.
50
103
51
104
#### OpenCL plugin
52
105
@@ -56,12 +109,18 @@ OpenCL implementations. They can be installed either in the standard Khronos
56
109
ICD-compatible way (e.g. listed in files under /etc/OpenCL/vendors on
57
110
Linux) or not, and the OpenCL plugin can hook up with both.
58
111
59
- TBD describe the nested OpenCL implementation discovery process performed by
112
+ TBD - implement and describe the nested OpenCL implementation discovery process performed by
60
113
the OpenCL plugin
61
114
62
115
### Device enumeration by plugins
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.)
119
+
120
+ ### Plugin Unloading
121
+ The plugins not chosen to be connected to should be unloaded.
63
122
64
- TBD
123
+ TBD - Unloading a bound plugin.
65
124
66
125
## PI API Specification
67
126
@@ -71,11 +130,11 @@ able to operate on the corresponding device. The core API further breaks down
71
130
into
72
131
- ** OpenCL-based** APIs which have OpenCL origin and semantics
73
132
- ** Extension** APIs which don't have counterparts in the OpenCL
74
- - ** Interoperability API** which allows interoperability with underlying APIs
133
+ - ** Interoperability API** which allows interoperability with underlying runtimes
75
134
such as OpenCL.
76
135
77
136
See [ pi.h] ( ../include/CL/sycl/detail/pi.h ) header for the full list and
78
- descriptions of PI APIs. [ TBD: link to pi.h doxygen here ]
137
+ descriptions of PI APIs.
79
138
80
139
### The Core OpenCL-based PI APIs
81
140
@@ -114,10 +173,10 @@ in a data section.
114
173
### The Interoperability PI APIs
115
174
116
175
These are APIs needed to implement DPC++ runtime interoperability with
117
- underlying "native" device runtimes such as OpenCL. Currently there are only
118
- OpenCL interoperability APIs, which is to be implemented by the OpenCL PI
119
- plugin only. These APIs match semantics of the corresponding OpenCL APIs
120
- 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.
121
180
For example:
122
181
123
182
```
@@ -129,6 +188,21 @@ pi_result piclProgramCreateWithSource(
129
188
pi_program * ret_program);
130
189
```
131
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
+
132
206
### PI Extension mechanism
133
207
134
208
TBD This section describes a mechanism for DPC++ or other runtimes to detect
0 commit comments