1010
1111#include " command_list_cache.hpp"
1212
13- #include " context.hpp"
14- #include " device.hpp"
13+ #include " ../ context.hpp"
14+ #include " ../ device.hpp"
1515
1616bool v2::immediate_command_list_descriptor_t ::operator ==(
1717 const immediate_command_list_descriptor_t &rhs) const {
@@ -76,7 +76,8 @@ command_list_cache_t::createCommandList(const command_list_descriptor_t &desc) {
7676 }
7777}
7878
79- raii::ze_command_list_t command_list_cache_t::getImmediateCommandList (
79+ raii::cache_borrowed_command_list_t
80+ command_list_cache_t::getImmediateCommandList (
8081 ze_device_handle_t ZeDevice, bool IsInOrder, uint32_t Ordinal,
8182 ze_command_queue_mode_t Mode, ze_command_queue_priority_t Priority,
8283 std::optional<uint32_t > Index) {
@@ -87,41 +88,29 @@ raii::ze_command_list_t command_list_cache_t::getImmediateCommandList(
8788 Desc.Mode = Mode;
8889 Desc.Priority = Priority;
8990 Desc.Index = Index;
90- return getCommandList (Desc);
91+
92+ auto CommandList = getCommandList (Desc).release ();
93+ return raii::cache_borrowed_command_list_t (
94+ CommandList, [Cache = this , Desc](ze_command_list_handle_t CmdList) {
95+ Cache->addCommandList (
96+ Desc, raii::ze_command_list_t (CmdList, &zeCommandListDestroy));
97+ });
9198}
9299
93- raii::ze_command_list_t
100+ raii::cache_borrowed_command_list_t
94101command_list_cache_t::getRegularCommandList (ze_device_handle_t ZeDevice,
95102 bool IsInOrder, uint32_t Ordinal) {
96103 regular_command_list_descriptor_t Desc;
97104 Desc.ZeDevice = ZeDevice;
98105 Desc.IsInOrder = IsInOrder;
99106 Desc.Ordinal = Ordinal;
100- return getCommandList (Desc);
101- }
102107
103- void command_list_cache_t::addImmediateCommandList (
104- raii::ze_command_list_t cmdList, ze_device_handle_t ZeDevice,
105- bool IsInOrder, uint32_t Ordinal, ze_command_queue_mode_t Mode,
106- ze_command_queue_priority_t Priority, std::optional<uint32_t > Index) {
107- immediate_command_list_descriptor_t Desc;
108- Desc.ZeDevice = ZeDevice;
109- Desc.Ordinal = Ordinal;
110- Desc.IsInOrder = IsInOrder;
111- Desc.Mode = Mode;
112- Desc.Priority = Priority;
113- Desc.Index = Index;
114- addCommandList (Desc, std::move (cmdList));
115- }
116-
117- void command_list_cache_t::addRegularCommandList (
118- raii::ze_command_list_t cmdList, ze_device_handle_t ZeDevice,
119- bool IsInOrder, uint32_t Ordinal) {
120- regular_command_list_descriptor_t Desc;
121- Desc.ZeDevice = ZeDevice;
122- Desc.IsInOrder = IsInOrder;
123- Desc.Ordinal = Ordinal;
124- addCommandList (Desc, std::move (cmdList));
108+ auto CommandList = getCommandList (Desc).release ();
109+ return raii::cache_borrowed_command_list_t (
110+ CommandList, [Cache = this , Desc](ze_command_list_handle_t CmdList) {
111+ Cache->addCommandList (
112+ Desc, raii::ze_command_list_t (CmdList, &zeCommandListDestroy));
113+ });
125114}
126115
127116raii::ze_command_list_t
@@ -151,4 +140,25 @@ void command_list_cache_t::addCommandList(const command_list_descriptor_t &desc,
151140 auto [it, _] = ZeCommandListCache.try_emplace (desc);
152141 it->second .emplace (std::move (cmdList));
153142}
143+
144+ size_t command_list_cache_t::getNumImmediateCommandLists () {
145+ std::unique_lock<ur_mutex> Lock (ZeCommandListCacheMutex);
146+ size_t NumLists = 0 ;
147+ for (auto &Pair : ZeCommandListCache) {
148+ if (std::holds_alternative<immediate_command_list_descriptor_t >(Pair.first ))
149+ NumLists += Pair.second .size ();
150+ }
151+ return NumLists;
152+ }
153+
154+ size_t command_list_cache_t::getNumRegularCommandLists () {
155+ std::unique_lock<ur_mutex> Lock (ZeCommandListCacheMutex);
156+ size_t NumLists = 0 ;
157+ for (auto &Pair : ZeCommandListCache) {
158+ if (std::holds_alternative<regular_command_list_descriptor_t >(Pair.first ))
159+ NumLists += Pair.second .size ();
160+ }
161+ return NumLists;
162+ }
163+
154164} // namespace v2
0 commit comments