Building PyTorch for the Raspberry Pi (32 bits)


I am trying to build PyTorch 1.10.2 as a wheel for the ARM 32 bits architecture. More specifically, I want to be able to run PyTorch in a Raspberry Pi.

I am able to run the build process up until the 60% mark, where it fails with the following message:

/workdir/pytorch/third_party/XNNPACK/src/qs8-gemm/gen/1x8c4-minmax-fp32-neondot.c: In function ‘xnn_qs8_gemm_minmax_fp32_ukernel_1x8c4__neondot’:
/workdir/pytorch/third_party/XNNPACK/src/qs8-gemm/gen/1x8c4-minmax-fp32-neondot.c:94:18: warning: implicit declaration of function ‘vcvtnq_s32_f32’; did you mean ‘vcvtq_s32_f32’? [-Wimplicit-function-declaration]
     vacc0x0123 = vcvtnq_s32_f32(vproduct0x0123);
/workdir/pytorch/third_party/XNNPACK/src/qs8-gemm/gen/1x8c4-minmax-fp32-neondot.c:94:16: error: incompatible types when assigning to type ‘int32x4_t’ from type ‘int’
     vacc0x0123 = vcvtnq_s32_f32(vproduct0x0123);

What I understand from this error message is that the vcvtnq_s32_f32 function, from XNNPACK, is missing. The default C behaviour is to implicitly declare a prototype with int as the return type, which is obviously not correct.

I found this issue, which led me to look around the PyTorch repo that I have checked out and the polyfill does exist, in the pytorch/third_party/XNNPACK/src/xnnpack/intrinsics-polyfill.h file:

// AArch32 GCC, see
// -
// -
#if XNN_ARCH_ARM && defined(__GNUC__) && !defined(__clang__) && defined(__ARM_NEON__)
#include <arm_neon.h>

int32x4_t vcvtnq_s32_f32(float32x4_t v) {
  return vcvtq_s32_f32(vrndnq_f32(v));
#endif  // AArch32 GCC

So, not only does the polyfill exist, but the affected file, pytorch/third_party/XNNPACK/src/qs8-gemm/gen/1x8c4-minmax-fp32-neondot.c, also includes the polyfill:

#include <assert.h>

#include <arm_neon.h>

#include <xnnpack/gemm.h>
#include <xnnpack/intrinsics-polyfill.h>
#include <xnnpack/math.h>

What can I do to make sure that XNNPACK finds and uses the polyfill? This is blocking me from being able to build PyTorch for the Raspberry Pi.


I run into exact same error, have you already found a solution?

I’ve switched to 64 bit Raspi OS which works for me.
Torch is available for 64 bit and it works fine.

1 Like