Skip to content

Fix: aligned\_alloc not declared when building PyTorch on Termux (Android, clang) #23

@Manamama

Description

@Manamama

Related: #5.

I have a deja vu that I had solved it some month ago but I forgot how, maybe via some cmake switches.

Symptom:

... /data/data/com.termux/files/home/downloads/pytorch/torch/csrc/inductor/aoti_torch/generated/c_shim_cuda.cpp                      [ 79%] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/native/mkl/SpectralOps.cpp.o                            In file included from /data/data/com.termux/files/home/downloads/pytorch/aten/src/ATen/native/mkl/SpectralOps.cpp:207:              /data/data/com.termux/files/home/downloads/pytorch/third_party/pocketfft/pocketfft_hdronly.h:159:15: error: no member named 'aligned_alloc' in the global namespace; did you mean simply 'aligned_alloc'?                                                                 159 |   void *ptr = ::aligned_alloc(align,(size+align-1)&(~(align-1)));                                                                 |               ^~~~~~~~~~~~~~~
      |               aligned_alloc                               /data/data/com.termux/files/home/downloads/pytorch/third_party/pocketfft/pocketfft_hdronly.h:156:14: note: 'aligned_alloc' declared here
  156 | inline void *aligned_alloc(size_t align, size_t size)           |              ^
1 error generated.                                                 

Ran into the same issue as in the older ticket most likely, but while building PyTorch on Termux (Android + clang/gcc), where ::aligned_alloc is technically C++17 but not provided by Android libc.

I vaguely remember that a version of this worked: sed -i 's/::aligned_alloc/aligned_alloc/g' third_party/pocketfft/pocketfft_hdronly.h

but not now: circular definition warning, etc.

More context: appears on pure Termux when compiling PyTorch, via cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DINTERN_BUILD_MOBILE=ON \ -DUSE_CUDA=OFF \ -DUSE_ROCM=OFF \ -DUSE_VULKAN=OFF \ -DUSE_XPU=OFF \ -DBUILD_PYTHON=OFF \ -DBUILD_TEST=OFF \ -DBUILD_BINARY=OFF \ -DBUILD_SHARED_LIBS=ON \ -DUSE_FBGEMM=OFF \ -DUSE_OPENMP=ON \ -DUSE_MKLDNN=OFF \ -DUSE_MKL=OFF \ -DUSE_NUMPY=ON

Ver. 1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions