11/*
2- * Copyright (C) 2020-2023 Intel Corporation
2+ * Copyright (C) 2020-2025 Intel Corporation
33 *
44 * SPDX-License-Identifier: MIT
55 *
66 */
77
88#include " level_zero/tools/source/sysman/memory/windows/os_memory_imp.h"
99
10+ #include " shared/source/helpers/hw_info.h"
1011#include " shared/source/os_interface/windows/wddm/wddm.h"
1112
1213#include " level_zero/tools/source/sysman/sysman.h"
1314#include " level_zero/tools/source/sysman/windows/kmd_sys_manager.h"
1415
16+ #include < Windows.h>
17+
1518template <typename I>
1619std::string intToHex (I w, size_t hexLength = sizeof (I) << 1) {
1720 static const char *digits = " 0123456789ABCDEF" ;
@@ -47,6 +50,8 @@ bool WddmMemoryImp::isMemoryModuleSupported() {
4750 KmdSysman::RequestProperty request;
4851 KmdSysman::ResponseProperty response;
4952
53+ bool isIntegratedDevice = pDevice->getHwInfo ().capabilityTable .isIntegratedDevice ;
54+
5055 request.commandId = KmdSysman::Command::Get;
5156 request.componentId = KmdSysman::Component::MemoryComponent;
5257 request.requestId = KmdSysman::Requests::Memory::NumMemoryDomains;
@@ -57,6 +62,10 @@ bool WddmMemoryImp::isMemoryModuleSupported() {
5762
5863 memcpy_s (&value, sizeof (uint32_t ), response.dataBuffer , sizeof (uint32_t ));
5964
65+ if (!value && isIntegratedDevice) {
66+ return true ;
67+ }
68+
6069 return (value > 0 );
6170}
6271ze_result_t WddmMemoryImp::getProperties (zes_mem_properties_t *pProperties) {
@@ -68,6 +77,21 @@ ze_result_t WddmMemoryImp::getProperties(zes_mem_properties_t *pProperties) {
6877
6978 pProperties->onSubdevice = isSubdevice;
7079 pProperties->subdeviceId = subdeviceId;
80+ pProperties->type = ZES_MEM_TYPE_FORCE_UINT32;
81+ pProperties->physicalSize = 0 ;
82+ pProperties->numChannels = -1 ;
83+ pProperties->busWidth = -1 ;
84+ pProperties->location = ZES_MEM_LOC_FORCE_UINT32;
85+
86+ bool isIntegratedDevice = pDevice->getHwInfo ().capabilityTable .isIntegratedDevice ;
87+ if (isIntegratedDevice) {
88+ pProperties->location = ZES_MEM_LOC_SYSTEM;
89+ ULONGLONG installedMemoryKb = 0 ;
90+ if (GetPhysicallyInstalledSystemMemory (&installedMemoryKb)) {
91+ pProperties->physicalSize = installedMemoryKb * 1024 ;
92+ }
93+ return ZE_RESULT_SUCCESS;
94+ }
7195
7296 request.commandId = KmdSysman::Command::Get;
7397 request.componentId = KmdSysman::Component::MemoryComponent;
@@ -93,7 +117,6 @@ ze_result_t WddmMemoryImp::getProperties(zes_mem_properties_t *pProperties) {
93117 return status;
94118 }
95119
96- pProperties->type = ZES_MEM_TYPE_FORCE_UINT32;
97120 if (vResponses[0 ].returnCode == KmdSysman::Success) {
98121 memcpy_s (&retValu32, sizeof (uint32_t ), vResponses[0 ].dataBuffer , sizeof (uint32_t ));
99122 switch (retValu32) {
@@ -139,33 +162,26 @@ ze_result_t WddmMemoryImp::getProperties(zes_mem_properties_t *pProperties) {
139162 }
140163 }
141164
142- pProperties->physicalSize = 0 ;
143165 if (vResponses[1 ].returnCode == KmdSysman::Success) {
144166 memcpy_s (&retValu64, sizeof (uint64_t ), vResponses[1 ].dataBuffer , sizeof (uint64_t ));
145167 pProperties->physicalSize = retValu64;
146168 }
147169
148- pProperties->numChannels = -1 ;
149170 if (vResponses[2 ].returnCode == KmdSysman::Success) {
150171 memcpy_s (&retValu32, sizeof (uint32_t ), vResponses[2 ].dataBuffer , sizeof (uint32_t ));
151172 pProperties->numChannels = retValu32;
152173 }
153174
154- pProperties->location = ZES_MEM_LOC_FORCE_UINT32;
155175 if (vResponses[3 ].returnCode == KmdSysman::Success) {
156176 memcpy_s (&retValu32, sizeof (uint32_t ), vResponses[3 ].dataBuffer , sizeof (uint32_t ));
157177 pProperties->location = static_cast <zes_mem_loc_t >(retValu32);
158178 }
159179
160- pProperties->busWidth = -1 ;
161180 if (vResponses[4 ].returnCode == KmdSysman::Success) {
162181 memcpy_s (&retValu32, sizeof (uint32_t ), vResponses[4 ].dataBuffer , sizeof (uint32_t ));
163182 pProperties->busWidth = retValu32;
164183 }
165184
166- pProperties->subdeviceId = 0 ;
167- pProperties->onSubdevice = false ;
168-
169185 return ZE_RESULT_SUCCESS;
170186}
171187
@@ -229,14 +245,21 @@ ze_result_t WddmMemoryImp::getState(zes_mem_state_t *pState) {
229245 request.componentId = KmdSysman::Component::MemoryComponent;
230246 request.requestId = KmdSysman::Requests::Memory::CurrentTotalAllocableMem;
231247
248+ bool isIntegratedDevice = pDevice->getHwInfo ().capabilityTable .isIntegratedDevice ;
249+
232250 status = pKmdSysManager->requestSingle (request, response);
233251
234- if (status != ZE_RESULT_SUCCESS) {
252+ if (status != ZE_RESULT_SUCCESS && !isIntegratedDevice ) {
235253 return status;
236254 }
237255
238256 memcpy_s (&retValu64, sizeof (uint64_t ), response.dataBuffer , sizeof (uint64_t ));
239- pState->size = retValu64;
257+
258+ if (isIntegratedDevice && pKmdSysManager->GetWddmAccess ()) {
259+ pState->size = pKmdSysManager->GetWddmAccess ()->getSystemSharedMemory ();
260+ } else {
261+ pState->size = retValu64;
262+ }
240263
241264 if (!pdhInitialized) {
242265 if (pdhOpenQuery && pdhOpenQuery (NULL , NULL , &gpuQuery) == ERROR_SUCCESS) {
@@ -245,14 +268,19 @@ ze_result_t WddmMemoryImp::getState(zes_mem_state_t *pState) {
245268 }
246269
247270 if (!pdhCounterAdded && pdhAddEnglishCounterW && pKmdSysManager->GetWddmAccess ()) {
248- std::wstring counterStr = constructCounterStr (L" GPU Adapter Memory" , L" Dedicated Usage" , pKmdSysManager->GetWddmAccess ()->getAdapterLuid (), 0 );
249- pdhCounterAdded = (pdhAddEnglishCounterW (gpuQuery, counterStr.c_str (), NULL , &dedicatedUsage) == ERROR_SUCCESS);
271+ if (isIntegratedDevice) {
272+ std::wstring counterStr = constructCounterStr (L" GPU Adapter Memory" , L" Shared Usage" , pKmdSysManager->GetWddmAccess ()->getAdapterLuid (), 0 );
273+ pdhCounterAdded = (pdhAddEnglishCounterW (gpuQuery, counterStr.c_str (), NULL , &usage) == ERROR_SUCCESS);
274+ } else {
275+ std::wstring counterStr = constructCounterStr (L" GPU Adapter Memory" , L" Dedicated Usage" , pKmdSysManager->GetWddmAccess ()->getAdapterLuid (), 0 );
276+ pdhCounterAdded = (pdhAddEnglishCounterW (gpuQuery, counterStr.c_str (), NULL , &usage) == ERROR_SUCCESS);
277+ }
250278 }
251279
252280 if (pdhCounterAdded && pdhCollectQueryData && pdhGetFormattedCounterValue) {
253281 PDH_FMT_COUNTERVALUE counterVal;
254282 pdhCollectQueryData (gpuQuery);
255- pdhGetFormattedCounterValue (dedicatedUsage , PDH_FMT_LARGE, NULL , &counterVal);
283+ pdhGetFormattedCounterValue (usage , PDH_FMT_LARGE, NULL , &counterVal);
256284 retValu64 = counterVal.largeValue ;
257285 pState->free = pState->size - retValu64;
258286 }
0 commit comments