Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/usr/include/c++/6/cmath:45:23: fatal error: math.h: No such file or directory #106

Closed
sbelharbi opened this issue Mar 21, 2019 · 3 comments

Comments

@sbelharbi
Copy link

sbelharbi commented Mar 21, 2019

Hi,
config:
Ubuntu: 18.04
gcc: 5.5, 6.5, 7.3
cuda: 9.1
python: 3.7
pytorch: 1.0

This issue is related to some posted issues. Sorry for repetition.

I am sure the error is related to the version of cuda, gcc. For now, I changed the version of gcc (using update-alternatives) and the wheel of pytorch (compiled using different cuda).

I obtain the error below. Any pointer is much appreciated!!! thanks
Since the error points to missing headers, I reinstalled:

sudo apt install --reinstall libstdc++-{5, 6, 7}-dev.

But the error persists.

Traceback (most recent call last):
  File "/home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 946, in _build_extension_module
    check=True)
  File "/home/brian/anaconda3/lib/python3.7/subprocess.py", line 468, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3291, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-99c8874721c0>", line 1, in <module>
    runfile('/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/test.py', wdir='/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1')
  File "/home/brian/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/brian/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/test.py", line 3, in <module>
    from deepmil.deeplabv3 import Res_Deeplab
  File "/home/brian/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/deepmil/deeplabv3.py", line 17, in <module>
    from libs import InPlaceABN, InPlaceABNSync
  File "/home/brian/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/__init__.py", line 1, in <module>
    from .bn import ABN, InPlaceABN, InPlaceABNSync
  File "/home/brian/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/bn.py", line 10, in <module>
    from .functions import *
  File "/home/brian/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/functions.py", line 18, in <module>
    extra_cuda_cflags=["--expt-extended-lambda"])
  File "/home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 645, in load
    is_python_module)
  File "/home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 814, in _jit_compile
    with_cuda=with_cuda)
  File "/home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 863, in _write_ninja_file_and_build
    _build_extension_module(name, build_directory, verbose)
  File "/home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 959, in _build_extension_module
    raise RuntimeError(message)
RuntimeError: Error building extension 'inplace_abn': [1/3] /usr/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/torch/csrc/api/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/TH -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/THC -isystem /usr/include -isystem /home/brian/Venvs/pytorch.1.0.1/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --compiler-options '-fPIC' --expt-extended-lambda -std=c++11 -c /mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/src/inplace_abn_cuda.cu -o inplace_abn_cuda.cuda.o
FAILED: inplace_abn_cuda.cuda.o 
/usr/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/torch/csrc/api/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/TH -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/THC -isystem /usr/include -isystem /home/brian/Venvs/pytorch.1.0.1/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --compiler-options '-fPIC' --expt-extended-lambda -std=c++11 -c /mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/src/inplace_abn_cuda.cu -o inplace_abn_cuda.cuda.o
In file included from /usr/include/crt/math_functions.h:8835:0,
                 from /usr/include/crt/common_functions.h:271,
                 from /usr/include/common_functions.h:50,
                 from /usr/include/cuda_runtime.h:115,
                 from <command-line>:0:
/usr/include/c++/6/cmath:45:23: fatal error: math.h: No such file or directory
 #include_next <math.h>
                       ^
compilation terminated.
[2/3] /usr/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/torch/csrc/api/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/TH -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/THC -isystem /usr/include -isystem /home/brian/Venvs/pytorch.1.0.1/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --compiler-options '-fPIC' --expt-extended-lambda -std=c++11 -c /mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/src/inplace_abn_cuda_half.cu -o inplace_abn_cuda_half.cuda.o
FAILED: inplace_abn_cuda_half.cuda.o 
/usr/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/torch/csrc/api/include -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/TH -isystem /home/brian/Venvs/pytorch.1.0.1/lib/python3.7/site-packages/torch/lib/include/THC -isystem /usr/include -isystem /home/brian/Venvs/pytorch.1.0.1/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --compiler-options '-fPIC' --expt-extended-lambda -std=c++11 -c /mnt/0890ce70-3387-4496-a36e-fe2ed1d8596f/research/code/glas-1/libs/src/inplace_abn_cuda_half.cu -o inplace_abn_cuda_half.cuda.o
In file included from /usr/include/crt/math_functions.h:8835:0,
                 from /usr/include/crt/common_functions.h:271,
                 from /usr/include/common_functions.h:50,
                 from /usr/include/cuda_runtime.h:115,
                 from <command-line>:0:
/usr/include/c++/6/cmath:45:23: fatal error: math.h: No such file or directory
 #include_next <math.h>
                       ^
compilation terminated.
ninja: build stopped: subcommand failed.
@sbelharbi
Copy link
Author

Fixed.
Cause of the issue: mismatch of the gcc, cuda versions (pytorch pre-compiled version made things worse).

Ubuntu: 18.04

Fix:

  1. Install cuda 10.0 (https://developer.nvidia.com/cuda-10.0-download-archive)
  2. Switch to gcc 7.3 (if you have many versions of gcc use update-alternatives. Ubuntu 18.04 comes by default with gcc 7.3.)
  3. Install the pytoch wheel for the version 1.0.0 for cuda 10.0: cu100/torch-1.0.0-cp37-cp37m-linux_x86_64.whl
  4. If you have many versions of cuda: add the following to ~/.bashrc and specify the cuda version you intend to use:
CUDAVER=cuda-10.0
export PATH=/usr/local/$CUDAVER/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib64:$LD_LIBRARY_PATH
export CUDA_PATH=/usr/local/$CUDAVER
export CUDA_ROOT=/usr/local/$CUDAVER
export CUDA_HOME=/usr/local/$CUDAVER
export CUDA_HOST_COMPILER=/usr/bin/gcc-7.3

Closed.

@coderbusy7
Copy link

To include files, use isystem instead of I. That's it!

@8secz-johndpope
Copy link

cudatoolkit 11.2 / or change to latest version - https://developer.nvidia.com/Cuda-downloads

add to ~/.bashrc or ~/.zshrc

CUDAVER=cuda-11.2
export PATH=/usr/local/$CUDAVER/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/$CUDAVER/lib64:$LD_LIBRARY_PATH
export CUDA_PATH=/usr/local/$CUDAVER
export CUDA_ROOT=/usr/local/$CUDAVER
export CUDA_HOME=/usr/local/$CUDAVER
export CUDA_HOST_COMPILER=/usr/bin/gcc-10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants