diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 74d7be8c2c..f6bed1d89b 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -721,7 +721,7 @@ ze_result_t ContextImp::openIpcMemHandles(ze_device_handle_t hDevice, handles.push_back(static_cast(handle)); } - auto neoDevice = Device::fromHandle(hDevice)->getNEODevice()->getRootDevice(); + auto neoDevice = Device::fromHandle(hDevice)->getNEODevice(); NEO::SvmAllocationData allocDataInternal(neoDevice->getRootDeviceIndex()); *pptr = this->driverHandle->importFdHandles(neoDevice, flags, handles, nullptr, nullptr, allocDataInternal); if (nullptr == *pptr) { 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 067423bca4..23c8aa54ab 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -4670,6 +4670,51 @@ TEST_F(MultipleDevicePeerAllocationTest, ASSERT_EQ(result, ZE_RESULT_SUCCESS); } +TEST_F(MultipleDevicePeerAllocationTest, + whenGettingAllocationProperityOfAnIpcBufferThenTheSameSubDeviceIsReturned) { + for (auto l0Device : driverHandle->devices) { + uint32_t nSubDevices = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, l0Device->getSubDevices(&nSubDevices, nullptr)); + EXPECT_EQ(numSubDevices, nSubDevices); + std::vector subDevices(nSubDevices); + EXPECT_EQ(ZE_RESULT_SUCCESS, l0Device->getSubDevices(&nSubDevices, subDevices.data())); + + for (auto subDevice : subDevices) { + constexpr size_t size = 1ul << 18; + ze_device_mem_alloc_desc_t deviceDesc{}; + void *ptr = nullptr; + + EXPECT_EQ(ZE_RESULT_SUCCESS, context->allocDeviceMem(subDevice, &deviceDesc, size, 1ul, &ptr)); + EXPECT_NE(nullptr, ptr); + + uint32_t numIpcHandles = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->getIpcMemHandles(ptr, &numIpcHandles, nullptr)); + EXPECT_EQ(numIpcHandles, 2u); + + std::vector ipcHandles(numIpcHandles); + EXPECT_EQ(ZE_RESULT_SUCCESS, context->getIpcMemHandles(ptr, &numIpcHandles, ipcHandles.data())); + + void *ipcPtr = nullptr; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->openIpcMemHandles(subDevice, numIpcHandles, ipcHandles.data(), 0, &ipcPtr)); + EXPECT_NE(nullptr, ipcPtr); + + ze_device_handle_t registeredDevice = nullptr; + ze_memory_allocation_properties_t allocProp{}; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->getMemAllocProperties(ipcPtr, &allocProp, ®isteredDevice)); + EXPECT_EQ(ZE_MEMORY_TYPE_DEVICE, allocProp.type); + EXPECT_EQ(subDevice, registeredDevice); + + EXPECT_EQ(ZE_RESULT_SUCCESS, context->closeIpcMemHandle(ipcPtr)); + + for (auto &ipcHandle : ipcHandles) { + EXPECT_EQ(ZE_RESULT_SUCCESS, context->putIpcMemHandle(ipcHandle)); + } + + EXPECT_EQ(ZE_RESULT_SUCCESS, context->freeMem(ptr)); + } + } +} + struct MemoryFailedOpenIpcHandleTest : public ::testing::Test { void SetUp() override {