Use createHostUnifiedMemoryAllocation in clHostMemAllocINTEL

Unlock multi device setup for host allocation

Related-To: NEO-5422
Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala
2021-01-05 10:11:24 +00:00
committed by Compute-Runtime-Automation
parent 92f067b9aa
commit 3385500396
3 changed files with 44 additions and 5 deletions

View File

@ -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(

View File

@ -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);
}

View File

@ -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_t>(size, MemoryConstants::pageSize64k);
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(memoryProperties);
std::vector<uint32_t> 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<uint32_t const>());
SvmAllocationData allocData(maxRootDeviceIndex);