1 /*
2 * Copyright (C) 2020-2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/test/common/cmd_parse/gen_cmd_parse.h"
9 #include "shared/test/common/mocks/mock_graphics_allocation.h"
10 #include "shared/test/common/mocks/mock_memory_manager.h"
11 #include "shared/test/common/test_macros/test.h"
12
13 #include "level_zero/core/source/image/image_hw.h"
14 #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
15 #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
16 #include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
17
18 namespace L0 {
19 namespace ult {
20
21 struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandListCreateNegativeTestL0::ult::MemoryManagerCommandListCreateNegativeTest22 MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
allocateGraphicsMemoryWithPropertiesL0::ult::MemoryManagerCommandListCreateNegativeTest23 NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
24 if (forceFailureInPrimaryAllocation) {
25 return nullptr;
26 }
27 return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
28 }
29 bool forceFailureInPrimaryAllocation = false;
30 };
31
32 struct CommandListCreateNegativeTest : public ::testing::Test {
SetUpL0::ult::CommandListCreateNegativeTest33 void SetUp() override {
34 executionEnvironment = new NEO::ExecutionEnvironment();
35 executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
36 for (uint32_t i = 0; i < numRootDevices; i++) {
37 executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
38 }
39
40 memoryManager = new MemoryManagerCommandListCreateNegativeTest(*executionEnvironment);
41 executionEnvironment->memoryManager.reset(memoryManager);
42
43 std::vector<std::unique_ptr<NEO::Device>> devices;
44 for (uint32_t i = 0; i < numRootDevices; i++) {
45 neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
46 devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
47 }
48
49 driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
50 driverHandle->initialize(std::move(devices));
51
52 device = driverHandle->devices[0];
53 }
TearDownL0::ult::CommandListCreateNegativeTest54 void TearDown() override {
55 }
56
57 NEO::ExecutionEnvironment *executionEnvironment = nullptr;
58 std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
59 NEO::MockDevice *neoDevice = nullptr;
60 L0::Device *device = nullptr;
61 MemoryManagerCommandListCreateNegativeTest *memoryManager = nullptr;
62 const uint32_t numRootDevices = 1u;
63 };
64
TEST_F(CommandListCreateNegativeTest,whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned)65 TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned) {
66 ze_result_t returnValue;
67 memoryManager->forceFailureInPrimaryAllocation = true;
68 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
69 EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
70 ASSERT_EQ(nullptr, commandList);
71 }
72
TEST_F(CommandListCreateNegativeTest,whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned)73 TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned) {
74 ze_result_t returnValue;
75 const ze_command_queue_desc_t desc = {};
76 bool internalEngine = true;
77 memoryManager->forceFailureInPrimaryAllocation = true;
78 std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily,
79 device,
80 &desc,
81 internalEngine,
82 NEO::EngineGroupType::RenderCompute,
83 returnValue));
84 EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
85 ASSERT_EQ(nullptr, commandList);
86 }
87
88 using CommandListCreate = Test<DeviceFixture>;
89
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenGettingAllocInRangeThenAllocFromMapReturned,IsAtLeastSkl)90 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGettingAllocInRangeThenAllocFromMapReturned, IsAtLeastSkl) {
91 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
92 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
93 uint64_t gpuAddress = 0x1200;
94 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
95 size_t allocSize = 0x1000;
96 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
97 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
98 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
99
100 auto newBufferPtr = ptrOffset(cpuPtr, 0x10);
101 auto newBufferSize = allocSize - 0x20;
102 auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
103 EXPECT_NE(newAlloc, nullptr);
104 commandList->hostPtrMap.clear();
105 }
106
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenSizeIsOutOfRangeThenNullPtrReturned,IsAtLeastSkl)107 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenSizeIsOutOfRangeThenNullPtrReturned, IsAtLeastSkl) {
108 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
109 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
110 uint64_t gpuAddress = 0x1200;
111 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
112 size_t allocSize = 0x1000;
113 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
114 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
115 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
116
117 auto newBufferPtr = ptrOffset(cpuPtr, 0x10);
118 auto newBufferSize = allocSize + 0x20;
119 auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
120 EXPECT_EQ(newAlloc, nullptr);
121 commandList->hostPtrMap.clear();
122 }
123
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenPtrIsOutOfRangeThenNullPtrReturned,IsAtLeastSkl)124 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsOutOfRangeThenNullPtrReturned, IsAtLeastSkl) {
125 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
126 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
127 uint64_t gpuAddress = 0x1200;
128 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
129 size_t allocSize = 0x1000;
130 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
131 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
132 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
133
134 auto newBufferPtr = reinterpret_cast<const void *>(gpuAddress - 0x100);
135 auto newBufferSize = allocSize - 0x200;
136 auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
137 EXPECT_EQ(newAlloc, nullptr);
138 commandList->hostPtrMap.clear();
139 }
140
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenGetHostPtrAllocCalledThenCorrectOffsetIsSet,IsAtLeastSkl)141 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGetHostPtrAllocCalledThenCorrectOffsetIsSet, IsAtLeastSkl) {
142 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
143 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
144 uint64_t gpuAddress = 0x1200;
145 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
146 size_t allocSize = 0x1000;
147 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
148 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
149 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
150
151 size_t expectedOffset = 0x10;
152 auto newBufferPtr = ptrOffset(cpuPtr, expectedOffset);
153 auto newBufferSize = allocSize - 0x20;
154 auto newAlloc = commandList->getHostPtrAlloc(newBufferPtr, newBufferSize, false);
155 EXPECT_NE(nullptr, newAlloc);
156 commandList->hostPtrMap.clear();
157 }
158
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenPtrIsInMapThenAllocationReturned,IsAtLeastSkl)159 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapThenAllocationReturned, IsAtLeastSkl) {
160 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
161 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
162 uint64_t gpuAddress = 0x1200;
163 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
164 size_t allocSize = 0x1000;
165 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
166 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
167 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
168
169 auto newBufferPtr = cpuPtr;
170 auto newBufferSize = allocSize - 0x20;
171 auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
172 EXPECT_EQ(newAlloc, &alloc);
173 commandList->hostPtrMap.clear();
174 }
175
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenPtrIsInMapButWithBiggerSizeThenNullPtrReturned,IsAtLeastSkl)176 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapButWithBiggerSizeThenNullPtrReturned, IsAtLeastSkl) {
177 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
178 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
179 uint64_t gpuAddress = 0x1200;
180 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
181 size_t allocSize = 0x1000;
182 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
183 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
184 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
185
186 auto newBufferPtr = cpuPtr;
187 auto newBufferSize = allocSize + 0x20;
188 auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
189 EXPECT_EQ(newAlloc, nullptr);
190 commandList->hostPtrMap.clear();
191 }
192
HWTEST2_F(CommandListCreate,givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNullPtrReturned,IsAtLeastSkl)193 HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNullPtrReturned, IsAtLeastSkl) {
194 auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
195 commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
196 uint64_t gpuAddress = 0x1200;
197 const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
198 size_t allocSize = 0x1000;
199 NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
200 commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
201 EXPECT_EQ(commandList->getHostPtrMap().size(), 1u);
202
203 auto newBufferPtr = reinterpret_cast<const void *>(gpuAddress - 0x10);
204 auto newBufferSize = allocSize - 0x20;
205 auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
206 EXPECT_EQ(newAlloc, nullptr);
207 commandList->hostPtrMap.clear();
208 }
209
HWTEST2_F(CommandListCreate,givenCmdListHostPointerUsedWhenGettingAlignedAllocationThenRetrieveProperOffsetAndAddress,IsAtLeastSkl)210 HWTEST2_F(CommandListCreate,
211 givenCmdListHostPointerUsedWhenGettingAlignedAllocationThenRetrieveProperOffsetAndAddress,
212 IsAtLeastSkl) {
213 auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
214 commandList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
215
216 size_t cmdListHostPtrSize = MemoryConstants::pageSize;
217 void *cmdListHostBuffer = device->getNEODevice()->getMemoryManager()->allocateSystemMemory(cmdListHostPtrSize, cmdListHostPtrSize);
218 void *startMemory = cmdListHostBuffer;
219 void *baseAddress = alignDown(startMemory, MemoryConstants::pageSize);
220 size_t expectedOffset = ptrDiff(startMemory, baseAddress);
221
222 AlignedAllocationData outData = commandList->getAlignedAllocation(device, startMemory, cmdListHostPtrSize, false);
223 ASSERT_NE(nullptr, outData.alloc);
224 auto firstAlloc = outData.alloc;
225 auto expectedGpuAddress = static_cast<uintptr_t>(alignDown(outData.alloc->getGpuAddress(), MemoryConstants::pageSize));
226 EXPECT_EQ(startMemory, outData.alloc->getUnderlyingBuffer());
227 EXPECT_EQ(expectedGpuAddress, outData.alignedAllocationPtr);
228 EXPECT_EQ(expectedOffset, outData.offset);
229
230 size_t offset = 0x21u;
231 void *offsetMemory = ptrOffset(startMemory, offset);
232 expectedOffset = ptrDiff(offsetMemory, baseAddress);
233 EXPECT_EQ(outData.offset + offset, expectedOffset);
234
235 outData = commandList->getAlignedAllocation(device, offsetMemory, 4u, false);
236 ASSERT_NE(nullptr, outData.alloc);
237 EXPECT_EQ(firstAlloc, outData.alloc);
238 EXPECT_EQ(startMemory, outData.alloc->getUnderlyingBuffer());
239 EXPECT_EQ(expectedGpuAddress, outData.alignedAllocationPtr);
240 EXPECT_EQ((expectedOffset & (EncodeSurfaceState<FamilyType>::getSurfaceBaseAddressAlignment() - 1)), outData.offset);
241
242 commandList->removeHostPtrAllocations();
243 device->getNEODevice()->getMemoryManager()->freeSystemMemory(cmdListHostBuffer);
244 }
245
246 using PlatformSupport = IsWithinProducts<IGFX_SKYLAKE, IGFX_ICELAKE>;
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryCopyRegionHavingHostMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound,PlatformSupport)247 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionHavingHostMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound, PlatformSupport) {
248 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
249
250 ze_result_t result = ZE_RESULT_SUCCESS;
251 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
252 auto &commandContainer = commandList->commandContainer;
253
254 void *srcBuffer = reinterpret_cast<void *>(0x1234);
255 void *dstBuffer = reinterpret_cast<void *>(0x2345);
256 uint32_t width = 16;
257 uint32_t height = 16;
258
259 ze_event_pool_desc_t eventPoolDesc = {};
260 eventPoolDesc.count = 2;
261 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
262 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
263 std::vector<ze_event_handle_t> events;
264
265 ze_event_desc_t eventDesc = {};
266 eventDesc.index = 0;
267 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
268 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
269 events.push_back(event.get());
270 eventDesc.index = 1;
271 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
272 events.push_back(event1.get());
273
274 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
275 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
276 result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
277 srcBuffer, &sr, width, 0, events[0], 1u, &events[1]);
278 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
279
280 GenCmdList cmdList;
281 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
282 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
283
284 auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
285 EXPECT_NE(cmdList.end(), itor);
286 itor++;
287 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
288 EXPECT_NE(cmdList.end(), itor);
289 itor++;
290 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
291 EXPECT_NE(cmdList.end(), itor);
292 itor++;
293 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
294 EXPECT_NE(cmdList.end(), itor);
295 itor++;
296 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
297 EXPECT_NE(cmdList.end(), itor);
298 itor++;
299 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
300 EXPECT_NE(cmdList.end(), itor);
301 itor++;
302 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
303 EXPECT_NE(cmdList.end(), itor);
304 itor++;
305 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
306 EXPECT_EQ(cmdList.end(), itor);
307 }
308
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryCopyRegionHavingDeviceMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsNotFound,PlatformSupport)309 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionHavingDeviceMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsNotFound, PlatformSupport) {
310 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
311
312 ze_result_t result = ZE_RESULT_SUCCESS;
313 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
314 auto &commandContainer = commandList->commandContainer;
315
316 void *srcBuffer = nullptr;
317 void *dstBuffer = nullptr;
318 ze_device_mem_alloc_desc_t deviceDesc = {};
319 result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &srcBuffer);
320 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
321 result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &dstBuffer);
322 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
323
324 uint32_t width = 16;
325 uint32_t height = 16;
326
327 ze_event_pool_desc_t eventPoolDesc = {};
328 eventPoolDesc.count = 2;
329 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
330 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
331 std::vector<ze_event_handle_t> events;
332
333 ze_event_desc_t eventDesc = {};
334 eventDesc.index = 0;
335 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
336 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
337 events.push_back(event.get());
338 eventDesc.index = 1;
339 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
340 events.push_back(event1.get());
341
342 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
343 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
344 result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
345 srcBuffer, &sr, width, 0, events[0], 1u, &events[1]);
346 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
347
348 GenCmdList cmdList;
349 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
350 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
351
352 auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
353 EXPECT_NE(cmdList.end(), itor);
354 itor++;
355 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
356 EXPECT_NE(cmdList.end(), itor);
357 itor++;
358 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
359 EXPECT_NE(cmdList.end(), itor);
360 itor++;
361 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
362 EXPECT_NE(cmdList.end(), itor);
363 itor++;
364 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
365 EXPECT_NE(cmdList.end(), itor);
366 itor++;
367 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
368 EXPECT_NE(cmdList.end(), itor);
369 itor++;
370 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
371 EXPECT_EQ(cmdList.end(), itor);
372
373 context->freeMem(srcBuffer);
374 context->freeMem(dstBuffer);
375 }
376
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryFillHavingDeviceMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsNotFound,PlatformSupport)377 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryFillHavingDeviceMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsNotFound, PlatformSupport) {
378 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
379
380 ze_result_t result = ZE_RESULT_SUCCESS;
381 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
382 auto &commandContainer = commandList->commandContainer;
383
384 void *dstBuffer = nullptr;
385 ze_device_mem_alloc_desc_t deviceDesc = {};
386 result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &dstBuffer);
387 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
388
389 ze_event_pool_desc_t eventPoolDesc = {};
390 eventPoolDesc.count = 2;
391 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
392 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
393 std::vector<ze_event_handle_t> events;
394
395 ze_event_desc_t eventDesc = {};
396 eventDesc.index = 0;
397 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
398 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
399 events.push_back(event.get());
400 eventDesc.index = 1;
401 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
402 events.push_back(event1.get());
403
404 int one = 1;
405 result = commandList->appendMemoryFill(dstBuffer, reinterpret_cast<void *>(&one), sizeof(one), 4096u,
406 events[0], 1u, &events[1]);
407 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
408
409 GenCmdList cmdList;
410 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
411 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
412
413 auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
414 EXPECT_NE(cmdList.end(), itor);
415 itor++;
416 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
417 EXPECT_NE(cmdList.end(), itor);
418 itor++;
419 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
420 EXPECT_NE(cmdList.end(), itor);
421 itor++;
422 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
423 EXPECT_NE(cmdList.end(), itor);
424 itor++;
425 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
426 EXPECT_NE(cmdList.end(), itor);
427 itor++;
428 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
429 EXPECT_NE(cmdList.end(), itor);
430 itor++;
431 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
432 EXPECT_EQ(cmdList.end(), itor);
433
434 context->freeMem(dstBuffer);
435 }
436
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryFillHavingSharedMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound,PlatformSupport)437 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryFillHavingSharedMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound, PlatformSupport) {
438 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
439
440 ze_result_t result = ZE_RESULT_SUCCESS;
441 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
442 auto &commandContainer = commandList->commandContainer;
443
444 void *dstBuffer = nullptr;
445 ze_device_mem_alloc_desc_t deviceDesc = {};
446 ze_host_mem_alloc_desc_t hostDesc = {};
447 result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, 16384u, 4096u, &dstBuffer);
448 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
449
450 ze_event_pool_desc_t eventPoolDesc = {};
451 eventPoolDesc.count = 2;
452 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
453 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
454 std::vector<ze_event_handle_t> events;
455
456 ze_event_desc_t eventDesc = {};
457 eventDesc.index = 0;
458 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
459 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
460 events.push_back(event.get());
461 eventDesc.index = 1;
462 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
463 events.push_back(event1.get());
464
465 int one = 1;
466 result = commandList->appendMemoryFill(dstBuffer, reinterpret_cast<void *>(&one), sizeof(one), 4096u,
467 events[0], 1u, &events[1]);
468 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
469
470 GenCmdList cmdList;
471 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
472 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
473
474 auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
475 EXPECT_NE(cmdList.end(), itor);
476 itor++;
477 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
478 EXPECT_NE(cmdList.end(), itor);
479 itor++;
480 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
481 EXPECT_NE(cmdList.end(), itor);
482 itor++;
483 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
484 EXPECT_NE(cmdList.end(), itor);
485 itor++;
486 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
487 EXPECT_NE(cmdList.end(), itor);
488 itor++;
489 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
490 EXPECT_NE(cmdList.end(), itor);
491 itor++;
492 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
493 EXPECT_NE(cmdList.end(), itor);
494 itor++;
495 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
496 EXPECT_EQ(cmdList.end(), itor);
497
498 context->freeMem(dstBuffer);
499 }
500
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryFillHavingHostMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound,PlatformSupport)501 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryFillHavingHostMemoryWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound, PlatformSupport) {
502 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
503
504 ze_result_t result = ZE_RESULT_SUCCESS;
505 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
506 auto &commandContainer = commandList->commandContainer;
507
508 void *dstBuffer = nullptr;
509 ze_host_mem_alloc_desc_t hostDesc = {};
510 result = context->allocHostMem(&hostDesc, 16384u, 4090u, &dstBuffer);
511 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
512
513 ze_event_pool_desc_t eventPoolDesc = {};
514 eventPoolDesc.count = 2;
515 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
516 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
517 std::vector<ze_event_handle_t> events;
518
519 ze_event_desc_t eventDesc = {};
520 eventDesc.index = 0;
521 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
522 eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
523 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
524 events.push_back(event.get());
525 eventDesc.index = 1;
526 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
527 events.push_back(event1.get());
528
529 int one = 1;
530 result = commandList->appendMemoryFill(dstBuffer, reinterpret_cast<void *>(&one), sizeof(one), 4090u,
531 events[0], 1u, &events[1]);
532 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
533
534 GenCmdList cmdList;
535 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
536 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
537
538 auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
539 EXPECT_NE(cmdList.end(), itor);
540 itor++;
541 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
542 EXPECT_NE(cmdList.end(), itor);
543 itor++;
544 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
545 EXPECT_NE(cmdList.end(), itor);
546 itor++;
547 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
548 EXPECT_NE(cmdList.end(), itor);
549 itor++;
550 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
551 EXPECT_NE(cmdList.end(), itor);
552 itor++;
553 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
554 EXPECT_NE(cmdList.end(), itor);
555 itor++;
556 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
557 EXPECT_EQ(cmdList.end(), itor);
558
559 context->freeMem(dstBuffer);
560 }
561
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryFillHavingEventsWithDeviceScopeThenPCDueToWaitEventIsAddedAndPCDueToSignalEventIsAddedWithDCFlush,PlatformSupport)562 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryFillHavingEventsWithDeviceScopeThenPCDueToWaitEventIsAddedAndPCDueToSignalEventIsAddedWithDCFlush, PlatformSupport) {
563 using SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
564 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
565
566 ze_result_t result = ZE_RESULT_SUCCESS;
567 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
568 auto &commandContainer = commandList->commandContainer;
569
570 void *dstBuffer = nullptr;
571 ze_host_mem_alloc_desc_t hostDesc = {};
572 result = context->allocHostMem(&hostDesc, 16384u, 4090u, &dstBuffer);
573 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
574
575 ze_event_pool_desc_t eventPoolDesc = {};
576 eventPoolDesc.count = 2;
577 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
578 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
579 std::vector<ze_event_handle_t> events;
580
581 ze_event_desc_t eventDesc = {};
582 eventDesc.index = 0;
583 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_DEVICE;
584 eventDesc.signal = ZE_EVENT_SCOPE_FLAG_DEVICE;
585 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
586 events.push_back(event.get());
587 eventDesc.index = 1;
588 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
589 events.push_back(event1.get());
590
591 int one = 1;
592 result = commandList->appendMemoryFill(dstBuffer, reinterpret_cast<void *>(&one), sizeof(one), 4090u,
593 events[0], 1u, &events[1]);
594 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
595
596 GenCmdList cmdList;
597 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
598 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
599
600 auto itor = find<SEMAPHORE_WAIT *>(cmdList.begin(), cmdList.end());
601 EXPECT_NE(cmdList.end(), itor);
602 itor++;
603 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
604 EXPECT_NE(cmdList.end(), itor);
605 itor++;
606 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
607 EXPECT_NE(cmdList.end(), itor);
608 itor++;
609 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
610 EXPECT_NE(cmdList.end(), itor);
611 auto cmd = genCmdCast<PIPE_CONTROL *>(*itor);
612 EXPECT_TRUE(cmd->getDcFlushEnable());
613
614 context->freeMem(dstBuffer);
615 }
616
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryFillHavingEventsWithDeviceScopeThenPCDueToWaitEventIsNotAddedAndPCDueToSignalEventIsAddedWithOutDCFlush,PlatformSupport)617 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryFillHavingEventsWithDeviceScopeThenPCDueToWaitEventIsNotAddedAndPCDueToSignalEventIsAddedWithOutDCFlush, PlatformSupport) {
618 using SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
619 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
620
621 ze_result_t result = ZE_RESULT_SUCCESS;
622 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
623 auto &commandContainer = commandList->commandContainer;
624
625 void *dstBuffer = nullptr;
626 ze_host_mem_alloc_desc_t hostDesc = {};
627 result = context->allocHostMem(&hostDesc, 16384u, 4090u, &dstBuffer);
628 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
629
630 ze_event_pool_desc_t eventPoolDesc = {};
631 eventPoolDesc.count = 2;
632 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
633 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
634 std::vector<ze_event_handle_t> events;
635
636 ze_event_desc_t eventDesc = {};
637 eventDesc.index = 0;
638 eventDesc.wait = 0;
639 eventDesc.signal = 0;
640 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
641 events.push_back(event.get());
642 eventDesc.index = 1;
643 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
644 events.push_back(event1.get());
645
646 int one = 1;
647 result = commandList->appendMemoryFill(dstBuffer, reinterpret_cast<void *>(&one), sizeof(one), 4090u,
648 events[0], 1u, &events[1]);
649 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
650
651 GenCmdList cmdList;
652 ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
653 cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
654
655 auto itor = find<SEMAPHORE_WAIT *>(cmdList.begin(), cmdList.end());
656 EXPECT_NE(cmdList.end(), itor);
657 itor++;
658 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
659 EXPECT_NE(cmdList.end(), itor);
660 itor++;
661 itor = find<PIPE_CONTROL *>(itor, cmdList.end());
662 EXPECT_NE(cmdList.end(), itor);
663 auto cmd = genCmdCast<PIPE_CONTROL *>(*itor);
664 EXPECT_FALSE(cmd->getDcFlushEnable());
665
666 context->freeMem(dstBuffer);
667 }
668
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned,IsAtLeastSkl)669 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, IsAtLeastSkl) {
670 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
671
672 ze_result_t result = ZE_RESULT_SUCCESS;
673 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, 0u, result));
674
675 void *srcBuffer = reinterpret_cast<void *>(0x1234);
676 void *dstBuffer = reinterpret_cast<void *>(0x2345);
677 uint32_t width = 16;
678 uint32_t height = 16;
679
680 ze_event_pool_desc_t eventPoolDesc = {};
681 eventPoolDesc.count = 2;
682 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
683 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
684 std::vector<ze_event_handle_t> events;
685
686 ze_event_desc_t eventDesc = {};
687 eventDesc.index = 0;
688 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
689 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
690 events.push_back(event.get());
691 eventDesc.index = 1;
692 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
693 events.push_back(event1.get());
694
695 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
696 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
697 result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
698 srcBuffer, &sr, width, 0, events[0], 1u, &events[1]);
699 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
700 }
701
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryCopyRegionWithSignalAndInvalidWaitHandleUsingCopyEngineThenErrorIsReturned,IsAtLeastSkl)702 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionWithSignalAndInvalidWaitHandleUsingCopyEngineThenErrorIsReturned, IsAtLeastSkl) {
703 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
704
705 ze_result_t result = ZE_RESULT_SUCCESS;
706 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, 0u, result));
707
708 void *srcBuffer = reinterpret_cast<void *>(0x1234);
709 void *dstBuffer = reinterpret_cast<void *>(0x2345);
710 uint32_t width = 16;
711 uint32_t height = 16;
712
713 ze_event_pool_desc_t eventPoolDesc = {};
714 eventPoolDesc.count = 2;
715 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
716 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
717 std::vector<ze_event_handle_t> events;
718
719 ze_event_desc_t eventDesc = {};
720 eventDesc.index = 0;
721 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
722 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
723 events.push_back(event.get());
724 eventDesc.index = 1;
725 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
726 events.push_back(event1.get());
727
728 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
729 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
730 result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
731 srcBuffer, &sr, width, 0, events[0], 1u, nullptr);
732 EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
733 }
734
HWTEST2_F(CommandListCreate,givenCommandListWhenMemoryCopyRegionHasEmptyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned,IsAtLeastSkl)735 HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionHasEmptyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, IsAtLeastSkl) {
736 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
737
738 ze_result_t result = ZE_RESULT_SUCCESS;
739 std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, 0u, result));
740
741 void *srcBuffer = reinterpret_cast<void *>(0x1234);
742 void *dstBuffer = reinterpret_cast<void *>(0x2345);
743
744 ze_event_pool_desc_t eventPoolDesc = {};
745 eventPoolDesc.count = 2;
746 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
747 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
748 std::vector<ze_event_handle_t> events;
749
750 ze_event_desc_t eventDesc = {};
751 eventDesc.index = 0;
752 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
753 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
754 events.push_back(event.get());
755 eventDesc.index = 1;
756 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
757 events.push_back(event1.get());
758
759 // set regions to 0
760 ze_copy_region_t sr = {0U, 0U, 0U, 0U, 0U, 0U};
761 ze_copy_region_t dr = {0U, 0U, 0U, 0U, 0U, 0U};
762 result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, 0, 0,
763 srcBuffer, &sr, 0, 0, events[0], 1u, &events[1]);
764 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
765 }
766
HWTEST2_F(CommandListCreate,givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingRenderEngineThenSuccessIsReturned,IsAtLeastSkl)767 HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingRenderEngineThenSuccessIsReturned, IsAtLeastSkl) {
768 const ze_command_queue_desc_t desc = {};
769 bool internalEngine = true;
770
771 ze_result_t result = ZE_RESULT_SUCCESS;
772 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
773 device,
774 &desc,
775 internalEngine,
776 NEO::EngineGroupType::RenderCompute,
777 result));
778 ASSERT_NE(nullptr, commandList0);
779
780 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
781 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
782
783 void *srcBuffer = reinterpret_cast<void *>(0x1234);
784 void *dstBuffer = reinterpret_cast<void *>(0x2345);
785 uint32_t width = 16;
786 uint32_t height = 16;
787
788 ze_event_pool_desc_t eventPoolDesc = {};
789 eventPoolDesc.count = 2;
790 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
791 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
792 std::vector<ze_event_handle_t> events;
793
794 ze_event_desc_t eventDesc = {};
795 eventDesc.index = 0;
796 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
797 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
798 events.push_back(event.get());
799 eventDesc.index = 1;
800 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
801 events.push_back(event1.get());
802
803 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
804 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
805 result = commandList0->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
806 srcBuffer, &sr, width, 0, events[0], 1u, &events[1]);
807 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
808 }
809
TEST_F(CommandListCreate,givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingRenderEngineInALoopThenSuccessIsReturned)810 TEST_F(CommandListCreate, givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingRenderEngineInALoopThenSuccessIsReturned) {
811 const ze_command_queue_desc_t desc = {};
812 bool internalEngine = true;
813
814 ze_result_t ret = ZE_RESULT_SUCCESS;
815 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
816 device,
817 &desc,
818 internalEngine,
819 NEO::EngineGroupType::RenderCompute,
820 ret));
821 ASSERT_NE(nullptr, commandList0);
822
823 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
824 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
825
826 void *srcBuffer = reinterpret_cast<void *>(0x1234);
827 void *dstBuffer = reinterpret_cast<void *>(0x2345);
828 uint32_t width = 16;
829 uint32_t height = 16;
830
831 ze_event_pool_desc_t eventPoolDesc = {};
832 eventPoolDesc.count = 2;
833 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, ret));
834 EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
835 std::vector<ze_event_handle_t> events;
836
837 ze_event_desc_t eventDesc = {};
838 eventDesc.index = 0;
839 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
840 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
841 events.push_back(event.get());
842 eventDesc.index = 1;
843 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
844 events.push_back(event1.get());
845
846 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
847 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
848
849 for (auto i = 0; i < 2000; i++) {
850 ret = commandList0->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
851 srcBuffer, &sr, width, 0, events[0], 1u, &events[1]);
852 }
853 EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
854 }
855
HWTEST2_F(CommandListCreate,givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned,IsAtLeastSkl)856 HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, IsAtLeastSkl) {
857 const ze_command_queue_desc_t desc = {};
858 bool internalEngine = true;
859
860 ze_result_t returnValue;
861 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
862 device,
863 &desc,
864 internalEngine,
865 NEO::EngineGroupType::Copy,
866 returnValue));
867 ASSERT_NE(nullptr, commandList0);
868
869 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
870 if (neoDevice->getInternalCopyEngine()) {
871 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalCopyEngine()->commandStreamReceiver);
872 } else {
873 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
874 }
875
876 void *srcBuffer = reinterpret_cast<void *>(0x1234);
877 void *dstBuffer = reinterpret_cast<void *>(0x2345);
878 uint32_t width = 16;
879 uint32_t height = 16;
880
881 ze_event_pool_desc_t eventPoolDesc = {};
882 eventPoolDesc.count = 2;
883 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, returnValue));
884 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
885 std::vector<ze_event_handle_t> events;
886
887 ze_event_desc_t eventDesc = {};
888 eventDesc.index = 0;
889 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
890 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
891 events.push_back(event.get());
892 eventDesc.index = 1;
893 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
894 events.push_back(event1.get());
895
896 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
897 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
898 auto result = commandList0->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
899 srcBuffer, &sr, width, 0, events[0], 1u, &events[1]);
900 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
901 }
902
903 struct CommandListCreateWithBcs : public CommandListCreate {
SetUpL0::ult::CommandListCreateWithBcs904 void SetUp() override {
905 VariableBackup<HardwareInfo> backupHwInfo(defaultHwInfo.get());
906 defaultHwInfo->capabilityTable.blitterOperationsSupported = true;
907 CommandListCreate::SetUp();
908 }
909 };
HWTEST2_F(CommandListCreateWithBcs,givenImmediateCommandListWhenCopyRegionFromImageToImageUsingRenderThenSuccessIsReturned,IsAtLeastXeHpCore)910 HWTEST2_F(CommandListCreateWithBcs, givenImmediateCommandListWhenCopyRegionFromImageToImageUsingRenderThenSuccessIsReturned, IsAtLeastXeHpCore) {
911 const ze_command_queue_desc_t queueDesc = {};
912 bool internalEngine = true;
913
914 ze_result_t returnValue;
915 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
916 device,
917 &queueDesc,
918 internalEngine,
919 NEO::EngineGroupType::Copy,
920 returnValue));
921 ASSERT_NE(nullptr, commandList0);
922
923 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
924 if (neoDevice->getInternalCopyEngine()) {
925 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalCopyEngine()->commandStreamReceiver);
926 } else {
927 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
928 }
929
930 ze_image_desc_t desc = {};
931 desc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC;
932 desc.type = ZE_IMAGE_TYPE_3D;
933 desc.format.layout = ZE_IMAGE_FORMAT_LAYOUT_8_8_8_8;
934 desc.format.type = ZE_IMAGE_FORMAT_TYPE_UINT;
935 desc.width = 11;
936 desc.height = 13;
937 desc.depth = 17;
938
939 desc.format.x = ZE_IMAGE_FORMAT_SWIZZLE_A;
940 desc.format.y = ZE_IMAGE_FORMAT_SWIZZLE_0;
941 desc.format.z = ZE_IMAGE_FORMAT_SWIZZLE_1;
942 desc.format.w = ZE_IMAGE_FORMAT_SWIZZLE_X;
943 auto imageHWSrc = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
944 auto imageHWDst = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
945 imageHWSrc->initialize(device, &desc);
946 imageHWDst->initialize(device, &desc);
947
948 ze_image_region_t srcRegion = {4, 4, 4, 2, 2, 2};
949 ze_image_region_t dstRegion = {4, 4, 4, 2, 2, 2};
950 returnValue = commandList0->appendImageCopyRegion(imageHWDst->toHandle(), imageHWSrc->toHandle(), &dstRegion, &srcRegion, nullptr, 0, nullptr);
951 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
952 }
953
HWTEST2_F(CommandListCreateWithBcs,givenImmediateCommandListWhenCopyRegionFromImageToImageUsingCopyWintInvalidRegionArguementsThenErrorIsReturned,IsAtLeastXeHpCore)954 HWTEST2_F(CommandListCreateWithBcs, givenImmediateCommandListWhenCopyRegionFromImageToImageUsingCopyWintInvalidRegionArguementsThenErrorIsReturned, IsAtLeastXeHpCore) {
955 const ze_command_queue_desc_t queueDesc = {};
956 bool internalEngine = true;
957
958 neoDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.blitterOperationsSupported = true;
959 ze_result_t returnValue;
960 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
961 device,
962 &queueDesc,
963 internalEngine,
964 NEO::EngineGroupType::Copy,
965 returnValue));
966 ASSERT_NE(nullptr, commandList0);
967
968 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
969 if (neoDevice->getInternalCopyEngine()) {
970 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalCopyEngine()->commandStreamReceiver);
971 } else {
972 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
973 }
974
975 ze_image_desc_t desc = {};
976 desc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC;
977 desc.type = ZE_IMAGE_TYPE_3D;
978 desc.format.layout = ZE_IMAGE_FORMAT_LAYOUT_8_8_8_8;
979 desc.format.type = ZE_IMAGE_FORMAT_TYPE_UINT;
980 desc.width = 11;
981 desc.height = 13;
982 desc.depth = 17;
983
984 desc.format.x = ZE_IMAGE_FORMAT_SWIZZLE_A;
985 desc.format.y = ZE_IMAGE_FORMAT_SWIZZLE_0;
986 desc.format.z = ZE_IMAGE_FORMAT_SWIZZLE_1;
987 desc.format.w = ZE_IMAGE_FORMAT_SWIZZLE_X;
988
989 auto imageHWSrc = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
990 auto imageHWDst = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
991 imageHWSrc->initialize(device, &desc);
992 imageHWDst->initialize(device, &desc);
993
994 ze_image_region_t srcRegion = {4, 4, 4, 2, 2, 2};
995 ze_image_region_t dstRegion = {2, 2, 2, 4, 4, 4};
996 returnValue = commandList0->appendImageCopyRegion(imageHWDst->toHandle(), imageHWSrc->toHandle(), &dstRegion, &srcRegion, nullptr, 0, nullptr);
997 EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, returnValue);
998 }
999
HWTEST2_F(CommandListCreateWithBcs,givenImmediateCommandListWhenCopyFromImageToImageUsingRenderThenSuccessIsReturned,IsAtLeastXeHpCore)1000 HWTEST2_F(CommandListCreateWithBcs, givenImmediateCommandListWhenCopyFromImageToImageUsingRenderThenSuccessIsReturned, IsAtLeastXeHpCore) {
1001 const ze_command_queue_desc_t queueDesc = {};
1002 bool internalEngine = true;
1003
1004 neoDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.blitterOperationsSupported = true;
1005 ze_result_t returnValue;
1006 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
1007 device,
1008 &queueDesc,
1009 internalEngine,
1010 NEO::EngineGroupType::Copy,
1011 returnValue));
1012 ASSERT_NE(nullptr, commandList0);
1013
1014 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
1015 if (neoDevice->getInternalCopyEngine()) {
1016 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalCopyEngine()->commandStreamReceiver);
1017 } else {
1018 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
1019 }
1020
1021 ze_image_desc_t desc = {};
1022 desc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC;
1023 desc.type = ZE_IMAGE_TYPE_3D;
1024 desc.format.layout = ZE_IMAGE_FORMAT_LAYOUT_8_8_8_8;
1025 desc.format.type = ZE_IMAGE_FORMAT_TYPE_UINT;
1026 desc.width = 11;
1027 desc.height = 13;
1028 desc.depth = 17;
1029
1030 desc.format.x = ZE_IMAGE_FORMAT_SWIZZLE_A;
1031 desc.format.y = ZE_IMAGE_FORMAT_SWIZZLE_0;
1032 desc.format.z = ZE_IMAGE_FORMAT_SWIZZLE_1;
1033 desc.format.w = ZE_IMAGE_FORMAT_SWIZZLE_X;
1034
1035 auto imageHWSrc = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
1036 auto imageHWDst = std::make_unique<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
1037 imageHWSrc->initialize(device, &desc);
1038 imageHWDst->initialize(device, &desc);
1039
1040 returnValue = commandList0->appendImageCopy(imageHWDst->toHandle(), imageHWSrc->toHandle(), nullptr, 0, nullptr);
1041 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
1042 }
1043
HWTEST2_F(CommandListCreateWithBcs,givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndInvalidWaitHandleUsingCopyEngineThenErrorIsReturned,IsAtLeastSkl)1044 HWTEST2_F(CommandListCreateWithBcs, givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndInvalidWaitHandleUsingCopyEngineThenErrorIsReturned, IsAtLeastSkl) {
1045 const ze_command_queue_desc_t desc = {};
1046 bool internalEngine = true;
1047
1048 neoDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.blitterOperationsSupported = true;
1049 ze_result_t result = ZE_RESULT_SUCCESS;
1050 std::unique_ptr<L0::CommandList> commandList0(CommandList::createImmediate(productFamily,
1051 device,
1052 &desc,
1053 internalEngine,
1054 NEO::EngineGroupType::Copy,
1055 result));
1056 ASSERT_NE(nullptr, commandList0);
1057
1058 CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
1059 if (neoDevice->getInternalCopyEngine()) {
1060 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalCopyEngine()->commandStreamReceiver);
1061 } else {
1062 EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
1063 }
1064
1065 void *srcBuffer = reinterpret_cast<void *>(0x1234);
1066 void *dstBuffer = reinterpret_cast<void *>(0x2345);
1067 uint32_t width = 16;
1068 uint32_t height = 16;
1069
1070 ze_event_pool_desc_t eventPoolDesc = {};
1071 eventPoolDesc.count = 2;
1072 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
1073 EXPECT_EQ(ZE_RESULT_SUCCESS, result);
1074 std::vector<ze_event_handle_t> events;
1075
1076 ze_event_desc_t eventDesc = {};
1077 eventDesc.index = 0;
1078 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
1079 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
1080 events.push_back(event.get());
1081 eventDesc.index = 1;
1082 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
1083 events.push_back(event1.get());
1084
1085 ze_copy_region_t sr = {0U, 0U, 0U, width, height, 0U};
1086 ze_copy_region_t dr = {0U, 0U, 0U, width, height, 0U};
1087 result = commandList0->appendMemoryCopyRegion(dstBuffer, &dr, width, 0,
1088 srcBuffer, &sr, width, 0, events[0], 1u, nullptr);
1089 EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
1090 }
1091
TEST_F(CommandListCreate,whenCreatingImmCmdListWithASyncModeAndAppendSignalEventWithTimestampThenUpdateTaskCountNeededFlagIsDisabled)1092 TEST_F(CommandListCreate, whenCreatingImmCmdListWithASyncModeAndAppendSignalEventWithTimestampThenUpdateTaskCountNeededFlagIsDisabled) {
1093 ze_command_queue_desc_t desc = {};
1094 desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
1095 ze_result_t returnValue;
1096 std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue));
1097 ASSERT_NE(nullptr, commandList);
1098
1099 EXPECT_EQ(device, commandList->device);
1100 EXPECT_EQ(1u, commandList->cmdListType);
1101 EXPECT_NE(nullptr, commandList->cmdQImmediate);
1102
1103 ze_event_pool_desc_t eventPoolDesc = {};
1104 eventPoolDesc.count = 1;
1105 eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
1106
1107 ze_event_desc_t eventDesc = {};
1108 eventDesc.index = 0;
1109 eventDesc.signal = 0;
1110 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
1111
1112 ze_event_handle_t event = nullptr;
1113
1114 std::unique_ptr<L0::EventPool> eventPool(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, returnValue));
1115 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
1116 ASSERT_NE(nullptr, eventPool);
1117
1118 eventPool->createEvent(&eventDesc, &event);
1119
1120 std::unique_ptr<L0::Event> event_object(L0::Event::fromHandle(event));
1121 ASSERT_NE(nullptr, event_object->csr);
1122 ASSERT_EQ(device->getNEODevice()->getDefaultEngine().commandStreamReceiver, event_object->csr);
1123
1124 commandList->appendSignalEvent(event);
1125
1126 auto result = event_object->hostSignal();
1127 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
1128
1129 EXPECT_EQ(event_object->queryStatus(), ZE_RESULT_SUCCESS);
1130 }
1131
TEST_F(CommandListCreate,whenCreatingImmCmdListWithASyncModeAndAppendBarrierThenUpdateTaskCountNeededFlagIsDisabled)1132 TEST_F(CommandListCreate, whenCreatingImmCmdListWithASyncModeAndAppendBarrierThenUpdateTaskCountNeededFlagIsDisabled) {
1133 ze_command_queue_desc_t desc = {};
1134 desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
1135 ze_result_t returnValue;
1136 std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue));
1137 ASSERT_NE(nullptr, commandList);
1138
1139 EXPECT_EQ(device, commandList->device);
1140 EXPECT_EQ(1u, commandList->cmdListType);
1141 EXPECT_NE(nullptr, commandList->cmdQImmediate);
1142
1143 ze_event_pool_desc_t eventPoolDesc = {};
1144 eventPoolDesc.count = 1;
1145 eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
1146
1147 ze_event_desc_t eventDesc = {};
1148 eventDesc.index = 0;
1149 eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
1150 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
1151
1152 ze_event_handle_t event = nullptr;
1153
1154 std::unique_ptr<L0::EventPool> eventPool(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, returnValue));
1155 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
1156 ASSERT_NE(nullptr, eventPool);
1157
1158 eventPool->createEvent(&eventDesc, &event);
1159
1160 std::unique_ptr<L0::Event> event_object(L0::Event::fromHandle(event));
1161 ASSERT_NE(nullptr, event_object->csr);
1162 ASSERT_EQ(device->getNEODevice()->getDefaultEngine().commandStreamReceiver, event_object->csr);
1163
1164 commandList->appendBarrier(event, 0, nullptr);
1165
1166 auto result = event_object->hostSignal();
1167 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
1168
1169 EXPECT_EQ(event_object->queryStatus(), ZE_RESULT_SUCCESS);
1170
1171 commandList->appendBarrier(nullptr, 0, nullptr);
1172 }
1173
TEST_F(CommandListCreate,whenCreatingImmCmdListWithASyncModeAndAppendEventResetThenUpdateTaskCountNeededFlagIsDisabled)1174 TEST_F(CommandListCreate, whenCreatingImmCmdListWithASyncModeAndAppendEventResetThenUpdateTaskCountNeededFlagIsDisabled) {
1175 ze_command_queue_desc_t desc = {};
1176 desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
1177 ze_result_t returnValue;
1178 std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue));
1179 ASSERT_NE(nullptr, commandList);
1180
1181 EXPECT_EQ(device, commandList->device);
1182 EXPECT_EQ(1u, commandList->cmdListType);
1183 EXPECT_NE(nullptr, commandList->cmdQImmediate);
1184
1185 ze_event_pool_desc_t eventPoolDesc = {};
1186 eventPoolDesc.count = 1;
1187 eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
1188
1189 ze_event_desc_t eventDesc = {};
1190 eventDesc.index = 0;
1191 eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
1192 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
1193
1194 ze_event_handle_t event = nullptr;
1195
1196 std::unique_ptr<L0::EventPool> eventPool(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, returnValue));
1197 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
1198 ASSERT_NE(nullptr, eventPool);
1199
1200 eventPool->createEvent(&eventDesc, &event);
1201
1202 std::unique_ptr<L0::Event> event_object(L0::Event::fromHandle(event));
1203 ASSERT_NE(nullptr, event_object->csr);
1204 ASSERT_EQ(device->getNEODevice()->getDefaultEngine().commandStreamReceiver, event_object->csr);
1205
1206 commandList->appendEventReset(event);
1207
1208 auto result = event_object->hostSignal();
1209 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
1210
1211 EXPECT_EQ(event_object->queryStatus(), ZE_RESULT_SUCCESS);
1212 }
1213
TEST_F(CommandListCreateWithBcs,givenQueueDescriptionwhenCreatingImmediateCommandListForCopyEnigneThenItHasImmediateCommandQueueCreated)1214 TEST_F(CommandListCreateWithBcs, givenQueueDescriptionwhenCreatingImmediateCommandListForCopyEnigneThenItHasImmediateCommandQueueCreated) {
1215 auto &engineGroups = neoDevice->getRegularEngineGroups();
1216 for (uint32_t ordinal = 0; ordinal < engineGroups.size(); ordinal++) {
1217 for (uint32_t index = 0; index < engineGroups[ordinal].engines.size(); index++) {
1218 ze_command_queue_desc_t desc = {};
1219 desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
1220 desc.ordinal = ordinal;
1221 desc.index = index;
1222 ze_result_t returnValue;
1223 std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::Copy, returnValue));
1224 ASSERT_NE(nullptr, commandList);
1225
1226 EXPECT_EQ(device, commandList->device);
1227 EXPECT_EQ(CommandList::CommandListType::TYPE_IMMEDIATE, commandList->cmdListType);
1228 EXPECT_NE(nullptr, commandList->cmdQImmediate);
1229
1230 ze_event_pool_desc_t eventPoolDesc = {};
1231 eventPoolDesc.count = 3;
1232 eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
1233
1234 ze_event_desc_t eventDesc = {};
1235 eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
1236 eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
1237 auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, returnValue));
1238 EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
1239 auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
1240 auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
1241 auto event2 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
1242 ze_event_handle_t events[] = {event1->toHandle(), event2->toHandle()};
1243
1244 commandList->appendBarrier(nullptr, 0, nullptr);
1245 commandList->appendBarrier(event->toHandle(), 2, events);
1246
1247 auto result = event->hostSignal();
1248 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
1249 result = event1->hostSignal();
1250 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
1251 result = event2->hostSignal();
1252 ASSERT_EQ(ZE_RESULT_SUCCESS, result);
1253 }
1254 }
1255 }
1256
HWTEST2_F(CommandListCreate,whenGettingCommandsToPatchThenCorrectValuesAreReturned,IsAtLeastSkl)1257 HWTEST2_F(CommandListCreate, whenGettingCommandsToPatchThenCorrectValuesAreReturned, IsAtLeastSkl) {
1258 auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
1259 EXPECT_EQ(&commandList->requiredStreamState, &commandList->getRequiredStreamState());
1260 EXPECT_EQ(&commandList->finalStreamState, &commandList->getFinalStreamState());
1261 EXPECT_EQ(&commandList->commandsToPatch, &commandList->getCommandsToPatch());
1262 }
1263
HWTEST2_F(CommandListCreate,givenNonEmptyCommandsToPatchWhenClearCommandsToPatchIsCalledThenCommandsAreCorrectlyCleared,IsAtLeastSkl)1264 HWTEST2_F(CommandListCreate, givenNonEmptyCommandsToPatchWhenClearCommandsToPatchIsCalledThenCommandsAreCorrectlyCleared, IsAtLeastSkl) {
1265 using VFE_STATE_TYPE = typename FamilyType::VFE_STATE_TYPE;
1266
1267 auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1268 EXPECT_TRUE(pCommandList->commandsToPatch.empty());
1269 EXPECT_NO_THROW(pCommandList->clearCommandsToPatch());
1270 EXPECT_TRUE(pCommandList->commandsToPatch.empty());
1271
1272 CommandList::CommandToPatch commandToPatch{};
1273 pCommandList->commandsToPatch.push_back(commandToPatch);
1274 EXPECT_ANY_THROW(pCommandList->clearCommandsToPatch());
1275 pCommandList->commandsToPatch.clear();
1276
1277 commandToPatch.type = CommandList::CommandToPatch::CommandType::FrontEndState;
1278 pCommandList->commandsToPatch.push_back(commandToPatch);
1279 EXPECT_ANY_THROW(pCommandList->clearCommandsToPatch());
1280 pCommandList->commandsToPatch.clear();
1281
1282 commandToPatch.pCommand = new VFE_STATE_TYPE;
1283 pCommandList->commandsToPatch.push_back(commandToPatch);
1284 EXPECT_NO_THROW(pCommandList->clearCommandsToPatch());
1285 EXPECT_TRUE(pCommandList->commandsToPatch.empty());
1286 }
1287
1288 } // namespace ult
1289 } // namespace L0
1290