diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index aee6d7c818..254f31f076 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -339,12 +339,14 @@ Buffer *Buffer::create(Context *context, auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; auto hwInfo = rootDeviceEnvironment.getHardwareInfo(); auto &gfxCoreHelper = rootDeviceEnvironment.getHelper(); + auto &productHelper = rootDeviceEnvironment.getHelper(); bool compressionEnabled = MemObjHelper::isSuitableForCompression(GfxCoreHelper::compressedBuffersSupported(*hwInfo), memoryProperties, *context, gfxCoreHelper.isBufferSizeSuitableForCompression(size)); - + auto isNewCoherencyModelSupported = productHelper.isNewCoherencyModelSupported(); allocationInfo.allocationType = getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, - memoryManager->isLocalMemorySupported(rootDeviceIndex)); + memoryManager->isLocalMemorySupported(rootDeviceIndex), + isNewCoherencyModelSupported); if (allocationCpuPtr) { forceCopyHostPtr = !useHostPtr && !copyHostPtr; @@ -372,6 +374,9 @@ Buffer *Buffer::create(Context *context, allocationInfo.zeroCopyAllowed = false; allocationInfo.allocateMemory = true; } + } else if (isNewCoherencyModelSupported) { + allocationInfo.zeroCopyAllowed = false; + allocationInfo.allocateMemory = true; } if (debugManager.flags.DisableZeroCopyForUseHostPtr.get()) { @@ -638,13 +643,14 @@ void Buffer::checkMemory(const MemoryProperties &memoryProperties, } AllocationType Buffer::getGraphicsAllocationTypeAndCompressionPreference(const MemoryProperties &properties, - bool &compressionEnabled, bool isLocalMemoryEnabled) { + bool &compressionEnabled, bool isLocalMemoryEnabled, + bool isNewCoherencyModelSupported) { if (properties.flags.forceHostMemory) { compressionEnabled = false; return AllocationType::bufferHostMemory; } - if (properties.flags.useHostPtr && !isLocalMemoryEnabled) { + if (properties.flags.useHostPtr && (!isLocalMemoryEnabled && !isNewCoherencyModelSupported)) { compressionEnabled = false; return AllocationType::bufferHostMemory; } diff --git a/opencl/source/mem_obj/buffer.h b/opencl/source/mem_obj/buffer.h index e54eb0879c..a4fbca27a2 100644 --- a/opencl/source/mem_obj/buffer.h +++ b/opencl/source/mem_obj/buffer.h @@ -208,7 +208,8 @@ class Buffer : public MemObj { uint32_t rootDeviceIndex, bool forceCopyHostPtr); static AllocationType getGraphicsAllocationTypeAndCompressionPreference(const MemoryProperties &properties, - bool &compressionEnabled, bool localMemoryEnabled); + bool &compressionEnabled, bool localMemoryEnabled, + bool isNewCoherencyModelSupported); static bool isReadOnlyMemoryPermittedByFlags(const MemoryProperties &properties); void transferData(void *dst, void *src, size_t copySize, size_t copyOffset); diff --git a/opencl/test/unit_test/api/cl_create_buffer_tests.cpp b/opencl/test/unit_test/api/cl_create_buffer_tests.cpp index 4153cd7243..4db3093275 100644 --- a/opencl/test/unit_test/api/cl_create_buffer_tests.cpp +++ b/opencl/test/unit_test/api/cl_create_buffer_tests.cpp @@ -470,7 +470,7 @@ TEST_F(ClCreateBufferTests, WhenCreatingBufferWithPropertiesThenPropertiesAreCor using clCreateBufferTestsWithRestrictions = api_test_using_aligned_memory_manager; -TEST_F(clCreateBufferTestsWithRestrictions, GivenMemoryManagerRestrictionsWhenMinIsLessThanHostPtrThenUseZeroCopy) { +TEST_F(clCreateBufferTestsWithRestrictions, GivenMemoryManagerRestrictionsAndOldCoherencyModelWhenMinIsLessThanHostPtrThenUseZeroCopy) { std::unique_ptr hostMem(nullptr); unsigned char *destMem = nullptr; cl_mem_flags flags = CL_MEM_USE_HOST_PTR; @@ -495,7 +495,13 @@ TEST_F(clCreateBufferTestsWithRestrictions, GivenMemoryManagerRestrictionsWhenMi EXPECT_NE(nullptr, buffer); Buffer *bufferObj = NEO::castToObject(buffer); - EXPECT_TRUE(bufferObj->isMemObjZeroCopy()); + + auto &productHelper = device->getProductHelper(); + if (productHelper.isNewCoherencyModelSupported()) { + EXPECT_FALSE(bufferObj->isMemObjZeroCopy()); + } else { + EXPECT_TRUE(bufferObj->isMemObjZeroCopy()); + } retVal = clReleaseMemObject(buffer); EXPECT_EQ(CL_SUCCESS, retVal); diff --git a/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp b/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp index bb181a6c29..a39cad1ee4 100644 --- a/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp +++ b/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp @@ -136,7 +136,7 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, GivenUnalignedSrcPtrWhenWritingBufferThenMe delete[] bufferPtrBase; } -HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresWhenReadingWritingMemoryThenCpuReadWriteIsAllowed) { +HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresAndOldCoherencyModelWhenReadingWritingMemoryThenCpuReadWriteIsAllowed) { DebugManagerStateRestore restorer; debugManager.flags.ForceLocalMemoryAccessMode.set(static_cast(LocalMemoryAccessMode::defaultMode)); cl_int retVal; @@ -152,13 +152,14 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresWhenReadingWri auto mockContext = std::unique_ptr(new MockContext(mockDevice.get())); auto memoryManager = static_cast(mockDevice->getMemoryManager()); memoryManager->turnOnFakingBigAllocations(); - + auto &productHelper = mockDevice->getProductHelper(); + auto isZeroCopyAllowed = !productHelper.isNewCoherencyModelSupported(); std::unique_ptr buffer(Buffer::create(context, CL_MEM_USE_HOST_PTR, size, alignedBufferPtr, retVal)); EXPECT_EQ(retVal, CL_SUCCESS); - EXPECT_TRUE(buffer->isMemObjZeroCopy()); + EXPECT_EQ(isZeroCopyAllowed, buffer->isMemObjZeroCopy()); // zeroCopy == true && aligned/unaligned hostPtr - EXPECT_TRUE(buffer->isReadWriteOnCpuPreferred(alignedHostPtr, MemoryConstants::cacheLineSize + 1, mockDevice->getDevice())); + EXPECT_EQ(isZeroCopyAllowed, buffer->isReadWriteOnCpuPreferred(alignedHostPtr, MemoryConstants::cacheLineSize + 1, mockDevice->getDevice())); EXPECT_TRUE(buffer->isReadWriteOnCpuPreferred(unalignedHostPtr, MemoryConstants::cacheLineSize, mockDevice->getDevice())); buffer.reset(Buffer::create(context, CL_MEM_USE_HOST_PTR, size, unalignedBufferPtr, retVal)); @@ -172,11 +173,11 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresWhenReadingWri // platform LP == true && size <= 10 MB mockDevice->deviceInfo.platformLP = true; - EXPECT_TRUE(buffer->isReadWriteOnCpuPreferred(smallBufferPtr, 1 * MemoryConstants::megaByte, mockDevice->getDevice())); + EXPECT_EQ(isZeroCopyAllowed, buffer->isReadWriteOnCpuPreferred(smallBufferPtr, 1 * MemoryConstants::megaByte, mockDevice->getDevice())); // platform LP == false && size <= 10 MB mockDevice->deviceInfo.platformLP = false; - EXPECT_TRUE(buffer->isReadWriteOnCpuPreferred(smallBufferPtr, 1 * MemoryConstants::megaByte, mockDevice->getDevice())); + EXPECT_EQ(isZeroCopyAllowed, buffer->isReadWriteOnCpuPreferred(smallBufferPtr, 1 * MemoryConstants::megaByte, mockDevice->getDevice())); buffer.reset(Buffer::create(mockContext.get(), CL_MEM_ALLOC_HOST_PTR, largeBufferSize, nullptr, retVal)); @@ -189,7 +190,7 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresWhenReadingWri alignedFree(alignedBufferPtr); } -HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresWhenReadingWritingMemoryThenCpuReadWriteIsNotAllowed) { +HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresAndOldCoherencyModelWhenReadingWritingMemoryThenCpuReadWriteIsNotAllowed) { cl_int retVal; size_t size = MemoryConstants::cacheLineSize; auto alignedBufferPtr = alignedMalloc(MemoryConstants::cacheLineSize + 1, MemoryConstants::cacheLineSize); @@ -204,10 +205,11 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, GivenSpecificMemoryStructuresWhenReadingWri auto memoryManager = static_cast(mockDevice->getMemoryManager()); memoryManager->turnOnFakingBigAllocations(); - + auto &productHelper = mockDevice->getProductHelper(); + auto isZeroCopyAllowed = !productHelper.isNewCoherencyModelSupported(); std::unique_ptr buffer(Buffer::create(context, CL_MEM_USE_HOST_PTR, size, alignedBufferPtr, retVal)); EXPECT_EQ(retVal, CL_SUCCESS); - EXPECT_TRUE(buffer->isMemObjZeroCopy()); + EXPECT_EQ(isZeroCopyAllowed, buffer->isMemObjZeroCopy()); // non blocking EXPECT_FALSE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_NDRANGE_KERNEL, false, size, unalignedHostPtr, 0u, nullptr)); diff --git a/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp b/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp index bbc25fa895..10df5b4dd9 100644 --- a/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp +++ b/opencl/test/unit_test/context/driver_diagnostics_enqueue_tests.cpp @@ -148,7 +148,11 @@ TEST_F(PerformanceHintEnqueueBufferTest, GivenNonBlockingReadAndSharedMemWhenEnq nullptr, nullptr); - snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_RECT_DOESNT_REQUIRES_COPY_DATA], static_cast(buffer), address); + if (isZeroCopyAllowed) { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_RECT_DOESNT_REQUIRES_COPY_DATA], static_cast(buffer), address); + } else { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_BUFFER_DOESNT_MEET_ALIGNMENT_RESTRICTIONS], address, MemoryConstants::cacheLineSize, MemoryConstants::pageSize, MemoryConstants::pageSize); + } EXPECT_TRUE(containsHint(expectedHint, userData)); } @@ -184,7 +188,11 @@ TEST_F(PerformanceHintEnqueueBufferTest, GivenNonBlockingWriteAndBufferSharesMem 0, nullptr, nullptr); - snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + if (isZeroCopyAllowed) { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + } else { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA], static_cast(buffer), address); + } EXPECT_TRUE(containsHint(expectedHint, userData)); } @@ -220,7 +228,11 @@ TEST_F(PerformanceHintEnqueueBufferTest, GivenBlockingWriteAndBufferSharesMemWit 0, nullptr, nullptr); - snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + if (isZeroCopyAllowed) { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + } else { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA], static_cast(buffer), address); + } EXPECT_TRUE(containsHint(expectedHint, userData)); } @@ -256,7 +268,11 @@ TEST_F(PerformanceHintEnqueueBufferTest, GivenNonBlockingReadAndBufferSharesMemW 0, nullptr, nullptr); - snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + if (isZeroCopyAllowed) { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + } else { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_REQUIRES_COPY_DATA], static_cast(buffer), address); + } EXPECT_TRUE(containsHint(expectedHint, userData)); } @@ -292,7 +308,11 @@ TEST_F(PerformanceHintEnqueueBufferTest, GivenBlockingReadAndBufferSharesMemWith 0, nullptr, nullptr); - snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + if (isZeroCopyAllowed) { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer), address); + } else { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_READ_BUFFER_REQUIRES_COPY_DATA], static_cast(buffer), address); + } EXPECT_TRUE(containsHint(expectedHint, userData)); } @@ -343,8 +363,11 @@ TEST_F(PerformanceHintEnqueueBufferTest, GivenNonBlockingWriteAndSharedMemWhenEn 0, nullptr, nullptr); - - snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_RECT_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer)); + if (isZeroCopyAllowed) { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_RECT_DOESNT_REQUIRE_COPY_DATA], static_cast(buffer)); + } else { + snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_ENQUEUE_WRITE_BUFFER_RECT_REQUIRES_COPY_DATA], static_cast(buffer)); + } EXPECT_TRUE(containsHint(expectedHint, userData)); } diff --git a/opencl/test/unit_test/context/driver_diagnostics_tests.h b/opencl/test/unit_test/context/driver_diagnostics_tests.h index ab400797fe..1da4a587b2 100644 --- a/opencl/test/unit_test/context/driver_diagnostics_tests.h +++ b/opencl/test/unit_test/context/driver_diagnostics_tests.h @@ -141,6 +141,8 @@ struct PerformanceHintEnqueueBufferTest : public PerformanceHintEnqueueTest { MemoryConstants::cacheLineSize, address, retVal); + auto &productHelper = context->getDevice(0)->getProductHelper(); + isZeroCopyAllowed = !productHelper.isNewCoherencyModelSupported(); } void TearDown() override { @@ -150,6 +152,7 @@ struct PerformanceHintEnqueueBufferTest : public PerformanceHintEnqueueTest { } void *address = nullptr; Buffer *buffer = nullptr; + bool isZeroCopyAllowed = true; }; struct PerformanceHintEnqueueReadBufferTest : public PerformanceHintEnqueueBufferTest, @@ -215,6 +218,9 @@ struct PerformanceHintEnqueueMapTest : public PerformanceHintEnqueueTest, if (context->getDevice(0)->getRootDeviceEnvironment().getProductHelper().isDcFlushMitigated()) { GTEST_SKIP(); } + if (context->getDevice(0)->getRootDeviceEnvironment().getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } } void TearDown() override { diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index a872de6cbf..692a40ed05 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -440,7 +440,7 @@ TEST(Buffer, givenCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferC bool compressionEnabled = MemObjHelper::isSuitableForCompression(true, memoryProperties, context, true); EXPECT_TRUE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, false); EXPECT_TRUE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } @@ -453,7 +453,7 @@ TEST(Buffer, givenCompressedBuffersDisabledLocalMemoryEnabledWhenAllocationTypeI bool compressionEnabled = MemObjHelper::isSuitableForCompression(false, memoryProperties, context, true); EXPECT_FALSE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } @@ -467,7 +467,7 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledWhenAllocationTypeIsQuerie bool compressionEnabled = MemObjHelper::isSuitableForCompression(false, memoryProperties, context, true); EXPECT_FALSE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::bufferHostMemory, type); } @@ -481,7 +481,7 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueried bool compressionEnabled = MemObjHelper::isSuitableForCompression(false, memoryProperties, context, true); EXPECT_FALSE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } @@ -495,7 +495,7 @@ TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsRet bool compressionEnabled = MemObjHelper::isSuitableForCompression(false, memoryProperties, context, true); EXPECT_FALSE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } @@ -509,7 +509,7 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndCompressedBuffersEnable bool compressionEnabled = MemObjHelper::isSuitableForCompression(true, memoryProperties, context, true); EXPECT_TRUE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::bufferHostMemory, type); } @@ -523,7 +523,7 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndCompressedBuffersEnabled bool compressionEnabled = MemObjHelper::isSuitableForCompression(true, memoryProperties, context, true); EXPECT_TRUE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true, false); EXPECT_TRUE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } @@ -537,7 +537,7 @@ TEST(Buffer, givenUseHostPointerFlagAndForceSharedPhysicalStorageWhenLocalMemory bool compressionEnabled = MemObjHelper::isSuitableForCompression(true, memoryProperties, context, true); EXPECT_TRUE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, true, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::bufferHostMemory, type); } @@ -551,7 +551,7 @@ TEST(Buffer, givenAllocHostPtrFlagAndCompressedBuffersEnabledWhenAllocationTypeI bool compressionEnabled = MemObjHelper::isSuitableForCompression(true, memoryProperties, context, true); EXPECT_TRUE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, false); EXPECT_TRUE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } @@ -564,11 +564,24 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndCompressedBuffersDisabledWhenAlloca bool compressionEnabled = MemObjHelper::isSuitableForCompression(false, memoryProperties, context, true); EXPECT_FALSE(compressionEnabled); - auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false); + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, false); EXPECT_FALSE(compressionEnabled); EXPECT_EQ(AllocationType::buffer, type); } +TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndCompressedBuffersEnabledAndNewCoherencyModelEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) { + cl_mem_flags flags = CL_MEM_USE_HOST_PTR; + MockContext context; + MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); + + bool compressionEnabled = MemObjHelper::isSuitableForCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled, false, true); + EXPECT_TRUE(compressionEnabled); + EXPECT_EQ(AllocationType::buffer, type); +} + TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInSystemMemoryPoolAndCopyOnCpuDisabledThenAllocationIsWrittenByEnqueueWriteBuffer) { DebugManagerStateRestore restorer; debugManager.flags.CopyHostPtrOnCpu.set(0); @@ -1359,10 +1372,15 @@ TEST(Buffers64on32Tests, given32BitBufferCreatedWithUseHostPtrFlagThatIsZeroCopy (void *)offsetedPtr, retVal); EXPECT_EQ(CL_SUCCESS, retVal); - - EXPECT_TRUE(buffer->isMemObjZeroCopy()); EXPECT_EQ((void *)offsetedPtr, buffer->getCpuAddressForMapping()); - EXPECT_EQ((void *)offsetedPtr, buffer->getCpuAddressForMemoryTransfer()); + + auto &productHelper = context.getDevice(0)->getProductHelper(); + if (productHelper.isNewCoherencyModelSupported()) { + EXPECT_FALSE(buffer->isMemObjZeroCopy()); + } else { + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + EXPECT_EQ((void *)offsetedPtr, buffer->getCpuAddressForMemoryTransfer()); + } delete buffer; debugManager.flags.Force32bitAddressing.set(false); diff --git a/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp b/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp index 3c2938fc7e..211d7841b2 100644 --- a/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp +++ b/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp @@ -431,7 +431,7 @@ TEST(MemObjHelper, givenDifferentCapabilityAndDebugFlagValuesWhenCheckingBufferC bool compressionEnabled = MemObjHelper::isSuitableForCompression(GfxCoreHelper::compressedBuffersSupported(*defaultHwInfo), memoryProperties, context, true); MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference( - memoryProperties, compressionEnabled, false); + memoryProperties, compressionEnabled, false, false); bool expectBufferCompressed = ftrRenderCompressedBuffers && (enableMultiTileCompressionValue == 1); if (expectBufferCompressed) { @@ -483,7 +483,7 @@ TEST(MemObjHelper, givenDifferentValuesWhenCheckingBufferCompressionSupportThenC bool compressionEnabled = MemObjHelper::isSuitableForCompression(GfxCoreHelper::compressedBuffersSupported(*defaultHwInfo), memoryProperties, context, true); MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference( - memoryProperties, compressionEnabled, false); + memoryProperties, compressionEnabled, false, false); bool isCompressionDisabled = isValueSet(flags, CL_MEM_UNCOMPRESSED_HINT_INTEL) || isValueSet(flagsIntel, CL_MEM_UNCOMPRESSED_HINT_INTEL); diff --git a/opencl/test/unit_test/mem_obj/zero_copy_tests.cpp b/opencl/test/unit_test/mem_obj/zero_copy_tests.cpp index 028bdcdabd..4e472f8db9 100644 --- a/opencl/test/unit_test/mem_obj/zero_copy_tests.cpp +++ b/opencl/test/unit_test/mem_obj/zero_copy_tests.cpp @@ -13,6 +13,7 @@ #include "opencl/source/cl_device/cl_device.h" #include "opencl/source/mem_obj/buffer.h" #include "opencl/test/unit_test/fixtures/cl_device_fixture.h" +#include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "gtest/gtest.h" @@ -83,6 +84,10 @@ TEST_P(ZeroCopyBufferTest, GivenCacheAlignedPointerWhenCreatingBufferThenZeroCop passedPtr, retVal); EXPECT_EQ(CL_SUCCESS, retVal); + auto &productHelper = pClDevice->getProductHelper(); + if (flags & CL_MEM_USE_HOST_PTR) { + shouldBeZeroCopy = shouldBeZeroCopy && !productHelper.isNewCoherencyModelSupported(); + } EXPECT_EQ(shouldBeZeroCopy, buffer->isMemObjZeroCopy()) << "Zero Copy not handled properly"; if (!shouldBeZeroCopy && flags & CL_MEM_USE_HOST_PTR) { EXPECT_NE(buffer->getCpuAddress(), hostPtr); @@ -148,7 +153,7 @@ TEST(ZeroCopyWithDebugFlag, GivenBufferInputsThatWouldResultInZeroCopyAndDisable EXPECT_NE(mapAllocation, bufferAllocation); } -TEST(ZeroCopyBufferWith32BitAddressing, GivenDeviceSupporting32BitAddressingWhenAskedForBufferCreationFromHostPtrThenNonZeroCopyBufferIsReturned) { +TEST(ZeroCopyBufferWith32BitAddressing, GivenDeviceSupporting32BitAddressingAndOldCoherencyModelWhenAskedForBufferCreationFromHostPtrThenNonZeroCopyBufferIsReturned) { DebugManagerStateRestore dbgRestorer; debugManager.flags.Force32bitAddressing.set(true); MockContext context; @@ -158,8 +163,13 @@ TEST(ZeroCopyBufferWith32BitAddressing, GivenDeviceSupporting32BitAddressingWhen std::unique_ptr buffer(Buffer::create(&context, CL_MEM_USE_HOST_PTR, size, hostPtr, retVal)); EXPECT_EQ(CL_SUCCESS, retVal); + auto &productHelper = context.getDevice(0)->getProductHelper(); + if (productHelper.isNewCoherencyModelSupported()) { + EXPECT_FALSE(buffer->isMemObjZeroCopy()); + } else { + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + } - EXPECT_TRUE(buffer->isMemObjZeroCopy()); if constexpr (is64bit) { EXPECT_TRUE(buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->is32BitAllocation()); } diff --git a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp index 26aee6cc4d..87c3ec2f7e 100644 --- a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp @@ -96,10 +96,16 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationTh TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHostPtrThen32BitBufferIsReturned) { DebugManagerStateRestore dbgRestorer; + auto isNewCoherencyModelSupported = pClDevice->getProductHelper().isNewCoherencyModelSupported(); + mock->ioctlExpected.gemUserptr = 1; mock->ioctlExpected.gemWait = 1; mock->ioctlExpected.gemClose = 1; - + if (isNewCoherencyModelSupported) { + mock->ioctlExpected.gemUserptr = 2; + mock->ioctlExpected.gemWait = 2; + mock->ioctlExpected.gemClose = 2; + } debugManager.flags.Force32bitAddressing.set(true); MockContext context(pClDevice); memoryManager->setForce32BitAllocations(true); @@ -118,7 +124,6 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromH retVal); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_TRUE(buffer->isMemObjZeroCopy()); auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); auto drmAllocation = static_cast(buffer->getGraphicsAllocation(rootDeviceIndex)); @@ -135,15 +140,20 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromH auto bufferObject = drmAllocation->getBO(); - EXPECT_EQ(drmAllocation->getUnderlyingBuffer(), reinterpret_cast(offsetedPtr)); - // Gpu address should be different EXPECT_NE(offsetedPtr, drmAllocation->getGpuAddress()); - // Gpu address offset iqual to cpu offset - EXPECT_EQ(allocationGpuOffset, ptrOffset); - - EXPECT_EQ(allocationPageOffset, ptrOffset); + if (isNewCoherencyModelSupported) { + EXPECT_FALSE(buffer->isMemObjZeroCopy()); + EXPECT_EQ(allocationGpuOffset, 0ull); + EXPECT_EQ(allocationPageOffset, 0ull); + } else { + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + EXPECT_EQ(drmAllocation->getUnderlyingBuffer(), reinterpret_cast(offsetedPtr)); + // Gpu address offset iqual to cpu offset + EXPECT_EQ(allocationGpuOffset, ptrOffset); + EXPECT_EQ(allocationPageOffset, ptrOffset); + } auto boAddress = bufferObject->peekAddress(); EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); @@ -152,6 +162,7 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromH TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64BitHostPtrThen32BitBufferIsReturned) { DebugManagerStateRestore dbgRestorer; + auto isNewCoherencyModelSupported = pClDevice->getProductHelper().isNewCoherencyModelSupported(); { if (is32bit) { mock->ioctlExpected.total = -1; @@ -159,7 +170,11 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom6 mock->ioctlExpected.gemUserptr = 1; mock->ioctlExpected.gemWait = 1; mock->ioctlExpected.gemClose = 1; - + if (isNewCoherencyModelSupported) { + mock->ioctlExpected.gemUserptr = 2; + mock->ioctlExpected.gemWait = 2; + mock->ioctlExpected.gemClose = 2; + } debugManager.flags.Force32bitAddressing.set(true); MockContext context(pClDevice); memoryManager->setForce32BitAllocations(true); @@ -178,7 +193,6 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom6 retVal); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_TRUE(buffer->isMemObjZeroCopy()); auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); @@ -191,8 +205,13 @@ TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom6 auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); auto bufferObject = drmAllocation->getBO(); - - EXPECT_EQ(allocationPageOffset, ptrOffset); + if (isNewCoherencyModelSupported) { + EXPECT_FALSE(buffer->isMemObjZeroCopy()); + EXPECT_EQ(allocationPageOffset, 0ull); + } else { + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + EXPECT_EQ(allocationPageOffset, ptrOffset); + } auto boAddress = bufferObject->peekAddress(); EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress);