google / gemmlowp

Low-precision matrix multiplication
Apache License 2.0
1.78k stars 451 forks source link

run dotprod instruction failed on apple A12 and qualcomm 845 #175

Closed xyoungli closed 5 years ago

xyoungli commented 5 years ago

hi, i tested the udot gemm kernel on "kernel_neon.h" on qualcomm 845 big core and iphone A12, but get errors like following: android, qualcomm 845: "Illegal instruction " iphone xr, A12: "Thread 1: EXC_BAD_INSTRUCTION (code=1, subcode=0x6f80e048)" i would like to ask how to enable or run sdot on these devices

i tested this instruction "MRS %[id], ID_AA64ISAR0_EL1", and got "Illegal instruction"?

bjacob commented 5 years ago

It is expected that dot-product instructions (UDOT, SDOT) generate 'illegal instruction' on both the Apple A12 and Qualcomm 845 CPUs. Neither of these CPUs support this new instruction. An example of a CPU that does support this new instruction is the qualcomm 855. https://www.qualcomm.com/products/snapdragon-855-mobile-platform

Regarding your other question, the instruction MRS %[id], ID_AA64ISAR0_EL1 generates 'illegal instruction' for a different reason: it is only legal in kernel code (that is the meaning of the _EL1 suffix). it is the operating system's task to expose this information to user-space. Here is how you would perform such userspace detection on Linux, but this requires a recent Linux version -- at least 4.15 I believe.

#include <sys/auxv.h>

...

inline bool DetectDotprodByLinuxAuxvMethod() {
  // This is the value of HWCAP_ASIMDDP in sufficiently recent Linux headers,
  // however we need to support building against older headers for the time
  // being.
  const int kAsimddpBit = 1 << 20;
  return getauxval(AT_HWCAP) & kAsimddpBit;
}