Skip to content

Commit cfd3945

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
WSL - fixing missing GPU VA reservation
Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
1 parent caf1ab6 commit cfd3945

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

shared/source/os_interface/windows/thk_wrapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class ThkWrapper {
9696
return *this;
9797
}
9898

99+
ThkWrapper &operator=(Func func) {
100+
mFunc = func;
101+
return *this;
102+
}
103+
99104
// This operator overload is for implicit casting ThkWrapper struct to Function Pointer in GetPfn methods like GetEscapePfn() or for comparing against NULL function pointer
100105
operator Func() const {
101106
return mFunc;

shared/source/os_interface/windows/wddm/configure_device_address_space_drm_or_wddm.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ bool Wddm::configureDeviceAddressSpace() {
3838
? maximumApplicationAddress + 1u
3939
: 0u;
4040

41+
D3DDDI_RESERVEGPUVIRTUALADDRESS svmRangeReservationDesc = {};
42+
svmRangeReservationDesc.BaseAddress = MemoryConstants::pageSize64k;
43+
svmRangeReservationDesc.MinimumAddress = 0;
44+
svmRangeReservationDesc.MaximumAddress = svmSize;
45+
svmRangeReservationDesc.Size = svmSize - svmRangeReservationDesc.BaseAddress;
46+
svmRangeReservationDesc.hAdapter = getAdapter();
47+
NTSTATUS status = getGdi()->reserveGpuVirtualAddress(&svmRangeReservationDesc);
48+
UNRECOVERABLE_IF(status != STATUS_SUCCESS);
49+
4150
bool obtainMinAddress = rootDeviceEnvironment.getHardwareInfo()->platform.eRenderCoreFamily == IGFX_GEN12LP_CORE;
4251
return gmmMemory->configureDevice(getAdapter(), device, getGdi()->escape, svmSize, featureTable->ftrL3IACoherency, minAddress, obtainMinAddress);
4352
}

shared/test/common/mock_gmm/mock_gmm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool copyInputArgs = false;
1515

1616
namespace GmmInterface {
1717
GMM_STATUS initialize(GMM_INIT_IN_ARGS *pInArgs, GMM_INIT_OUT_ARGS *pOutArgs) {
18-
pOutArgs->pGmmClientContext = reinterpret_cast<GMM_CLIENT_CONTEXT *>(0x01);
18+
pOutArgs->pGmmClientContext = reinterpret_cast<GMM_CLIENT_CONTEXT *>(0x08);
1919
if (pInArgs) {
2020
if (pInArgs->Platform.eProductFamily == PRODUCT_FAMILY::IGFX_UNKNOWN &&
2121
pInArgs->Platform.ePCHProductFamily == PCH_PRODUCT_FAMILY::PCH_UNKNOWN) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (C) 2021 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
set(NEO_CORE_OS_INTERFACE_TESTS_WDDM_LINUX
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/configure_device_address_space_drm_or_wddm_test.cpp
10+
)
11+
12+
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_WDDM_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_WDDM_LINUX})
13+
14+
if(UNIX AND NOT DISABLE_WDDM_LINUX)
15+
target_sources(${TARGET_NAME} PRIVATE
16+
${NEO_CORE_OS_INTERFACE_TESTS_WDDM_LINUX}
17+
)
18+
endif()
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/gdi_interface.h"
9+
#include "shared/source/os_interface/windows/os_environment_win.h"
10+
#include "shared/source/os_interface/windows/wddm/wddm.h"
11+
#include "shared/test/common/helpers/default_hw_info.h"
12+
#include "shared/test/common/mocks/mock_execution_environment.h"
13+
#include "shared/test/common/mocks/mock_gmm_client_context.h"
14+
15+
#include "test.h"
16+
17+
#include "gmm_memory.h"
18+
19+
struct MockWddmLinux : NEO::Wddm {
20+
MockWddmLinux(std::unique_ptr<NEO::HwDeviceIdWddm> hwDeviceId, NEO::RootDeviceEnvironment &rootDeviceEnvironment)
21+
: NEO::Wddm(std::move(hwDeviceId), rootDeviceEnvironment) {
22+
}
23+
24+
using Wddm::gfxPlatform;
25+
using Wddm::gmmMemory;
26+
};
27+
28+
struct MockGmmMemoryWddmLinux : NEO::GmmMemory {
29+
MockGmmMemoryWddmLinux(NEO::GmmClientContext *gmmClientContext) : NEO::GmmMemory(gmmClientContext) {
30+
}
31+
32+
bool setDeviceInfo(GMM_DEVICE_INFO *deviceInfo) override {
33+
return true;
34+
}
35+
};
36+
37+
NTSTATUS __stdcall closeAdapterMock(CONST D3DKMT_CLOSEADAPTER *arg) {
38+
return 0;
39+
}
40+
41+
template <typename T>
42+
struct RestorePoint {
43+
RestorePoint(T &obj) : obj(obj), prev(obj) {
44+
}
45+
46+
~RestorePoint() {
47+
obj = prev;
48+
}
49+
50+
T &obj;
51+
T prev;
52+
};
53+
54+
D3DDDI_RESERVEGPUVIRTUALADDRESS receivedReserveGpuVaArgs = {};
55+
56+
NTSTATUS __stdcall reserveDeviceAddressSpaceMock(D3DDDI_RESERVEGPUVIRTUALADDRESS *arg) {
57+
receivedReserveGpuVaArgs = *arg;
58+
return 0;
59+
}
60+
61+
TEST(WddmLinux, whenConfiguringDeviceAddressSpaceThenReserveGpuVAForUSM) {
62+
RestorePoint receivedReserveGpuVaArgsGlobalsRestorer{receivedReserveGpuVaArgs};
63+
64+
NEO::MockExecutionEnvironment mockExecEnv;
65+
NEO::MockRootDeviceEnvironment mockRootDeviceEnvironment{mockExecEnv};
66+
std::unique_ptr<NEO::HwDeviceIdWddm> hwDeviceIdIn;
67+
auto osEnvironment = std::make_unique<NEO::OsEnvironmentWin>();
68+
osEnvironment->gdi->closeAdapter = closeAdapterMock;
69+
osEnvironment->gdi->reserveGpuVirtualAddress = reserveDeviceAddressSpaceMock;
70+
hwDeviceIdIn.reset(new NEO::HwDeviceIdWddm(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique<NEO::UmKmDataTranslator>()));
71+
72+
MockWddmLinux wddm{std::move(hwDeviceIdIn), mockRootDeviceEnvironment};
73+
auto mockGmmClientContext = NEO::GmmClientContext::create<NEO::MockGmmClientContext>(nullptr, NEO::defaultHwInfo.get());
74+
wddm.gmmMemory = std::make_unique<MockGmmMemoryWddmLinux>(mockGmmClientContext.get());
75+
*wddm.gfxPlatform = NEO::defaultHwInfo->platform;
76+
wddm.configureDeviceAddressSpace();
77+
78+
auto maximumApplicationAddress = MemoryConstants::max64BitAppAddress;
79+
auto productFamily = wddm.gfxPlatform->eProductFamily;
80+
auto svmSize = NEO::hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace >= MemoryConstants::max64BitAppAddress
81+
? maximumApplicationAddress + 1u
82+
: 0u;
83+
84+
EXPECT_EQ(MemoryConstants::pageSize64k, receivedReserveGpuVaArgs.BaseAddress);
85+
EXPECT_EQ(0U, receivedReserveGpuVaArgs.MinimumAddress);
86+
EXPECT_EQ(svmSize, receivedReserveGpuVaArgs.MaximumAddress);
87+
EXPECT_EQ(svmSize - receivedReserveGpuVaArgs.BaseAddress, receivedReserveGpuVaArgs.Size);
88+
EXPECT_EQ(wddm.getAdapter(), receivedReserveGpuVaArgs.hAdapter);
89+
}

0 commit comments

Comments
 (0)