Fix P2P support for implicit scaling (2)
When creating a remote allocation for P2P access, pass the correct device handle so all handles are used. Related-To: LOCI-3122 Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
parent
e6c0d2d1e8
commit
3f5c3a8cdf
|
@ -503,8 +503,9 @@ ze_result_t ContextImp::openIpcMemHandles(ze_device_handle_t hDevice,
|
|||
sizeof(handle));
|
||||
handles.push_back(static_cast<NEO::osHandle>(handle));
|
||||
}
|
||||
auto neoDevice = Device::fromHandle(hDevice)->getNEODevice()->getRootDevice();
|
||||
|
||||
*pptr = this->driverHandle->importFdHandles(hDevice, flags, handles, nullptr);
|
||||
*pptr = this->driverHandle->importFdHandles(neoDevice, flags, handles, nullptr);
|
||||
if (nullptr == *pptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#include "level_zero/core/source/context/context_imp.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) {
|
||||
|
@ -20,7 +20,7 @@ bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory
|
|||
}
|
||||
|
||||
void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) {
|
||||
return this->driverHandle->importFdHandle(hDevice, flags, handle, nullptr);
|
||||
return this->driverHandle->importFdHandle(Device::fromHandle(hDevice)->getNEODevice(), flags, handle, nullptr);
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
|
|
@ -40,7 +40,7 @@ void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, z
|
|||
if (isNTHandle) {
|
||||
return this->driverHandle->importNTHandle(hDevice, reinterpret_cast<void *>(handle));
|
||||
} else if (driverType == NEO::DriverModelType::DRM) {
|
||||
return this->driverHandle->importFdHandle(hDevice, flags, handle, nullptr);
|
||||
return this->driverHandle->importFdHandle(Device::fromHandle(hDevice)->getNEODevice(), flags, handle, nullptr);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -449,8 +449,7 @@ bool DriverHandleImp::isRemoteResourceNeeded(void *ptr, NEO::GraphicsAllocation
|
|||
return (alloc == nullptr || (allocData && ((allocData->gpuAllocations.getGraphicsAllocations().size() - 1) < device->getRootDeviceIndex())));
|
||||
}
|
||||
|
||||
void *DriverHandleImp::importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc) {
|
||||
auto neoDevice = Device::fromHandle(hDevice)->getNEODevice();
|
||||
void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc) {
|
||||
NEO::osHandle osHandle = static_cast<NEO::osHandle>(handle);
|
||||
NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(),
|
||||
MemoryConstants::pageSize,
|
||||
|
@ -490,8 +489,7 @@ void *DriverHandleImp::importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_
|
|||
return reinterpret_cast<void *>(alloc->getGpuAddress());
|
||||
}
|
||||
|
||||
void *DriverHandleImp::importFdHandles(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, std::vector<NEO::osHandle> handles, NEO::GraphicsAllocation **pAlloc) {
|
||||
auto neoDevice = Device::fromHandle(hDevice)->getNEODevice();
|
||||
void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, std::vector<NEO::osHandle> handles, NEO::GraphicsAllocation **pAlloc) {
|
||||
NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(),
|
||||
MemoryConstants::pageSize,
|
||||
NEO::AllocationType::BUFFER,
|
||||
|
@ -552,19 +550,20 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device,
|
|||
alloc = allocData->gpuAllocations.getDefaultGraphicsAllocation();
|
||||
UNRECOVERABLE_IF(alloc == nullptr);
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
uint32_t numHandles = alloc->getNumHandles();
|
||||
|
||||
if (!deviceImp->isSubdevice && deviceImp->isImplicitScalingCapable()) {
|
||||
uint32_t numHandles = alloc->getNumHandles();
|
||||
if (numHandles > 1) {
|
||||
UNRECOVERABLE_IF(numHandles == 0);
|
||||
std::vector<NEO::osHandle> handles;
|
||||
for (uint32_t i = 0; i < numHandles; i++) {
|
||||
int handle = static_cast<int>(alloc->peekInternalHandle(this->getMemoryManager(), i));
|
||||
handles.push_back(handle);
|
||||
}
|
||||
peerPtr = this->importFdHandles(device, flags, handles, &alloc);
|
||||
auto neoDevice = device->getNEODevice()->getRootDevice();
|
||||
peerPtr = this->importFdHandles(neoDevice, flags, handles, &alloc);
|
||||
} else {
|
||||
uint64_t handle = alloc->peekInternalHandle(this->getMemoryManager());
|
||||
peerPtr = this->importFdHandle(device, flags, handle, &alloc);
|
||||
peerPtr = this->importFdHandle(device->getNEODevice(), flags, handle, &alloc);
|
||||
}
|
||||
|
||||
if (peerPtr == nullptr) {
|
||||
|
|
|
@ -37,8 +37,8 @@ struct DriverHandleImp : public DriverHandle {
|
|||
|
||||
NEO::MemoryManager *getMemoryManager() override;
|
||||
void setMemoryManager(NEO::MemoryManager *memoryManager) override;
|
||||
MOCKABLE_VIRTUAL void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc);
|
||||
MOCKABLE_VIRTUAL void *importFdHandles(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, std::vector<NEO::osHandle> handles, NEO::GraphicsAllocation **pAlloc);
|
||||
MOCKABLE_VIRTUAL void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc);
|
||||
MOCKABLE_VIRTUAL void *importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, std::vector<NEO::osHandle> handles, NEO::GraphicsAllocation **pAlloc);
|
||||
MOCKABLE_VIRTUAL void *importNTHandle(ze_device_handle_t hDevice, void *handle);
|
||||
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
|
||||
NEO::SVMAllocsManager *getSvmAllocsManager() override;
|
||||
|
|
|
@ -45,7 +45,7 @@ struct DeviceFixture {
|
|||
};
|
||||
|
||||
struct DriverHandleGetMemHandlePtrMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
if (failHandleLookup) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace L0 {
|
|||
namespace ult {
|
||||
|
||||
struct DriverHandleGetFdMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ struct DriverHandleGetMemHandleMock : public L0::DriverHandleImp {
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
if (mockFd == allocationFdMap.second) {
|
||||
return allocationFdMap.first;
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ struct MemoryExportImportWinHandleTest : public ::testing::Test {
|
|||
};
|
||||
|
||||
struct DriverHandleGetIpcHandleMock : public DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc) override {
|
||||
void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc) override {
|
||||
EXPECT_EQ(handle, static_cast<uint64_t>(mockFd));
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
|
|
|
@ -180,7 +180,7 @@ TEST_F(MemoryExportImportImplicitScalingTest,
|
|||
void *ipcPtr;
|
||||
NEO::GraphicsAllocation *ipcAlloc = nullptr;
|
||||
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(context->getDriverHandle());
|
||||
ipcPtr = driverHandleImp->importFdHandles(device->toHandle(), flags, handles, &ipcAlloc);
|
||||
ipcPtr = driverHandleImp->importFdHandles(device->getNEODevice(), flags, handles, &ipcAlloc);
|
||||
EXPECT_NE(ipcPtr, nullptr);
|
||||
EXPECT_NE(ipcAlloc, nullptr);
|
||||
|
||||
|
@ -230,7 +230,7 @@ TEST_F(MemoryExportImportImplicitScalingTest,
|
|||
void *ipcPtr;
|
||||
NEO::GraphicsAllocation *ipcAlloc = nullptr;
|
||||
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(context->getDriverHandle());
|
||||
ipcPtr = driverHandleImp->importFdHandles(device->toHandle(), flags, handles, &ipcAlloc);
|
||||
ipcPtr = driverHandleImp->importFdHandles(device->getNEODevice(), flags, handles, &ipcAlloc);
|
||||
EXPECT_NE(ipcPtr, nullptr);
|
||||
EXPECT_NE(ipcAlloc, nullptr);
|
||||
|
||||
|
@ -277,6 +277,41 @@ TEST_F(MemoryExportImportImplicitScalingTest,
|
|||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(MemoryExportImportImplicitScalingTest,
|
||||
whenCallingGetImportFdHandleAndAllocationFailsThenNullptrIsReturned) {
|
||||
currMemoryManager->failOnCreateGraphicsAllocationFromSharedHandle = true;
|
||||
|
||||
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);
|
||||
|
||||
uint64_t handle = 0u;
|
||||
memcpy_s(&handle,
|
||||
sizeof(handle),
|
||||
reinterpret_cast<void *>(ipcHandle.data),
|
||||
sizeof(handle));
|
||||
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
NEO::GraphicsAllocation *ipcAlloc = nullptr;
|
||||
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(context->getDriverHandle());
|
||||
void *ipcPtr = driverHandleImp->importFdHandle(device->getNEODevice(), flags, handle, &ipcAlloc);
|
||||
EXPECT_EQ(ipcPtr, nullptr);
|
||||
|
||||
result = context->freeMem(ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
using MemoryTest = Test<DeviceFixture>;
|
||||
|
||||
struct CompressionMemoryTest : public MemoryTest {
|
||||
|
@ -1541,7 +1576,7 @@ TEST_F(ContextMemoryTests, givenMultipleSubDevicesWhenAllocatingThenUseCorrectGl
|
|||
}
|
||||
|
||||
struct DriverHandleFailGetFdMock : public L0::DriverHandleImp {
|
||||
void *importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
void *importFdHandle(NEO::Device *neoDevicee, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAloc) override {
|
||||
importFdHandleCalledTimes++;
|
||||
if (mockFd == allocationMap.second) {
|
||||
return allocationMap.first;
|
||||
|
@ -3630,7 +3665,7 @@ TEST_F(ImportFdUncachedTests,
|
|||
givenCallToImportFdHandleWithUncachedFlagsThenLocallyUncachedResourceIsSet) {
|
||||
ze_ipc_memory_flags_t flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED;
|
||||
uint64_t handle = 1;
|
||||
void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr);
|
||||
void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, nullptr);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr);
|
||||
|
@ -3643,7 +3678,7 @@ TEST_F(ImportFdUncachedTests,
|
|||
givenCallToImportFdHandleWithUncachedIpcFlagsThenLocallyUncachedResourceIsSet) {
|
||||
ze_ipc_memory_flags_t flags = ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED;
|
||||
uint64_t handle = 1;
|
||||
void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr);
|
||||
void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, nullptr);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr);
|
||||
|
@ -3656,7 +3691,7 @@ TEST_F(ImportFdUncachedTests,
|
|||
givenCallToImportFdHandleWithBothUncachedFlagsThenLocallyUncachedResourceIsSet) {
|
||||
ze_ipc_memory_flags_t flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED | ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED;
|
||||
uint64_t handle = 1;
|
||||
void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr);
|
||||
void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, nullptr);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr);
|
||||
|
@ -3669,7 +3704,7 @@ TEST_F(ImportFdUncachedTests,
|
|||
givenCallToImportFdHandleWithoutUncachedFlagsThenLocallyUncachedResourceIsNotSet) {
|
||||
ze_ipc_memory_flags_t flags = {};
|
||||
uint64_t handle = 1;
|
||||
void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr);
|
||||
void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, nullptr);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr);
|
||||
|
|
Loading…
Reference in New Issue