Skip to content

Commit 2be98a1

Browse files
Create kmd migrated allocation with initial placement
Implements ZE_HOST_MEM_ALLOC_FLAG_BIAS_INITIAL_PLACEMENT for zeMemAllocShared with KMD migrated allocation. Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
1 parent fc71a59 commit 2be98a1

19 files changed

+115
-41
lines changed

opencl/test/unit_test/helpers/memory_properties_helpers_tests.cpp

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

88
#include "shared/source/helpers/memory_properties_helpers.h"
9+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
910
#include "shared/test/common/mocks/mock_device.h"
1011
#include "shared/test/common/mocks/mock_graphics_allocation.h"
1112
#include "shared/test/common/mocks/ult_device_factory.h"
@@ -452,4 +453,48 @@ TEST_F(MemoryPropertiesHelperTests, WhenAdjustingDeviceBitfieldThenCorrectBitfie
452453
}
453454
}
454455
}
455-
}
456+
}
457+
458+
TEST_F(MemoryPropertiesHelperTests, WhenCallingGetInitialPlacementThenCorrectValueIsReturned) {
459+
MemoryProperties memoryProperties{};
460+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::CPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
461+
462+
memoryProperties.allocFlags.usmInitialPlacementCpu = false;
463+
memoryProperties.allocFlags.usmInitialPlacementGpu = false;
464+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::CPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
465+
466+
memoryProperties.allocFlags.usmInitialPlacementCpu = false;
467+
memoryProperties.allocFlags.usmInitialPlacementGpu = true;
468+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::GPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
469+
470+
memoryProperties.allocFlags.usmInitialPlacementCpu = true;
471+
memoryProperties.allocFlags.usmInitialPlacementGpu = false;
472+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::CPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
473+
474+
memoryProperties.allocFlags.usmInitialPlacementCpu = true;
475+
memoryProperties.allocFlags.usmInitialPlacementGpu = true;
476+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::CPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
477+
}
478+
479+
TEST_F(MemoryPropertiesHelperTests, givenUsmInitialPlacementSetWhenCallingHasInitialPlacementCpuThenCorrectValueIsReturned) {
480+
DebugManagerStateRestore restorer;
481+
MemoryProperties memoryProperties{};
482+
483+
for (auto intialPlacement : {-1, 0, 1}) {
484+
DebugManager.flags.UsmInitialPlacement.set(intialPlacement);
485+
if (intialPlacement == 1) {
486+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::GPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
487+
} else {
488+
EXPECT_EQ(GraphicsAllocation::UsmInitialPlacement::CPU, MemoryPropertiesHelper::getUSMInitialPlacement(memoryProperties));
489+
}
490+
}
491+
}
492+
493+
TEST_F(MemoryPropertiesHelperTests, WhenCallingSetInitialPlacementThenCorrectValueIsSetInAllocationProperties) {
494+
AllocationProperties allocationProperties{mockRootDeviceIndex, 0, GraphicsAllocation::AllocationType::UNIFIED_SHARED_MEMORY, mockDeviceBitfield};
495+
496+
for (auto initialPlacement : {GraphicsAllocation::UsmInitialPlacement::CPU, GraphicsAllocation::UsmInitialPlacement::GPU}) {
497+
MemoryPropertiesHelper::setUSMInitialPlacement(allocationProperties, initialPlacement);
498+
EXPECT_EQ(initialPlacement, allocationProperties.usmInitialPlacement);
499+
}
500+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -220,7 +220,7 @@ HWTEST2_F(MemoryInfoTest, givenMemoryInfoWithRegionsWhenCreatingGemWithExtension
220220
ASSERT_NE(nullptr, memoryInfo);
221221

222222
uint32_t handle = 0;
223-
std::vector<MemoryClassInstance> memClassInstance = {regionInfo[0].region, regionInfo[1].region};
223+
MemRegionsVec memClassInstance = {regionInfo[0].region, regionInfo[1].region};
224224
auto ret = memoryInfo->createGemExt(drm.get(), memClassInstance, 1024, handle);
225225
EXPECT_EQ(1u, handle);
226226
EXPECT_EQ(0u, ret);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) {
2525

2626
auto ioctlHelper = drm->getIoctlHelper();
2727
uint32_t handle = 0;
28-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
28+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
2929
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
3030

3131
EXPECT_EQ(0u, ret);
@@ -46,7 +46,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WithDrmTipWhenCreateGemExtWithDebugFlagTh
4646
testing::internal::CaptureStdout();
4747
auto ioctlHelper = drm->getIoctlHelper();
4848
uint32_t handle = 0;
49-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
49+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
5050
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
5151

5252
std::string output = testing::internal::GetCapturedStdout();
@@ -67,7 +67,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtWithDebugFlagThenPrintDeb
6767
testing::internal::CaptureStdout();
6868
auto ioctlHelper = drm->getIoctlHelper();
6969
uint32_t handle = 0;
70-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
70+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
7171
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
7272

7373
std::string output = testing::internal::GetCapturedStdout();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class IoctlHelperPrelimFixture : public ::testing::Test {
5555
TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtThenReturnSuccess) {
5656
auto ioctlHelper = drm->getIoctlHelper();
5757
uint32_t handle = 0;
58-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
58+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
5959
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
6060

6161
EXPECT_EQ(1u, handle);
@@ -70,7 +70,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtWithDebugFlagThenPr
7070
testing::internal::CaptureStdout();
7171
auto ioctlHelper = drm->getIoctlHelper();
7272
uint32_t handle = 0;
73-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
73+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
7474
ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
7575

7676
std::string output = testing::internal::GetCapturedStdout();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenCreateGemExtThenReturnCorrectVal
2222

2323
auto ioctlHelper = drm->getIoctlHelper();
2424
uint32_t handle = 0;
25-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
25+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
2626
auto ret = ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
2727

2828
EXPECT_EQ(0u, ret);
@@ -43,7 +43,7 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenCreateGemExtWithDebugFlagThenPri
4343
testing::internal::CaptureStdout();
4444
auto ioctlHelper = drm->getIoctlHelper();
4545
uint32_t handle = 0;
46-
std::vector<MemoryClassInstance> memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
46+
MemRegionsVec memClassInstance = {{I915_MEMORY_CLASS_DEVICE, 0}};
4747
ioctlHelper->createGemExt(drm.get(), memClassInstance, 1024, handle);
4848

4949
std::string output = testing::internal::GetCapturedStdout();

shared/source/helpers/memory_properties_helpers.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -35,5 +35,9 @@ class MemoryPropertiesHelper {
3535
bool deviceOnlyVisibilty, uint32_t cacheRegion);
3636

3737
static uint32_t getCacheRegion(const MemoryProperties &memoryProperties);
38+
39+
static GraphicsAllocation::UsmInitialPlacement getUSMInitialPlacement(const MemoryProperties &memoryProperties);
40+
41+
static void setUSMInitialPlacement(AllocationProperties &allocationProperties, GraphicsAllocation::UsmInitialPlacement initialPlacement);
3842
};
3943
} // namespace NEO

shared/source/helpers/memory_properties_helpers_base.inl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -41,4 +41,22 @@ DeviceBitfield MemoryPropertiesHelper::adjustDeviceBitfield(uint32_t rootDeviceI
4141
return deviceBitfieldIn;
4242
}
4343

44+
GraphicsAllocation::UsmInitialPlacement MemoryPropertiesHelper::getUSMInitialPlacement(const MemoryProperties &memoryProperties) {
45+
auto initialPlacement = GraphicsAllocation::UsmInitialPlacement::CPU;
46+
if (memoryProperties.allocFlags.usmInitialPlacementGpu) {
47+
initialPlacement = GraphicsAllocation::UsmInitialPlacement::GPU;
48+
}
49+
if (memoryProperties.allocFlags.usmInitialPlacementCpu) {
50+
initialPlacement = GraphicsAllocation::UsmInitialPlacement::CPU;
51+
}
52+
if (const int32_t debugFlag = DebugManager.flags.UsmInitialPlacement.get(); debugFlag != -1) {
53+
initialPlacement = debugFlag != 1 ? GraphicsAllocation::UsmInitialPlacement::CPU : GraphicsAllocation::UsmInitialPlacement::GPU;
54+
}
55+
return initialPlacement;
56+
}
57+
58+
void MemoryPropertiesHelper::setUSMInitialPlacement(AllocationProperties &allocationProperties, GraphicsAllocation::UsmInitialPlacement initialPlacement) {
59+
allocationProperties.usmInitialPlacement = initialPlacement;
60+
}
61+
4462
} // namespace NEO

shared/source/memory_manager/allocation_properties.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -38,6 +38,7 @@ struct AllocationProperties {
3838
size_t size = 0;
3939
size_t alignment = 0;
4040
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::UNKNOWN;
41+
GraphicsAllocation::UsmInitialPlacement usmInitialPlacement = GraphicsAllocation::UsmInitialPlacement::DEFAULT;
4142
ImageInfo *imgInfo = nullptr;
4243
bool multiStorageResource = false;
4344
ColouringPolicy colouringPolicy = ColouringPolicy::DeviceCountBased;
@@ -114,6 +115,7 @@ struct AllocationData {
114115
};
115116
static_assert(sizeof(AllocationData::flags) == sizeof(AllocationData::allFlags), "");
116117
GraphicsAllocation::AllocationType type = GraphicsAllocation::AllocationType::UNKNOWN;
118+
GraphicsAllocation::UsmInitialPlacement usmInitialPlacement = GraphicsAllocation::UsmInitialPlacement::DEFAULT;
117119
const void *hostPtr = nullptr;
118120
uint64_t gpuAddress = 0;
119121
size_t size = 0;

shared/source/memory_manager/graphics_allocation.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -103,6 +103,12 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
103103
COUNT
104104
};
105105

106+
enum UsmInitialPlacement {
107+
DEFAULT,
108+
CPU,
109+
GPU
110+
};
111+
106112
~GraphicsAllocation() override;
107113
GraphicsAllocation &operator=(const GraphicsAllocation &) = delete;
108114
GraphicsAllocation(const GraphicsAllocation &) = delete;

shared/source/memory_manager/memory_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
425425
allocationData.flags.preferCompressed = properties.flags.preferCompressed;
426426
allocationData.flags.preferCompressed |= CompressionSelector::preferCompressedAllocation(properties, *hwInfo);
427427
allocationData.flags.multiOsContextCapable = properties.flags.multiOsContextCapable;
428+
allocationData.usmInitialPlacement = properties.usmInitialPlacement;
428429

429430
if (properties.allocationType == GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA) {
430431
allocationData.flags.zeroMemory = 1;

0 commit comments

Comments
 (0)