1515#include < map>
1616#include < string>
1717#include < unordered_set>
18+ #include < vector>
1819
1920struct CommandListCacheTest : public uur ::urContextTest {};
2021
@@ -30,35 +31,28 @@ TEST_P(CommandListCacheTest, CanStoreAndRetriveImmediateAndRegularCmdLists) {
3031 ze_command_queue_priority_t Priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL;
3132
3233 static constexpr int numListsPerType = 3 ;
34+ std::vector<v2::raii::cache_borrowed_command_list_t > regCmdListOwners;
35+ std::vector<v2::raii::cache_borrowed_command_list_t > immCmdListOwners;
36+
3337 std::unordered_set<ze_command_list_handle_t > regCmdLists;
3438 std::unordered_set<ze_command_list_handle_t > immCmdLists;
3539
3640 // get command lists from the cache
3741 for (int i = 0 ; i < numListsPerType; ++i) {
38- auto [it, _] = regCmdLists. emplace (
39- cache.getRegularCommandList (device->ZeDevice , IsInOrder, Ordinal)
40- . release ());
42+ regCmdListOwners. emplace_back (
43+ cache.getRegularCommandList (device->ZeDevice , IsInOrder, Ordinal));
44+ auto [it, _] = regCmdLists. emplace (regCmdListOwners. back (). get ());
4145 ASSERT_TRUE (*it != nullptr );
4246
43- std::tie (it, _) = immCmdLists.emplace (
44- cache
45- .getImmediateCommandList (device->ZeDevice , IsInOrder, Ordinal,
46- Mode, Priority)
47- .release ());
47+ immCmdListOwners.emplace_back (cache.getImmediateCommandList (
48+ device->ZeDevice , IsInOrder, Ordinal, Mode, Priority));
49+ std::tie (it, _) = immCmdLists.emplace (immCmdListOwners.back ().get ());
4850 ASSERT_TRUE (*it != nullptr );
4951 }
5052
5153 // store them back into the cache
52- for (auto cmdList : regCmdLists) {
53- cache.addRegularCommandList (
54- v2::raii::ze_command_list_t (cmdList, &zeCommandListDestroy),
55- device->ZeDevice , IsInOrder, Ordinal);
56- }
57- for (auto cmdList : immCmdLists) {
58- cache.addImmediateCommandList (
59- v2::raii::ze_command_list_t (cmdList, &zeCommandListDestroy),
60- device->ZeDevice , IsInOrder, Ordinal, Mode, Priority);
61- }
54+ regCmdListOwners.clear ();
55+ immCmdListOwners.clear ();
6256
6357 // verify we get back the same command lists
6458 for (int i = 0 ; i < numListsPerType; ++i) {
@@ -72,6 +66,10 @@ TEST_P(CommandListCacheTest, CanStoreAndRetriveImmediateAndRegularCmdLists) {
7266
7367 ASSERT_EQ (regCmdLists.erase (regCmdList.get ()), 1 );
7468 ASSERT_EQ (immCmdLists.erase (immCmdList.get ()), 1 );
69+
70+ // release the command list manually so they are not added back to the cache
71+ zeCommandListDestroy (regCmdList.release ());
72+ zeCommandListDestroy (immCmdList.release ());
7573 }
7674}
7775
@@ -131,11 +129,6 @@ TEST_P(CommandListCacheTest, ImmediateCommandListsHaveProperAttributes) {
131129 } else {
132130 ASSERT_EQ (Ret, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
133131 }
134-
135- // store the list back to the cache
136- cache.addImmediateCommandList (std::move (CommandList),
137- device->ZeDevice , IsInOrder, Ordinal,
138- Mode, Priority, Index);
139132 }
140133
141134 // verify list creation without an index
0 commit comments