Skip to content

Commit 2055daf

Browse files
Allow cpu buffers copy on DG2 in 32bit
Resolves: NEO-6906, NEO-6000 Signed-off-by: Maciej Plewka <[email protected]>
1 parent fcd5930 commit 2055daf

File tree

9 files changed

+109
-2
lines changed

9 files changed

+109
-2
lines changed

opencl/source/mem_obj/buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ bool Buffer::isReadWriteOnCpuAllowed(const Device &device) {
643643
return false;
644644
}
645645

646-
if (graphicsAllocation->isAllocatedInLocalMemoryPool()) {
646+
if (graphicsAllocation->isAllocatedInLocalMemoryPool() && !graphicsAllocation->isAllocationLockable()) {
647647
return false;
648648
}
649649

opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared/source/helpers/basic_math.h"
1010
#include "shared/source/helpers/local_memory_access_modes.h"
1111
#include "shared/test/common/helpers/debug_manager_state_restore.h"
12+
#include "shared/test/common/mocks/mock_gmm.h"
1213
#include "shared/test/common/test_macros/test.h"
1314

1415
#include "opencl/test/unit_test/command_queue/enqueue_read_buffer_fixture.h"
@@ -331,7 +332,10 @@ TEST(ReadWriteBufferOnCpu, whenLocalMemoryPoolAllocationIsAskedForPreferenceThen
331332
cl_int retVal = 0;
332333
std::unique_ptr<Buffer> buffer(Buffer::create(&ctx, CL_MEM_READ_WRITE, MemoryConstants::pageSize, nullptr, retVal));
333334
ASSERT_NE(nullptr, buffer.get());
335+
auto gmm = std::make_unique<MockGmm>(device->getGmmHelper());
336+
reinterpret_cast<MemoryAllocation *>(buffer->getGraphicsAllocation(device->getRootDeviceIndex()))->setGmm(gmm.release(), 0);
334337
reinterpret_cast<MemoryAllocation *>(buffer->getGraphicsAllocation(device->getRootDeviceIndex()))->overrideMemoryPool(MemoryPool::LocalMemory);
338+
reinterpret_cast<MemoryAllocation *>(buffer->getGraphicsAllocation(device->getRootDeviceIndex()))->getDefaultGmm()->resourceParams.Flags.Info.NotLockable = 1;
335339

336340
EXPECT_FALSE(buffer->isReadWriteOnCpuAllowed(device->getDevice()));
337341
EXPECT_FALSE(buffer->isReadWriteOnCpuPreferred(reinterpret_cast<void *>(0x1000), MemoryConstants::pageSize, device->getDevice()));

opencl/test/unit_test/mem_obj/buffer_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ TEST(Buffer, whenBufferAllocatedInLocalMemoryThenCpuCopyIsDisallowed) {
6868
MockBuffer buffer(allocation);
6969
UltDeviceFactory factory{1, 0};
7070
auto &device = *factory.rootDevices[0];
71-
71+
auto gmm = std::make_unique<MockGmm>(device.getGmmHelper());
72+
allocation.setGmm(gmm.get(), 0);
73+
allocation.getDefaultGmm()->resourceParams.Flags.Info.NotLockable = 1;
7274
allocation.memoryPool = MemoryPool::LocalMemory;
7375
EXPECT_FALSE(buffer.isReadWriteOnCpuAllowed(device));
7476

opencl/test/unit_test/xe_hpg_core/dg2/windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
set(IGDRCL_SRCS_tests_xe_hpg_core_dg2_windows
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/wddm_tests_dg2.cpp
910
)
1011
if(WIN32)
1112
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_xe_hpg_core_dg2_windows})
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
using namespace NEO;
9+
10+
#include "shared/source/helpers/constants.h"
11+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
12+
#include "shared/test/common/helpers/ult_hw_config.h"
13+
#include "shared/test/common/helpers/variable_backup.h"
14+
#include "shared/test/common/mocks/mock_allocation_properties.h"
15+
#include "shared/test/common/mocks/mock_execution_environment.h"
16+
#include "shared/test/common/mocks/mock_wddm_residency_allocations_container.h"
17+
#include "shared/test/common/os_interface/windows/mock_wddm_memory_manager.h"
18+
19+
#include "opencl/source/platform/platform.h"
20+
#include "opencl/test/unit_test/mocks/mock_platform.h"
21+
#include "opencl/test/unit_test/os_interface/windows/mock_wddm_allocation.h"
22+
#include "opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h"
23+
24+
#include "mock_gmm_memory.h"
25+
26+
HWTEST_EXCLUDE_PRODUCT(PlatformWithFourDevicesTest, givenPlatformWithFourDevicesWhenCreateBufferThenAllocationIsColouredAndHasFourHandles, IGFX_DG2);
27+
28+
struct PlatformWithFourDevicesTestDG2 : public ::testing::Test {
29+
PlatformWithFourDevicesTestDG2() {
30+
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
31+
}
32+
void SetUp() override {
33+
DebugManager.flags.CreateMultipleSubDevices.set(4);
34+
initPlatform();
35+
}
36+
37+
DebugManagerStateRestore restorer;
38+
39+
VariableBackup<UltHwConfig> backup{&ultHwConfig};
40+
};
41+
42+
DG2TEST_F(PlatformWithFourDevicesTestDG2, givenPlatformWithFourDevicesWhenCreateBufferThenAllocationIsColouredAndHasFourHandles) {
43+
auto wddm = reinterpret_cast<WddmMock *>(platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Wddm>());
44+
wddm->mapGpuVaStatus = true;
45+
VariableBackup<bool> restorer{&wddm->callBaseMapGpuVa, false};
46+
47+
MockWddmMemoryManager memoryManager(true, true, *platform()->peekExecutionEnvironment());
48+
memoryManager.supportsMultiStorageResources = true;
49+
50+
platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->getMutableHardwareInfo()->featureTable.flags.ftrLocalMemory = true;
51+
platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]->getMutableHardwareInfo()->featureTable.flags.ftrMultiTileArch = true;
52+
53+
auto allocation = static_cast<WddmAllocation *>(memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, true, 4 * MemoryConstants::pageSize64k, AllocationType::BUFFER, true, 0b1111}));
54+
EXPECT_EQ(4u, allocation->getNumGmms());
55+
EXPECT_EQ(maxNBitValue(allocation->getNumGmms()), allocation->storageInfo.pageTablesVisibility.to_ullong());
56+
57+
EXPECT_FALSE(allocation->storageInfo.tileInstanced);
58+
EXPECT_TRUE(allocation->storageInfo.multiStorage);
59+
EXPECT_EQ(4u, wddm->mapGpuVirtualAddressResult.called);
60+
for (auto gmmIndex = 0u; gmmIndex < 4u; gmmIndex++) {
61+
auto gmm = allocation->getGmm(gmmIndex);
62+
EXPECT_EQ(allocation->storageInfo.pageTablesVisibility, gmm->resourceParams.MultiTileArch.GpuVaMappingSet);
63+
EXPECT_EQ(1u << gmmIndex, gmm->resourceParams.MultiTileArch.LocalMemEligibilitySet);
64+
EXPECT_EQ(1u << gmmIndex, gmm->resourceParams.MultiTileArch.LocalMemPreferredSet);
65+
EXPECT_EQ(MemoryConstants::pageSize64k, gmm->gmmResourceInfo->getSizeAllocation());
66+
EXPECT_FALSE(gmm->gmmResourceInfo->getResourceFlags()->Info.NonLocalOnly);
67+
if constexpr (is32bit) {
68+
EXPECT_FALSE(gmm->gmmResourceInfo->getResourceFlags()->Info.LocalOnly);
69+
EXPECT_FALSE(gmm->gmmResourceInfo->getResourceFlags()->Info.NotLockable);
70+
} else {
71+
EXPECT_TRUE(gmm->gmmResourceInfo->getResourceFlags()->Info.LocalOnly);
72+
EXPECT_TRUE(gmm->gmmResourceInfo->getResourceFlags()->Info.NotLockable);
73+
}
74+
}
75+
memoryManager.freeGraphicsMemory(allocation);
76+
}

shared/source/helpers/extra_allocation_data_xehp_and_later.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,11 @@ void HwHelperHw<Family>::setExtraAllocationData(AllocationData &allocationData,
3838
allocationData.storageInfo.isLockable = false;
3939
}
4040
}
41+
42+
if (HwInfoConfig::get(hwInfo.platform.eProductFamily)->isStorageInfoAdjustmentRequired()) {
43+
if (properties.allocationType == AllocationType::BUFFER && !properties.flags.preferCompressed && !properties.flags.shareable) {
44+
allocationData.storageInfo.isLockable = true;
45+
}
46+
}
4147
}
4248
} // namespace NEO

shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,11 @@ template <>
185185
bool HwInfoConfigHw<gfxProduct>::isMatrixMultiplyAccumulateSupported(const HardwareInfo &hwInfo) const {
186186
return true;
187187
}
188+
template <>
189+
bool HwInfoConfigHw<gfxProduct>::isStorageInfoAdjustmentRequired() const {
190+
if constexpr (is32bit) {
191+
return true;
192+
} else {
193+
return false;
194+
}
195+
}

shared/test/unit_test/xe_hpg_core/dg2/excludes_xe_hpg_core_dg2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTest, givenHwInfoConfigWhenAskedIfPipeControl
1717
HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTest, givenHwInfoConfigWhenAskedIfTile64With3DSurfaceOnBCSIsSupportedThenTrueIsReturned, IGFX_DG2);
1818
HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTest, WhenAllowRenderCompressionIsCalledThenTrueIsReturned, IGFX_DG2);
1919
HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTest, whenConvertingTimestampsToCsDomainThenNothingIsChanged, IGFX_DG2);
20+
HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTest, givenHwInfoConfigWhenAskedIfStorageInfoAdjustmentIsRequiredThenFalseIsReturned, IGFX_DG2);

shared/test/unit_test/xe_hpg_core/dg2/hw_info_config_tests_dg2.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,12 @@ DG2TEST_F(ProductConfigTests, givenDg2G11DeviceIdWhenDifferentRevisionIsPassedTh
450450
EXPECT_EQ(productConfig, DG2_G11);
451451
}
452452
}
453+
454+
DG2TEST_F(HwInfoConfigTestDg2, givenHwInfoConfigWhenAskedIfStorageInfoAdjustmentIsRequiredThenTrueIsReturned) {
455+
auto hwInfoConfig = HwInfoConfig::get(defaultHwInfo->platform.eProductFamily);
456+
if constexpr (is32bit) {
457+
EXPECT_TRUE(hwInfoConfig->isStorageInfoAdjustmentRequired());
458+
} else {
459+
EXPECT_FALSE(hwInfoConfig->isStorageInfoAdjustmentRequired());
460+
}
461+
}

0 commit comments

Comments
 (0)