Skip to content

Commit 325db6a

Browse files
Jaime ArteagaCompute-Runtime-Automation
Jaime Arteaga
authored andcommitted
Fix P2P support for implicit scaling
when using implicit scaling, 2 dma-buf handles, one per tile, are needed to support dma access from peer. Related-To: LOCI-3122 Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
1 parent 09c68a6 commit 325db6a

File tree

5 files changed

+93
-11
lines changed

5 files changed

+93
-11
lines changed

level_zero/core/source/driver/driver_handle_imp.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,22 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device,
554554
} else {
555555
alloc = allocData->gpuAllocations.getDefaultGraphicsAllocation();
556556
UNRECOVERABLE_IF(alloc == nullptr);
557-
uint64_t handle = alloc->peekInternalHandle(this->getMemoryManager());
558557
ze_ipc_memory_flags_t flags = {};
559558

560-
peerPtr = this->importFdHandle(device, flags, handle, &alloc);
559+
if (!deviceImp->isSubdevice && deviceImp->isImplicitScalingCapable()) {
560+
uint32_t numHandles = alloc->getNumHandles();
561+
UNRECOVERABLE_IF(numHandles == 0);
562+
std::vector<NEO::osHandle> handles;
563+
for (uint32_t i = 0; i < numHandles; i++) {
564+
int handle = static_cast<int>(alloc->peekInternalHandle(this->getMemoryManager(), i));
565+
handles.push_back(handle);
566+
}
567+
peerPtr = this->importFdHandles(device, flags, handles, &alloc);
568+
} else {
569+
uint64_t handle = alloc->peekInternalHandle(this->getMemoryManager());
570+
peerPtr = this->importFdHandle(device, flags, handle, &alloc);
571+
}
572+
561573
if (peerPtr == nullptr) {
562574
return nullptr;
563575
}

level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,18 @@ class IpcImplicitScalingMockGraphicsAllocation : public NEO::MemoryAllocation {
443443
uint32_t getNumHandles() override {
444444
return 2u;
445445
}
446+
447+
bool isResident(uint32_t contextId) const override {
448+
return false;
449+
}
446450
};
447451

448452
class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
449453
public:
450454
MemoryManagerOpenIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerIpcMock(executionEnvironment) {}
451455

452456
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
453-
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0,
457+
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex,
454458
NEO::AllocationType::BUFFER,
455459
reinterpret_cast<void *>(sharedHandleAddress++),
456460
0x1000,
@@ -465,7 +469,21 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
465469
if (failOnCreateGraphicsAllocationFromSharedHandle) {
466470
return nullptr;
467471
}
468-
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0,
472+
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex,
473+
NEO::AllocationType::BUFFER,
474+
reinterpret_cast<void *>(sharedHandleAddress++),
475+
0x1000,
476+
0,
477+
sizeof(uint32_t),
478+
MemoryPool::System4KBPages);
479+
alloc->setGpuBaseAddress(0xabcd);
480+
return alloc;
481+
}
482+
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
483+
if (failOnCreateGraphicsAllocationFromSharedHandle) {
484+
return nullptr;
485+
}
486+
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex,
469487
NEO::AllocationType::BUFFER,
470488
reinterpret_cast<void *>(sharedHandleAddress++),
471489
0x1000,
@@ -476,7 +494,7 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
476494
return alloc;
477495
}
478496
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override {
479-
auto alloc = new NEO::MockGraphicsAllocation(0,
497+
auto alloc = new NEO::MockGraphicsAllocation(0u,
480498
NEO::AllocationType::BUFFER,
481499
reinterpret_cast<void *>(sharedHandleAddress++),
482500
0x1000,
@@ -487,6 +505,14 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
487505
return alloc;
488506
};
489507

508+
void freeGraphicsMemory(GraphicsAllocation *gfxAllocation) override {
509+
delete gfxAllocation;
510+
}
511+
512+
void freeGraphicsMemory(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override {
513+
delete gfxAllocation;
514+
}
515+
490516
uint64_t sharedHandleAddress = 0x1234;
491517

492518
bool failOnCreateGraphicsAllocationFromSharedHandle = false;

level_zero/core/test/unit_tests/sources/device/test_device.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ TEST_F(MultipleDevicesTest, givenTheSameDeviceThenCanAccessPeerReturnsTrue) {
18511851
EXPECT_TRUE(canAccess);
18521852
}
18531853

1854-
TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerSuccessfullyCompletes) {
1854+
TEST_F(MultipleDevicesDisabledImplicitScalingTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerSuccessfullyCompletes) {
18551855
L0::Device *device0 = driverHandle->devices[0];
18561856
L0::Device *device1 = driverHandle->devices[1];
18571857

@@ -1864,7 +1864,7 @@ TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerSu
18641864
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
18651865
}
18661866

1867-
HWTEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyAndDeviceLostSynchronizeThenCanAccessPeerReturnsDeviceLost) {
1867+
HWTEST_F(MultipleDevicesDisabledImplicitScalingTest, givenTwoRootDevicesFromSameFamilyAndDeviceLostSynchronizeThenCanAccessPeerReturnsDeviceLost) {
18681868
constexpr size_t devicesCount{2};
18691869
ASSERT_LE(devicesCount, driverHandle->devices.size());
18701870

@@ -2095,7 +2095,7 @@ TEST_F(MultipleDevicesP2PDevice0Access1Atomic1Device1Access1Atomic1Test, WhenCal
20952095
EXPECT_TRUE(p2pProperties.flags & ZE_DEVICE_P2P_PROPERTY_FLAG_ATOMICS);
20962096
}
20972097

2098-
TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerReturnsTrue) {
2098+
TEST_F(MultipleDevicesDisabledImplicitScalingTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerReturnsTrue) {
20992099
L0::Device *device0 = driverHandle->devices[0];
21002100
L0::Device *device1 = driverHandle->devices[1];
21012101

@@ -2109,7 +2109,7 @@ TEST_F(MultipleDevicesTest, givenTwoRootDevicesFromSameFamilyThenCanAccessPeerRe
21092109
EXPECT_TRUE(canAccess);
21102110
}
21112111

2112-
TEST_F(MultipleDevicesTest, givenCanAccessPeerCalledTwiceThenCanAccessPeerReturnsSameValueEachTime) {
2112+
TEST_F(MultipleDevicesDisabledImplicitScalingTest, givenCanAccessPeerCalledTwiceThenCanAccessPeerReturnsSameValueEachTime) {
21132113
L0::Device *device0 = driverHandle->devices[0];
21142114
L0::Device *device1 = driverHandle->devices[1];
21152115

level_zero/core/test/unit_tests/sources/memory/test_memory.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,7 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
19901990
}
19911991

19921992
void SetUp() override {
1993+
DebugManagerStateRestore restorer;
19931994
NEO::MockCompilerEnableGuard mock(true);
19941995
DebugManager.flags.CreateMultipleSubDevices.set(numSubDevices);
19951996
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
@@ -2017,11 +2018,20 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
20172018
for (auto i = 0u; i < numRootDevices; i++) {
20182019
auto device = driverHandle->devices[i];
20192020
context->getDevices().insert(std::make_pair(device->toHandle(), device));
2021+
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>(device);
2022+
for (auto j = 0u; j < deviceImp->subDevices.size(); j++) {
2023+
auto subDevice = deviceImp->subDevices[j];
2024+
context->getDevices().insert(std::make_pair(subDevice->toHandle(), subDevice));
2025+
}
20202026
auto neoDevice = device->getNEODevice();
20212027
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
20222028
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
20232029
}
20242030
context->rootDeviceIndices.remove_duplicates();
2031+
2032+
currSvmAllocsManager = new NEO::SVMAllocsManager(currMemoryManager, driverHandle->devices[0]->isImplicitScalingCapable());
2033+
prevSvmAllocsManager = driverHandle->svmAllocsManager;
2034+
driverHandle->svmAllocsManager = currSvmAllocsManager;
20252035
}
20262036

20272037
void createKernel() {
@@ -2034,13 +2044,16 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
20342044
}
20352045

20362046
void TearDown() override {
2047+
driverHandle->svmAllocsManager = prevSvmAllocsManager;
2048+
delete currSvmAllocsManager;
20372049
driverHandle->setMemoryManager(prevMemoryManager);
20382050
delete currMemoryManager;
20392051
}
20402052

2041-
DebugManagerStateRestore restorer;
20422053
NEO::MemoryManager *prevMemoryManager = nullptr;
20432054
NEO::MemoryManager *currMemoryManager = nullptr;
2055+
NEO::SVMAllocsManager *prevSvmAllocsManager = nullptr;
2056+
NEO::SVMAllocsManager *currSvmAllocsManager = nullptr;
20442057
std::unique_ptr<DriverHandleImp> driverHandle;
20452058

20462059
std::unique_ptr<UltDeviceFactory> deviceFactory;
@@ -2312,6 +2325,37 @@ HWTEST2_F(MultipleDevicePeerAllocationTest,
23122325
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
23132326
}
23142327

2328+
HWTEST2_F(MultipleDevicePeerAllocationTest,
2329+
givenSubDeviceAllocationPassedToAppendBlitFillUsingDevice1ThenSuccessIsReturned,
2330+
IsAtLeastSkl) {
2331+
DebugManagerStateRestore restorer;
2332+
2333+
L0::Device *device0 = driverHandle->devices[0];
2334+
L0::Device *device = driverHandle->devices[1];
2335+
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>(device);
2336+
L0::Device *device1 = deviceImp->subDevices[0];
2337+
2338+
size_t size = 1024;
2339+
size_t alignment = 1u;
2340+
void *ptr = nullptr;
2341+
ze_device_mem_alloc_desc_t deviceDesc = {};
2342+
ze_result_t result = context->allocDeviceMem(device0->toHandle(),
2343+
&deviceDesc,
2344+
size, alignment, &ptr);
2345+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
2346+
EXPECT_NE(nullptr, ptr);
2347+
2348+
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
2349+
commandList->initialize(device1, NEO::EngineGroupType::RenderCompute, 0u);
2350+
2351+
uint32_t pattern = 1;
2352+
result = commandList->appendBlitFill(ptr, &pattern, sizeof(pattern), size, nullptr, 0, nullptr);
2353+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
2354+
2355+
result = context->freeMem(ptr);
2356+
ASSERT_EQ(result, ZE_RESULT_SUCCESS);
2357+
}
2358+
23152359
HWTEST2_F(MultipleDevicePeerAllocationTest,
23162360
givenDeviceAllocationPassedToAppendBlitFillUsingDevice0ThenSuccessIsReturned,
23172361
IsAtLeastSkl) {

shared/source/memory_manager/graphics_allocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
163163
uint32_t getInspectionId(uint32_t contextId) const { return usageInfos[contextId].inspectionId; }
164164
void setInspectionId(uint32_t newInspectionId, uint32_t contextId) { usageInfos[contextId].inspectionId = newInspectionId; }
165165

166-
bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); }
166+
MOCKABLE_VIRTUAL bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); }
167167
bool isAlwaysResident(uint32_t contextId) const { return GraphicsAllocation::objectAlwaysResident == getResidencyTaskCount(contextId); }
168168
void updateResidencyTaskCount(uint32_t newTaskCount, uint32_t contextId) {
169169
if (usageInfos[contextId].residencyTaskCount != GraphicsAllocation::objectAlwaysResident || newTaskCount == GraphicsAllocation::objectNotResident) {

0 commit comments

Comments
 (0)