From 9c1e7422b11fd5ba83e53ad312294b3cbfc10192 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 3 Nov 2021 08:36:11 +0000 Subject: [PATCH] DG1: don't use blitter when creating buffer Signed-off-by: Mateusz Jablonski --- opencl/source/mem_obj/buffer.cpp | 11 +++- .../gen12lp/buffer_tests_gen12lp.inl | 23 +++++++ .../unit_test/mem_obj/buffer_bcs_tests.cpp | 61 ++++++++----------- opencl/test/unit_test/mocks/mock_context.cpp | 25 ++++++++ opencl/test/unit_test/mocks/mock_context.h | 14 +++++ 5 files changed, 99 insertions(+), 35 deletions(-) diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 5bad225bc3..1e34e327ee 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -23,6 +23,7 @@ #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/memory_manager/unified_memory_manager.h" +#include "shared/source/os_interface/hw_info_config.h" #include "shared/source/utilities/debug_settings_reader_creator.h" #include "opencl/source/cl_device/cl_device.h" @@ -386,7 +387,15 @@ Buffer *Buffer::create(Context *context, bool gpuCopyRequired = (gmm && gmm->isCompressionEnabled) || !MemoryPool::isSystemMemoryPool(allocationInfo[rootDeviceIndex].memory->getMemoryPool()); if (gpuCopyRequired) { - auto blitMemoryToAllocationResult = BlitHelperFunctions::blitMemoryToAllocation(pBuffer->getContext()->getDevice(0u)->getDevice(), allocationInfo[rootDeviceIndex].memory, pBuffer->getOffset(), hostPtr, {size, 1, 1}); + + auto &device = pBuffer->getContext()->getDevice(0u)->getDevice(); + auto &hwInfo = device.getHardwareInfo(); + auto hwInfoConfig = HwInfoConfig::get(hwInfo.platform.eProductFamily); + auto blitMemoryToAllocationResult = BlitOperationResult::Unsupported; + + if (hwInfoConfig->isBlitterFullySupported(hwInfo)) { + blitMemoryToAllocationResult = BlitHelperFunctions::blitMemoryToAllocation(device, allocationInfo[rootDeviceIndex].memory, pBuffer->getOffset(), hostPtr, {size, 1, 1}); + } if (blitMemoryToAllocationResult != BlitOperationResult::Success) { auto cmdQ = context->getSpecialQueue(rootDeviceIndex); diff --git a/opencl/test/unit_test/gen12lp/buffer_tests_gen12lp.inl b/opencl/test/unit_test/gen12lp/buffer_tests_gen12lp.inl index 081a4df109..b1382f6f5d 100644 --- a/opencl/test/unit_test/gen12lp/buffer_tests_gen12lp.inl +++ b/opencl/test/unit_test/gen12lp/buffer_tests_gen12lp.inl @@ -8,6 +8,8 @@ #include "shared/source/device/device.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/mocks/mock_memory_manager.h" +#include "shared/test/unit_test/utilities/base_object_utils.h" #include "opencl/source/cl_device/cl_device.h" #include "opencl/source/mem_obj/buffer.h" @@ -139,3 +141,24 @@ GEN12LPTEST_F(BufferTestsTgllp, givenBufferReadonlyL1ForceDisabledWhenProgrammin const auto actualMocs = surfaceState.getMemoryObjectControlState(); EXPECT_EQ(expectedMocs, actualMocs); } +using Gen12lpCreateBufferTest = ::testing::Test; +GEN12LPTEST_F(Gen12lpCreateBufferTest, WhenCreatingBufferWithCopyHostPtrThenDontUseBlitOperation) { + uint32_t hostPtr = 0; + auto rootDeviceIndex = 1u; + auto hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = true; + + EXPECT_FALSE(HwInfoConfig::get(hwInfo.platform.eProductFamily)->isBlitterFullySupported(hwInfo)); + std::unique_ptr newDevice = std::make_unique(MockClDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex)); + std::unique_ptr newBcsMockContext = std::make_unique(newDevice.get()); + + auto bcsCsr = static_cast *>(newBcsMockContext->bcsCsr.get()); + + static_cast(newDevice->getExecutionEnvironment()->memoryManager.get())->enable64kbpages[rootDeviceIndex] = true; + static_cast(newDevice->getExecutionEnvironment()->memoryManager.get())->localMemorySupported[rootDeviceIndex] = true; + + EXPECT_EQ(0u, bcsCsr->blitBufferCalled); + cl_int retVal = 0; + auto bufferForBlt = clUniquePtr(Buffer::create(newBcsMockContext.get(), CL_MEM_COPY_HOST_PTR, sizeof(hostPtr), &hostPtr, retVal)); + EXPECT_EQ(0u, bcsCsr->blitBufferCalled); +} \ No newline at end of file diff --git a/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp index 4f634faaf7..bf69f94697 100644 --- a/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp @@ -29,40 +29,7 @@ #include using namespace NEO; - struct BcsBufferTests : public ::testing::Test { - class BcsMockContext : public MockContext { - public: - BcsMockContext(ClDevice *device) : MockContext(device) { - bcsOsContext.reset(OsContext::create(nullptr, 0, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, device->getDeviceBitfield()))); - bcsCsr.reset(createCommandStream(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield())); - bcsCsr->setupContext(*bcsOsContext); - bcsCsr->initializeTagAllocation(); - bcsCsr->createGlobalFenceAllocation(); - - auto mockBlitMemoryToAllocation = [this](const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr, - Vec3 size) -> BlitOperationResult { - auto blitProperties = BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::HostPtrToBuffer, - *bcsCsr, memory, nullptr, - hostPtr, - memory->getGpuAddress(), 0, - 0, 0, size, 0, 0, 0, 0); - - BlitPropertiesContainer container; - container.push_back(blitProperties); - bcsCsr->blitBuffer(container, true, false, const_cast(device)); - - return BlitOperationResult::Success; - }; - blitMemoryToAllocationFuncBackup = mockBlitMemoryToAllocation; - } - - std::unique_ptr bcsOsContext; - std::unique_ptr bcsCsr; - VariableBackup blitMemoryToAllocationFuncBackup{ - &BlitHelperFunctions::blitMemoryToAllocation}; - }; - template class MyMockCsr : public UltCommandStreamReceiver { public: @@ -149,7 +116,11 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBufferWithInitializationDataAndBcsCsrWhe HWTEST_TEMPLATED_F(BcsBufferTests, givenBufferWithNotDefaultRootDeviceIndexAndBcsCsrWhenCreatingThenUseBlitOperation) { auto rootDeviceIndex = 1u; - std::unique_ptr newDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr, rootDeviceIndex)); + auto hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = true; + + REQUIRE_FULL_BLITTER_OR_SKIP(&hwInfo); + std::unique_ptr newDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex)); std::unique_ptr newBcsMockContext = std::make_unique(newDevice.get()); auto bcsCsr = static_cast *>(newBcsMockContext->bcsCsr.get()); @@ -162,6 +133,28 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBufferWithNotDefaultRootDeviceIndexAndBc EXPECT_EQ(1u, bcsCsr->blitBufferCalled); } +using NoBcsBufferTests = ::testing::Test; +HWTEST_F(NoBcsBufferTests, givenProductWithNoFullyBlitterSupportWhenCreatingBufferWithCopyHostPtrThenDontUseBlitOperation) { + uint32_t hostPtr = 0; + auto rootDeviceIndex = 1u; + auto hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = false; + + EXPECT_FALSE(HwInfoConfig::get(hwInfo.platform.eProductFamily)->isBlitterFullySupported(hwInfo)); + std::unique_ptr newDevice = std::make_unique(MockClDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex)); + std::unique_ptr newBcsMockContext = std::make_unique(newDevice.get()); + + auto bcsCsr = static_cast *>(newBcsMockContext->bcsCsr.get()); + + static_cast(newDevice->getExecutionEnvironment()->memoryManager.get())->enable64kbpages[rootDeviceIndex] = true; + static_cast(newDevice->getExecutionEnvironment()->memoryManager.get())->localMemorySupported[rootDeviceIndex] = true; + + EXPECT_EQ(0u, bcsCsr->blitBufferCalled); + cl_int retVal = 0; + auto bufferForBlt = clUniquePtr(Buffer::create(newBcsMockContext.get(), CL_MEM_COPY_HOST_PTR, sizeof(hostPtr), &hostPtr, retVal)); + EXPECT_EQ(0u, bcsCsr->blitBufferCalled); +} + HWTEST_TEMPLATED_F(BcsBufferTests, givenBcsSupportedWhenEnqueueBufferOperationIsCalledThenUseBcsCsr) { DebugManager.flags.EnableBlitterForEnqueueOperations.set(0); auto mockCmdQueue = static_cast *>(commandQueue.get()); diff --git a/opencl/test/unit_test/mocks/mock_context.cpp b/opencl/test/unit_test/mocks/mock_context.cpp index b8908ee7ab..d382a2d1f8 100644 --- a/opencl/test/unit_test/mocks/mock_context.cpp +++ b/opencl/test/unit_test/mocks/mock_context.cpp @@ -12,6 +12,7 @@ #include "shared/source/memory_manager/deferred_deleter.h" #include "shared/source/memory_manager/os_agnostic_memory_manager.h" #include "shared/source/memory_manager/unified_memory_manager.h" +#include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/mocks/mock_svm_manager.h" #include "opencl/source/command_queue/command_queue.h" @@ -211,4 +212,28 @@ MockUnrestrictiveContextMultiGPU::MockUnrestrictiveContextMultiGPU() : MockConte initializeWithDevices(ClDeviceVector{deviceIds, 6}, true); } +BcsMockContext::BcsMockContext(ClDevice *device) : MockContext(device) { + bcsOsContext.reset(OsContext::create(nullptr, 0, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, device->getDeviceBitfield()))); + bcsCsr.reset(createCommandStream(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield())); + bcsCsr->setupContext(*bcsOsContext); + bcsCsr->initializeTagAllocation(); + bcsCsr->createGlobalFenceAllocation(); + + auto mockBlitMemoryToAllocation = [this](const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr, + Vec3 size) -> BlitOperationResult { + auto blitProperties = BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::HostPtrToBuffer, + *bcsCsr, memory, nullptr, + hostPtr, + memory->getGpuAddress(), 0, + 0, 0, size, 0, 0, 0, 0); + + BlitPropertiesContainer container; + container.push_back(blitProperties); + bcsCsr->blitBuffer(container, true, false, const_cast(device)); + + return BlitOperationResult::Success; + }; + blitMemoryToAllocationFuncBackup = mockBlitMemoryToAllocation; +} +BcsMockContext::~BcsMockContext() = default; } // namespace NEO diff --git a/opencl/test/unit_test/mocks/mock_context.h b/opencl/test/unit_test/mocks/mock_context.h index 8a8e66f112..9e7f4937ff 100644 --- a/opencl/test/unit_test/mocks/mock_context.h +++ b/opencl/test/unit_test/mocks/mock_context.h @@ -6,6 +6,9 @@ */ #pragma once +#include "shared/source/helpers/blit_commands_helper.h" +#include "shared/test/common/helpers/variable_backup.h" + #include "opencl/source/context/context.h" #include "opencl/source/sharings/sharing_factory.h" #include "opencl/test/unit_test/mocks/ult_cl_device_factory.h" @@ -15,6 +18,7 @@ namespace NEO { class AsyncEventsHandler; +class OsContext; class MockContext : public Context { public: @@ -94,4 +98,14 @@ struct MockUnrestrictiveContextMultiGPU : MockContext { ClDevice *pSubDevice11 = nullptr; }; +class BcsMockContext : public MockContext { + public: + BcsMockContext(ClDevice *device); + ~BcsMockContext() override; + + std::unique_ptr bcsOsContext; + std::unique_ptr bcsCsr; + VariableBackup blitMemoryToAllocationFuncBackup{ + &BlitHelperFunctions::blitMemoryToAllocation}; +}; } // namespace NEO