Revert "feature: Refactor IPC memory data"

This reverts commit 9c93af7462.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2023-01-21 11:46:44 +01:00
committed by Compute-Runtime-Automation
parent dce17d319f
commit c262ee94c0
4 changed files with 18 additions and 112 deletions

View File

@@ -500,10 +500,10 @@ ze_result_t ContextImp::getIpcMemHandle(const void *ptr,
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
IpcMemoryData &ipcData = *reinterpret_cast<IpcMemoryData *>(pIpcHandle->data);
ipcData = {};
ipcData.handle = handle;
ipcData.type = static_cast<uint8_t>(Context::parseUSMType(allocData->memoryType));
memcpy_s(reinterpret_cast<void *>(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<const IpcMemoryData *>(pIpcHandle.data);
uint64_t handle = ipcData.handle;
uint8_t type = ipcData.type;
NEO::AllocationType allocationType = NEO::AllocationType::UNKNOWN;
if (static_cast<ze_memory_type_t>(type) == ZE_MEMORY_TYPE_HOST) {
allocationType = NEO::AllocationType::BUFFER_HOST_MEMORY;
} else if (static_cast<ze_memory_type_t>(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;

View File

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

View File

@@ -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<uint8_t>(Context::parseUSMType(allocData->memoryType));
IpcMemoryData &ipcData = *reinterpret_cast<IpcMemoryData *>(pIpcHandle->data);
ipcData = {};
ipcData.handle = handle;
ipcData.type = type;
memcpy_s(reinterpret_cast<void *>(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<uint8_t>(Context::parseUSMType(allocData->memoryType));
IpcMemoryData &ipcData = *reinterpret_cast<IpcMemoryData *>(pIpcHandle->data);
ipcData = {};
ipcData.handle = handle;
ipcData.type = type;
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
sizeof(ze_ipc_mem_handle_t),
&handle,
sizeof(handle));
return ZE_RESULT_SUCCESS;
}

View File

@@ -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<NEO::MockDriverModelDRM>());
ze_ipc_memory_flags_t flags = {};
void *ipcPtr;
IpcMemoryData &ipcData = *reinterpret_cast<IpcMemoryData *>(ipcHandle.data);
ipcData.type = static_cast<uint8_t>(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<NEO::MockDriverModelDRM>());
ze_ipc_memory_flags_t flags = {};
void *ipcPtr;
IpcMemoryData &ipcData = *reinterpret_cast<IpcMemoryData *>(ipcHandle.data);
ipcData.type = static_cast<uint8_t>(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;