MLIR 23.0.0git
LevelZeroRuntimeWrappers.cpp
Go to the documentation of this file.
1//===- LevelZeroRuntimeWrappers.cpp - MLIR Level Zero (L0) wrapper library-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implements wrappers around the Level Zero (L0) runtime library with C linkage
10//
11//===----------------------------------------------------------------------===//
12
13#include "level_zero/ze_api.h"
14#include <cassert>
15#include <deque>
16#include <exception>
17#include <functional>
18#include <iostream>
19#include <limits>
20#include <memory>
21#include <stdexcept>
22#include <unordered_set>
23#include <vector>
24
25namespace {
26template <typename F>
27auto catchAll(F &&func) {
28 try {
29 return func();
30 } catch (const std::exception &e) {
31 std::cerr << "An exception was thrown: " << e.what() << std::endl;
32 std::abort();
33 } catch (...) {
34 std::cerr << "An unknown exception was thrown." << std::endl;
35 std::abort();
36 }
37}
38
39#define L0_SAFE_CALL(call) \
40 { \
41 ze_result_t status = (call); \
42 if (status != ZE_RESULT_SUCCESS) { \
43 const char *errorString; \
44 zeDriverGetLastErrorDescription(NULL, &errorString); \
45 std::cerr << "L0 error " << status << ": " << errorString << std::endl; \
46 std::abort(); \
47 } \
48 }
49} // namespace
50
51//===----------------------------------------------------------------------===//
52// L0 RT context & device setters
53//===----------------------------------------------------------------------===//
54
55// Returns the L0 driver handle for the given index. Default index is 0
56// (i.e., returns the first driver handle of the available drivers).
57
58static ze_driver_handle_t getDriver(uint32_t idx = 0) {
59 ze_init_driver_type_desc_t driver_type = {};
60 driver_type.stype = ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC;
61 driver_type.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU;
62 driver_type.pNext = nullptr;
63 uint32_t driverCount{0};
64 thread_local static std::vector<ze_driver_handle_t> drivers;
65 thread_local static bool isDriverInitialised{false};
66 if (isDriverInitialised && idx < drivers.size())
67 return drivers[idx];
68 L0_SAFE_CALL(zeInitDrivers(&driverCount, nullptr, &driver_type));
69 if (!driverCount)
70 throw std::runtime_error("No L0 drivers found.");
71 drivers.resize(driverCount);
72 L0_SAFE_CALL(zeInitDrivers(&driverCount, drivers.data(), &driver_type));
73 if (idx >= driverCount)
74 throw std::runtime_error(std::string("Requested driver idx out-of-bound, "
75 "number of availabe drivers: ") +
76 std::to_string(driverCount));
77 isDriverInitialised = true;
78 return drivers[idx];
79}
80
81static ze_device_handle_t getDevice(const uint32_t driverIdx = 0,
82 const int32_t devIdx = 0) {
83 thread_local static ze_device_handle_t l0Device;
84 thread_local int32_t currDevIdx{-1};
85 thread_local uint32_t currDriverIdx{0};
86 if (currDriverIdx == driverIdx && currDevIdx == devIdx)
87 return l0Device;
88 auto driver = getDriver(driverIdx);
89 uint32_t deviceCount{0};
90 L0_SAFE_CALL(zeDeviceGet(driver, &deviceCount, nullptr));
91 if (!deviceCount)
92 throw std::runtime_error("getDevice failed: did not find L0 device.");
93 if (static_cast<int>(deviceCount) < devIdx + 1)
94 throw std::runtime_error("getDevice failed: devIdx out-of-bounds.");
95 std::vector<ze_device_handle_t> devices(deviceCount);
96 L0_SAFE_CALL(zeDeviceGet(driver, &deviceCount, devices.data()));
97 l0Device = devices[devIdx];
98 currDriverIdx = driverIdx;
99 currDevIdx = devIdx;
100 return l0Device;
101}
102
103// Returns the default L0 context of the defult driver.
104static ze_context_handle_t getContext(ze_driver_handle_t driver) {
105 thread_local static ze_context_handle_t context;
106 thread_local static bool isContextInitialised{false};
107 if (isContextInitialised)
108 return context;
109 ze_context_desc_t ctxtDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
110 L0_SAFE_CALL(zeContextCreate(driver, &ctxtDesc, &context));
111 isContextInitialised = true;
112 return context;
113}
114
115//===----------------------------------------------------------------------===//
116// L0 RT helper structs
117//===----------------------------------------------------------------------===//
118
120 void operator()(ze_context_handle_t ctx) const {
121 if (ctx)
122 L0_SAFE_CALL(zeContextDestroy(ctx));
123 }
124};
125
127 void operator()(ze_command_list_handle_t cmdList) const {
128 if (cmdList)
129 L0_SAFE_CALL(zeCommandListDestroy(cmdList));
130 }
131};
133 std::unique_ptr<std::remove_pointer<ze_context_handle_t>::type,
136 std::unique_ptr<std::remove_pointer<ze_command_list_handle_t>::type,
139 ze_driver_handle_t driver{nullptr};
140 ze_device_handle_t device{nullptr};
142 // Usually, one immediate command list with ordinal 0 suffices for
143 // both copy and compute ops, but leaves HW underutilized.
145 // Copy engines can be used for both memcpy and memset, but
146 // they have limitations for memset pattern size (e.g., 1 byte).
149
151 L0RTContextWrapper(const uint32_t driverIdx = 0, const int32_t devIdx = 0)
152 : driver(getDriver(driverIdx)), device(getDevice(devIdx)) {
153 // Create context
154 ze_context_handle_t ctx = getContext(driver);
155 context.reset(ctx);
156
157 // Determine ordinals
158 uint32_t computeEngineOrdinal = -1u, copyEngineOrdinal = -1u;
159 ze_device_properties_t deviceProperties{};
160 L0_SAFE_CALL(zeDeviceGetProperties(device, &deviceProperties));
161 uint32_t queueGroupCount = 0;
162 L0_SAFE_CALL(zeDeviceGetCommandQueueGroupProperties(
163 device, &queueGroupCount, nullptr));
164 std::vector<ze_command_queue_group_properties_t> queueGroupProperties(
165 queueGroupCount);
166 L0_SAFE_CALL(zeDeviceGetCommandQueueGroupProperties(
167 device, &queueGroupCount, queueGroupProperties.data()));
168
169 for (uint32_t queueGroupIdx = 0; queueGroupIdx < queueGroupCount;
170 ++queueGroupIdx) {
171 const auto &group = queueGroupProperties[queueGroupIdx];
172 if (group.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE)
173 computeEngineOrdinal = queueGroupIdx;
174 else if (group.flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY) {
175 copyEngineOrdinal = queueGroupIdx;
176 copyEngineMaxMemoryFillPatternSize = group.maxMemoryFillPatternSize;
177 }
178 if (copyEngineOrdinal != -1u && computeEngineOrdinal != -1u)
179 break;
180 }
181
182 // Fallback to the default queue if no dedicated copy queue is available.
183 if (copyEngineOrdinal == -1u)
184 copyEngineOrdinal = computeEngineOrdinal;
185
186 assert(copyEngineOrdinal != -1u && computeEngineOrdinal != -1u &&
187 "Expected two engines to be available.");
188
189 // Create copy command list
190 ze_command_queue_desc_t cmdQueueDesc{
191 ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC,
192 nullptr,
193 copyEngineOrdinal, // ordinal
194 0, // index (assume one physical engine in the group)
195 0, // flags
196 ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS,
197 ZE_COMMAND_QUEUE_PRIORITY_NORMAL};
198
199 ze_command_list_handle_t rawCmdListCopy = nullptr;
200 L0_SAFE_CALL(zeCommandListCreateImmediate(context.get(), device,
201 &cmdQueueDesc, &rawCmdListCopy));
202 immCmdListCopy.reset(rawCmdListCopy);
203
204 // Create compute command list
205 cmdQueueDesc.ordinal = computeEngineOrdinal;
206 ze_command_list_handle_t rawCmdListCompute = nullptr;
207 L0_SAFE_CALL(zeCommandListCreateImmediate(
208 context.get(), device, &cmdQueueDesc, &rawCmdListCompute));
209 immCmdListCompute.reset(rawCmdListCompute);
210 }
213 // Allow move
215 L0RTContextWrapper &operator=(L0RTContextWrapper &&) noexcept = default;
216 ~L0RTContextWrapper() = default;
217};
218
220 void operator()(ze_event_handle_t event) const {
221 if (event)
222 L0_SAFE_CALL(zeEventDestroy(event));
223 }
224};
225
227 void operator()(ze_event_pool_handle_t pool) const {
228 if (pool)
229 L0_SAFE_CALL(zeEventPoolDestroy(pool));
230 }
231};
232
234 std::unique_ptr<std::remove_pointer<ze_event_handle_t>::type,
237 std::unique_ptr<std::remove_pointer<ze_event_pool_handle_t>::type,
239
240// L0 only supports pre-determined sizes of event pools,
241// implement a runtime data structure to avoid running out of events.
242
244 constexpr static size_t numEventsPerPool{128};
245
246 std::vector<UniqueZeEventPool> eventPools;
247 std::vector<UniqueZeEvent> availableEvents;
248 std::unordered_map<ze_event_handle_t, UniqueZeEvent> takenEvents;
249
250 // Limit the number of events to avoid running out of memory.
251 // The limit is set to 32K events, which should be sufficient for most use
252 // cases.
253 size_t maxEventsCount{32768}; // 32K events
257
261
264
265 // Allow move
266 DynamicEventPool(DynamicEventPool &&) noexcept = default;
267 DynamicEventPool &operator=(DynamicEventPool &&) noexcept = default;
268
270 assert(takenEvents.empty() && "Some events were not released");
271 }
272
273 void createNewPool(size_t numEvents) {
274 ze_event_pool_desc_t eventPoolDesc = {};
275 eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
276 eventPoolDesc.count = numEvents;
277
278 ze_event_pool_handle_t rawPool = nullptr;
279 L0_SAFE_CALL(zeEventPoolCreate(rtCtx->context.get(), &eventPoolDesc, 1,
280 &rtCtx->device, &rawPool));
281
282 eventPools.emplace_back(UniqueZeEventPool(rawPool));
283 currentEventsLimit += numEvents;
284 }
285
286 ze_event_handle_t takeEvent() {
287 ze_event_handle_t rawEvent = nullptr;
288
289 if (!availableEvents.empty()) {
290 // Reuse one
291 auto uniqueEvent = std::move(availableEvents.back());
292 availableEvents.pop_back();
293 rawEvent = uniqueEvent.get();
294 takenEvents[rawEvent] = std::move(uniqueEvent);
295 } else {
297 throw std::runtime_error("DynamicEventPool: reached max events limit");
298 }
301
302 ze_event_desc_t eventDesc = {
303 ZE_STRUCTURE_TYPE_EVENT_DESC, nullptr,
304 static_cast<uint32_t>(currentEventsCnt % numEventsPerPool),
305 ZE_EVENT_SCOPE_FLAG_DEVICE, ZE_EVENT_SCOPE_FLAG_HOST};
306
307 ze_event_handle_t newEvent = nullptr;
309 zeEventCreate(eventPools.back().get(), &eventDesc, &newEvent));
310
311 takenEvents[newEvent] = UniqueZeEvent(newEvent);
312 rawEvent = newEvent;
314 }
315
316 return rawEvent;
317 }
318
319 void releaseEvent(ze_event_handle_t event) {
320 auto it = takenEvents.find(event);
321 assert(it != takenEvents.end() &&
322 "Attempting to release unknown or already released event");
323
324 L0_SAFE_CALL(zeEventHostReset(event));
325 availableEvents.emplace_back(std::move(it->second));
326 takenEvents.erase(it);
327 }
328};
329
331 thread_local static L0RTContextWrapper rtContext(0);
332 return rtContext;
333}
334
336 thread_local static DynamicEventPool dynEventPool{&getRtContext()};
337 return dynEventPool;
338}
339
341 // avoid event pointer invalidations
342 std::deque<ze_event_handle_t> implicitEventStack;
344
347
348 ze_event_handle_t *getLastImplicitEventPtr() {
349 // Assume current implicit events will not be used after `sync`.
350 return implicitEventStack.size() ? &implicitEventStack.back() : nullptr;
351 }
352
353 void sync(ze_event_handle_t explicitEvent = nullptr) {
354 ze_event_handle_t syncEvent{nullptr};
355 if (!explicitEvent) {
356 ze_event_handle_t *lastImplicitEventPtr = getLastImplicitEventPtr();
357 syncEvent = lastImplicitEventPtr ? *lastImplicitEventPtr : nullptr;
358 } else {
359 syncEvent = explicitEvent;
360 }
361 if (syncEvent)
362 L0_SAFE_CALL(zeEventHostSynchronize(
363 syncEvent, std::numeric_limits<uint64_t>::max()));
364 // All of the "implicit" events were signaled and are of no use, release
365 // them. "explicit" event must be "released" via mgpuEventDestroy
366 for (auto event : implicitEventStack)
367 dynEventPool.releaseEvent(event);
368 implicitEventStack.clear();
369 }
370
371 template <typename Func>
372 void enqueueOp(Func &&op) {
373 ze_event_handle_t newImplicitEvent = dynEventPool.takeEvent();
374 ze_event_handle_t *lastImplicitEventPtr = getLastImplicitEventPtr();
375 const uint32_t numWaitEvents = lastImplicitEventPtr ? 1 : 0;
376 std::forward<Func>(op)(newImplicitEvent, numWaitEvents,
377 lastImplicitEventPtr);
378 implicitEventStack.push_back(newImplicitEvent);
379 }
380};
381
382static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
383 assert(data);
384 ze_module_handle_t zeModule;
385 ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
386 nullptr,
387 ZE_MODULE_FORMAT_IL_SPIRV,
388 dataSize,
389 (const uint8_t *)data,
390 nullptr,
391 nullptr};
392 ze_module_build_log_handle_t buildLogHandle;
393 ze_result_t result =
394 zeModuleCreate(getRtContext().context.get(), getRtContext().device, &desc,
395 &zeModule, &buildLogHandle);
396 if (result != ZE_RESULT_SUCCESS) {
397 std::cerr << "Error creating module, error code: " << result << std::endl;
398 size_t logSize = 0;
399 L0_SAFE_CALL(zeModuleBuildLogGetString(buildLogHandle, &logSize, nullptr));
400 std::string buildLog(" ", logSize);
402 zeModuleBuildLogGetString(buildLogHandle, &logSize, buildLog.data()));
403 std::cerr << "Build log:\n" << buildLog << std::endl;
404 std::abort();
405 }
406 return zeModule;
407}
408
409//===----------------------------------------------------------------------===//
410// L0 Wrappers definition
411//===----------------------------------------------------------------------===//
412
415}
416
417extern "C" void mgpuStreamSynchronize(StreamWrapper *stream) {
418 if (stream)
419 stream->sync();
420}
421
422extern "C" void mgpuStreamDestroy(StreamWrapper *stream) { delete stream; }
423
424extern "C" void mgpuStreamWaitEvent(StreamWrapper *stream,
425 ze_event_handle_t event) {
426 assert(stream && "Invalid stream");
427 assert(event && "Invalid event");
428 stream->sync(event);
429}
430
431extern "C" ze_event_handle_t mgpuEventCreate() {
433}
434
435extern "C" void mgpuEventDestroy(ze_event_handle_t event) {
436 return getDynamicEventPool().releaseEvent(event);
437}
438
439extern "C" void mgpuEventSynchronize(ze_event_handle_t event) {
441 zeEventHostSynchronize(event, std::numeric_limits<uint64_t>::max()));
442 L0_SAFE_CALL(zeEventHostReset(event));
443}
444
445extern "C" void mgpuEventRecord(ze_event_handle_t event,
446 StreamWrapper *stream) {
447 L0_SAFE_CALL(zeCommandListAppendSignalEvent(
448 getRtContext().immCmdListCopy.get(), event));
449 L0_SAFE_CALL(zeCommandListAppendSignalEvent(
450 getRtContext().immCmdListCompute.get(), event));
451}
452
453extern "C" void *mgpuMemAlloc(uint64_t size, StreamWrapper *stream,
454 bool isShared) {
455 return catchAll([&]() {
456 void *memPtr = nullptr;
457 constexpr size_t alignment{64};
458 ze_device_mem_alloc_desc_t deviceDesc = {};
459 deviceDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
460 if (isShared) {
461 ze_host_mem_alloc_desc_t hostDesc = {};
462 hostDesc.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC;
463 L0_SAFE_CALL(zeMemAllocShared(getRtContext().context.get(), &deviceDesc,
464 &hostDesc, size, alignment,
465 getRtContext().device, &memPtr));
466 } else {
467 L0_SAFE_CALL(zeMemAllocDevice(getRtContext().context.get(), &deviceDesc,
468 size, alignment, getRtContext().device,
469 &memPtr));
470 }
471 if (!memPtr)
472 throw std::runtime_error("mem allocation failed!");
473 return memPtr;
474 });
475}
476
477extern "C" void mgpuMemFree(void *ptr, StreamWrapper *stream) {
478 stream->sync();
479 if (ptr)
480 L0_SAFE_CALL(zeMemFree(getRtContext().context.get(), ptr));
481}
482
483extern "C" void mgpuMemcpy(void *dst, void *src, size_t sizeBytes,
484 StreamWrapper *stream) {
485 stream->enqueueOp([&](ze_event_handle_t newEvent, uint32_t numWaitEvents,
486 ze_event_handle_t *waitEvents) {
487 L0_SAFE_CALL(zeCommandListAppendMemoryCopy(
488 getRtContext().immCmdListCopy.get(), dst, src, sizeBytes, newEvent,
489 numWaitEvents, waitEvents));
490 });
491}
492
493template <typename PATTERN_TYPE>
494static void mgpuMemset(void *dst, PATTERN_TYPE value, size_t count,
495 StreamWrapper *stream) {
496 L0RTContextWrapper &rtContext = getRtContext();
497 auto listType =
498 rtContext.copyEngineMaxMemoryFillPatternSize >= sizeof(PATTERN_TYPE)
499 ? rtContext.immCmdListCopy.get()
500 : rtContext.immCmdListCompute.get();
501 stream->enqueueOp([&](ze_event_handle_t newEvent, uint32_t numWaitEvents,
502 ze_event_handle_t *waitEvents) {
503 L0_SAFE_CALL(zeCommandListAppendMemoryFill(
504 listType, dst, &value, sizeof(PATTERN_TYPE),
505 count * sizeof(PATTERN_TYPE), newEvent, numWaitEvents, waitEvents));
506 });
507}
508extern "C" void mgpuMemset32(void *dst, unsigned int value, size_t count,
509 StreamWrapper *stream) {
510 mgpuMemset<unsigned int>(dst, value, count, stream);
511}
512
513extern "C" void mgpuMemset16(void *dst, unsigned short value, size_t count,
514 StreamWrapper *stream) {
515 mgpuMemset<unsigned short>(dst, value, count, stream);
516}
517
518extern "C" ze_module_handle_t mgpuModuleLoad(const void *data,
519 size_t gpuBlobSize) {
520 return catchAll([&]() { return loadModule(data, gpuBlobSize); });
521}
522
523extern "C" ze_kernel_handle_t mgpuModuleGetFunction(ze_module_handle_t module,
524 const char *name) {
525 assert(module && name);
526 ze_kernel_handle_t zeKernel;
527 ze_kernel_desc_t desc = {};
528 desc.pKernelName = name;
529 L0_SAFE_CALL(zeKernelCreate(module, &desc, &zeKernel));
530 return zeKernel;
531}
532
533extern "C" void mgpuLaunchKernel(ze_kernel_handle_t kernel, size_t gridX,
534 size_t gridY, size_t gridZ, size_t blockX,
535 size_t blockY, size_t blockZ,
536 size_t sharedMemBytes, StreamWrapper *stream,
537 void **params, void ** /*extra*/,
538 size_t paramsCount) {
539
540 if (sharedMemBytes > 0) {
541 paramsCount = paramsCount - 1; // Last param is shared memory size
543 zeKernelSetArgumentValue(kernel, paramsCount, sharedMemBytes, nullptr));
544 }
545 for (size_t i = 0; i < paramsCount; ++i)
546 L0_SAFE_CALL(zeKernelSetArgumentValue(kernel, static_cast<uint32_t>(i),
547 sizeof(void *), params[i]));
548 L0_SAFE_CALL(zeKernelSetGroupSize(kernel, blockX, blockY, blockZ));
549 ze_group_count_t dispatch;
550 dispatch.groupCountX = static_cast<uint32_t>(gridX);
551 dispatch.groupCountY = static_cast<uint32_t>(gridY);
552 dispatch.groupCountZ = static_cast<uint32_t>(gridZ);
553 stream->enqueueOp([&](ze_event_handle_t newEvent, uint32_t numWaitEvents,
554 ze_event_handle_t *waitEvents) {
555 L0_SAFE_CALL(zeCommandListAppendLaunchKernel(
556 getRtContext().immCmdListCompute.get(), kernel, &dispatch, newEvent,
557 numWaitEvents, waitEvents));
558 });
559}
560
561extern "C" void mgpuModuleUnload(ze_module_handle_t module) {
562 L0_SAFE_CALL(zeModuleDestroy(module));
563}
564
565extern "C" void mgpuSetDefaultDevice(int32_t devIdx) {
566 catchAll([&]() {
567 // For now, a user must ensure that streams and events complete
568 // and are destroyed before switching a device.
571 });
572}
std::unique_ptr< std::remove_pointer< ze_event_handle_t >::type, ZeEventDeleter > UniqueZeEvent
void mgpuSetDefaultDevice(int32_t devIdx)
static ze_module_handle_t loadModule(const void *data, size_t dataSize)
static L0RTContextWrapper & getRtContext()
void mgpuMemset16(void *dst, unsigned short value, size_t count, StreamWrapper *stream)
#define L0_SAFE_CALL(call)
static void mgpuMemset(void *dst, PATTERN_TYPE value, size_t count, StreamWrapper *stream)
static ze_device_handle_t getDevice(const uint32_t driverIdx=0, const int32_t devIdx=0)
static DynamicEventPool & getDynamicEventPool()
std::unique_ptr< std::remove_pointer< ze_context_handle_t >::type, ZeContextDeleter > UniqueZeContext
void * mgpuMemAlloc(uint64_t size, StreamWrapper *stream, bool isShared)
void mgpuStreamDestroy(StreamWrapper *stream)
ze_module_handle_t mgpuModuleLoad(const void *data, size_t gpuBlobSize)
void mgpuEventSynchronize(ze_event_handle_t event)
void mgpuModuleUnload(ze_module_handle_t module)
static ze_driver_handle_t getDriver(uint32_t idx=0)
void mgpuMemset32(void *dst, unsigned int value, size_t count, StreamWrapper *stream)
StreamWrapper * mgpuStreamCreate()
std::unique_ptr< std::remove_pointer< ze_command_list_handle_t >::type, ZeCommandListDeleter > UniqueZeCommandList
void mgpuEventDestroy(ze_event_handle_t event)
void mgpuStreamSynchronize(StreamWrapper *stream)
ze_kernel_handle_t mgpuModuleGetFunction(ze_module_handle_t module, const char *name)
void mgpuMemcpy(void *dst, void *src, size_t sizeBytes, StreamWrapper *stream)
void mgpuStreamWaitEvent(StreamWrapper *stream, ze_event_handle_t event)
void mgpuMemFree(void *ptr, StreamWrapper *stream)
void mgpuEventRecord(ze_event_handle_t event, StreamWrapper *stream)
ze_event_handle_t mgpuEventCreate()
std::unique_ptr< std::remove_pointer< ze_event_pool_handle_t >::type, ZeEventPoolDeleter > UniqueZeEventPool
void mgpuLaunchKernel(ze_kernel_handle_t kernel, size_t gridX, size_t gridY, size_t gridZ, size_t blockX, size_t blockY, size_t blockZ, size_t sharedMemBytes, StreamWrapper *stream, void **params, void **, size_t paramsCount)
b getContext())
void createNewPool(size_t numEvents)
L0RTContextWrapper * rtCtx
DynamicEventPool & operator=(const DynamicEventPool &)=delete
static constexpr size_t numEventsPerPool
void releaseEvent(ze_event_handle_t event)
DynamicEventPool(DynamicEventPool &&) noexcept=default
DynamicEventPool(L0RTContextWrapper *rtCtx)
std::vector< UniqueZeEventPool > eventPools
std::unordered_map< ze_event_handle_t, UniqueZeEvent > takenEvents
ze_event_handle_t takeEvent()
std::vector< UniqueZeEvent > availableEvents
DynamicEventPool(const DynamicEventPool &)=delete
UniqueZeCommandList immCmdListCopy
L0RTContextWrapper()=default
L0RTContextWrapper & operator=(const L0RTContextWrapper &)=delete
L0RTContextWrapper(L0RTContextWrapper &&) noexcept=default
L0RTContextWrapper(const uint32_t driverIdx=0, const int32_t devIdx=0)
UniqueZeCommandList immCmdListCompute
L0RTContextWrapper(const L0RTContextWrapper &)=delete
ze_event_handle_t * getLastImplicitEventPtr()
void sync(ze_event_handle_t explicitEvent=nullptr)
StreamWrapper(DynamicEventPool &dynEventPool)
std::deque< ze_event_handle_t > implicitEventStack
DynamicEventPool & dynEventPool
void operator()(ze_command_list_handle_t cmdList) const
void operator()(ze_context_handle_t ctx) const
void operator()(ze_event_handle_t event) const
void operator()(ze_event_pool_handle_t pool) const