diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 292b77015f..2145a87bcc 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -3778,7 +3778,7 @@ void *clHostMemAllocINTEL( return nullptr; } - return neoContext->getSVMAllocsManager()->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); + return neoContext->getSVMAllocsManager()->createHostUnifiedMemoryAllocation(size, unifiedMemoryProperties); } void *clDeviceMemAllocINTEL( diff --git a/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl b/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl index 3e71c55957..2a2471124e 100644 --- a/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl +++ b/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,7 @@ #include "opencl/source/api/api.h" #include "opencl/test/unit_test/command_queue/command_queue_fixture.h" +#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" #include "opencl/test/unit_test/mocks/mock_memory_manager.h" @@ -1046,3 +1047,39 @@ TEST(clUnifiedSharedMemoryTests, givenUnifiedMemoryAllocationSizeGreaterThanMaxM EXPECT_EQ(nullptr, unfiedMemoryAllocation); } } + +using MultiRootDeviceClUnifiedSharedMemoryTests = MultiRootDeviceFixture; + +TEST_F(MultiRootDeviceClUnifiedSharedMemoryTests, WhenClHostMemAllocIntelIsCalledInMultiRootDeviceEnvironmentThenItAllocatesHostUnifiedMemoryAllocations) { + cl_int retVal = CL_SUCCESS; + auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(context.get(), nullptr, 4, 0, &retVal); + + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, unifiedMemoryHostAllocation); + + auto allocationsManager = context.get()->getSVMAllocsManager(); + + EXPECT_EQ(allocationsManager->getNumAllocs(), 1u); + + auto svmAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation); + auto graphicsAllocation1 = svmAllocation->gpuAllocations.getGraphicsAllocation(1u); + auto graphicsAllocation2 = svmAllocation->gpuAllocations.getGraphicsAllocation(2u); + + EXPECT_EQ(svmAllocation->size, 4u); + EXPECT_EQ(svmAllocation->memoryType, InternalMemoryType::HOST_UNIFIED_MEMORY); + + EXPECT_NE(graphicsAllocation1, nullptr); + EXPECT_NE(graphicsAllocation2, nullptr); + + EXPECT_EQ(graphicsAllocation1->getRootDeviceIndex(), 1u); + EXPECT_EQ(graphicsAllocation2->getRootDeviceIndex(), 2u); + + EXPECT_EQ(graphicsAllocation1->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + EXPECT_EQ(graphicsAllocation2->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + + EXPECT_EQ(graphicsAllocation1->getGpuAddress(), castToUint64(unifiedMemoryHostAllocation)); + EXPECT_EQ(graphicsAllocation2->getGpuAddress(), castToUint64(unifiedMemoryHostAllocation)); + + retVal = clMemFreeINTEL(context.get(), unifiedMemoryHostAllocation); + EXPECT_EQ(CL_SUCCESS, retVal); +} diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index 0bfe396a69..f88b4d9854 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -123,7 +123,7 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties) { size_t alignedSize = alignUp(size, MemoryConstants::pageSize64k); - GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; + GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(memoryProperties); std::vector rootDeviceIndicesVector(memoryProperties.rootDeviceIndices.begin(), memoryProperties.rootDeviceIndices.end()); @@ -138,6 +138,8 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size, deviceBitfield.count() > 1, deviceBitfield}; unifiedMemoryProperties.flags.shareable = memoryProperties.allocationFlags.flags.shareable; + unifiedMemoryProperties.flags.isUSMHostAllocation = true; + unifiedMemoryProperties.flags.isUSMDeviceAllocation = false; auto maxRootDeviceIndex = *std::max_element(rootDeviceIndicesVector.begin(), rootDeviceIndicesVector.end(), std::less()); SvmAllocationData allocData(maxRootDeviceIndex);