|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | #include "shared/test/common/helpers/debug_manager_state_restore.h"
|
| 9 | +#include "shared/test/common/helpers/variable_backup.h" |
9 | 10 | #include "shared/test/common/mocks/mock_graphics_allocation.h"
|
10 | 11 |
|
11 | 12 | #include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
12 | 13 | #include "opencl/test/unit_test/fixtures/context_fixture.h"
|
| 14 | +#include "opencl/test/unit_test/fixtures/platform_fixture.h" |
13 | 15 | #include "opencl/test/unit_test/mocks/mock_command_queue.h"
|
14 | 16 | #include "opencl/test/unit_test/mocks/mock_context.h"
|
15 | 17 | #include "opencl/test/unit_test/mocks/mock_kernel.h"
|
16 | 18 | #include "opencl/test/unit_test/mocks/mock_program.h"
|
| 19 | +#include "test.h" |
17 | 20 |
|
18 |
| -using namespace NEO; |
| 21 | +namespace NEO { |
19 | 22 |
|
20 |
| -TEST(KernelWithCacheFlushTests, givenDeviceWhichDoesntRequireCacheFlushWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
21 |
| - auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())); |
| 23 | +class KernelWithCacheFlushTests : public PlatformFixture, public testing::TestWithParam<std::tuple<const char *, const char *>> { |
| 24 | + public: |
| 25 | + void SetUp() override { |
| 26 | + } |
| 27 | + void TearDown() override { |
| 28 | + } |
| 29 | + void initializePlatform() { |
| 30 | + PlatformFixture::SetUp(); |
| 31 | + } |
| 32 | + void clearPlatform() { |
| 33 | + PlatformFixture::TearDown(); |
| 34 | + } |
| 35 | +}; |
| 36 | +TEST_F(KernelWithCacheFlushTests, givenDeviceWhichDoesntRequireCacheFlushWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 37 | + initializePlatform(); |
| 38 | + auto device = pPlatform->getClDevice(0); |
22 | 39 |
|
23 | 40 | auto mockKernel = std::make_unique<MockKernelWithInternals>(*device);
|
24 |
| - MockContext mockContext(device.get()); |
25 |
| - MockCommandQueue queue; |
| 41 | + MockContext mockContext(device); |
| 42 | + MockCommandQueue queue(mockContext); |
26 | 43 | bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(queue);
|
27 | 44 | EXPECT_FALSE(flushRequired);
|
| 45 | + clearPlatform(); |
28 | 46 | }
|
| 47 | +TEST_F(KernelWithCacheFlushTests, givenQueueWhichDoesntRequireCacheFlushWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 48 | + initializePlatform(); |
| 49 | + DebugManagerStateRestore dbgRestore; |
| 50 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 51 | + auto device = pPlatform->getClDevice(0); |
| 52 | + |
| 53 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 54 | + MockContext mockContext(device); |
| 55 | + MockCommandQueue queue(mockContext); |
| 56 | + |
| 57 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(queue); |
| 58 | + EXPECT_FALSE(flushRequired); |
| 59 | + clearPlatform(); |
| 60 | +} |
| 61 | +TEST_F(KernelWithCacheFlushTests, givenCacheFlushForAllQueuesDisabledWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 62 | + initializePlatform(); |
| 63 | + DebugManagerStateRestore dbgRestore; |
| 64 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 65 | + DebugManager.flags.EnableCacheFlushAfterWalkerForAllQueues.set(0); |
| 66 | + auto device = pPlatform->getClDevice(0); |
| 67 | + |
| 68 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 69 | + MockContext mockContext(device); |
| 70 | + MockCommandQueue queue(mockContext); |
| 71 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(queue); |
| 72 | + |
| 73 | + EXPECT_FALSE(flushRequired); |
| 74 | + clearPlatform(); |
| 75 | +} |
| 76 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushForMultiEngineEnabledWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 77 | + initializePlatform(); |
| 78 | + DebugManagerStateRestore dbgRestore; |
| 79 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 80 | + auto device = pPlatform->getClDevice(0); |
| 81 | + |
| 82 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 83 | + MockContext mockContext(device); |
| 84 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 85 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 86 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 87 | + ultCsr.multiOsContextCapable = true; |
| 88 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 89 | + |
| 90 | + EXPECT_FALSE(flushRequired); |
| 91 | + clearPlatform(); |
| 92 | +} |
| 93 | + |
| 94 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushForSingleDeviceProgramWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 95 | + DebugManagerStateRestore dbgRestore; |
| 96 | + DebugManager.flags.CreateMultipleSubDevices.set(1); |
| 97 | + initializePlatform(); |
| 98 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 99 | + auto device = pPlatform->getClDevice(0); |
| 100 | + |
| 101 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 102 | + MockContext mockContext(device); |
| 103 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 104 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 105 | + ultCsr.multiOsContextCapable = false; |
| 106 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 107 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 108 | + |
| 109 | + EXPECT_FALSE(flushRequired); |
| 110 | + clearPlatform(); |
| 111 | +} |
| 112 | + |
| 113 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushForDefaultTypeContextWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 114 | + DebugManagerStateRestore dbgRestore; |
| 115 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 116 | + uint32_t numDevices = 2; |
| 117 | + DebugManager.flags.CreateMultipleSubDevices.set(numDevices); |
| 118 | + initializePlatform(); |
| 119 | + auto device = pPlatform->getClDevice(0); |
| 120 | + |
| 121 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 122 | + MockContext mockContext(device); |
| 123 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 124 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 125 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 126 | + ultCsr.multiOsContextCapable = false; |
| 127 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 128 | + |
| 129 | + EXPECT_FALSE(flushRequired); |
| 130 | + clearPlatform(); |
| 131 | +} |
| 132 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushWithNullGlobalSurfaceWhenCheckIfKernelRequireFlushThenReturnedFalse) { |
| 133 | + DebugManagerStateRestore dbgRestore; |
| 134 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 135 | + uint32_t numDevices = 2; |
| 136 | + DebugManager.flags.CreateMultipleSubDevices.set(numDevices); |
| 137 | + initializePlatform(); |
| 138 | + auto device = pPlatform->getClDevice(0); |
| 139 | + |
| 140 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 141 | + MockContext mockContext(device); |
| 142 | + mockContext.contextType = ContextType::CONTEXT_TYPE_SPECIALIZED; |
| 143 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 144 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 145 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 146 | + ultCsr.multiOsContextCapable = false; |
| 147 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 148 | + |
| 149 | + EXPECT_FALSE(flushRequired); |
| 150 | + clearPlatform(); |
| 151 | +} |
| 152 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushWithGlobalSurfaceWhenCheckIfKernelRequireFlushThenReturnedTrue) { |
| 153 | + DebugManagerStateRestore dbgRestore; |
| 154 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 155 | + uint32_t numDevices = 2; |
| 156 | + DebugManager.flags.CreateMultipleSubDevices.set(numDevices); |
| 157 | + initializePlatform(); |
| 158 | + auto device = pPlatform->getClDevice(0); |
| 159 | + |
| 160 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 161 | + MockContext mockContext(device); |
| 162 | + mockContext.contextType = ContextType::CONTEXT_TYPE_SPECIALIZED; |
| 163 | + |
| 164 | + void *allocPtr = reinterpret_cast<void *>(static_cast<uintptr_t>(6 * MemoryConstants::pageSize)); |
| 165 | + MockGraphicsAllocation globalAllocation{allocPtr, MemoryConstants::pageSize * 2}; |
| 166 | + mockKernel->mockProgram->setGlobalSurface(&globalAllocation); |
| 167 | + |
| 168 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 169 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 170 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 171 | + ultCsr.multiOsContextCapable = false; |
| 172 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 173 | + |
| 174 | + EXPECT_TRUE(flushRequired); |
| 175 | + mockKernel->mockProgram->setGlobalSurface(nullptr); |
| 176 | + clearPlatform(); |
| 177 | +} |
| 178 | + |
| 179 | +HWTEST2_F(KernelWithCacheFlushTests, givenCacheFlushRequiredWhenEstimatingThenAddRequiredCommands, IsAtLeastXeHpCore) { |
| 180 | + DebugManagerStateRestore dbgRestore; |
| 181 | + DebugManager.flags.CreateMultipleSubDevices.set(2); |
| 182 | + |
| 183 | + initializePlatform(); |
| 184 | + |
| 185 | + if (!pPlatform->getClDevice(0)->getHardwareInfo().capabilityTable.supportCacheFlushAfterWalker) { |
| 186 | + clearPlatform(); |
| 187 | + GTEST_SKIP(); |
| 188 | + } |
| 189 | + |
| 190 | + auto device = pPlatform->getClDevice(0); |
| 191 | + |
| 192 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 193 | + MockContext mockContext(device); |
| 194 | + mockContext.contextType = ContextType::CONTEXT_TYPE_SPECIALIZED; |
| 195 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 196 | + |
| 197 | + CsrDependencies csrDeps; |
| 198 | + DispatchInfo dispatchInfo; |
| 199 | + MultiDispatchInfo multiDispatchInfo(mockKernel->mockKernel); |
| 200 | + dispatchInfo.setKernel(mockKernel->mockKernel); |
| 201 | + dispatchInfo.setNumberOfWorkgroups({1, 1, 1}); |
| 202 | + dispatchInfo.setTotalNumberOfWorkgroups({1, 1, 1}); |
| 203 | + multiDispatchInfo.push(dispatchInfo); |
| 204 | + |
| 205 | + size_t initialSize = 0; |
| 206 | + size_t sizeWithCacheFlush = 0; |
| 207 | + size_t expectedDiff = sizeof(typename FamilyType::PIPE_CONTROL); |
| 208 | + if constexpr (FamilyType::isUsingL3Control) { |
| 209 | + expectedDiff += sizeof(typename FamilyType::L3_CONTROL) + sizeof(typename FamilyType::L3_FLUSH_ADDRESS_RANGE); |
| 210 | + } |
| 211 | + |
| 212 | + { |
| 213 | + EXPECT_FALSE(mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ)); |
| 214 | + |
| 215 | + initialSize = EnqueueOperation<FamilyType>::getTotalSizeRequiredCS(CL_COMMAND_NDRANGE_KERNEL, csrDeps, false, false, false, *cmdQ, multiDispatchInfo, false); |
| 216 | + } |
| 217 | + |
| 218 | + { |
| 219 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 220 | + void *allocPtr = reinterpret_cast<void *>(static_cast<uintptr_t>(6 * MemoryConstants::pageSize)); |
| 221 | + MockGraphicsAllocation globalAllocation{allocPtr, MemoryConstants::pageSize * 2}; |
| 222 | + mockKernel->mockProgram->setGlobalSurface(&globalAllocation); |
| 223 | + |
| 224 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 225 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 226 | + ultCsr.multiOsContextCapable = false; |
| 227 | + EXPECT_TRUE(mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ)); |
| 228 | + |
| 229 | + sizeWithCacheFlush = EnqueueOperation<FamilyType>::getTotalSizeRequiredCS(CL_COMMAND_NDRANGE_KERNEL, csrDeps, false, false, false, *cmdQ, multiDispatchInfo, false); |
| 230 | + } |
| 231 | + |
| 232 | + EXPECT_EQ(initialSize + expectedDiff, sizeWithCacheFlush); |
| 233 | + |
| 234 | + mockKernel->mockProgram->setGlobalSurface(nullptr); |
| 235 | + clearPlatform(); |
| 236 | +} |
| 237 | + |
| 238 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushWithAllocationsRequireCacheFlushFlagOnWhenCheckIfKernelRequireFlushThenReturnedTrue) { |
| 239 | + DebugManagerStateRestore dbgRestore; |
| 240 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 241 | + uint32_t numDevices = 2; |
| 242 | + DebugManager.flags.CreateMultipleSubDevices.set(numDevices); |
| 243 | + initializePlatform(); |
| 244 | + auto device = pPlatform->getClDevice(0); |
| 245 | + |
| 246 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 247 | + MockContext mockContext(device); |
| 248 | + mockContext.contextType = ContextType::CONTEXT_TYPE_SPECIALIZED; |
| 249 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 250 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 251 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 252 | + ultCsr.multiOsContextCapable = false; |
| 253 | + mockKernel->mockKernel->svmAllocationsRequireCacheFlush = true; |
| 254 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 255 | + |
| 256 | + EXPECT_TRUE(flushRequired); |
| 257 | + clearPlatform(); |
| 258 | +} |
| 259 | +HWTEST_F(KernelWithCacheFlushTests, givenCacheFlushWithAllocationsWhichRequireCacheFlushWhenCheckIfKernelRequireFlushThenReturnedTrue) { |
| 260 | + DebugManagerStateRestore dbgRestore; |
| 261 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 262 | + uint32_t numDevices = 2; |
| 263 | + DebugManager.flags.CreateMultipleSubDevices.set(numDevices); |
| 264 | + initializePlatform(); |
| 265 | + auto device = pPlatform->getClDevice(0); |
| 266 | + |
| 267 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 268 | + MockContext mockContext(device); |
| 269 | + mockContext.contextType = ContextType::CONTEXT_TYPE_SPECIALIZED; |
| 270 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 271 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 272 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 273 | + ultCsr.multiOsContextCapable = false; |
| 274 | + mockKernel->mockKernel->svmAllocationsRequireCacheFlush = false; |
| 275 | + mockKernel->mockKernel->kernelArgRequiresCacheFlush.resize(2); |
| 276 | + MockGraphicsAllocation cacheRequiringAllocation; |
| 277 | + mockKernel->mockKernel->kernelArgRequiresCacheFlush[1] = &cacheRequiringAllocation; |
| 278 | + bool flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 279 | + |
| 280 | + EXPECT_TRUE(flushRequired); |
| 281 | + clearPlatform(); |
| 282 | +} |
| 283 | + |
| 284 | +HWTEST_F(KernelWithCacheFlushTests, |
| 285 | + givenEnableCacheFlushAfterWalkerForAllQueuesFlagSetWhenCheckIfKernelRequierFlushThenTrueIsAlwaysReturned) { |
| 286 | + DebugManagerStateRestore dbgRestore; |
| 287 | + DebugManager.flags.EnableCacheFlushAfterWalker.set(1); |
| 288 | + DebugManager.flags.EnableCacheFlushAfterWalkerForAllQueues.set(1); |
| 289 | + MockGraphicsAllocation cacheRequiringAllocation; |
| 290 | + |
| 291 | + for (auto isMultiEngine : ::testing::Bool()) { |
| 292 | + for (auto isMultiDevice : ::testing::Bool()) { |
| 293 | + for (auto isDefaultContext : ::testing::Bool()) { |
| 294 | + for (auto svmAllocationRequiresCacheFlush : ::testing::Bool()) { |
| 295 | + for (auto kernelArgRequiresCacheFlush : ::testing::Bool()) { |
| 296 | + auto deviceCount = (isMultiDevice ? 2 : 0); |
| 297 | + auto contextType = |
| 298 | + (isDefaultContext ? ContextType::CONTEXT_TYPE_DEFAULT : ContextType::CONTEXT_TYPE_SPECIALIZED); |
| 299 | + GraphicsAllocation *kernelArg = (kernelArgRequiresCacheFlush ? &cacheRequiringAllocation : nullptr); |
| 300 | + |
| 301 | + DebugManager.flags.CreateMultipleSubDevices.set(deviceCount); |
| 302 | + initializePlatform(); |
| 303 | + |
| 304 | + auto device = pPlatform->getClDevice(0); |
| 305 | + MockContext mockContext(device); |
| 306 | + mockContext.contextType = contextType; |
| 307 | + auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(&mockContext, device, nullptr); |
| 308 | + cmdQ->requiresCacheFlushAfterWalker = true; |
| 309 | + auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(cmdQ->getGpgpuCommandStreamReceiver()); |
| 310 | + ultCsr.multiOsContextCapable = isMultiEngine; |
| 311 | + |
| 312 | + auto mockKernel = std::make_unique<MockKernelWithInternals>(*device); |
| 313 | + mockKernel->mockKernel->svmAllocationsRequireCacheFlush = svmAllocationRequiresCacheFlush; |
| 314 | + mockKernel->mockKernel->kernelArgRequiresCacheFlush.resize(1); |
| 315 | + mockKernel->mockKernel->kernelArgRequiresCacheFlush[0] = kernelArg; |
| 316 | + |
| 317 | + auto flushRequired = mockKernel->mockKernel->Kernel::requiresCacheFlushCommand(*cmdQ.get()); |
| 318 | + EXPECT_TRUE(flushRequired); |
| 319 | + clearPlatform(); |
| 320 | + } |
| 321 | + } |
| 322 | + } |
| 323 | + } |
| 324 | + } |
| 325 | +} |
| 326 | +} // namespace NEO |
0 commit comments