Source build errors cast from PyObject to getter converts to incompatible function type [-Werror,-Wcast-function-type-strict]**

username: davidradl
cooked: <p>When trying to setup by source build I see errors like:</p>
<pre><code class="lang-auto">**/Users/davidradley/pytorch/torch/csrc/autograd/generated/python_functions_4.cpp:264:24:** **error:** **cast from 'PyObject *(*)(THPCppFunction *, void *)' (aka '_object *(*)(torch::autograd::THPCppFunction *, void *)') to 'getter' (aka '_object *(*)(_object *, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]**

{(char*)"_saved_LU", (getter)THPLinalgSlogdetBackward0_LU_getter, nullptr, nullptr, nullptr},
</code></pre>
<p>I am am using the brew llvm and have it first in my path; does anyone know what these sorts of errors indicate. Does it mean that the compiler I am using is mismatching the source code in terms of support for this cast? Or mismatching libraries?</p>
<p>My environment is</p>
<pre><code class="lang-auto">PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 13.4.1 (arm64)
GCC version: Could not collect
Clang version: 16.0.6
CMake version: version 3.26.4
Libc version: N/A

Python version: 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:41:52) [Clang 15.0.7 ] (64-bit runtime)
Python platform: macOS-13.4.1-arm64-arm-64bit
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Apple M1 Max

Versions of relevant libraries:
[pip3] flake8==6.0.0
[pip3] flake8-bugbear==23.3.23
[pip3] flake8-comprehensions==3.12.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-logging-format==0.9.0
[pip3] flake8-pyi==23.3.1
[pip3] flake8-simplify==0.19.3
[pip3] mypy==0.960
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.25.2
[pip3] torch==2.1.0a0+gitf353d17
[pip3] torchgen==0.0.1
[conda] numpy                     1.25.2                   pypi_0    pypi
[conda] torch                     2.1.0a0+gitf353d17          pypi_0    pypi
[conda] torchgen                  0.0.1                    pypi_0    pypi
</code></pre>
<p>I run export LLVM=$(brew --prefix llvm)</p>
<pre><code class="lang-auto">export OMP_PREFIX=$(brew --prefix libomp)

export PATH="${LLVM}/bin:$PATH";

export COMPILER=${LLVM}/bin/clang++

export CFLAGS="-I/usr/local/include -I${LLVM}/include"

export CXXFLAGS="-I/usr/local/include -I${LLVM}/include"

export LDFLAGS="-L/usr/local/lib -L${LLVM}/lib"

export CXX=${COMPILER}
cd ~/pytorch

git submodule deinit -f .

git clean -xdf

python setup.py clean

git submodule update --init --recursive
</code></pre>
<p>then</p>
<pre><code class="lang-auto">USE_DISTRIBUTED=0 CMAKE_OSX_ARCHITECTURES=arm64 
MACOSX_DEPLOYMENT_TARGET=10.9 USE_MKLDNN=OFF USE_QNNPACK=OFF WERROR=1 BUILD_TEST=OFF USE_PYTORCH_METAL=1 python setup.py develop
</code></pre>

username: davidradl
cooked: <p>I am still getting these errors. The following command fails:</p>
<pre><code class="lang-auto">
/opt/homebrew/opt/llvm/bin/clang++ -DAT_PER_OPERATOR_HEADERS -DFMT_HEADER_ONLY=1 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DTHP_BUILD_MAIN_LIB -DUSE_EXPERIMENTAL_CUDNN_V8_API -DUSE_EXTERNAL_MZCRC -DUSE_NUMPY -D_FILE_OFFSET_BITS=64 -Dtorch_python_EXPORTS -I/Users/davidradley/pytorch/build/aten/src -I/Users/davidradley/pytorch/aten/src -I/Users/davidradley/pytorch/build -I/Users/davidradley/pytorch -I/Users/davidradley/pytorch/third_party/onnx -I/Users/davidradley/pytorch/build/third_party/onnx -I/Users/davidradley/pytorch/third_party/foxi -I/Users/davidradley/pytorch/build/third_party/foxi -I/Users/davidradley/pytorch/torch/.. -I/Users/davidradley/pytorch/torch/../aten/src -I/Users/davidradley/pytorch/torch/../aten/src/TH -I/Users/davidradley/pytorch/build/caffe2/aten/src -I/Users/davidradley/pytorch/build/third_party -I/Users/davidradley/pytorch/torch/../third_party/valgrind-headers -I/Users/davidradley/pytorch/torch/../third_party/gloo -I/Users/davidradley/pytorch/torch/../third_party/onnx -I/Users/davidradley/pytorch/torch/../third_party/flatbuffers/include -I/Users/davidradley/pytorch/torch/../third_party/kineto/libkineto/include -I/Users/davidradley/pytorch/torch/csrc -I/Users/davidradley/pytorch/torch/csrc/api/include -I/Users/davidradley/pytorch/torch/lib -I/Users/davidradley/pytorch/torch/lib/libshm -I/Users/davidradley/pytorch/torch/csrc/api -I/Users/davidradley/pytorch/c10/.. -I/Users/davidradley/pytorch/torch/lib/libshm/../../../torch/lib -I/Users/davidradley/pytorch/third_party/fmt/include -isystem /Users/davidradley/pytorch/third_party/protobuf/src -isystem /Users/davidradley/pytorch/third_party/XNNPACK/include -isystem /Users/davidradley/pytorch/cmake/../third_party/eigen -isystem /Users/davidradley/miniconda3/include/python3.10 -isystem /Users/davidradley/miniconda3/lib/python3.10/site-packages/numpy/core/include -isystem /Users/davidradley/pytorch/cmake/../third_party/pybind11/include -I/usr/local/include -I/opt/homebrew/opt/llvm/include -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wvla-extension -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-range-loop-analysis -Wno-pass-failed -Wsuggest-override -Wno-error=pedantic -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override -Wno-error=inconsistent-missing-destructor-override -Wconstant-conversion -Wno-invalid-partial-specialization -Wno-unused-private-field -Wno-missing-braces -Wunused-lambda-capture -Qunused-arguments -fcolor-diagnostics -faligned-new -Wno-unused-but-set-variable -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -DUSE_MPS -Wno-unused-private-field -Wno-missing-braces -O3 -DNDEBUG -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -fPIC -D__NEON__ -DTH_HAVE_THREAD -Wno-unused-variable -MD -MT caffe2/torch/CMakeFiles/torch_python.dir/csrc/autograd/generated/python_functions_1.cpp.o -MF caffe2/torch/CMakeFiles/torch_python.dir/csrc/autograd/generated/python_functions_1.cpp.o.d -o caffe2/torch/CMakeFiles/torch_python.dir/csrc/autograd/generated/python_functions_1.cpp.o -c /Users/davidradley/pytorch/torch/csrc/autograd/generated/python_functions_1.cpp
</code></pre>
<p>If I remove <code>-Werror=cast-function-type</code> it does not produce the errors. See <a href="https://github.com/tskit-dev/tskit/issues/106" rel="noopener nofollow ugc">https://github.com/tskit-dev/tskit/issues/106</a></p>

username: davidradl
cooked: <aside class="quote no-group" data-username="davidradl" data-post="1" data-topic="187352">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/davidradl/48/61538_2.png" class="avatar"> davidradl:</div>
<blockquote>
<p><code>MACOSX_DEPLOYMENT_TARGET=10.9</code></p>
</blockquote>
</aside>
<p>I removed this as this was targetting a backlevel os level</p>

username: davidradl
cooked: <p>I cleaned out conda and cleaned out and did not use the llvm environment and the dev  setup has now gone through cleanly with llvm.  It is working for me now with gcc.</p>

username: zhanwenchen
cooked: <p>Same issue on Ubuntu 22.04 with CUDA 12.2 and with <code>export CMAKE_CXX_COMPILER=/opt/intel/oneapi/compiler/2023.1.0/linux/bin/icpx</code></p>