Repository navigation
Inconsistent GPU Memory Usage Reporting Between dpctl and xpu-smi #1761
Description
Description
When using dpctl to report GPU memory usage on Intel GPUs, the reported free and total memory values appear to be incorrect when compared to the output from xpu-smi. Specifically, dpctl reports 0 bytes of used memory, while xpu-smi correctly reports the used memory as 17 MiB.
Steps to Reproduce
- Set up an environment with
dpctlandxpu-smiinstalled. - Use the following Python script to get GPU memory information using
dpctl:
import os
import dpctl
from dpctl.utils import intel_device_info
def get_intel_gpu_memory_info():
try:
# Set the environment variable ZES_ENABLE_SYSMAN to 1
os.environ["ZES_ENABLE_SYSMAN"] = "1"
# Get the list of GPU devices
devices = dpctl.get_devices(device_type=dpctl.device_type.gpu)
for device in devices:
# Get Intel GPU device info
device_info = intel_device_info(device)
if device_info:
free_memory = device_info.get('free_memory', None)
if free_memory is not None:
free_memory_mib = free_memory / (1024 * 1024)
print(f"Free Memory: {free_memory_mib:.2f} MiB")
# Get the total global memory size
try:
global_mem_size = device.get_info(dpctl.device_info.global_mem_size)
except AttributeError:
global_mem_size = device.global_mem_size
global_mem_size_mib = global_mem_size / (1024 * 1024)
print(f"Total Memory: {global_mem_size_mib:.2f} MiB")
# Calculate and display used memory
if free_memory is not None and global_mem_size is not None:
used_memory = global_mem_size - free_memory
used_memory_mib = used_memory / (1024 * 1024)
print(f"Used Memory: {used_memory_mib:.2f} MiB")
else:
print("Unable to calculate used memory due to missing information.")
return
print("No Intel GPU devices found or no information available.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
get_intel_gpu_memory_info()- Compare the output with the results of running
xpu-smi stats -d 0:
xpu-smi stats -d 0Observed Behavior
- Output from the Python script using
dpctl:
Free Memory: 15473.60 MiB
Total Memory: 15473.60 MiB
Used Memory: 0.00 MiB
Also, python -c "import torch; import intel_extension_for_pytorch as ipex; print(torch.__version__); print(ipex.__version__); [print(f'[{i}]: {torch.xpu.get_device_properties(i)}') for i in range(torch.xpu.device_count())];" shows the following output which matches the total memory:
2.1.0.post2+cxx11.abi
2.1.30+xpu
[0]: _DeviceProperties(name='Intel(R) Arc(TM) A770 Graphics', platform_name='Intel(R) Level-Zero', dev_type='gpu', driver_version='1.3.27642', has_fp64=0, total_memory=15473MB, max_compute_units=512, gpu_eu_count=512)
- Output from
xpu-smi:
+-----------------------------+--------------------------------------------------------------------+
| Device ID | 0 |
+-----------------------------+--------------------------------------------------------------------+
| GPU Memory Used (MiB) | 17 |
| GPU Memory Util (%) | 0 |
+-----------------------------+--------------------------------------------------------------------+
Expected Behavior
The used memory reported by dpctl should match the used memory reported by xpu-smi.
Environment
- dpctl version: 0.17.0
- xpu-smi version: 1.2.38.20240718
- OS: HiveOS [Based on Ubuntu 20.04]
- Docker version: 24.0.7, build 24.0.7-0ubuntu2~20.04.1
- Docker image: intel/intel-extension-for-pytorch:2.1.30-xpu
- Python version: 3.10.12
- GPU: Intel(R) Arc(TM) A770 Graphics
Additional Information
Setting the environment variable ZES_ENABLE_SYSMAN to 1 was necessary as mentioned in the documentation, to report the free_memory. The discrepancy in reported values suggests a potential issue within the dpctl library or its interaction with the GPU drivers.
Further information on OS:
# uname -r
6.1.0-hiveos
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
The container was launched through the following command:
docker run -ti --cap-add=PERFMON --device /dev/dri intel/intel-extension-for-pytorch:2.1.30-xpu bash
The intel-basekit (provides the necessary SYCL runtime and development tools for dpctl) and xpu-smi packages were installed with the following commands before the testing the issue inside the container:
wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | gpg --yes --dearmor --output /usr/share/keyrings/intel-graphics.gpg \
wget https://github.com/intel/xpumanager/releases/download/V1.2.38/xpu-smi_1.2.38_20240718.060204.0db09695+deb10u1_amd64.deb \
apt update && apt install -y ./xpu-smi_1.2.38_20240718.060204.0db09695+deb10u1_amd64.deb intel-basekit \
source /opt/intel/oneapi/setvars.sh
Proposed Solution
Investigate and resolve the inconsistency in GPU memory reporting between dpctl and xpu-smi. Ensure that dpctl accurately reflects the actual GPU memory usage.
Thank you for looking into this issue. Please let me know if further information or testing is required.
Activity
oleksandr-pavlyk commentedon Jul 28, 2024
@avimanyu786 Please provide information about your GPU driver, e.g., output of
python -m dpctl -f.avimanyu786 commentedon Jul 28, 2024
Thank you for the assistance @oleksandr-pavlyk ! I will post the output as early as possible.
oleksandr-pavlyk commentedon Jul 28, 2024
Actually, you have already provided the information @avimanyu786 :
driver_version='1.3.27642'oleksandr-pavlyk commentedon Jul 28, 2024
While attempting to reproduce the reported behavior, I used
xpu-smion a machine where GPU is not utilities (Usedxpu-smi psto verify that onlyxpu-smiwas using GPU), and thexpu-smireported non-zero GPU memory footprint:So I assume an explanation for the discrepancy is that
xpu-smiitself uses some amount of GPU global memory.avimanyu786 commentedon Jul 28, 2024
I see. In that case, perhaps we could use a different approach. We could try to use the watch command with xpu-smi and then recheck with dpctl from a different terminal?
oleksandr-pavlyk commentedon Jul 28, 2024
Just to confirm, in one terminal I started
dpctl(and setZES_ENABLE_SYSMAN=1) and executed:In another terminal I executed
sudo xpu-smi stats -d 0which showed:and
xpu-smi psshowed:These figures are kind of consistent, accounting for some GPU global memory used by the driver.
avimanyu786 commentedon Jul 29, 2024
@oleksandr-pavlyk Thanks so much for these confirmations! I will test when I have access to my machine from my end and report back again if I face any issue.
avimanyu786 commentedon Jul 29, 2024
Hi @oleksandr-pavlyk,
I have conducted the tests (this time directly on the host) as suggested and observed the following results.
Terminal 1
Terminal 2
Summary
dpctlOutput:free_memory: 16225243136 bytes (15.1 GiB)used_memory: 0 bytestotal_memory: 15.1 GiB (implied fromglobal_mem_size)xpu-smi stats -d 0Output:GPU Memory Used (MiB): 18 MiBxpu-smi psOutput: EmptyAdditional Observation
Upon exiting the Python console after the
(y.nbytes + x.nbytes)step, thexpu-smiGPU memory usage drops to 17 MiB.Despite allocating memory in the Python script using
dpctl.tensor, theused_memoryreported bydpctlis 0 bytes, which is inconsistent with thexpu-smioutput, which is also showing only 18 MiB of GPU memory usage - just a 1 MiB difference. It seems there are issues withxpu-smias well on my machine.UPDATE
Further investigated with PyOpenCL:
Output:
xpu-smi stats -d 0output:So at this point xpu-smi seems to be working correctly. When I tried to check with dpctl while the pyopencl program was running, I'm still getting the same output:
Environment
Please let me know if any further information or testing is required.
avimanyu786 commentedon Jul 29, 2024
From the overall testing on my machine so far, it looks like that both on host and on docker, the
free_memorykey from thedpctl.utils.intel_device_info(sycl_device)dictionary, is reporting the same value asdpctl.device_info.global_mem_sizeeven though the memory is being consumed on the Intel Arc GPU.oleksandr-pavlyk commentedon Jul 29, 2024
@avimanyu786 The
dpctluses this feature of DPC++ https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/supported/sycl_ext_intel_device_info.md#free-global-memoryCould you compile the following C++ executable and check whether its output is consistent with output of
dpctl:Once compiled, execute as
$ ZES_ENABLE_SYSMAN=1 ./mem.x. This is the output I observe when no processes other thanmemaccess GPU:This is what I observe when Python script allocating
xandyfrom earlier discussion allocate 1Gb:If the native application also reports the same value, as
dpctldoes, try upgrading GPU drivers (https://dgpu-docs.intel.com/driver/installation.html)avimanyu786 commentedon Jul 30, 2024
Hi @oleksandr-pavlyk ,
Based on the above suggestion, I faced the same issue on the host machine with
icpx(both when idle and after tensor allocation in Python):Device: Intel(R) Arc(TM) A770 Graphics [1.3.27642] Global device memory size: 16225243136 bytes Free memory: 16225243136 bytes Implied memory in use: 0 bytesAfter switching to HiveOS based on Ubuntu 22.04, I'm facing the same issue, even after upgrading the driver from 1.3.27642 to 1.3.29735:
Device: Intel(R) Arc(TM) A770 Graphics [1.3.29735] Global device memory size: 16225243136 bytes Free memory: 16225243136 bytes Implied memory in use: 0 bytesTo update the driver on the host, I followed the client GPU documentation for Intel Arc.
Summary
icpxbased on Intel BaseKit documentation for apt.The output for Intel Data Center GPU Max 1100 shows a different driver version 7.66.28691. Possibly, this driver might include features or fixes that are not present in the driver versions available for the Intel Arc A770, which could explain the discrepancy in reported free memory. I'll wait for your further feedback. Thanks.
oleksandr-pavlyk commentedon Jul 31, 2024
It may be that a discrepancy is indeed explained by the driver. In that case one should file an issue with https://github.com/intel/compute-runtime and provide this C++ reproducer, driver version, OS version and the compiler version.
I do not think the behavior you are witnessing is caused by an issue with Python, as you have confirmed by running a stand-alone executable compiled from C++ code.
avimanyu786 commentedon Jul 31, 2024
Many many thanks @oleksandr-pavlyk for following up on this issue! I have filed the corresponding issue in the compute runtime repository: intel/compute-runtime#750
avimanyu786 commentedon Aug 1, 2024
For more added context, there is a python file called
check_xpu_smi.pyin the https://github.com/intel/xpumanager repository that fetches the value ofXPUM_STATS_MEMORY_USEDto report the used GPU memory. I found this when I searched for "GPU Memory Used" in that repository.