intel / intel-extension-for-pytorch

A Python package for extending the official PyTorch that can easily obtain performance on Intel platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to run interger matrix multiply

primenumber opened this issue · comments

Describe the bug

A runtime error occurs when performing int32 matrix multiplication on Arc GPU.

import torch
import intel_extension_for_pytorch as ipex

a = torch.randint(0, 2, (256, 64), dtype=torch.int32).to("xpu")
b = torch.randint(0, 2, (64, 16), dtype=torch.int32).to("xpu")
print(torch.mm(a, b))
# python src/test.py
Traceback (most recent call last):
  File "/workspace/src/test.py", line 6, in <module>
    print(torch.mm(a, b))
RuntimeError: could not create a primitive descriptor for a matmul primitive

int64, int16 matmul causes another error:

import torch
import intel_extension_for_pytorch as ipex

a = torch.randint(0, 2, (256, 64), dtype=torch.int16).to("xpu")
b = torch.randint(0, 2, (64, 16), dtype=torch.int16).to("xpu")
print(torch.mm(a, b))
# python src/test.py
Traceback (most recent call last):
  File "/workspace/src/test.py", line 6, in <module>
    print(torch.mm(a, b))
RuntimeError: Short is not supported in oneDNN!

int8 matrix multiplication is performed successfully.
It is normal to perform matrix multiplication on the CPU.

Versions

Collecting environment information...
PyTorch version: 2.1.0.post0+cxx11.abi
PyTorch CXX11 ABI: Yes
IPEX version: 2.1.20+xpu
IPEX commit: b78b4d97e
Build type: Release

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: N/A
IGC version: N/A
CMake version: N/A
Libc version: glibc-2.35

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.5.0-28-generic-x86_64-with-glibc2.35
Is XPU available: True
DPCPP runtime version: N/A
MKL version: N/A
GPU models and configuration:
[0] _DeviceProperties(name='Intel(R) Arc(TM) A770 Graphics', platform_name='Intel(R) Level-Zero', dev_type='gpu, support_fp64=0, total_memory=15473MB, max_compute_units=512, gpu_eu_count=512)
[1] _DeviceProperties(name='Intel(R) UHD Graphics 770', platform_name='Intel(R) Level-Zero', dev_type='gpu, support_fp64=0, total_memory=59784MB, max_compute_units=32, gpu_eu_count=32)
Intel OpenCL ICD version: 23.43.27642.40-803~22.04
Level Zero version: 1.3.27642.40-803~22.04

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      46 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             20
On-line CPU(s) list:                0-19
Vendor ID:                          GenuineIntel
Model name:                         13th Gen Intel(R) Core(TM) i5-13600K
CPU family:                         6
Model:                              183
Thread(s) per core:                 2
Core(s) per socket:                 14
Socket(s):                          1
Stepping:                           1
CPU max MHz:                        5100.0000
CPU min MHz:                        800.0000
BogoMIPS:                           6988.80
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
L1d cache:                          544 KiB (14 instances)
L1i cache:                          704 KiB (14 instances)
L2 cache:                           20 MiB (8 instances)
L3 cache:                           24 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-19
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Not affected
Vulnerability Retbleed:             Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced / Automatic IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] intel-extension-for-pytorch==2.1.20+xpu
[pip3] numpy==1.26.4
[pip3] torch==2.1.0.post0+cxx11.abi
[pip3] torchaudio==2.1.0.post0+cxx11.abi
[pip3] torchvision==0.16.0.post0+cxx11.abi
[conda] N/A

Hi @primenumber
As the error message indicates, matmul implementation for GPUs does not support integer types with 16, 32 or 64 bits. As GPUs usually have limited memory, it is not a common case that we do matrix multiplication for these integer types. I had a test with a NV V100 server, it also gives error:

# test for int32
(ptni0415) zailiwan@clx03-tce:~$ python ipex-609.py
Traceback (most recent call last):
  File "/home/zailiwan/ipex-609.py", line 6, in <module>
    print(torch.mm(a, b))
          ^^^^^^^^^^^^^^
RuntimeError: "addmm_cuda" not implemented for 'Int'
(ptni0415) zailiwan@clx03-tce:~$ vim ipex-609.py
# test for int16
(ptni0415) zailiwan@clx03-tce:~$ python ipex-609.py
Traceback (most recent call last):
  File "/home/zailiwan/ipex-609.py", line 6, in <module>
    print(torch.mm(a, b))
          ^^^^^^^^^^^^^^
RuntimeError: "addmm_cuda" not implemented for 'Short'

Hmm... It is difficult to understand from the error message that int32 is not supported. Can we improve this point?

Thanks for the advice, let me check with team for this.