From c262ee94c00998a993ccf147810f345b1e017fb7 Mon Sep 17 00:00:00 2001 From: Compute-Runtime-Validation Date: Sat, 21 Jan 2023 11:46:44 +0100 Subject: [PATCH] Revert "feature: Refactor IPC memory data" This reverts commit 9c93af746223a0a958790f202c86de831c929209. Signed-off-by: Compute-Runtime-Validation --- .../core/source/context/context_imp.cpp | 28 +++----- level_zero/core/source/context/context_imp.h | 8 --- .../unit_tests/fixtures/memory_ipc_fixture.h | 22 +++--- .../unit_tests/sources/memory/test_memory.cpp | 72 ------------------- 4 files changed, 18 insertions(+), 112 deletions(-) diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index e8298a2529..8ada169a2b 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -500,10 +500,10 @@ ze_result_t ContextImp::getIpcMemHandle(const void *ptr, return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; } - IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); - ipcData = {}; - ipcData.handle = handle; - ipcData.type = static_cast(Context::parseUSMType(allocData->memoryType)); + memcpy_s(reinterpret_cast(pIpcHandle->data), + sizeof(ze_ipc_mem_handle_t), + &handle, + sizeof(handle)); return ZE_RESULT_SUCCESS; } @@ -548,23 +548,15 @@ ze_result_t ContextImp::openIpcMemHandle(ze_device_handle_t hDevice, const ze_ipc_mem_handle_t &pIpcHandle, ze_ipc_memory_flags_t flags, void **ptr) { - const IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle.data); - - uint64_t handle = ipcData.handle; - uint8_t type = ipcData.type; - - NEO::AllocationType allocationType = NEO::AllocationType::UNKNOWN; - if (static_cast(type) == ZE_MEMORY_TYPE_HOST) { - allocationType = NEO::AllocationType::BUFFER_HOST_MEMORY; - } else if (static_cast(type) == ZE_MEMORY_TYPE_DEVICE) { - allocationType = NEO::AllocationType::BUFFER; - } else { - return ZE_RESULT_ERROR_INVALID_ARGUMENT; - } + uint64_t handle = 0u; + memcpy_s(&handle, + sizeof(handle), + pIpcHandle.data, + sizeof(handle)); *ptr = getMemHandlePtr(hDevice, handle, - allocationType, + NEO::AllocationType::BUFFER, flags); if (nullptr == *ptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; diff --git a/level_zero/core/source/context/context_imp.h b/level_zero/core/source/context/context_imp.h index b6e533d925..66f1fc2a5e 100644 --- a/level_zero/core/source/context/context_imp.h +++ b/level_zero/core/source/context/context_imp.h @@ -20,14 +20,6 @@ struct StructuresLookupTable; struct DriverHandleImp; struct Device; -#pragma pack(1) -struct IpcMemoryData { - uint64_t handle = 0; - uint8_t type = 0; -}; -#pragma pack() -static_assert(sizeof(IpcMemoryData) <= ZE_MAX_IPC_HANDLE_SIZE, "IpcMemoryData is bigger than ZE_MAX_IPC_HANDLE_SIZE"); - struct ContextImp : Context { ContextImp(DriverHandle *driverHandle); ~ContextImp() override = default; diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h index 14e0cb8283..c5b8ab83f6 100644 --- a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h @@ -377,13 +377,10 @@ struct ContextGetIpcHandleMock : public L0::ContextImp { ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override { uint64_t handle = driverHandle->mockFd; - NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); - uint8_t type = static_cast(Context::parseUSMType(allocData->memoryType)); - - IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); - ipcData = {}; - ipcData.handle = handle; - ipcData.type = type; + memcpy_s(reinterpret_cast(pIpcHandle->data), + sizeof(ze_ipc_mem_handle_t), + &handle, + sizeof(handle)); return ZE_RESULT_SUCCESS; } @@ -555,13 +552,10 @@ struct ContextIpcMock : public L0::ContextImp { ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override { uint64_t handle = mockFd; - NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); - uint8_t type = static_cast(Context::parseUSMType(allocData->memoryType)); - - IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); - ipcData = {}; - ipcData.handle = handle; - ipcData.type = type; + memcpy_s(reinterpret_cast(pIpcHandle->data), + sizeof(ze_ipc_mem_handle_t), + &handle, + sizeof(handle)); return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index 39ad75f109..a7ead00e2f 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -146,78 +146,6 @@ TEST_F(MemoryExportImportImplicitScalingTest, EXPECT_EQ(ZE_RESULT_SUCCESS, result); } -TEST_F(MemoryExportImportImplicitScalingTest, - whenCallingOpenIpcHandleWithIpcHandleAndSharedMemoryTypeThenInvalidArgumentIsReturned) { - DebugManagerStateRestore restorer; - DebugManager.flags.EnableImplicitScaling.set(0u); - - size_t size = 10; - size_t alignment = 1u; - void *ptr = nullptr; - - ze_device_mem_alloc_desc_t deviceDesc = {}; - ze_result_t result = context->allocDeviceMem(device->toHandle(), - &deviceDesc, - size, alignment, &ptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_NE(nullptr, ptr); - - ze_ipc_mem_handle_t ipcHandle; - result = context->getIpcMemHandle(ptr, &ipcHandle); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); - - ze_ipc_memory_flags_t flags = {}; - void *ipcPtr; - - IpcMemoryData &ipcData = *reinterpret_cast(ipcHandle.data); - ipcData.type = static_cast(ZE_MEMORY_TYPE_SHARED); - - result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); - - result = context->freeMem(ptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); -} - -TEST_F(MemoryExportImportImplicitScalingTest, - whenCallingOpenIpcHandleWithIpcHandleAndHostMemoryTypeThenInvalidArgumentIsReturned) { - DebugManagerStateRestore restorer; - DebugManager.flags.EnableImplicitScaling.set(0u); - - size_t size = 10; - size_t alignment = 1u; - void *ptr = nullptr; - - ze_device_mem_alloc_desc_t deviceDesc = {}; - ze_result_t result = context->allocDeviceMem(device->toHandle(), - &deviceDesc, - size, alignment, &ptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_NE(nullptr, ptr); - - ze_ipc_mem_handle_t ipcHandle; - result = context->getIpcMemHandle(ptr, &ipcHandle); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); - - ze_ipc_memory_flags_t flags = {}; - void *ipcPtr; - - IpcMemoryData &ipcData = *reinterpret_cast(ipcHandle.data); - ipcData.type = static_cast(ZE_MEMORY_TYPE_HOST); - - result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); - - result = context->freeMem(ptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); -} - TEST_F(MemoryExportImportImplicitScalingTest, whenCallingImportFdHandlesWithAllocationPointerThenAllocationIsReturned) { size_t size = 10;