Skip to content

Commit 280f379

Browse files
fix: aub residency in HW+AUB mode
Related-To: NEO-9230 Signed-off-by: Fabian Zwolinski <[email protected]> Source: 06ec4c3
1 parent bb1d8a2 commit 280f379

File tree

40 files changed

+857
-85
lines changed

40 files changed

+857
-85
lines changed

opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro
4040
auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]);
4141
mock->setupIoctlHelper(defaultHwInfo->platform.eProductFamily);
4242
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
43-
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
43+
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u, false);
4444

4545
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(executionEnvironment);
4646

@@ -112,7 +112,7 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen
112112
auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]);
113113
mock->setupIoctlHelper(defaultHwInfo->platform.eProductFamily);
114114
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
115-
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
115+
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u, false);
116116

117117
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(executionEnvironment);
118118

opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ClCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver
2929
auto osInterface = new OSInterface();
3030
osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
3131
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface.reset(osInterface);
32-
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, rootDeviceIndex);
32+
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, rootDeviceIndex, false);
3333
executionEnvironment->memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment));
3434
mdevice = std::make_unique<MockClDevice>(MockDevice::create<MockDevice>(executionEnvironment, rootDeviceIndex));
3535

shared/source/command_stream/command_stream_receiver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "shared/source/helpers/options.h"
1717
#include "shared/source/utilities/spinlock.h"
1818

19+
#include "aubstream/allocation_params.h"
20+
1921
#include <atomic>
2022
#include <cstddef>
2123
#include <cstdint>
@@ -245,6 +247,7 @@ class CommandStreamReceiver {
245247
virtual bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation);
246248
MOCKABLE_VIRTUAL bool writeMemory(GraphicsAllocation &gfxAllocation) { return writeMemory(gfxAllocation, false, 0, 0); }
247249
virtual bool writeMemory(GraphicsAllocation &gfxAllocation, bool isChunkCopy, uint64_t gpuVaChunkOffset, size_t chunkSize) { return false; }
250+
virtual void writeMemoryAub(aub_stream::AllocationParams &allocationParams){};
248251

249252
virtual bool isMultiOsContextCapable() const = 0;
250253

shared/source/command_stream/command_stream_receiver_simulated_common_hw.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#pragma once
99
#include "shared/source/command_stream/command_stream_receiver_hw.h"
10+
#include "shared/source/helpers/hardware_context_controller.h"
1011
#include "shared/source/memory_manager/memory_banks.h"
1112

1213
#include "aub_mapper_common.h"
@@ -20,7 +21,6 @@ struct AubStream;
2021
namespace NEO {
2122
class AddressMapper;
2223
class GraphicsAllocation;
23-
class HardwareContextController;
2424
template <typename GfxFamily>
2525
class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw<GfxFamily> {
2626
protected:
@@ -59,6 +59,9 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw<Gf
5959
virtual void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) = 0;
6060
virtual void writeMemoryWithAubManager(GraphicsAllocation &graphicsAllocation, bool isChunkCopy, uint64_t gpuVaChunkOffset, size_t chunkSize) = 0;
6161
virtual void writeMMIO(uint32_t offset, uint32_t value) = 0;
62+
void writeMemoryAub(aub_stream::AllocationParams &allocationParams) override {
63+
hardwareContextController->writeMemory(allocationParams);
64+
}
6265

6366
virtual void setAubWritable(bool writable, GraphicsAllocation &graphicsAllocation) = 0;
6467
virtual bool isAubWritable(GraphicsAllocation &graphicsAllocation) const = 0;

shared/source/os_interface/aub_memory_operations_handler.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
#include "shared/source/os_interface/aub_memory_operations_handler.h"
99

10+
#include "shared/source/aub/aub_helper.h"
1011
#include "shared/source/aub_mem_dump/aub_mem_dump.h"
12+
#include "shared/source/command_stream/command_stream_receiver.h"
13+
#include "shared/source/device/device.h"
1114
#include "shared/source/gmm_helper/cache_settings_helper.h"
1215
#include "shared/source/gmm_helper/gmm.h"
16+
#include "shared/source/gmm_helper/gmm_helper.h"
1317
#include "shared/source/memory_manager/graphics_allocation.h"
1418

1519
#include "aubstream/allocation_params.h"
@@ -29,7 +33,12 @@ MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device,
2933
auto lock = acquireLock(resourcesLock);
3034
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
3135
for (const auto &allocation : gfxAllocations) {
32-
aub_stream::AllocationParams params(allocation->getGpuAddress(),
36+
if (!isAubWritable(*allocation, device)) {
37+
continue;
38+
}
39+
40+
uint64_t gpuAddress = device ? device->getGmmHelper()->decanonize(allocation->getGpuAddress()) : allocation->getGpuAddress();
41+
aub_stream::AllocationParams params(gpuAddress,
3342
allocation->getUnderlyingBuffer(),
3443
allocation->getUnderlyingBufferSize(),
3544
allocation->storageInfo.getMemoryBanks(),
@@ -43,10 +52,19 @@ MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device,
4352
params.additionalParams.uncached = CacheSettingsHelper::isUncachedType(gmm->resourceParams.Usage);
4453
}
4554

46-
aubManager->writeMemory2(params);
55+
if (allocation->storageInfo.cloningOfPageTables || !allocation->isAllocatedInLocalMemoryPool()) {
56+
aubManager->writeMemory2(params);
57+
} else {
58+
device->getDefaultEngine().commandStreamReceiver->writeMemoryAub(params);
59+
}
60+
4761
if (!allocation->getAubInfo().writeMemoryOnly) {
4862
residentAllocations.push_back(allocation);
4963
}
64+
65+
if (AubHelper::isOneTimeAubWritableAllocationType(allocation->getAllocationType())) {
66+
setAubWritable(false, *allocation, device);
67+
}
5068
}
5169
return MemoryOperationsStatus::SUCCESS;
5270
}
@@ -79,8 +97,44 @@ MemoryOperationsStatus AubMemoryOperationsHandler::isResident(Device *device, Gr
7997
return MemoryOperationsStatus::SUCCESS;
8098
}
8199
}
100+
82101
void AubMemoryOperationsHandler::setAubManager(aub_stream::AubManager *aubManager) {
83102
this->aubManager = aubManager;
84103
}
85104

105+
bool AubMemoryOperationsHandler::isAubWritable(GraphicsAllocation &graphicsAllocation, Device *device) const {
106+
if (!device) {
107+
return false;
108+
}
109+
auto bank = static_cast<uint32_t>(getMemoryBanksBitfield(&graphicsAllocation, device).to_ulong());
110+
if (bank == 0u || graphicsAllocation.storageInfo.cloningOfPageTables) {
111+
bank = GraphicsAllocation::defaultBank;
112+
}
113+
return graphicsAllocation.isAubWritable(bank);
114+
}
115+
116+
void AubMemoryOperationsHandler::setAubWritable(bool writable, GraphicsAllocation &graphicsAllocation, Device *device) {
117+
if (!device) {
118+
return;
119+
}
120+
auto bank = static_cast<uint32_t>(getMemoryBanksBitfield(&graphicsAllocation, device).to_ulong());
121+
if (bank == 0u || graphicsAllocation.storageInfo.cloningOfPageTables) {
122+
bank = GraphicsAllocation::defaultBank;
123+
}
124+
graphicsAllocation.setAubWritable(writable, bank);
125+
}
126+
127+
DeviceBitfield AubMemoryOperationsHandler::getMemoryBanksBitfield(GraphicsAllocation *allocation, Device *device) const {
128+
if (allocation->getMemoryPool() == MemoryPool::LocalMemory) {
129+
if (allocation->storageInfo.memoryBanks.any()) {
130+
if (allocation->storageInfo.cloningOfPageTables ||
131+
device->getDefaultEngine().commandStreamReceiver->isMultiOsContextCapable()) {
132+
return allocation->storageInfo.memoryBanks;
133+
}
134+
}
135+
return device->getDeviceBitfield();
136+
}
137+
return {};
138+
}
139+
86140
} // namespace NEO

shared/source/os_interface/aub_memory_operations_handler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright (C) 2019-2022 Intel Corporation
2+
* Copyright (C) 2019-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#pragma once
9+
#include "shared/source/helpers/device_bitfield.h"
910
#include "shared/source/memory_manager/memory_operations_handler.h"
1011
#include "shared/source/utilities/spinlock.h"
1112

@@ -30,7 +31,11 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler {
3031

3132
void setAubManager(aub_stream::AubManager *aubManager);
3233

34+
bool isAubWritable(GraphicsAllocation &graphicsAllocation, Device *device) const;
35+
void setAubWritable(bool writable, GraphicsAllocation &graphicsAllocation, Device *device);
36+
3337
protected:
38+
DeviceBitfield getMemoryBanksBitfield(GraphicsAllocation *allocation, Device *device) const;
3439
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock) {
3540
return std::unique_lock<SpinLock>{lock};
3641
}

shared/source/os_interface/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
3838
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_create.cpp
3939
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_default.cpp
4040
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_default.h
41+
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_with_aub_dump.h
4142
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_create_multi_host_allocation.cpp
4243
${CMAKE_CURRENT_SOURCE_DIR}/drm_version.cpp
4344
${CMAKE_CURRENT_SOURCE_DIR}/drm_wrappers_checks.cpp

shared/source/os_interface/linux/drm_memory_operations_handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2022 Intel Corporation
2+
* Copyright (C) 2019-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -25,7 +25,7 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
2525

2626
virtual MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) = 0;
2727

28-
static std::unique_ptr<DrmMemoryOperationsHandler> create(Drm &drm, uint32_t rootDeviceIndex);
28+
static std::unique_ptr<DrmMemoryOperationsHandler> create(Drm &drm, uint32_t rootDeviceIndex, bool withAubDump);
2929

3030
uint32_t getRootDeviceIndex() const {
3131
return this->rootDeviceIndex;
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Intel Corporation
2+
* Copyright (C) 2020-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -8,18 +8,28 @@
88
#include "shared/source/execution_environment/root_device_environment.h"
99
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
1010
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
11+
#include "shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h"
1112
#include "shared/source/os_interface/linux/drm_neo.h"
1213

1314
namespace NEO {
1415

15-
std::unique_ptr<DrmMemoryOperationsHandler> DrmMemoryOperationsHandler::create(Drm &drm, uint32_t rootDeviceIndex) {
16+
std::unique_ptr<DrmMemoryOperationsHandler> DrmMemoryOperationsHandler::create(Drm &drm, uint32_t rootDeviceIndex, bool withAubDump) {
1617
bool useVmBind = drm.isVmBindAvailable();
18+
auto rootDeviceEnv = drm.getRootDeviceEnvironment().executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get();
1719

1820
if (useVmBind) {
19-
return std::make_unique<DrmMemoryOperationsHandlerBind>(drm.getRootDeviceEnvironment(), rootDeviceIndex);
21+
if (withAubDump) {
22+
return std::make_unique<DrmMemoryOperationsHandlerWithAubDump<DrmMemoryOperationsHandlerBind>>(*rootDeviceEnv, rootDeviceIndex);
23+
} else {
24+
return std::make_unique<DrmMemoryOperationsHandlerBind>(drm.getRootDeviceEnvironment(), rootDeviceIndex);
25+
}
2026
}
2127

22-
return std::make_unique<DrmMemoryOperationsHandlerDefault>(rootDeviceIndex);
28+
if (withAubDump) {
29+
return std::make_unique<DrmMemoryOperationsHandlerWithAubDump<DrmMemoryOperationsHandlerDefault>>(*rootDeviceEnv, rootDeviceIndex);
30+
} else {
31+
return std::make_unique<DrmMemoryOperationsHandlerDefault>(rootDeviceIndex);
32+
}
2333
}
2434

2535
} // namespace NEO

shared/source/os_interface/linux/drm_memory_operations_handler_default.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Intel Corporation
2+
* Copyright (C) 2020-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -12,9 +12,11 @@
1212

1313
namespace NEO {
1414
class OsContextLinux;
15+
struct RootDeviceEnvironment;
1516
class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler {
1617
public:
1718
DrmMemoryOperationsHandlerDefault(uint32_t rootDeviceIndex);
19+
DrmMemoryOperationsHandlerDefault(const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t rootDeviceIndex) : DrmMemoryOperationsHandlerDefault(rootDeviceIndex) {}
1820
~DrmMemoryOperationsHandlerDefault() override;
1921

2022
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override;

0 commit comments

Comments
 (0)