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

g++/c++ compiler incompatibility #974

Open
wpm opened this issue Oct 2, 2020 · 7 comments
Open

g++/c++ compiler incompatibility #974

wpm opened this issue Oct 2, 2020 · 7 comments

Comments

@wpm
Copy link

wpm commented Oct 2, 2020

I am working with an application that uses Pytorch and Apex. The application requires that Apex be compiled with the --cpp_ext and --cuda_ext flags. I set up my environment like so.

conda create -n layoutlm
conda activate layoutlm
conda install -c creditx gcc-7
conda install pytorch cudatoolkit=10.1 -c pytorch
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

I see the following warning when Apex compiles.

                                  !! WARNING !!

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Your compiler (c++) is not compatible with the compiler Pytorch was
    built with for this platform, which is g++ on linux. Please
    use g++ to to compile your extension. Alternatively, you may
    compile PyTorch from source using c++, and then you can also use
    c++ to compile your extension.

    See https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md for help
    with compiling PyTorch from source.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Looking at the build logs it does appear that sometimes g++ is being used and other times c++.

The application I'm building ultimately fails with a mysterious error, so I'm trying to see if this compiler incompatibility is the cause.

How do I "use g++ to compile [my] extension"? I don't see a Makefile in Apex, and it doesn't look like it's possible to specify a compiler using the options in setup.py.

  • Pytorch 1.6
  • Apex installed from latest source
  • CUDA 10.1
  • CentOS Linux release 7.6.1810 (Core)
@calee88
Copy link

calee88 commented Dec 11, 2020

I'm having the same problem. Any progress?

@calee88
Copy link

calee88 commented Dec 11, 2020

I just removed every c++ and make one link to the g++.
Something like this:

which c++
mv c++ c--
ln -s g++ c++

After that I can install the apex.
It is really painful to install anything on a CentOS.

@EeyoreLee
Copy link

EeyoreLee commented Nov 12, 2021

I just set the environment variable CXX=g++. Then it work

Updates:
Using environment variables is a more reasonable way, otherwise c++ will not be used correctly if using the way @calee88 proposed.
There are three ways follows to choose according to your situation:

  • Add CXX=g++ in front of the execution command like CXX=g++ pip install xxx
  • execute export CXX=g++ first. This will increment an environment variable for the current session rather than for an individual command
  • Add a line of code export CXX=g++ to the corresponding shell resource file. Since most people choose bash, you need to execute a command like echo "export CXX=g++" >> ~/.bashrc. This will be fixed to add this environment variable before you enter the bash environment.

I personally recommend the first one, because it won't affect other commands. The second is a good choice if you need this environment variable multiple times. The third is not recommended unless you always want to use g++ by default.

@ChambinLee
Copy link

I just set the environment variable CXX=g++. Then it work

Than you! This work for me!

@jbh1998
Copy link

jbh1998 commented Nov 30, 2021

I just set the environment variable CXX=g++. Then it work

how to set the environment variable?

@ChambinLee
Copy link

I just set the environment variable CXX=g++. Then it work

how to set the environment variable?

Hello, you can try this: export CXX=g++
it works for me.

@Cucaracha18
Copy link

yes that works. Thank you

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

6 participants