mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
Fix missing handle in external memory
Related-To: NEO-6757 Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
0a4adc7c72
commit
9529f21182
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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});
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user