Skip to content

Support NVCC '-ccbin' argument#145

Closed
colesbury wants to merge 1 commit intoccache:masterfrom
colesbury:ccbin
Closed

Support NVCC '-ccbin' argument#145
colesbury wants to merge 1 commit intoccache:masterfrom
colesbury:ccbin

Conversation

@colesbury
Copy link
Contributor

Fixes #144

@jrosdahl jrosdahl added the issue: feature New feature label Feb 8, 2017
@jrosdahl
Copy link
Member

jrosdahl commented Feb 8, 2017

Thanks, looks reasonable. However, I see an edge case: If -ccbin specifies a directory and compiler_check is content then the content of the directory node is hashed. I guess it works, but is it the wanted behavior?

How does NVCC find the compiler to run if -ccbin specifies a directory?

@jeremad
Copy link

jeremad commented May 12, 2017

If this help in any way, it works like a charm on my big complicated CUDA project 👍

@lukeyeager
Copy link

I'm using this branch for Caffe2 builds, both locally and on TravisCI: facebookarchive/caffe2#735

I have requested CMake support for ccache+nvcc here, in anticipation of this being merged.
https://gitlab.kitware.com/cmake/cmake/issues/16953

facebook-github-bot pushed a commit to facebookarchive/caffe2 that referenced this pull request Jun 16, 2017
Summary:
Uncached build: https://travis-ci.org/lukeyeager/caffe2/builds/239677224
Cached build: https://travis-ci.org/lukeyeager/caffe2/builds/239686725

* Parallel builds everywhere
* All builds use CCache for quick build times (help from pytorch/pytorch#614, ccache/ccache#145)
* Run ctests when available (continuation of #550)
* Upgraded from cuDNN v5 to v6
* Fixed MKL build (by updating pkg version)
* Fixed android builds (b6f905a#commitcomment-22404119)

* ~~Building NNPACK fails with no discernible error message (currently disabled entirely)~~
* ~~Android builds continue to fail with existing error:~~
* ~~OSX builds time-out:~~

| Before | After | Changes |
| --- | --- | --- |
| COMPILER=g++ | linux | without CUDA |
| COMPILER=g++-5 | linux-gcc5 | without CUDA |
| COMPILER=g++ | linux-cuda | updated to cuDNN v6 |
| BLAS=MKL | linux-mkl | updated pkg version |
| BUILD_TARGET=android | linux-android | |
| COMPILER=clang++ | osx | |
| BUILD_TARGET=ios | osx-ios | |
| BUILD_TARGET=android | osx-android | |
| QUICKTEST | **GONE** | |
| COMPILER=g++-4.8 | **GONE** | |
| COMPILER=g++-4.9 | **GONE** | |
Closes #735

Reviewed By: Yangqing

Differential Revision: D5228966

Pulled By: bwasti

fbshipit-source-id: 6cfa6f5ff05fbd5c2078beea79564f1f3b9812fe
@lukeyeager
Copy link

CMake now supports -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache. It will be in v3.9.
https://gitlab.kitware.com/cmake/cmake/merge_requests/949

Thanks @bradking!

@bradking
Copy link

It will be in v3.9.

Actually it will be in CMake 3.10 (and is already available in nightly binaries). We're already in the release candidate cycle for CMake 3.9 so it's too late for new features in general.

@colesbury
Copy link
Contributor Author

@lukeyeager, do you know how nvcc chooses the compiler if -ccbin is a directory?

@lukeyeager
Copy link

Here's the --help information for that flag with the CUDA 8.0 compiler:

--compiler-bindir <path>                   (-ccbin)                          
        Specify the directory in which the host compiler executable resides.  The
        host compiler executable name can be also specified to ensure that the correct
        host compiler is selected.  In addition, driver prefix options ('--input-drive-prefix',
        '--dependency-drive-prefix', or '--drive-prefix') may need to be specified,
        if nvcc is executed in a Cygwin shell or a MinGW shell on Windows.

I'm not sure what that means, exactly. Let me go find one of the compiler guys ...

@lukeyeager
Copy link

When you pass a directory to -ccbin, nvcc is going to look for a binary matching the name of the standard compiler on your platform in that directory (gcc on linux, probably clang on osx, and whatever the name of the binary is for the msvc compiler on windows). I believe that without the -ccbin flag, nvcc looks for the same binary, but looks for it in $PATH.

But, as @bas-aarts pointed out, the compiler is often dynamically linked to libraries outside of that directory, and may even call out to other backend executables, etc. So just getting a checksum of the binary isn't strictly safe. How does ccache typically handle this? It might be a good enough solution to just use the last modified date of the directory.

@bas-aarts
Copy link

Assuming no-one intentionally messes with their compiler installation, a checksum on the version string should suffice.

@afbjorklund
Copy link
Contributor

Sounds like this flag could be related to the $CCACHE_PATH, then ?

You can use a custom command to $CCACHE_COMPILERCHECK,
if you feel that mtime (or content, if paranoid) is not enough a check.

@lukeyeager
Copy link

Seems like this strategy should be sufficient:

if [ -f "$ccbin" ]; then
    # File: md5sum
    ccache_hash="$(md5sum "$ccbin" | awk '{print $1}')"
elif [ -d "$ccbin" ]; then
    # Directory: mtime
    ccache_hash="$(stat -c %Y "$ccbin")"
else
    echo "'$ccbin' is not a file or directory"
    exit 1
fi

@colesbury
Copy link
Contributor Author

@jrosdahl, what do you think the best strategy is? Should we:

  1. keep the behavior in the PR (hash the directory node)
  2. guess the which compiler NVCC will use (gcc/clang/msvc)
  3. bail out if -ccbin refers to a directory

@jrosdahl
Copy link
Member

@jrosdahl, what do you think the best strategy is? Should we:

  1. keep the behavior in the PR (hash the directory node)
  2. guess the which compiler NVCC will use (gcc/clang/msvc)
  3. bail out if -ccbin refers to a directory

I'd say 2 or 3. Would it be hard to guess the compiler?

@jrosdahl
Copy link
Member

This PR says "Fixes #144" which is now closed since #193 also fixed #144, but the hashing part of this PR was not included in #193. So I guess this PR is still partly relevant? @colesbury + @seeraven: Correct?

@seeraven
Copy link
Contributor

seeraven commented Feb 1, 2018

@jrosdahl: Yes that's right.

@jrosdahl jrosdahl added this to the 3.4 milestone Feb 3, 2018
jrosdahl added a commit that referenced this pull request Feb 3, 2018
@jrosdahl
Copy link
Member

jrosdahl commented Feb 3, 2018

Applied the remaining parts now, thanks!

Also, I took a shot at option 2 discussed previously ("guess the which compiler NVCC will use (gcc/clang/msvc)") in 9c051cc. @colesbury and/or @seeraven: I would appreciate it if you could review my commit.

@jrosdahl
Copy link
Member

jrosdahl commented Feb 8, 2018

Closing this now. (A review of my commit would still be appreciated...)

@jrosdahl jrosdahl closed this Feb 8, 2018
ezyang pushed a commit to ezyang/ATen that referenced this pull request Apr 19, 2018
Summary:
Uncached build: https://travis-ci.org/lukeyeager/caffe2/builds/239677224
Cached build: https://travis-ci.org/lukeyeager/caffe2/builds/239686725

* Parallel builds everywhere
* All builds use CCache for quick build times (help from pytorch/pytorch#614, ccache/ccache#145)
* Run ctests when available (continuation of facebookarchive/caffe2#550)
* Upgraded from cuDNN v5 to v6
* Fixed MKL build (by updating pkg version)
* Fixed android builds (facebookarchive/caffe2@b6f905a#commitcomment-22404119)

* ~~Building NNPACK fails with no discernible error message (currently disabled entirely)~~
* ~~Android builds continue to fail with existing error:~~
* ~~OSX builds time-out:~~

| Before | After | Changes |
| --- | --- | --- |
| COMPILER=g++ | linux | without CUDA |
| COMPILER=g++-5 | linux-gcc5 | without CUDA |
| COMPILER=g++ | linux-cuda | updated to cuDNN v6 |
| BLAS=MKL | linux-mkl | updated pkg version |
| BUILD_TARGET=android | linux-android | |
| COMPILER=clang++ | osx | |
| BUILD_TARGET=ios | osx-ios | |
| BUILD_TARGET=android | osx-android | |
| QUICKTEST | **GONE** | |
| COMPILER=g++-4.8 | **GONE** | |
| COMPILER=g++-4.9 | **GONE** | |
Closes facebookarchive/caffe2#735

Reviewed By: Yangqing

Differential Revision: D5228966

Pulled By: bwasti

fbshipit-source-id: 6cfa6f5ff05fbd5c2078beea79564f1f3b9812fe
zdevito pushed a commit to zdevito/ATen that referenced this pull request Apr 19, 2018
Summary:
Uncached build: https://travis-ci.org/lukeyeager/caffe2/builds/239677224
Cached build: https://travis-ci.org/lukeyeager/caffe2/builds/239686725

* Parallel builds everywhere
* All builds use CCache for quick build times (help from pytorch/pytorch#614, ccache/ccache#145)
* Run ctests when available (continuation of facebookarchive/caffe2#550)
* Upgraded from cuDNN v5 to v6
* Fixed MKL build (by updating pkg version)
* Fixed android builds (facebookarchive/caffe2@b6f905a#commitcomment-22404119)

* ~~Building NNPACK fails with no discernible error message (currently disabled entirely)~~
* ~~Android builds continue to fail with existing error:~~
* ~~OSX builds time-out:~~

| Before | After | Changes |
| --- | --- | --- |
| COMPILER=g++ | linux | without CUDA |
| COMPILER=g++-5 | linux-gcc5 | without CUDA |
| COMPILER=g++ | linux-cuda | updated to cuDNN v6 |
| BLAS=MKL | linux-mkl | updated pkg version |
| BUILD_TARGET=android | linux-android | |
| COMPILER=clang++ | osx | |
| BUILD_TARGET=ios | osx-ios | |
| BUILD_TARGET=android | osx-android | |
| QUICKTEST | **GONE** | |
| COMPILER=g++-4.8 | **GONE** | |
| COMPILER=g++-4.9 | **GONE** | |
Closes facebookarchive/caffe2#735

Reviewed By: Yangqing

Differential Revision: D5228966

Pulled By: bwasti

fbshipit-source-id: 6cfa6f5ff05fbd5c2078beea79564f1f3b9812fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue: feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants