Unified memory sharing 10/n
Enable creating allocations from non-NT handles Change-Id: Ifd8c67dfd5624182aed76457b1d80bcc2659dd45 Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com> Related-To: NEO-3771
This commit is contained in:
parent
9562daa2d0
commit
bd9cd46ab9
|
@ -20,7 +20,7 @@ using namespace NEO;
|
||||||
Buffer *UnifiedBuffer::createSharedUnifiedBuffer(Context *context, cl_mem_flags flags, UnifiedSharingMemoryDescription extMem, cl_int *errcodeRet) {
|
Buffer *UnifiedBuffer::createSharedUnifiedBuffer(Context *context, cl_mem_flags flags, UnifiedSharingMemoryDescription extMem, cl_int *errcodeRet) {
|
||||||
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
|
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
|
||||||
|
|
||||||
auto graphicsAllocation = UnifiedBuffer::createGraphicsAllocation(context, extMem);
|
auto graphicsAllocation = UnifiedBuffer::createGraphicsAllocation(context, extMem, GraphicsAllocation::AllocationType::SHARED_BUFFER);
|
||||||
if (!graphicsAllocation) {
|
if (!graphicsAllocation) {
|
||||||
errorCode.set(CL_INVALID_MEM_OBJECT);
|
errorCode.set(CL_INVALID_MEM_OBJECT);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -29,7 +29,7 @@ Image *UnifiedImage::createSharedUnifiedImage(Context *context, cl_mem_flags fla
|
||||||
imgInfo.imgDesc = Image::convertDescriptor(*imageDesc);
|
imgInfo.imgDesc = Image::convertDescriptor(*imageDesc);
|
||||||
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat;
|
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat;
|
||||||
|
|
||||||
GraphicsAllocation *graphicsAllocation = createGraphicsAllocation(context, description);
|
GraphicsAllocation *graphicsAllocation = createGraphicsAllocation(context, description, GraphicsAllocation::AllocationType::SHARED_IMAGE);
|
||||||
if (!graphicsAllocation) {
|
if (!graphicsAllocation) {
|
||||||
errorCode.set(CL_INVALID_MEM_OBJECT);
|
errorCode.set(CL_INVALID_MEM_OBJECT);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -30,11 +30,16 @@ void UnifiedSharing::synchronizeObject(UpdateData &updateData) {
|
||||||
void UnifiedSharing::releaseResource(MemObj *memObject) {
|
void UnifiedSharing::releaseResource(MemObj *memObject) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description) {
|
GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, GraphicsAllocation::AllocationType allocationType) {
|
||||||
|
auto memoryManager = context->getMemoryManager();
|
||||||
switch (description.type) {
|
switch (description.type) {
|
||||||
case UnifiedSharingHandleType::Win32Nt: {
|
case UnifiedSharingHandleType::Win32Nt: {
|
||||||
auto graphicsAllocation = context->getMemoryManager()->createGraphicsAllocationFromNTHandle(description.handle, 0u);
|
return memoryManager->createGraphicsAllocationFromNTHandle(description.handle, 0u);
|
||||||
return graphicsAllocation;
|
}
|
||||||
|
case UnifiedSharingHandleType::LinuxFd:
|
||||||
|
case UnifiedSharingHandleType::Win32Shared: {
|
||||||
|
const AllocationProperties properties{0u, false, 0u, allocationType, false};
|
||||||
|
return memoryManager->createGraphicsAllocationFromSharedHandle(((osHandle)(uint64_t)description.handle), properties, false);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -39,7 +39,7 @@ class UnifiedSharing : public SharingHandler {
|
||||||
void synchronizeObject(UpdateData &updateData) override;
|
void synchronizeObject(UpdateData &updateData) override;
|
||||||
void releaseResource(MemObj *memObject) override;
|
void releaseResource(MemObj *memObject) override;
|
||||||
|
|
||||||
static GraphicsAllocation *createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description);
|
static GraphicsAllocation *createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, GraphicsAllocation::AllocationType allocationType);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnifiedSharingFunctions *sharingFunctions;
|
UnifiedSharingFunctions *sharingFunctions;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2019 Intel Corporation
|
* Copyright (C) 2019-2020 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
|
@ -57,15 +57,7 @@ TEST_F(UnifiedSharingBufferTestsWithMemoryManager, givenUnsupportedHandleTypeWhe
|
||||||
desc.handle = reinterpret_cast<void *>(0x1234);
|
desc.handle = reinterpret_cast<void *>(0x1234);
|
||||||
|
|
||||||
auto buffer = std::unique_ptr<Buffer>(UnifiedBuffer::createSharedUnifiedBuffer(context.get(), flags, desc, &retVal));
|
auto buffer = std::unique_ptr<Buffer>(UnifiedBuffer::createSharedUnifiedBuffer(context.get(), flags, desc, &retVal));
|
||||||
ASSERT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
||||||
|
|
||||||
desc.type = UnifiedSharingHandleType::Win32Shared;
|
|
||||||
buffer = std::unique_ptr<Buffer>(UnifiedBuffer::createSharedUnifiedBuffer(context.get(), flags, desc, &retVal));
|
|
||||||
ASSERT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
|
||||||
|
|
||||||
desc.type = UnifiedSharingHandleType::LinuxFd;
|
|
||||||
buffer = std::unique_ptr<Buffer>(UnifiedBuffer::createSharedUnifiedBuffer(context.get(), flags, desc, &retVal));
|
|
||||||
ASSERT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnifiedSharingBufferTestsWithMemoryManager, givenValidContextAndMemoryManagerWhenCreatingBufferFromSharedHandleThenReturnSuccess) {
|
TEST_F(UnifiedSharingBufferTestsWithMemoryManager, givenValidContextAndMemoryManagerWhenCreatingBufferFromSharedHandleThenReturnSuccess) {
|
||||||
|
|
|
@ -66,16 +66,6 @@ TEST_F(UnifiedSharingImageTestsWithMemoryManager, givenUnsupportedHandleTypeWhen
|
||||||
auto image = std::unique_ptr<Image>(UnifiedImage::createSharedUnifiedImage(context.get(), flags, desc,
|
auto image = std::unique_ptr<Image>(UnifiedImage::createSharedUnifiedImage(context.get(), flags, desc,
|
||||||
&format, &imageDesc, &retVal));
|
&format, &imageDesc, &retVal));
|
||||||
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
||||||
|
|
||||||
desc.type = UnifiedSharingHandleType::Win32Shared;
|
|
||||||
image = std::unique_ptr<Image>(UnifiedImage::createSharedUnifiedImage(context.get(), flags, desc,
|
|
||||||
&format, &imageDesc, &retVal));
|
|
||||||
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
|
||||||
|
|
||||||
desc.type = UnifiedSharingHandleType::LinuxFd;
|
|
||||||
image = std::unique_ptr<Image>(UnifiedImage::createSharedUnifiedImage(context.get(), flags, desc,
|
|
||||||
&format, &imageDesc, &retVal));
|
|
||||||
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnifiedSharingImageTestsWithMemoryManager, givenValidContextAndMemoryManagerWhenCreatingImageFromSharedHandleThenReturnSuccess) {
|
TEST_F(UnifiedSharingImageTestsWithMemoryManager, givenValidContextAndMemoryManagerWhenCreatingImageFromSharedHandleThenReturnSuccess) {
|
||||||
|
|
|
@ -162,3 +162,79 @@ TEST_F(UnifiedSharingTestsWithMemoryManager, givenUnifiedSharingHandlerWhenAcqui
|
||||||
sharingHandler->release(buffer.get());
|
sharingHandler->release(buffer.get());
|
||||||
EXPECT_EQ(1u, sharingHandler->releaseResourceCalled);
|
EXPECT_EQ(1u, sharingHandler->releaseResourceCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManager {
|
||||||
|
struct MemoryManagerCheckingAllocationMethod : MockMemoryManager {
|
||||||
|
using MockMemoryManager::MockMemoryManager;
|
||||||
|
|
||||||
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override {
|
||||||
|
this->createFromNTHandleCalled = true;
|
||||||
|
this->handle = (osHandle)(uint64_t)handle;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override {
|
||||||
|
this->createFromSharedHandleCalled = true;
|
||||||
|
this->handle = handle;
|
||||||
|
this->properties = std::make_unique<AllocationProperties>(properties);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool createFromNTHandleCalled = false;
|
||||||
|
bool createFromSharedHandleCalled = false;
|
||||||
|
osHandle handle;
|
||||||
|
std::unique_ptr<AllocationProperties> properties;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MockSharingHandler : UnifiedSharing {
|
||||||
|
using UnifiedSharing::createGraphicsAllocation;
|
||||||
|
};
|
||||||
|
|
||||||
|
void SetUp() override {
|
||||||
|
UnifiedSharingTestsWithMemoryManager::SetUp();
|
||||||
|
this->memoryManager = std::make_unique<MemoryManagerCheckingAllocationMethod>();
|
||||||
|
this->memoryManagerBackup = std::make_unique<VariableBackup<MemoryManager *>>(&this->context->memoryManager, this->memoryManager.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MemoryManagerCheckingAllocationMethod> memoryManager;
|
||||||
|
std::unique_ptr<VariableBackup<MemoryManager *>> memoryManagerBackup;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsNtHandleWhenCreateGraphicsAllocationIsCalledThenUseNtHandleMethod) {
|
||||||
|
UnifiedSharingMemoryDescription desc{};
|
||||||
|
desc.handle = reinterpret_cast<void *>(0x1234);
|
||||||
|
desc.type = UnifiedSharingHandleType::Win32Nt;
|
||||||
|
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::SHARED_IMAGE;
|
||||||
|
MockSharingHandler::createGraphicsAllocation(this->context.get(), desc, allocationType);
|
||||||
|
|
||||||
|
EXPECT_TRUE(memoryManager->createFromNTHandleCalled);
|
||||||
|
EXPECT_FALSE(memoryManager->createFromSharedHandleCalled);
|
||||||
|
EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) {
|
||||||
|
UnifiedSharingMemoryDescription desc{};
|
||||||
|
desc.handle = reinterpret_cast<void *>(0x1234);
|
||||||
|
desc.type = UnifiedSharingHandleType::Win32Shared;
|
||||||
|
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::SHARED_IMAGE;
|
||||||
|
MockSharingHandler::createGraphicsAllocation(this->context.get(), desc, allocationType);
|
||||||
|
|
||||||
|
EXPECT_FALSE(memoryManager->createFromNTHandleCalled);
|
||||||
|
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
|
||||||
|
EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle);
|
||||||
|
const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false};
|
||||||
|
EXPECT_EQ(expectedProperties.allFlags, memoryManager->properties->allFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UnifiedSharingCreateAllocationTests, givenLinuxSharedHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) {
|
||||||
|
UnifiedSharingMemoryDescription desc{};
|
||||||
|
desc.handle = reinterpret_cast<void *>(0x1234);
|
||||||
|
desc.type = UnifiedSharingHandleType::LinuxFd;
|
||||||
|
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::SHARED_IMAGE;
|
||||||
|
MockSharingHandler::createGraphicsAllocation(this->context.get(), desc, allocationType);
|
||||||
|
|
||||||
|
EXPECT_FALSE(memoryManager->createFromNTHandleCalled);
|
||||||
|
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
|
||||||
|
EXPECT_EQ((osHandle)(uint64_t)desc.handle, memoryManager->handle);
|
||||||
|
const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false};
|
||||||
|
EXPECT_EQ(expectedProperties.allFlags, memoryManager->properties->allFlags);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue