Fix missing handle in external memory

Related-To: NEO-6757

Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com>
This commit is contained in:
Baj, Tomasz
2022-05-31 09:36:11 +00:00
committed by Compute-Runtime-Automation
parent 0a4adc7c72
commit 9529f21182
4 changed files with 36 additions and 15 deletions

View File

@ -147,7 +147,7 @@ cl_mem Buffer::validateInputAndCreateBuffer(cl_context context,
if (memoryProperties.handle) {
if (validateHandleType(memoryProperties, extMem)) {
extMem.handle = &memoryProperties.handle;
extMem.handle = reinterpret_cast<void *>(memoryProperties.handle);
extMem.size = size;
pBuffer = UnifiedBuffer::createSharedUnifiedBuffer(pContext, flags, extMem, &retVal);
} else {

View File

@ -98,24 +98,31 @@ struct ValidExportHostPtr
MemoryManagementFixture::TearDown();
}
Buffer *createBuffer() {
return Buffer::create(
context.get(),
flags,
g_scTestBufferSizeInBytes,
pHostPtr,
retVal);
}
cl_int retVal = CL_INVALID_VALUE;
Buffer *buffer = nullptr;
};
TEST_F(ValidExportHostPtr, givenPropertiesWithDmaBufWhenValidateInputAndCreateBufferThenCorrectBufferIsSet) {
cl_mem_properties properties[] = {CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR, 0x1234, 0};
auto buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), properties, flags, 0, g_scTestBufferSizeInBytes, nullptr, retVal);
EXPECT_EQ(retVal, CL_SUCCESS);
EXPECT_NE(nullptr, buffer);
TEST_F(ValidExportHostPtr, givenInvalidPropertiesWithDmaBufWhenValidateInputAndCreateBufferThenCorrectBufferIsSet) {
osHandle invalidHandle = static_cast<MockMemoryManager *>(pClExecutionEnvironment->memoryManager.get())->invalidSharedHandle;
cl_mem_properties properties[] = {CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR, invalidHandle, 0};
cl_mem buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), properties, flags, 0, g_scTestBufferSizeInBytes, nullptr, retVal);
EXPECT_EQ(retVal, CL_INVALID_MEM_OBJECT);
EXPECT_EQ(static_cast<MockMemoryManager *>(pClExecutionEnvironment->memoryManager.get())->capturedSharedHandle, properties[1]);
EXPECT_EQ(buffer, nullptr);
clReleaseMemObject(buffer);
}
TEST_F(ValidExportHostPtr, givenPropertiesWithDmaBufWhenValidateInputAndCreateBufferThenCorrectBufferIsSet) {
cl_mem_properties properties[] = {CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR, 0x1234, 0};
cl_mem buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), properties, flags, 0, g_scTestBufferSizeInBytes, nullptr, retVal);
EXPECT_EQ(retVal, CL_SUCCESS);
EXPECT_EQ(static_cast<MockMemoryManager *>(pClExecutionEnvironment->memoryManager.get())->capturedSharedHandle, properties[1]);
EXPECT_NE(buffer, nullptr);
clReleaseMemObject(buffer);
}

View File

@ -152,6 +152,17 @@ GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromExistingStora
return allocation;
}
GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
if (handle != invalidSharedHandle) {
auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation);
this->capturedSharedHandle = handle;
return allocation;
} else {
this->capturedSharedHandle = handle;
return nullptr;
}
}
bool MockMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) {
copyMemoryToAllocationBanksCalled++;
copyMemoryToAllocationBanksParamsPassed.push_back({graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, handleMask});

View File

@ -82,6 +82,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override;
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override;
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
void *allocateSystemMemory(size_t size, size_t alignment) override;
@ -220,6 +221,8 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
uint32_t handleFenceCompletionCalled = 0u;
uint32_t waitForEnginesCompletionCalled = 0u;
uint32_t allocateGraphicsMemoryWithPropertiesCount = 0;
osHandle capturedSharedHandle = 0u;
osHandle invalidSharedHandle = -1;
bool allocationCreated = false;
bool allocation64kbPageCreated = false;
bool allocationInDevicePoolCreated = false;