Skip to content

Commit b9d65b6

Browse files
committed
Add support for making buffer resident for their lifetime.
Change-Id: Idde4c561b0968858202a78719942f30ab89ffde6 Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
1 parent 5985506 commit b9d65b6

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

core/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableFreeMemory, false, "Enable freeMemory in memo
110110
DECLARE_DEBUG_VARIABLE(bool, ForceSamplerLowFilteringPrecision, false, "Force Low Filtering Precision Sampler mode")
111111
DECLARE_DEBUG_VARIABLE(bool, UseBindlessBuffers, false, "Force compiler to use bindless buffer addressing instead of stateful one")
112112
DECLARE_DEBUG_VARIABLE(bool, UseBindlessImages, false, "Force compiler to use bindless image addressing instead of stateful one")
113+
DECLARE_DEBUG_VARIABLE(bool, MakeAllBuffersResident, false, "Make all buffers resident after creation")
113114
DECLARE_DEBUG_VARIABLE(int32_t, EnableIntelVme, -1, "-1: default, 0: disabled, 1: Enables cl_intel_motion_estimation extension")
114115
DECLARE_DEBUG_VARIABLE(int32_t, EnableIntelAdvancedVme, -1, "-1: default, 0: disabled, 1: Enables cl_intel_advanced_motion_estimation extension")
115116
DECLARE_DEBUG_VARIABLE(int32_t, EnableBlitterOperationsSupport, -1, "-1: default, 0: disable, 1: enable")

runtime/mem_obj/buffer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "runtime/mem_obj/buffer.h"
99

1010
#include "core/debug_settings/debug_settings_manager.h"
11+
#include "core/execution_environment/root_device_environment.h"
1112
#include "core/gmm_helper/gmm.h"
1213
#include "core/gmm_helper/gmm_helper.h"
1314
#include "core/helpers/aligned_memory.h"
@@ -18,6 +19,7 @@
1819
#include "core/helpers/timestamp_packet.h"
1920
#include "core/memory_manager/host_ptr_manager.h"
2021
#include "core/memory_manager/memory_manager.h"
22+
#include "core/memory_manager/memory_operations_handler.h"
2123
#include "core/memory_manager/unified_memory_manager.h"
2224
#include "runtime/command_queue/command_queue.h"
2325
#include "runtime/command_stream/command_stream_receiver.h"
@@ -320,6 +322,11 @@ Buffer *Buffer::create(Context *context,
320322
return nullptr;
321323
}
322324

325+
if (DebugManager.flags.MakeAllBuffersResident.get()) {
326+
auto graphicsAllocation = pBuffer->getGraphicsAllocation();
327+
context->getDevice(0u)->getRootDeviceEnvironment().memoryOperationsInterface->makeResident(ArrayRef<GraphicsAllocation *>(&graphicsAllocation, 1));
328+
}
329+
323330
return pBuffer;
324331
}
325332

unit_tests/mem_obj/buffer_tests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
#include "core/helpers/array_count.h"
1212
#include "core/helpers/hw_helper.h"
1313
#include "core/memory_manager/allocations_list.h"
14+
#include "core/memory_manager/memory_operations_handler.h"
1415
#include "core/memory_manager/unified_memory_manager.h"
1516
#include "core/os_interface/os_context.h"
1617
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
18+
#include "core/unit_tests/helpers/ult_hw_config.h"
1719
#include "core/unit_tests/utilities/base_object_utils.h"
1820
#include "public/cl_ext_private.h"
1921
#include "runtime/command_queue/command_queue_hw.h"
@@ -29,6 +31,7 @@
2931
#include "unit_tests/gen_common/matchers.h"
3032
#include "unit_tests/helpers/hw_parse.h"
3133
#include "unit_tests/helpers/unit_test_helper.h"
34+
#include "unit_tests/helpers/variable_backup.h"
3235
#include "unit_tests/mocks/mock_buffer.h"
3336
#include "unit_tests/mocks/mock_command_queue.h"
3437
#include "unit_tests/mocks/mock_context.h"
@@ -1831,6 +1834,24 @@ TEST(SharedBuffersTest, whenBuffersIsCreatedWithSharingHandlerThenItIsSharedBuff
18311834
buffer->release();
18321835
}
18331836

1837+
TEST(ResidencyTests, whenBuffersIsCreatedWithMakeResidentFlagThenItSuccessfulyCreates) {
1838+
VariableBackup<UltHwConfig> backup(&ultHwConfig);
1839+
ultHwConfig.useMockedGetDevicesFunc = false;
1840+
DebugManagerStateRestore restorer;
1841+
DebugManager.flags.MakeAllBuffersResident.set(true);
1842+
1843+
size_t numRootDevices = 0u;
1844+
getDevices(numRootDevices, *platform()->peekExecutionEnvironment());
1845+
platform()->initialize(1u, 0u);
1846+
auto device = platform()->getClDevice(0u);
1847+
1848+
MockContext context(device, false);
1849+
auto retValue = CL_SUCCESS;
1850+
auto clBuffer = clCreateBuffer(&context, 0u, 4096u, nullptr, &retValue);
1851+
ASSERT_EQ(retValue, CL_SUCCESS);
1852+
clReleaseMemObject(clBuffer);
1853+
}
1854+
18341855
class BufferTests : public ::testing::Test {
18351856
protected:
18361857
void SetUp() override {

unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
*/
77

88
#include "core/os_interface/windows/wddm_memory_operations_handler.h"
9+
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
10+
#include "core/unit_tests/helpers/ult_hw_config.h"
911
#include "core/utilities/stackvec.h"
12+
#include "runtime/device/cl_device.h"
1013
#include "test.h"
14+
#include "unit_tests/helpers/variable_backup.h"
1115
#include "unit_tests/mocks/mock_allocation_properties.h"
16+
#include "unit_tests/mocks/mock_context.h"
1217
#include "unit_tests/mocks/mock_wddm.h"
1318
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
1419
#include "unit_tests/os_interface/windows/wddm_fixture.h"
@@ -84,3 +89,29 @@ TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenEvictingResid
8489
EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS);
8590
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
8691
}
92+
93+
TEST(WddmResidentBufferTests, whenBuffersIsCreatedWithMakeResidentFlagSetThenItIsMadeResidentUponCreation) {
94+
VariableBackup<UltHwConfig> backup(&ultHwConfig);
95+
ultHwConfig.useMockedGetDevicesFunc = false;
96+
DebugManagerStateRestore restorer;
97+
DebugManager.flags.MakeAllBuffersResident.set(true);
98+
99+
size_t numRootDevices = 0u;
100+
getDevices(numRootDevices, *platform()->peekExecutionEnvironment());
101+
platform()->initialize(1u, 0u);
102+
auto device = platform()->getClDevice(0u);
103+
104+
MockContext context(device, false);
105+
auto retValue = CL_SUCCESS;
106+
auto clBuffer = clCreateBuffer(&context, 0u, 4096u, nullptr, &retValue);
107+
ASSERT_EQ(retValue, CL_SUCCESS);
108+
109+
auto memoryOperationsHandler = context.getDevice(0)->getRootDeviceEnvironment().memoryOperationsInterface.get();
110+
auto neoBuffer = castToObject<MemObj>(clBuffer);
111+
auto bufferAllocation = neoBuffer->getGraphicsAllocation();
112+
auto status = memoryOperationsHandler->isResident(*bufferAllocation);
113+
114+
EXPECT_EQ(status, MemoryOperationsStatus::SUCCESS);
115+
116+
clReleaseMemObject(clBuffer);
117+
}

unit_tests/test_files/igdrcl.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ UseBindlessImages = 0
128128
PrintProgramBinaryProcessingTime = 0
129129
OverrideGpuAddressSpace = -1
130130
OverrideMaxWorkgroupSize = -1
131-
DisableTimestampPacketOptimizations = 0
131+
DisableTimestampPacketOptimizations = 0
132+
MakeAllBuffersResident = 0

0 commit comments

Comments
 (0)