diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index 6191f5c8a4..cf6e44cd17 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -494,8 +494,8 @@ void Context::initializeUsmAllocationPools() { if (!(svmMemoryManager && this->isSingleDeviceContext())) { return; } - - bool enabled = false; + auto &productHelper = getDevices()[0]->getProductHelper(); + bool enabled = productHelper.isUsmPoolAllocatorSupported(); size_t poolSize = 2 * MemoryConstants::megaByte; if (debugManager.flags.EnableDeviceUsmAllocationPool.get() != -1) { enabled = debugManager.flags.EnableDeviceUsmAllocationPool.get() > 0; @@ -511,7 +511,7 @@ void Context::initializeUsmAllocationPools() { usmDeviceMemAllocPool.initialize(svmMemoryManager, memoryProperties, poolSize); } - enabled = false; + enabled = productHelper.isUsmPoolAllocatorSupported(); poolSize = 2 * MemoryConstants::megaByte; if (debugManager.flags.EnableHostUsmAllocationPool.get() != -1) { enabled = debugManager.flags.EnableHostUsmAllocationPool.get() > 0; diff --git a/opencl/test/unit_test/api/cl_set_kernel_arg_svm_pointer_tests.inl b/opencl/test/unit_test/api/cl_set_kernel_arg_svm_pointer_tests.inl index 28db8a4bc0..a1d9f8f3f1 100644 --- a/opencl/test/unit_test/api/cl_set_kernel_arg_svm_pointer_tests.inl +++ b/opencl/test/unit_test/api/cl_set_kernel_arg_svm_pointer_tests.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -221,6 +221,7 @@ TEST_F(clSetKernelArgSVMPointerTests, givenSvmAndValidArgValueWhenSettingSameKer void *const ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4); EXPECT_NE(nullptr, ptrSvm); auto callCounter = 0u; + auto svmData = mockSvmManager->getSVMAlloc(ptrSvm); // first set arg - called mockSvmManager->allocationsCounter = 0u; auto retVal = clSetKernelArgSVMPointer( @@ -261,7 +262,7 @@ TEST_F(clSetKernelArgSVMPointerTests, givenSvmAndValidArgValueWhenSettingSameKer ++mockSvmManager->allocationsCounter; // different pointer - called - void *const nextPtrSvm = static_cast(ptrSvm) + 1; + void *const nextPtrSvm = ptrOffset(ptrSvm, 1); retVal = clSetKernelArgSVMPointer( pMockMultiDeviceKernel, // cl_kernel kernel 0, // cl_uint arg_index @@ -272,18 +273,7 @@ TEST_F(clSetKernelArgSVMPointerTests, givenSvmAndValidArgValueWhenSettingSameKer ++mockSvmManager->allocationsCounter; // different allocId - called - pMockKernel->kernelArguments[0].allocId = 2; - retVal = clSetKernelArgSVMPointer( - pMockMultiDeviceKernel, // cl_kernel kernel - 0, // cl_uint arg_index - nextPtrSvm // const void *arg_value - ); - EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(++callCounter, pMockKernel->setArgSvmAllocCalls); - ++mockSvmManager->allocationsCounter; - - // allocId = 3 - called - pMockKernel->kernelArguments[0].allocId = 3; + pMockKernel->kernelArguments[0].allocId = svmData->getAllocId() + 1; retVal = clSetKernelArgSVMPointer( pMockMultiDeviceKernel, // cl_kernel kernel 0, // cl_uint arg_index diff --git a/opencl/test/unit_test/context/context_negative_tests.cpp b/opencl/test/unit_test/context/context_negative_tests.cpp index d867940d4a..462ff68e9b 100644 --- a/opencl/test/unit_test/context/context_negative_tests.cpp +++ b/opencl/test/unit_test/context/context_negative_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,6 +32,7 @@ TEST_F(ContextFailureInjection, GivenFailedAllocationInjectionWhenCreatingContex debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(0); // failing to allocate pool buffer is non-critical debugManager.flags.SetAmountOfReusableAllocationsPerCmdQueue.set(0); // same for preallocations debugManager.flags.EnableDeviceUsmAllocationPool.set(0); // usm device allocation pooling + debugManager.flags.EnableHostUsmAllocationPool.set(0); // usm host allocation pooling auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); cl_device_id deviceID = device.get(); diff --git a/opencl/test/unit_test/context/context_usm_memory_pool_tests.cpp b/opencl/test/unit_test/context/context_usm_memory_pool_tests.cpp index f8fee4a66a..1498c429e4 100644 --- a/opencl/test/unit_test/context/context_usm_memory_pool_tests.cpp +++ b/opencl/test/unit_test/context/context_usm_memory_pool_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_usm_memory_pool.h" +#include "shared/test/common/test_macros/hw_test.h" #include "opencl/source/cl_device/cl_device.h" #include "opencl/test/unit_test/mocks/mock_context.h" @@ -40,7 +41,7 @@ struct ContextUsmPoolFlagValuesTest : public ::testing::Test { using ContextUsmPoolDefaultFlagsTest = ContextUsmPoolFlagValuesTest<-1, -1>; -TEST_F(ContextUsmPoolDefaultFlagsTest, givenDefaultDebugFlagsWhenCreatingContextThenPoolsAreNotInitialized) { +HWTEST2_F(ContextUsmPoolDefaultFlagsTest, givenDefaultDebugFlagsWhenCreatingContextThenPoolsAreNotInitialized, IsNotXeHpgCore) { EXPECT_FALSE(mockDeviceUsmMemAllocPool->isInitialized()); EXPECT_EQ(0u, mockDeviceUsmMemAllocPool->poolSize); EXPECT_EQ(nullptr, mockDeviceUsmMemAllocPool->pool); @@ -50,6 +51,18 @@ TEST_F(ContextUsmPoolDefaultFlagsTest, givenDefaultDebugFlagsWhenCreatingContext EXPECT_EQ(nullptr, mockHostUsmMemAllocPool->pool); } +HWTEST2_F(ContextUsmPoolDefaultFlagsTest, givenDefaultDebugFlagsWhenCreatingContextThenPoolsAreInitialized, IsXeHpgCore) { + EXPECT_TRUE(mockDeviceUsmMemAllocPool->isInitialized()); + EXPECT_EQ(2 * MemoryConstants::megaByte, mockDeviceUsmMemAllocPool->poolSize); + EXPECT_NE(nullptr, mockDeviceUsmMemAllocPool->pool); + EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, mockDeviceUsmMemAllocPool->poolMemoryType); + + EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized()); + EXPECT_EQ(2 * MemoryConstants::megaByte, mockHostUsmMemAllocPool->poolSize); + EXPECT_NE(nullptr, mockHostUsmMemAllocPool->pool); + EXPECT_EQ(InternalMemoryType::hostUnifiedMemory, mockHostUsmMemAllocPool->poolMemoryType); +} + using ContextUsmPoolEnabledFlagsTest = ContextUsmPoolFlagValuesTest<1, 3>; TEST_F(ContextUsmPoolEnabledFlagsTest, givenEnabledDebugFlagsWhenCreatingContextThenPoolsAreInitialized) { EXPECT_TRUE(mockDeviceUsmMemAllocPool->isInitialized()); diff --git a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp index 4ececfb3b3..3e2ec93762 100644 --- a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -52,6 +52,7 @@ class AggregatedSmallBuffersTestTemplate : public ::testing::Test { void setUpImpl() { debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(poolBufferFlag); debugManager.flags.EnableDeviceUsmAllocationPool.set(0); + debugManager.flags.EnableHostUsmAllocationPool.set(0); this->deviceFactory = std::make_unique(2, 0); this->device = deviceFactory->rootDevices[rootDeviceIndex]; this->mockMemoryManager = static_cast(device->getMemoryManager()); diff --git a/shared/source/os_interface/product_helper.h b/shared/source/os_interface/product_helper.h index e05f67358c..6ffd120e48 100644 --- a/shared/source/os_interface/product_helper.h +++ b/shared/source/os_interface/product_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -161,6 +161,7 @@ class ProductHelper { virtual bool isResolveDependenciesByPipeControlsSupported(const HardwareInfo &hwInfo, bool isOOQ, TaskCountType queueTaskCount, const CommandStreamReceiver &queueCsr) const = 0; virtual bool isMidThreadPreemptionDisallowedForRayTracingKernels() const = 0; virtual bool isBufferPoolAllocatorSupported() const = 0; + virtual bool isUsmPoolAllocatorSupported() const = 0; virtual bool isTlbFlushRequired() const = 0; virtual bool isDummyBlitWaRequired() const = 0; virtual bool isDetectIndirectAccessInKernelSupported(const KernelDescriptor &kernelDescriptor, const bool isPrecompiled) const = 0; diff --git a/shared/source/os_interface/product_helper.inl b/shared/source/os_interface/product_helper.inl index e0c41ca646..425ef3dcda 100644 --- a/shared/source/os_interface/product_helper.inl +++ b/shared/source/os_interface/product_helper.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -584,6 +584,11 @@ bool ProductHelperHw::isBufferPoolAllocatorSupported() const { return false; } +template +bool ProductHelperHw::isUsmPoolAllocatorSupported() const { + return false; +} + template void ProductHelperHw::fillScmPropertiesSupportStructureBase(StateComputeModePropertiesSupport &propertiesSupport) const { propertiesSupport.coherencyRequired = getScmPropertyCoherencyRequiredSupport(); diff --git a/shared/source/os_interface/product_helper_hw.h b/shared/source/os_interface/product_helper_hw.h index 02af2a101a..528474b10b 100644 --- a/shared/source/os_interface/product_helper_hw.h +++ b/shared/source/os_interface/product_helper_hw.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -112,6 +112,7 @@ class ProductHelperHw : public ProductHelper { bool isResolveDependenciesByPipeControlsSupported(const HardwareInfo &hwInfo, bool isOOQ, TaskCountType queueTaskCount, const CommandStreamReceiver &queueCsr) const override; bool isMidThreadPreemptionDisallowedForRayTracingKernels() const override; bool isBufferPoolAllocatorSupported() const override; + bool isUsmPoolAllocatorSupported() const override; bool isTlbFlushRequired() const override; bool isDummyBlitWaRequired() const override; bool isDetectIndirectAccessInKernelSupported(const KernelDescriptor &kernelDescriptor, const bool isPrecompiled) const override; diff --git a/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl b/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl index fbd72f7494..99b418c122 100644 --- a/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl +++ b/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -213,6 +213,11 @@ bool ProductHelperHw::isBufferPoolAllocatorSupported() const { return true; } +template <> +bool ProductHelperHw::isUsmPoolAllocatorSupported() const { + return true; +} + template <> std::optional ProductHelperHw::getAubStreamProductFamily() const { return aub_stream::ProductFamily::Dg2; diff --git a/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl b/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl index f61705d273..59daecd635 100644 --- a/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl +++ b/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -73,6 +73,11 @@ bool ProductHelperHw::isBufferPoolAllocatorSupported() const { return true; } +template <> +bool ProductHelperHw::isUsmPoolAllocatorSupported() const { + return true; +} + template <> uint64_t ProductHelperHw::overridePatIndex(bool isUncachedType, uint64_t patIndex) const { if (isUncachedType) { diff --git a/shared/test/unit_test/os_interface/product_helper_tests.cpp b/shared/test/unit_test/os_interface/product_helper_tests.cpp index 35b7b5d082..fa765cc42f 100644 --- a/shared/test/unit_test/os_interface/product_helper_tests.cpp +++ b/shared/test/unit_test/os_interface/product_helper_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -772,6 +772,14 @@ HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsBufferPoolAllocator EXPECT_TRUE(productHelper->isBufferPoolAllocatorSupported()); } +HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsUsmPoolAllocatorSupportedThenCorrectValueIsReturned, IsNotXeHpgCore) { + EXPECT_FALSE(productHelper->isUsmPoolAllocatorSupported()); +} + +HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsUsmPoolAllocatorSupportedThenCorrectValueIsReturned, IsXeHpgCore) { + EXPECT_TRUE(productHelper->isUsmPoolAllocatorSupported()); +} + HWTEST_F(ProductHelperTest, givenProductHelperWhenCheckingIsUnlockingLockedPtrNecessaryThenReturnFalse) { EXPECT_FALSE(productHelper->isUnlockingLockedPtrNecessary(pInHwInfo)); }