[llvm] [OFFLOAD][L0] Refactor AsyncQueues (PR #199684)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 29 01:48:35 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: Alex Duran (adurang)
<details>
<summary>Changes</summary>
This PR introduces a major refactor on how L0 queues are used in the plugin as the current design is too tied to OpenMP behavior. There are two major changes:
* We no longer have a per-thread queue cache as this resulted in a single logical queue backed up by multiple L0 queues. We now have a per device cache which should have a similar level of reuse performance.
* The AsyncQueueTy type has been largely extended to hide the logic of the different queues types (which are now subclasses of AsyncQueueTy). This has greatly simplified the L0Device implementation.
As part of this refactor a number of other changes happened:
* Copy command lists were removed in favor of the ZE_COMMAND_QUEUE_FLAG_COPY_OFFLOAD_HINT driver hint.
* Support for inorder queues was added (can be selected using LIBOMPTARGET_LEVEL_ZERO_COMMAND_MODE=inorder).
* Sync queues now use inorder queues.
* Queue operations conditionally only use events when necessary (OMPT, profiling or queue logic).
* MemFill now support asynchronous operations
There are a few more things that still need to be adjusted and cleanup but as this PR is already big enough as it is, I'll prepare a follow-up to fix them.
---
Patch is 71.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/199684.diff
16 Files Affected:
- (modified) offload/plugins-nextgen/level_zero/CMakeLists.txt (+1)
- (modified) offload/plugins-nextgen/level_zero/dynamic_l0/level_zero/ze_api.h (+1)
- (modified) offload/plugins-nextgen/level_zero/include/AsyncQueue.h (+174-11)
- (added) offload/plugins-nextgen/level_zero/include/L0CmdListManager.h (+116)
- (modified) offload/plugins-nextgen/level_zero/include/L0Device.h (+62-63)
- (modified) offload/plugins-nextgen/level_zero/include/L0Kernel.h (+6-10)
- (modified) offload/plugins-nextgen/level_zero/include/L0Memory.h (-39)
- (modified) offload/plugins-nextgen/level_zero/include/L0Options.h (+1-1)
- (modified) offload/plugins-nextgen/level_zero/include/L0Plugin.h (-24)
- (removed) offload/plugins-nextgen/level_zero/include/TLS.h (-71)
- (modified) offload/plugins-nextgen/level_zero/src/L0Device.cpp (+81-371)
- (modified) offload/plugins-nextgen/level_zero/src/L0Kernel.cpp (+12-87)
- (modified) offload/plugins-nextgen/level_zero/src/L0Memory.cpp (+2-2)
- (modified) offload/plugins-nextgen/level_zero/src/L0Options.cpp (+2)
- (modified) offload/plugins-nextgen/level_zero/src/L0Program.cpp (+2-2)
- (added) offload/plugins-nextgen/level_zero/src/L0Queue.cpp (+374)
``````````diff
diff --git a/offload/plugins-nextgen/level_zero/CMakeLists.txt b/offload/plugins-nextgen/level_zero/CMakeLists.txt
index 7cc195d85031f..c11f436861284 100644
--- a/offload/plugins-nextgen/level_zero/CMakeLists.txt
+++ b/offload/plugins-nextgen/level_zero/CMakeLists.txt
@@ -17,6 +17,7 @@ set(LEVEL_ZERO_SRC_FILES
src/L0Plugin.cpp
src/L0Program.cpp
src/L0Options.cpp
+ src/L0Queue.cpp
)
target_sources(omptarget.rtl.level_zero PRIVATE
diff --git a/offload/plugins-nextgen/level_zero/dynamic_l0/level_zero/ze_api.h b/offload/plugins-nextgen/level_zero/dynamic_l0/level_zero/ze_api.h
index 17e35a37f116e..c6d03dcecee8c 100644
--- a/offload/plugins-nextgen/level_zero/dynamic_l0/level_zero/ze_api.h
+++ b/offload/plugins-nextgen/level_zero/dynamic_l0/level_zero/ze_api.h
@@ -235,6 +235,7 @@ typedef uint32_t ze_command_queue_flags_t;
typedef enum _ze_command_queue_flag_t {
ZE_COMMAND_QUEUE_FLAG_EXPLICIT_ONLY = ZE_BIT(0),
ZE_COMMAND_QUEUE_FLAG_IN_ORDER = ZE_BIT(1),
+ ZE_COMMAND_QUEUE_FLAG_COPY_OFFLOAD_HINT = ZE_BIT(2),
ZE_COMMAND_QUEUE_FLAG_FORCE_UINT32 = 0x7fffffff
} ze_command_queue_flag_t;
diff --git a/offload/plugins-nextgen/level_zero/include/AsyncQueue.h b/offload/plugins-nextgen/level_zero/include/AsyncQueue.h
index fb38999b2125d..a88ffbd4c311e 100644
--- a/offload/plugins-nextgen/level_zero/include/AsyncQueue.h
+++ b/offload/plugins-nextgen/level_zero/include/AsyncQueue.h
@@ -13,32 +13,195 @@
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
+#include "L0Defs.h"
+#include "L0Trace.h"
+#include "PluginInterface.h"
+
+#include <mutex>
#include <tuple>
-#include "L0Memory.h"
+#include "L0CmdListManager.h"
+#include "L0Options.h"
namespace llvm::omp::target::plugin {
+class L0DeviceTy;
+struct L0LaunchEnvTy;
+
/// Abstract queue that supports asynchronous command submission.
struct AsyncQueueTy {
+ /// Device owning this queue.
+ L0DeviceTy &Device;
+ /// Underlying immediate command list.
+ L0CmdListManagerTy *CmdList = nullptr;
+ /// Whether the queue is in-order or out-of-order.
+ bool IsInorder;
+
+ AsyncQueueTy(L0DeviceTy &Device, bool IsInorder = true)
+ : Device(Device), IsInorder(IsInorder) {}
+ virtual ~AsyncQueueTy() {}
+
+ /// Clear data.
+ void reset() { resetImpl(); }
+
+ ze_command_list_handle_t getCmdList() const { return CmdList->getCmdList(); }
+
+ Error init();
+ Error deinit();
+ Error synchronize() { return synchronizeImpl(); }
+ Expected<bool> hasPendingWork() { return hasPendingWorkImpl(); }
+
+ Error memoryCopy(void *Dst, const void *Src, size_t Size) {
+ if (Size == 0)
+ return Plugin::success();
+ if (Dst == Src)
+ return Plugin::success();
+
+ return memoryCopyImpl(Dst, Src, Size);
+ }
+
+ Error dataRetrieve(void *HstPtr, const void *TgtPtr, int64_t Size) {
+ return dataRetrieveImpl(HstPtr, TgtPtr, Size);
+ }
+
+ Error dataSubmit(void *TgtPtr, const void *HstPtr, int64_t Size) {
+ return dataSubmitImpl(TgtPtr, HstPtr, Size);
+ }
+
+ Error memoryFill(void *Ptr, const void *Pattern, size_t PatternSize,
+ size_t Size) {
+ return memoryFillImpl(Ptr, Pattern, PatternSize, Size);
+ }
+
+ Error launchKernel(ze_kernel_handle_t Kernel, L0LaunchEnvTy &KEnv) {
+ return launchKernelImpl(Kernel, KEnv);
+ }
+
+ virtual Error initImpl() { return Plugin::success(); }
+ virtual Error deinitImpl() { return Plugin::success(); }
+ virtual void resetImpl() {}
+
+ virtual Error synchronizeImpl() = 0;
+ virtual Expected<bool> hasPendingWorkImpl() = 0;
+ virtual Error memoryCopyImpl(void *Dst, const void *Src, size_t Size) = 0;
+ virtual Error dataRetrieveImpl(void *HstPtr, const void *TgtPtr,
+ int64_t Size) {
+ return memoryCopy(HstPtr, TgtPtr, Size);
+ }
+ virtual Error dataSubmitImpl(void *TgtPtr, const void *HstPtr, int64_t Size) {
+ return memoryCopy(TgtPtr, HstPtr, Size);
+ }
+ virtual Error launchKernelImpl(ze_kernel_handle_t Kernel,
+ L0LaunchEnvTy &KEnv) = 0;
+
+ virtual Error memoryFillImpl(void *Ptr, const void *Pattern,
+ size_t PatternSize, size_t Size) {
+ return CmdList->appendMemoryFill(Ptr, Pattern, PatternSize, Size);
+ }
+};
+
+class L0AsyncQueueTy : public AsyncQueueTy {
+protected:
/// List of events attached to submitted commands.
llvm::SmallVector<ze_event_handle_t> WaitEvents;
+ /// Kernel event not signaled.
+ ze_event_handle_t KernelEvent = nullptr;
/// Pending staging buffer to host copies.
llvm::SmallVector<std::tuple<void *, void *, size_t>> H2MList;
/// Pending USM memory copy commands that must wait for kernel completion.
llvm::SmallVector<std::tuple<const void *, void *, size_t>> USM2MList;
- /// Kernel event not signaled.
- ze_event_handle_t KernelEvent = nullptr;
- /// Clear data.
- void reset() {
- WaitEvents.clear();
- H2MList.clear();
- USM2MList.clear();
- KernelEvent = nullptr;
- }
+
+ virtual std::tuple<size_t, ze_event_handle_t *> getMemCopyEvents();
+ virtual std::tuple<size_t, ze_event_handle_t *> getLaunchKernelEvents();
+ void processCopyQueues();
+
+public:
+ L0AsyncQueueTy(L0DeviceTy &Device)
+ : AsyncQueueTy(Device, /*IsInorder*/ false) {}
+ virtual ~L0AsyncQueueTy() {}
+
+ L0AsyncQueueTy(const L0AsyncQueueTy &) = delete;
+ L0AsyncQueueTy(const L0AsyncQueueTy &&) = delete;
+ L0AsyncQueueTy &operator=(const L0AsyncQueueTy &) = delete;
+ L0AsyncQueueTy &operator=(const L0AsyncQueueTy &&) = delete;
+
+ Error deinitImpl() override;
+ void resetImpl() override;
+ Error synchronizeImpl() override;
+ Expected<bool> hasPendingWorkImpl() override;
+ Error memoryCopyImpl(void *Dst, const void *Src, size_t Size) override;
+ Error dataRetrieveImpl(void *HstPtr, const void *TgtPtr,
+ int64_t Size) override;
+ Error dataSubmitImpl(void *TgtPtr, const void *HstPtr, int64_t Size) override;
+ Error launchKernelImpl(ze_kernel_handle_t Kernel,
+ L0LaunchEnvTy &KEnv) override;
+ Error memoryFillImpl(void *Ptr, const void *Pattern, size_t PatternSize,
+ size_t Size) override;
};
-using AsyncQueuePoolTy = ObjPool<AsyncQueueTy>;
+class L0AsyncOrderedQueueTy : public L0AsyncQueueTy {
+public:
+ L0AsyncOrderedQueueTy(L0DeviceTy &Device) : L0AsyncQueueTy(Device) {}
+ virtual ~L0AsyncOrderedQueueTy() {}
+
+ L0AsyncOrderedQueueTy(const L0AsyncOrderedQueueTy &) = delete;
+ L0AsyncOrderedQueueTy(const L0AsyncOrderedQueueTy &&) = delete;
+ L0AsyncOrderedQueueTy &operator=(const L0AsyncOrderedQueueTy &) = delete;
+ L0AsyncOrderedQueueTy &operator=(const L0AsyncOrderedQueueTy &&) = delete;
+
+ Error synchronizeImpl() override;
+ std::tuple<size_t, ze_event_handle_t *> getMemCopyEvents() override;
+ std::tuple<size_t, ze_event_handle_t *> getLaunchKernelEvents() override;
+};
+
+class L0InorderQueueTy : public AsyncQueueTy {
+public:
+ L0InorderQueueTy(L0DeviceTy &Device) : AsyncQueueTy(Device) {}
+ virtual ~L0InorderQueueTy() {}
+
+ L0InorderQueueTy(const L0InorderQueueTy &) = delete;
+ L0InorderQueueTy(const L0InorderQueueTy &&) = delete;
+ L0InorderQueueTy &operator=(const L0InorderQueueTy &) = delete;
+ L0InorderQueueTy &operator=(const L0InorderQueueTy &&) = delete;
+
+ Error synchronizeImpl() override;
+ Expected<bool> hasPendingWorkImpl() override;
+ Error memoryCopyImpl(void *Dst, const void *Src, size_t Size) override;
+ Error launchKernelImpl(ze_kernel_handle_t Kernel,
+ L0LaunchEnvTy &KEnv) override;
+};
+
+class L0SyncQueueTy : public L0InorderQueueTy {
+public:
+ L0SyncQueueTy(L0DeviceTy &Device) : L0InorderQueueTy(Device) {}
+ virtual ~L0SyncQueueTy() {}
+
+ L0SyncQueueTy(const L0SyncQueueTy &) = delete;
+ L0SyncQueueTy(const L0SyncQueueTy &&) = delete;
+ L0SyncQueueTy &operator=(const L0SyncQueueTy &) = delete;
+ L0SyncQueueTy &operator=(const L0SyncQueueTy &&) = delete;
+
+ Error synchronizeImpl() override { return Plugin::success(); }
+ Expected<bool> hasPendingWorkImpl() override { return false; }
+ Error memoryCopyImpl(void *Dst, const void *Src, size_t Size) override;
+ Error launchKernelImpl(ze_kernel_handle_t Kernel,
+ L0LaunchEnvTy &KEnv) override;
+};
+
+/// Simple cache for queue objects.
+class L0QueueCacheTy {
+ L0DeviceTy &Device;
+ llvm::SmallVector<AsyncQueueTy *> Queues;
+ std::mutex Mtx;
+ CommandModeTy CachedCmdMode = CommandModeTy::InOrder;
+
+public:
+ L0QueueCacheTy(L0DeviceTy &Device) : Device(Device) {}
+ Expected<AsyncQueueTy *> getQueue();
+ void releaseQueue(AsyncQueueTy *Queue);
+ Error deinit();
+ void setCommandMode(CommandModeTy CmdMode) { CachedCmdMode = CmdMode; }
+};
} // namespace llvm::omp::target::plugin
#endif // OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
diff --git a/offload/plugins-nextgen/level_zero/include/L0CmdListManager.h b/offload/plugins-nextgen/level_zero/include/L0CmdListManager.h
new file mode 100644
index 0000000000000..94a1427a8f8cd
--- /dev/null
+++ b/offload/plugins-nextgen/level_zero/include/L0CmdListManager.h
@@ -0,0 +1,116 @@
+//===--- Level Zero Target RTL Implementation -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Command List Manager for Level Zero.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0CMDLISTMANAGER_H
+#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0CMDLISTMANAGER_H
+
+#include "L0Defs.h"
+#include "L0Trace.h"
+#include <mutex>
+
+namespace llvm::omp::target::plugin {
+
+/// Manager for Level Zero command list operations.
+/// Encapsulates all zeCommandListAppend* calls with thread safety.
+class L0CmdListManagerTy {
+ /// Underlying immediate command list.
+ ze_command_list_handle_t CmdList;
+ /// Mutex to protect L0 operations that are not thread safe.
+ std::mutex Mtx;
+
+public:
+ L0CmdListManagerTy(ze_command_list_handle_t CmdList) : CmdList(CmdList) {}
+
+ ze_command_list_handle_t getCmdList() const { return CmdList; }
+
+ Error hostSynchronize(uint64_t TimeoutNs = L0DefaultTimeout) {
+ CALL_ZE_RET_ERROR(zeCommandListHostSynchronize, CmdList, TimeoutNs);
+ return Plugin::success();
+ }
+
+ Expected<bool> queryPendingWork() {
+ ze_result_t RC;
+ CALL_ZE(RC, zeCommandListHostSynchronize, CmdList, 0);
+ if (RC == ZE_RESULT_SUCCESS)
+ return false;
+ if (RC == ZE_RESULT_NOT_READY)
+ return true;
+ return Plugin::error(ErrorCode::UNKNOWN,
+ "zeCommandListHostSynchronize query failed: %s",
+ getZeErrorName(RC));
+ }
+
+ Error eventHostSynchronize(ze_event_handle_t Event,
+ uint64_t TimeoutNs = L0DefaultTimeout) {
+ CALL_ZE_RET_ERROR(zeEventHostSynchronize, Event, TimeoutNs);
+ return Plugin::success();
+ }
+
+ Error appendMemoryCopy(void *Dst, const void *Src, size_t Size,
+ ze_event_handle_t SignalEvent = nullptr,
+ uint32_t NumWaitEvents = 0,
+ ze_event_handle_t *WaitEvents = nullptr) {
+ std::lock_guard<std::mutex> Lock(Mtx);
+ CALL_ZE_RET_ERROR(zeCommandListAppendMemoryCopy, CmdList, Dst, Src, Size,
+ SignalEvent, NumWaitEvents, WaitEvents);
+ return Plugin::success();
+ }
+
+ Error appendMemoryCopyRegion(void *Dst, const ze_copy_region_t *DstRegion,
+ uint32_t DstPitch, uint32_t DstSlicePitch,
+ const void *Src,
+ const ze_copy_region_t *SrcRegion,
+ uint32_t SrcPitch, uint32_t SrcSlicePitch,
+ ze_event_handle_t SignalEvent = nullptr,
+ uint32_t NumWaitEvents = 0,
+ ze_event_handle_t *WaitEvents = nullptr) {
+ std::lock_guard<std::mutex> Lock(Mtx);
+ CALL_ZE_RET_ERROR(zeCommandListAppendMemoryCopyRegion, CmdList, Dst,
+ DstRegion, DstPitch, DstSlicePitch, Src, SrcRegion,
+ SrcPitch, SrcSlicePitch, SignalEvent, NumWaitEvents,
+ WaitEvents);
+ return Plugin::success();
+ }
+
+ Error appendMemoryFill(void *Ptr, const void *Pattern, size_t PatternSize,
+ size_t Size, ze_event_handle_t SignalEvent = nullptr,
+ uint32_t NumWaitEvents = 0,
+ ze_event_handle_t *WaitEvents = nullptr) {
+ std::lock_guard<std::mutex> Lock(Mtx);
+ CALL_ZE_RET_ERROR(zeCommandListAppendMemoryFill, CmdList, Ptr, Pattern,
+ PatternSize, Size, SignalEvent, NumWaitEvents,
+ WaitEvents);
+ return Plugin::success();
+ }
+
+ Error appendLaunchKernel(ze_kernel_handle_t Kernel,
+ const ze_group_count_t *pLaunchFuncArgs,
+ ze_event_handle_t SignalEvent = nullptr,
+ uint32_t NumWaitEvents = 0,
+ ze_event_handle_t *WaitEvents = nullptr,
+ bool Cooperative = false) {
+ std::lock_guard<std::mutex> Lock(Mtx);
+ if (Cooperative) {
+ CALL_ZE_RET_ERROR(zeCommandListAppendLaunchCooperativeKernel, CmdList,
+ Kernel, pLaunchFuncArgs, SignalEvent, NumWaitEvents,
+ WaitEvents);
+ } else {
+ CALL_ZE_RET_ERROR(zeCommandListAppendLaunchKernel, CmdList, Kernel,
+ pLaunchFuncArgs, SignalEvent, NumWaitEvents,
+ WaitEvents);
+ }
+ return Plugin::success();
+ }
+};
+
+} // namespace llvm::omp::target::plugin
+#endif // OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0CMDLISTMANAGER_H
diff --git a/offload/plugins-nextgen/level_zero/include/L0Device.h b/offload/plugins-nextgen/level_zero/include/L0Device.h
index cb6a190590677..925b51e9cd8c6 100644
--- a/offload/plugins-nextgen/level_zero/include/L0Device.h
+++ b/offload/plugins-nextgen/level_zero/include/L0Device.h
@@ -18,10 +18,10 @@
#include "PerThreadTable.h"
#include "AsyncQueue.h"
+#include "L0CmdListManager.h"
#include "L0Context.h"
#include "L0Program.h"
#include "PluginInterface.h"
-#include "TLS.h"
namespace llvm::omp::target::plugin {
@@ -75,49 +75,15 @@ struct L0DeviceIdTy {
};
class L0DeviceTLSTy {
- /// Immediate command list for each device.
- ze_command_list_handle_t ImmCmdList = nullptr;
-
- /// Immediate copy command list for each device.
- ze_command_list_handle_t ImmCopyCmdList = nullptr;
-
public:
L0DeviceTLSTy() = default;
- ~L0DeviceTLSTy() {
- assert(!ImmCmdList && !ImmCopyCmdList &&
- "L0DeviceTLSTy destroyed without clearing resources");
- }
-
+ ~L0DeviceTLSTy() {}
L0DeviceTLSTy(const L0DeviceTLSTy &) = delete;
- L0DeviceTLSTy(L0DeviceTLSTy &&Other) {
- ImmCmdList = std::exchange(Other.ImmCmdList, nullptr);
- ImmCopyCmdList = std::exchange(Other.ImmCopyCmdList, nullptr);
- }
-
- Error deinit() {
- if (ImmCmdList)
- CALL_ZE_RET_ERROR(zeCommandListDestroy, ImmCmdList);
- if (ImmCopyCmdList)
- CALL_ZE_RET_ERROR(zeCommandListDestroy, ImmCopyCmdList);
-
- ImmCmdList = nullptr;
- ImmCopyCmdList = nullptr;
-
- return Plugin::success();
- }
-
L0DeviceTLSTy &operator=(const L0DeviceTLSTy &) = delete;
L0DeviceTLSTy &operator=(L0DeviceTLSTy &&) = delete;
+ L0DeviceTLSTy(L0DeviceTLSTy &&Other) {}
- ze_command_list_handle_t getImmCmdList() const { return ImmCmdList; }
- void setImmCmdList(ze_command_list_handle_t ImmCmdListIn) {
- ImmCmdList = ImmCmdListIn;
- }
-
- ze_command_list_handle_t getImmCopyCmdList() const { return ImmCopyCmdList; }
- void setImmCopyCmdList(ze_command_list_handle_t ImmCopyCmdListIn) {
- ImmCopyCmdList = ImmCopyCmdListIn;
- }
+ Error deinit() { return Plugin::success(); }
};
struct L0DeviceTLSTableTy
@@ -161,14 +127,10 @@ class L0DeviceTy final : public GenericDeviceTy {
static constexpr uint32_t MaxOrdinal =
std::numeric_limits<decltype(MaxOrdinal)>::max();
std::pair<uint32_t, uint32_t> ComputeOrdinal{MaxOrdinal, 0};
- /// Command queue group ordinals for copying.
- std::pair<uint32_t, uint32_t> CopyOrdinal{MaxOrdinal, 0};
/// Command queue index for each device.
uint32_t ComputeIndex = 0;
- bool IsAsyncEnabled = false;
-
/// Whether the device supports cooperative kernels.
bool SupportsCooperativeKernels = false;
@@ -185,14 +147,14 @@ class L0DeviceTy final : public GenericDeviceTy {
/// MemAllocator for this device.
MemAllocatorTy MemAllocator;
+ /// Cache of queues for this device.
+ L0QueueCacheTy QueueCache;
+
DeviceArchTy computeArch() const;
/// Get default compute group ordinal. Returns Ordinal-NumQueues pair.
std::pair<uint32_t, uint32_t> findComputeOrdinal();
- /// Get copy command queue group ordinal. Returns Ordinal-NumQueues pair.
- std::pair<uint32_t, uint32_t> findCopyOrdinal(bool LinkCopy = false);
-
/// Helper function to call global constructors or destructors.
Error callGlobalCtorDtorCommon(GenericPluginTy &Plugin, DeviceImageTy &Image,
bool IsCtor);
@@ -206,7 +168,7 @@ class L0DeviceTy final : public GenericDeviceTy {
const std::string_view zeId, int32_t ComputeIndex)
: GenericDeviceTy(Plugin, DeviceId, NumDevices, SPIRVGridValues),
l0Context(DriverInfo), zeDevice(zeDevice), zeId(zeId),
- ComputeIndex(ComputeIndex) {
+ ComputeIndex(ComputeIndex), QueueCache(*this) {
DeviceProperties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
DeviceProperties.pNext = nullptr;
ComputeProperties.stype = ZE_STRUCTURE_TYPE_DEVICE_COMPUTE_PROPERTIES;
@@ -400,11 +362,6 @@ class L0DeviceTy final : public GenericDeviceTy {
uint32_t getComputeEngine() const { return ComputeOrdinal.first; }
uint32_t getNumComputeQueues() const { return ComputeOrdinal.second; }
- bool hasMainCopyEngine() const { return CopyOrdinal.first != MaxOrdinal; }
- uint32_t getMainCopyEngine() const { return CopyOrdinal.first; }
-
- bool asyncEnabled() const { return IsAsyncEnabled; }
-
void reportDeviceInfo() const;
/// Create an immediate command list.
@@ -416,23 +373,60 @@ class L0DeviceTy final : public GenericDeviceTy {
return createImmCmdList(getComputeEngine(), getComputeIndex(), InOrder);
}
- /// Create an immediate command list for copying.
- Expected<ze_command_list_handle_t> createImmCopyCmdList();
- Expected<ze_command_list_handle_t> getImmCmdList();
- Expected<ze_command_list_handle_t> getImmCopyCmdList();
+ /// Release an immediate command list.
+ Error releaseImmCmdList(ze_command_list_handle_t CmdList) {
+ CALL_ZE_RET_ERROR(zeCommandListDestroy, CmdList);
+ return Plugin::success();
+ }
- /// Enqueue copy command.
- Error enqueueMemCopy(void *Dst, const void *Src, size_t Size,
- __tgt_async_info *AsyncInfo = nullptr,
- bool UseCopyEngine = true);
+ Expected<L0CmdListManagerTy *> getCmdListManager(bool InOrder = false) {
+ auto CmdListOrErr = createImmCmdList(InOrder);
+ if (!CmdListOrErr)
+ return CmdListOrErr.takeError();
+ return new L0CmdListManagerTy(*CmdListOrErr);
+ }
- /// Enqueue asynchronous copy command.
- Error enqueueMemCopyAsync(void *Dst, const void *Src, size_t Size,
- __tgt_async_info *AsyncInfo, bool CopyTo = true);
+ Error releaseCmdListManager(L0CmdListManagerTy *CmndListMngr) {
+ if (CmndListMngr) {
+ auto CmdList = CmndListMngr->getCmdList();
+ CALL_ZE_RET_ERROR(zeCommandListDestroy, CmdList);
+ delete CmndListMngr;
+ }
+ return Plugin::success();
+ }
+
+ /// Enqueue non-blocking memory copy.
+ Error enqueueMemCopy(void *Dst, const void *Src, size_t Size,
+ __tgt_async_info *AsyncInfo) {
+ auto QueueOrErr = getOrCreateQueue(AsyncInfo);
+ if (!QueueOrErr)
+ return QueueOrErr.takeError();
+ AsyncQue...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/199684
More information about the llvm-commits
mailing list