Skip to content

Commit 1fa74b9

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
Changing sysmem allocation logic for WSL
Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
1 parent 73b0df3 commit 1fa74b9

File tree

13 files changed

+140
-22
lines changed

13 files changed

+140
-22
lines changed

opencl/test/unit_test/device/device_caps_tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,30 @@ TEST_F(DeviceGetCapsTest, givenGlobalMemSizeAndSharedSystemAllocationsSupportedW
529529
EXPECT_EQ(caps.maxMemAllocSize, expectedSize);
530530
}
531531

532+
TEST_F(DeviceGetCapsTest, whenDriverModelHasLimitationForMaxMemoryAllocationSizeThenTakeItIntoAccount) {
533+
struct MockDriverModel : NEO::DriverModel {
534+
size_t maxAllocSize;
535+
536+
MockDriverModel(size_t maxAllocSize) : NEO::DriverModel(NEO::DriverModelType::UNKNOWN), maxAllocSize(maxAllocSize) {}
537+
538+
void setGmmInputArgs(void *args) override {}
539+
uint32_t getDeviceHandle() const override { return {}; }
540+
PhysicalDevicePciBusInfo getPciBusInfo() const override { return {}; }
541+
size_t getMaxMemAllocSize() const override {
542+
return maxAllocSize;
543+
}
544+
};
545+
546+
DebugManagerStateRestore dbgRestorer;
547+
size_t maxAllocSizeTestValue = 512;
548+
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
549+
device->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface());
550+
device->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<MockDriverModel>(maxAllocSizeTestValue));
551+
device->initializeCaps();
552+
const auto &caps = device->getDeviceInfo();
553+
EXPECT_EQ(maxAllocSizeTestValue, caps.maxMemAllocSize);
554+
}
555+
532556
TEST_F(DeviceGetCapsTest, WhenDeviceIsCreatedThenExtensionsStringEndsWithSpace) {
533557
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
534558
const auto &caps = device->getDeviceInfo();

opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,22 +1606,25 @@ TEST_F(MockWddmMemoryManagerTest, givenAllocateGraphicsMemoryForBufferAndRequest
16061606
wddm->mapGpuVaStatus = true;
16071607
VariableBackup<bool> restorer{&wddm->callBaseMapGpuVa, false};
16081608

1609-
DebugManager.flags.Enable64kbpages.set(true);
1610-
MemoryManagerCreate<MockWddmMemoryManager> memoryManager(true, false, *executionEnvironment);
1611-
if (memoryManager.isLimitedGPU(0)) {
1612-
GTEST_SKIP();
1609+
for (bool enable64KBpages : {true, false}) {
1610+
wddm->createAllocationResult.called = 0U;
1611+
DebugManager.flags.Enable64kbpages.set(enable64KBpages);
1612+
MemoryManagerCreate<MockWddmMemoryManager> memoryManager(true, false, *executionEnvironment);
1613+
if (memoryManager.isLimitedGPU(0)) {
1614+
GTEST_SKIP();
1615+
}
1616+
EXPECT_EQ(0, wddm->createAllocationResult.called);
1617+
1618+
memoryManager.hugeGfxMemoryChunkSize = MemoryConstants::pageSize64k - MemoryConstants::pageSize;
1619+
1620+
WddmAllocation *wddmAlloc = static_cast<WddmAllocation *>(memoryManager.allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize64k * 3, GraphicsAllocation::AllocationType::BUFFER, mockDeviceBitfield}));
1621+
EXPECT_NE(nullptr, wddmAlloc);
1622+
EXPECT_EQ(4, wddmAlloc->getNumGmms());
1623+
EXPECT_EQ(4, wddm->createAllocationResult.called);
1624+
EXPECT_EQ(wddmAlloc->getGpuAddressToModify(), GmmHelper::canonize(wddmAlloc->reservedGpuVirtualAddress));
1625+
1626+
memoryManager.freeGraphicsMemory(wddmAlloc);
16131627
}
1614-
EXPECT_EQ(0, wddm->createAllocationResult.called);
1615-
1616-
memoryManager.hugeGfxMemoryChunkSize = MemoryConstants::pageSize64k - MemoryConstants::pageSize;
1617-
1618-
WddmAllocation *wddmAlloc = static_cast<WddmAllocation *>(memoryManager.allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize64k * 3, GraphicsAllocation::AllocationType::BUFFER, mockDeviceBitfield}));
1619-
EXPECT_NE(nullptr, wddmAlloc);
1620-
EXPECT_EQ(4, wddmAlloc->getNumGmms());
1621-
EXPECT_EQ(4, wddm->createAllocationResult.called);
1622-
EXPECT_EQ(wddmAlloc->getGpuAddressToModify(), GmmHelper::canonize(wddmAlloc->reservedGpuVirtualAddress));
1623-
1624-
memoryManager.freeGraphicsMemory(wddmAlloc);
16251628
}
16261629

16271630
TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenCorrectHugeGfxMemoryChunkIsSet) {

shared/source/device/device_caps.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ void Device::initializeCaps() {
7878
deviceInfo.maxMemAllocSize = std::min(deviceInfo.maxMemAllocSize, this->hardwareCapabilities.maxMemAllocSize);
7979
}
8080

81+
// Some specific driver model configurations may impose additional limitations
82+
auto driverModelMaxMemAlloc = std::numeric_limits<size_t>::max();
83+
if (this->executionEnvironment->rootDeviceEnvironments[0]->osInterface) {
84+
driverModelMaxMemAlloc = this->executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->getMaxMemAllocSize();
85+
}
86+
deviceInfo.maxMemAllocSize = std::min<std::uint64_t>(driverModelMaxMemAlloc, deviceInfo.maxMemAllocSize);
87+
8188
deviceInfo.profilingTimerResolution = getProfilingTimerResolution();
8289
if (DebugManager.flags.OverrideProfilingTimerResolution.get() != -1) {
8390
deviceInfo.profilingTimerResolution = static_cast<double>(DebugManager.flags.OverrideProfilingTimerResolution.get());

shared/source/os_interface/os_interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "shared/source/os_interface/driver_info.h"
1212

1313
#include <cstdint>
14+
#include <limits>
1415
#include <memory>
1516
#include <vector>
1617

@@ -78,6 +79,10 @@ class DriverModel : public NonCopyableClass {
7879

7980
virtual PhysicalDevicePciBusInfo getPciBusInfo() const = 0;
8081

82+
virtual size_t getMaxMemAllocSize() const {
83+
return std::numeric_limits<size_t>::max();
84+
}
85+
8186
protected:
8287
DriverModelType driverModelType;
8388
};

shared/source/os_interface/windows/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
6060
${CMAKE_CURRENT_SOURCE_DIR}/init_wddm_os_interface.cpp
6161
${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener${KMDAF_FILE_SUFFIX}.cpp
6262
${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener.h
63+
${CMAKE_CURRENT_SOURCE_DIR}/max_chunk_size_${DRIVER_MODEL}.cpp
6364
${CMAKE_CURRENT_SOURCE_DIR}/os_context_win.cpp
6465
${CMAKE_CURRENT_SOURCE_DIR}/os_context_win.h
6566
${CMAKE_CURRENT_SOURCE_DIR}/os_environment_win.cpp
@@ -75,6 +76,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
7576
${CMAKE_CURRENT_SOURCE_DIR}/wddm/adapter_factory_dxcore.h
7677
${CMAKE_CURRENT_SOURCE_DIR}/wddm/configure_device_address_space_${DRIVER_MODEL}.cpp
7778
${CMAKE_CURRENT_SOURCE_DIR}/wddm/set_gmm_input_args_${DRIVER_MODEL}.cpp
79+
${CMAKE_CURRENT_SOURCE_DIR}/wddm/max_mem_alloc_size_${DRIVER_MODEL}.cpp
7880
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.cpp
7981
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.h
8082
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_defs.h
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/wddm_memory_manager.h"
9+
10+
namespace NEO {
11+
12+
size_t WddmMemoryManager::getHugeGfxMemoryChunkSize() const {
13+
return 31 * MemoryConstants::megaByte;
14+
}
15+
16+
} // namespace NEO
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/wddm_memory_manager.h"
9+
10+
namespace NEO {
11+
12+
size_t WddmMemoryManager::getHugeGfxMemoryChunkSize() const {
13+
return 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize64k;
14+
}
15+
16+
} // namespace NEO
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/wddm/wddm.h"
9+
10+
namespace NEO {
11+
12+
size_t Wddm::getMaxMemAllocSize() const {
13+
return MemoryConstants::gigaByte;
14+
}
15+
16+
} // namespace NEO
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/wddm/wddm.h"
9+
10+
namespace NEO {
11+
12+
size_t Wddm::getMaxMemAllocSize() const {
13+
return std::numeric_limits<size_t>::max();
14+
}
15+
16+
} // namespace NEO

shared/source/os_interface/windows/wddm/wddm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class Wddm : public DriverModel {
185185

186186
PhysicalDevicePciBusInfo getPciBusInfo() const override;
187187

188+
size_t getMaxMemAllocSize() const override;
189+
188190
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevices(ExecutionEnvironment &executionEnvironment);
189191

190192
protected:

0 commit comments

Comments
 (0)