-
Notifications
You must be signed in to change notification settings - Fork 579
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
Using Ninja with nvcc_wrapper re-compiles sources every time #321
Comments
this is what I get. looks like the same as you do dir-nb (gcc) 11 $ ninja commonTools/gtest/CMakeFiles/gtest.dir/gtest/gtest-all.cc.o /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(3756): warning: function "testing::::TestNameIs::operator()" was declared but never referenced /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(7921): warning: variable "testing::internal::kPathSeparatorString" was declared but never referenced /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(3752): warning: function "testing::::TestNameIs::TestNameIs(const char *)" was declared but never referenced /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(3756): warning: function "testing::::TestNameIs::operator()" was declared but never referenced dir-nb (gcc) 12 $ ninja -t deps commonTools/gtest/CMakeFiles/gtest.dir/gtest/gtest-all.cc.o dir-nb (gcc) 13 $ ninja -d explain commonTools/gtest/CMakeFiles/gtest.dir/gtest/gtest-all.cc.o /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(3756): warning: function "testing::::TestNameIs::operator()" was declared but never referenced /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(7921): warning: variable "testing::internal::kPathSeparatorString" was declared but never referenced /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(3752): warning: function "testing::::TestNameIs::TestNameIs(const char *)" was declared but never referenced /home/mbetten/Trilinos/Trilinos/commonTools/gtest/gtest/gtest-all.cc(3756): warning: function "testing::::TestNameIs::operator()" was declared but never referenced dir-nb (gcc) 14 $ |
CC: @bartlettroscoe |
Btw Bart: this is not the compiler wrapper, but rather the NVCC two pass process. NVCC first goes through the file and generates effectively two new source files: one where all Cuda device specific code is removed, which then gets passed along to the host compiler (by default g++). The other file has only the Cuda device code which then is compiled by the thing generating PTX code (actually its a bit more complicated than that, but this is the basic gist). This causes all kinds of weird temporary files to pop up, which all kinds of tools accustomed to the normal GCC tool-chain have no idea what to do with. |
It is good to know this is due to nvcc and not specific to nvcc_wrapper. That means that putting in a fix for this into CMake should be worth the effort and will benefit projects other than Trilinos and CASL VERA, etc. This is definitely worth fixing. |
Yes Ross this is true. Also note that other labs are going down the same route as Sandia, i.e. having Cuda code in their main cpp files so that they must compile everything with NVCC. |
Is this the repo: https://github.com/kokkos/nvcc_wrapper ? Note that when you snapshot into Kokkos, then you should use the snapshot script to record the SHA1 and origin repo info so you can trace the versions between the different reps. See the process at: http://trac.trilinos.org/wiki/TriBITSTrilinosDev#update_snapshot (Just replace "TriBITS" with "nvcc_wrapper" and "Trilinos" with "kokkos".) |
Jup that is it and will do. |
It is this pass that should be responsible for generating the depfile for ninja via |
It would be great if NVIDIA could fix this but we cannot wait for NVIDIA since we have to use existing installations of CUDA (and we have to fix this now).
Would it be possible to set up |
Yes, this should be possible. It can invoke the compiler and ask it to produce the depfile but not actually compile anything. Then strip these flags and do not pass them to nvcc or the compiler it invokes. I'm not familiar enough with nvcc_wrapper to provide more details though. |
@crtrott, as the maintainer of nvcc_wrapper, would this be possible? I guess we could mess around with it and try? It is just a bash script: https://github.com/kokkos/nvcc_wrapper/blob/master/nvcc_wrapper On that point, are their any automated unit tests for nvcc_wrapper? We could use dummy programs for the host compiler and nvcc to make sure that the argument parsing and filtering is done correctly. There is actually a simple Python script in TriBITS that could help with this: https://github.com/TriBITSPub/TriBITS/blob/master/tribits/python_utils/mockprogram.py Alternatively, I see that there are If there are no unit tests for nvcc_wrapper (which is over 200 lines long), then I could help you set up some of these automated tests (using the Python unittest module to avoid dependencies on anything else). It would make me nervous to have a script that complex and that important without any unit tests. |
There are no unit-tests currently. Essentially we are doing integration testing since it is used nightly to build Trilinos and Kokkos standalone. I think Mike also set up a nightly Sierra build using nvcc_wrapper, to check whether NVCC can handle it. With regards to just invoking the host compiler: that is not an option. The source files contain Cuda extensions (such as device host) which the host compiler can not understand. But maybe the solution is as simple as adding "-MD" to shared args without an argument and "-MF" to shared args with an argument in the script. We recently added -MT. |
Those integration tests are important obviously but that does not support test-driven development very well. It should not be hard to set up some basic unit tests that pin down the most critical behavior (just a couple of hours of work or less should do it). I can start the testing infrastructure if you are supportive of this and will maintain this. Once this is set up, anyone can safely change nvcc_wrapper without fear of breaking existing important use cases, and get that feedback very fast (i.e. seconds instead of hours or days).
If just the preprocessor of the host compiler is run, would it get tripped up by CUDA extensions? Does the pre-processor even care about C++ syntax?
What specifically are you suggesting? Can you give a concrete use case for how |
Ross feel to set something up. My feeling was so far that it is sufficiently complicated to get anything approaching significant test coverage, and until recently nvcc_wrapper was maintained inside of Kokkos. So before something got changed it got tested against a Kokkos build. With regards to the flags I just checked. NVCC knows about MT but not about MF or MD. That means we already do the right thing. I.e. nvcc_wrapper will pass MF and MD only to the host compiler, MT goes to both. The only part which might be off is the order of MD MT and MF, but MT will keep its argument next to it. So I currently don't have a good idea what to do. You can try and add an option to give the file just to the host compiler if all of those flags are present (assuming you only run the preprocessor). I am not 100% confident that will work as intended. In particular the preprocessor will not define the defines NVCC automatically adds. That means you will have a miss identification of the compiler inside of Kokkos, which will probably screw up the include files and might even produce a preprocessor error via #error, since the Trilinos configuration is saying that we indeed try to compile for CUDA. If that is the case (which I highly suspect) you might be able to extract all the defines we use from NVCC, and add them manually through nvcc_wrapper for a preprocessor run. But that is starting to get really messy. |
Okay, I will block off some time in the next few days to fork the nvcc_wrapper git repo and add a Python-based unit test harness to start testing some obvious use cases. Once the basic testing utilities are written, it will be easy to add new test cases and getting pretty good coverage (100% line coverage) as long as nvcc_wrapper only parses the input command-line args and then constructs command-line args for the host and nvcc compiler (i.e. does not create or read files itself, which it does not appear to be doing currently). After that I will add a PR for this.
That is unfortunate.
I agree that this is not a very nice game to play. But with some introspective configure-time tests, it should be possible to figure out what defines NVCC is using for a given platform. Then you could just pass those through the invocation of nvcc_wrapper automatically with TriBITS. Does that make sense? Anyway, I will need to get set up to invoke nvcc_wrapper on my own so that I can see these issues myself. I will need to do this anyway as part of #172 (and take this burden off of @bathmatt). @bradking, given all of this, would it be possible to make the CMake parsing of the output from nvcc more robust without having to do lots of work with nvcc_wrapper? If that is possible, then that is likely the best short-term solution given there will be other projects that will want to use CMake+Ninja+CUDA/nvcc without the help of nvcc_wrapper. |
CMake is not parsing anything in this case. The generated depfile is loaded directly by Ninja. Also, by the time nvcc returns the temporary I was able to get $ >test.cc
$ nvcc -MT test.cc.o -o /dev/null -Xcompiler -MD,-MF,test.cc.o.d -x cu -E test.cc
$ nvcc -o test.cc.o -x cu -c test.cc
$ head -3 test.cc.o.d
test.o: test.cc /usr/include/stdc-predef.h /usr/include/cuda_runtime.h \
/usr/include/host_config.h /usr/include/features.h \
/usr/include/x86_64-linux-gnu/sys/cdefs.h \ One could teach |
Yeah that might be worth a try. |
Actually in my previous example we should not be giving $ >test.cc
$ nvcc -o /dev/null -x cu -E test.cc -Xcompiler -MD,-MT,test.cc.o,-MF,test.cc.o.d
$ nvcc -o test.cc.o -x cu -c test.cc
$ head -3 test.cc.o.d
test.cc.o: test.cc /usr/include/stdc-predef.h /usr/include/cuda_runtime.h \
/usr/include/host_config.h /usr/include/features.h \
/usr/include/x86_64-linux-gnu/sys/cdefs.h \ |
I think the next action is to have someone update nvcc_wrapper to do what @bradking suggests in the above comment. If no one gets to that, I was going to give that a try. But I am getting hammered to get some other things done so I have not been able to get this this yet. I will add an explicit set of tasks for this for now. |
I guess I don't understand what needs to be done. Are you saying you just $ nvcc -o /dev/null -x cu -E test.cc -Xcompiler On Thu, May 12, 2016 at 12:50 PM, Roscoe A. Bartlett <
|
Yes, I think that is what @bradking is suggesting. We just need to have someone see if this works with nvcc_wrapper. It will be a little while before I can get set up to try this myself to experiment with this. |
@bradking, now that SNL has a contract with Kitware to help support Trilinos at SNL, do you think you might look into updating the nvcc_wrapper to address problem with Ninja dependencies as per your above comment? Otherwise, I will wait until we have Ninja Fortran support integrated into CMake 'master' and a more standard way to install Fortran-enabled Ninja executables. |
@bartlettroscoe see kokkos/nvcc_wrapper#5 for a proposed fix to the |
@bradking, thanks for putting this together. @bathmatt, do you have a current Trilinos configure script for one of the ATTB CUDA machines set up so that we can try this patch provided by Brad? |
@bathmatt, do you have a current Trilinos configure script for one of the ATTB CUDA machines set up so that we can try this patch provided by Brad in kokkos/nvcc_wrapper#5? If you do, then Joe F. or I can give it a try on hansen or shiller. @crtrott, do you have any objection to the changes in kokkos/nvcc_wrapper#5? After we are able to test this with Ninja, then is this something that you would accept? |
@bathmatt recently mentioned that this is still a problem on machines using nvcc and ninja. He states this is a significant productivity issue for those builds. The PR kokkos/nvcc_wrapper#5 now has merge conflicts so we will need to update nvcc_wrapper again in order to retry these. I think the best time to address this might be when we get a standard ATDM configuration of Trilinos running (which will be happening soon). When we get on a machine with a CUDA build using nvcc_wrapper we will try out ninja and revisit this patch in kokkos/nvcc_wrapper#5 and work to get it merged into the offical source repo for nvcc_wrapper. Once we get to that point, I will create a new issue in https://gitlab.kitware.com/snl/project-1/. |
kokkos/nvcc_wrapper#5 has been merged. |
This issue has had no activity for 365 days and is marked for closure. It will be closed after an additional 30 days of inactivity. |
This issue was closed due to inactivity for 395 days. |
Discussion in #261 found the problem can be reproduced with stock CMake and Ninja, so I'm starting a new issue for it since it is independent of the custom (Fortran-supporting) CMake and Ninja versions reported there. Here are steps to reproduce on Linux:
The compiler wrappers somehow use a temporary already-preprocessed
.ii
file as input to theg++-4.9
call. This causes the-MD
option to generate a depfile listing only the temporary file. Ninja records this dependency and then cannot find it on the next build.Tasks:
The text was updated successfully, but these errors were encountered: