fix: Fix HostPointerManager multi-allocation for non-zero root device indices

Related-To: NEO-15430

Previously, HostPointerManager constructed HostPointerData and
MultiGraphicsAllocation using devices.size()-1 as the max root device index.
This caused aborts when devices with non-zero root device indices were used,
since the internal allocation vector was undersized.
This change computes the maximum root device index from the input device vector
and uses it to size HostPointerData and MultiGraphicsAllocation correctly.

Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek
2025-10-14 20:55:16 +00:00
committed by Compute-Runtime-Automation
parent 9cc773f7ab
commit 1410459836
2 changed files with 38 additions and 2 deletions

View File

@@ -82,7 +82,11 @@ ze_result_t HostPointerManager::createHostPointerMultiAllocation(std::vector<Dev
return ZE_RESULT_ERROR_INVALID_SIZE;
}
HostPointerData hostData(static_cast<uint32_t>(devices.size() - 1));
uint32_t maxRootDeviceIndex = 0;
for (auto device : devices) {
maxRootDeviceIndex = std::max(maxRootDeviceIndex, device->getRootDeviceIndex());
}
HostPointerData hostData(maxRootDeviceIndex);
hostData.basePtr = ptr;
hostData.size = size;
for (auto device : devices) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -16,7 +16,10 @@
#include "level_zero/core/source/context/context.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "level_zero/core/test/unit_tests/mocks/mock_host_pointer_manager.h"
namespace L0 {
@@ -487,5 +490,34 @@ TEST_F(ForceEnabledHostPointerManagerTest, givenHostPointerManagerForceEnabledTh
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
using MultiDeviceHostPointerManagerTests = Test<MultiDeviceFixture>;
TEST_F(MultiDeviceHostPointerManagerTests, createHostPointerMultiAllocationHandlesNonZeroRootDeviceIndex) {
// Create a NEO device with rootDeviceIndex == 1
const uint32_t rootDeviceIndex = 1;
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), rootDeviceIndex));
MockDeviceImp l0Device(neoDevice);
NEO::DeviceVector neoDevices;
neoDevices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto hostDriverHandle = std::make_unique<L0::ult::DriverHandle>();
hostDriverHandle->initialize(std::move(neoDevices));
std::vector<L0::Device *> devices;
devices.push_back(&l0Device);
size_t bufferSize = 4096;
void *buffer = malloc(bufferSize);
// Should not abort, should succeed
auto openHostPointerManager = static_cast<L0::ult::HostPointerManager *>(hostDriverHandle->hostPointerManager.get());
auto result = openHostPointerManager->createHostPointerMultiAllocation(devices, buffer, bufferSize);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
openHostPointerManager->freeHostPointerAllocation(buffer);
free(buffer);
}
} // namespace ult
} // namespace L0