|
21 | 21 | #include <zes_api.h>
|
22 | 22 |
|
23 | 23 | #include "ur_level_zero_common.hpp"
|
24 |
| - |
25 |
| -struct _ur_platform_handle_t; |
26 |
| -// using ur_platform_handle_t = _ur_platform_handle_t *; |
27 |
| -struct _ur_device_handle_t; |
28 |
| -// using ur_device_handle_t = _ur_device_handle_t *; |
29 |
| - |
30 |
| -struct _ur_platform_handle_t : public _ur_platform { |
31 |
| - _ur_platform_handle_t(ze_driver_handle_t Driver) : ZeDriver{Driver} {} |
32 |
| - // Performs initialization of a newly constructed PI platform. |
33 |
| - ur_result_t initialize(); |
34 |
| - |
35 |
| - // Level Zero lacks the notion of a platform, but there is a driver, which is |
36 |
| - // a pretty good fit to keep here. |
37 |
| - ze_driver_handle_t ZeDriver; |
38 |
| - |
39 |
| - // Cache versions info from zeDriverGetProperties. |
40 |
| - std::string ZeDriverVersion; |
41 |
| - std::string ZeDriverApiVersion; |
42 |
| - ze_api_version_t ZeApiVersion; |
43 |
| - |
44 |
| - // Cache driver extensions |
45 |
| - std::unordered_map<std::string, uint32_t> zeDriverExtensionMap; |
46 |
| - |
47 |
| - // Flags to tell whether various Level Zero platform extensions are available. |
48 |
| - bool ZeDriverGlobalOffsetExtensionFound{false}; |
49 |
| - bool ZeDriverModuleProgramExtensionFound{false}; |
50 |
| - |
51 |
| - // Cache UR devices for reuse |
52 |
| - std::vector<std::unique_ptr<ur_device_handle_t_>> PiDevicesCache; |
53 |
| - ur_shared_mutex PiDevicesCacheMutex; |
54 |
| - bool DeviceCachePopulated = false; |
55 |
| - |
56 |
| - // Check the device cache and load it if necessary. |
57 |
| - ur_result_t populateDeviceCacheIfNeeded(); |
58 |
| - |
59 |
| - // Return the PI device from cache that represents given native device. |
60 |
| - // If not found, then nullptr is returned. |
61 |
| - ur_device_handle_t getDeviceFromNativeHandle(ze_device_handle_t); |
62 |
| -}; |
63 |
| - |
64 |
| -enum EventsScope { |
65 |
| - // All events are created host-visible. |
66 |
| - AllHostVisible, |
67 |
| - // All events are created with device-scope and only when |
68 |
| - // host waits them or queries their status that a proxy |
69 |
| - // host-visible event is created and set to signal after |
70 |
| - // original event signals. |
71 |
| - OnDemandHostVisibleProxy, |
72 |
| - // All events are created with device-scope and only |
73 |
| - // when a batch of commands is submitted for execution a |
74 |
| - // last command in that batch is added to signal host-visible |
75 |
| - // completion of each command in this batch (the default mode). |
76 |
| - LastCommandInBatchHostVisible |
77 |
| -}; |
78 |
| - |
79 |
| -struct _ur_device_handle_t : _ur_object { |
80 |
| - _ur_device_handle_t(ze_device_handle_t Device, ur_platform_handle_t Plt, |
81 |
| - ur_device_handle_t ParentDevice = nullptr) |
82 |
| - : ZeDevice{Device}, Platform{Plt}, RootDevice{ParentDevice}, |
83 |
| - ZeDeviceProperties{}, ZeDeviceComputeProperties{} { |
84 |
| - // NOTE: one must additionally call initialize() to complete |
85 |
| - // UR device creation. |
86 |
| - } |
87 |
| - |
88 |
| - // The helper structure that keeps info about a command queue groups of the |
89 |
| - // device. It is not changed after it is initialized. |
90 |
| - struct queue_group_info_t { |
91 |
| - enum type { |
92 |
| - MainCopy, |
93 |
| - LinkCopy, |
94 |
| - Compute, |
95 |
| - Size // must be last |
96 |
| - }; |
97 |
| - |
98 |
| - // Keep the ordinal of the commands group as returned by |
99 |
| - // zeDeviceGetCommandQueueGroupProperties. A value of "-1" means that |
100 |
| - // there is no such queue group available in the Level Zero runtime. |
101 |
| - int32_t ZeOrdinal{-1}; |
102 |
| - |
103 |
| - // Keep the index of the specific queue in this queue group where |
104 |
| - // all the command enqueues of the corresponding type should go to. |
105 |
| - // The value of "-1" means that no hard binding is defined and |
106 |
| - // implementation can choose specific queue index on its own. |
107 |
| - int32_t ZeIndex{-1}; |
108 |
| - |
109 |
| - // Keeps the queue group properties. |
110 |
| - ZeStruct<ze_command_queue_group_properties_t> ZeProperties; |
111 |
| - }; |
112 |
| - |
113 |
| - std::vector<queue_group_info_t> QueueGroup = |
114 |
| - std::vector<queue_group_info_t>(queue_group_info_t::Size); |
115 |
| - |
116 |
| - // This returns "true" if a main copy engine is available for use. |
117 |
| - bool hasMainCopyEngine() const { |
118 |
| - return QueueGroup[queue_group_info_t::MainCopy].ZeOrdinal >= 0; |
119 |
| - } |
120 |
| - |
121 |
| - // This returns "true" if a link copy engine is available for use. |
122 |
| - bool hasLinkCopyEngine() const { |
123 |
| - return QueueGroup[queue_group_info_t::LinkCopy].ZeOrdinal >= 0; |
124 |
| - } |
125 |
| - |
126 |
| - // This returns "true" if a main or link copy engine is available for use. |
127 |
| - bool hasCopyEngine() const { |
128 |
| - return hasMainCopyEngine() || hasLinkCopyEngine(); |
129 |
| - } |
130 |
| - |
131 |
| - // Initialize the entire UR device. |
132 |
| - // Optional param `SubSubDeviceOrdinal` `SubSubDeviceIndex` are the compute |
133 |
| - // command queue ordinal and index respectively, used to initialize |
134 |
| - // sub-sub-devices. |
135 |
| - ur_result_t initialize(int SubSubDeviceOrdinal = -1, |
136 |
| - int SubSubDeviceIndex = -1); |
137 |
| - |
138 |
| - // Level Zero device handle. |
139 |
| - // This field is only set at _ur_device_handle_t creation time, and cannot |
140 |
| - // change. Therefore it can be accessed without holding a lock on this |
141 |
| - // _ur_device_handle_t. |
142 |
| - const ze_device_handle_t ZeDevice; |
143 |
| - |
144 |
| - // Keep the subdevices that are partitioned from this ur_device_handle_t for |
145 |
| - // reuse The order of sub-devices in this vector is repeated from the |
146 |
| - // ze_device_handle_t array that are returned from zeDeviceGetSubDevices() |
147 |
| - // call, which will always return sub-devices in the fixed same order. |
148 |
| - std::vector<ur_device_handle_t> SubDevices; |
149 |
| - |
150 |
| - // PI platform to which this device belongs. |
151 |
| - // This field is only set at _ur_device_handle_t creation time, and cannot |
152 |
| - // change. Therefore it can be accessed without holding a lock on this |
153 |
| - // _ur_device_handle_t. |
154 |
| - ur_platform_handle_t Platform; |
155 |
| - |
156 |
| - // Root-device of a sub-device, null if this is not a sub-device. |
157 |
| - // This field is only set at _ur_device_handle_t creation time, and cannot |
158 |
| - // change. Therefore it can be accessed without holding a lock on this |
159 |
| - // _ur_device_handle_t. |
160 |
| - const ur_device_handle_t RootDevice; |
161 |
| - |
162 |
| - enum ImmCmdlistMode { |
163 |
| - // Immediate commandlists are not used. |
164 |
| - NotUsed = 0, |
165 |
| - // One set of compute and copy immediate commandlists per queue. |
166 |
| - PerQueue, |
167 |
| - // One set of compute and copy immediate commandlists per host thread that |
168 |
| - // accesses the queue. |
169 |
| - PerThreadPerQueue |
170 |
| - }; |
171 |
| - // Read env settings to select immediate commandlist mode. |
172 |
| - ImmCmdlistMode useImmediateCommandLists(); |
173 |
| - |
174 |
| - // Returns whether immediate command lists are used on this device. |
175 |
| - ImmCmdlistMode ImmCommandListUsed{}; |
176 |
| - |
177 |
| - // Scope of events used for events on the device |
178 |
| - // Can be adjusted with UR_DEVICE_SCOPE_EVENTS |
179 |
| - // for non-immediate command lists |
180 |
| - EventsScope ZeEventsScope = AllHostVisible; |
181 |
| - |
182 |
| - bool isSubDevice() { return RootDevice != nullptr; } |
183 |
| - |
184 |
| - // Is this a Data Center GPU Max series (aka PVC)? |
185 |
| - // TODO: change to use |
186 |
| - // https://spec.oneapi.io/level-zero/latest/core/api.html#ze-device-ip-version-ext-t |
187 |
| - // when that is stable. |
188 |
| - bool isPVC() { |
189 |
| - return (ZeDeviceProperties->deviceId & 0xff0) == 0xbd0 || |
190 |
| - (ZeDeviceProperties->deviceId & 0xff0) == 0xb60; |
191 |
| - } |
192 |
| - |
193 |
| - // Does this device represent a single compute slice? |
194 |
| - bool isCCS() const { |
195 |
| - return QueueGroup[_ur_device_handle_t::queue_group_info_t::Compute] |
196 |
| - .ZeIndex >= 0; |
197 |
| - } |
198 |
| - |
199 |
| - // Cache of the immutable device properties. |
200 |
| - ZeCache<ZeStruct<ze_device_properties_t>> ZeDeviceProperties; |
201 |
| - ZeCache<ZeStruct<ze_device_compute_properties_t>> ZeDeviceComputeProperties; |
202 |
| - ZeCache<ZeStruct<ze_device_image_properties_t>> ZeDeviceImageProperties; |
203 |
| - ZeCache<ZeStruct<ze_device_module_properties_t>> ZeDeviceModuleProperties; |
204 |
| - ZeCache<std::pair<std::vector<ZeStruct<ze_device_memory_properties_t>>, |
205 |
| - std::vector<ZeStruct<ze_device_memory_ext_properties_t>>>> |
206 |
| - ZeDeviceMemoryProperties; |
207 |
| - ZeCache<ZeStruct<ze_device_memory_access_properties_t>> |
208 |
| - ZeDeviceMemoryAccessProperties; |
209 |
| - ZeCache<ZeStruct<ze_device_cache_properties_t>> ZeDeviceCacheProperties; |
210 |
| -}; |
| 24 | +#include "ur_level_zero_context.hpp" |
| 25 | +#include "ur_level_zero_device.hpp" |
| 26 | +#include "ur_level_zero_event.hpp" |
| 27 | +#include "ur_level_zero_kernel.hpp" |
| 28 | +#include "ur_level_zero_mem.hpp" |
| 29 | +#include "ur_level_zero_platform.hpp" |
| 30 | +#include "ur_level_zero_program.hpp" |
| 31 | +#include "ur_level_zero_queue.hpp" |
| 32 | +#include "ur_level_zero_sampler.hpp" |
| 33 | +#include "ur_level_zero_usm.hpp" |
0 commit comments