-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8229 from jakirkham/add_nvcc_wrapper
Shim package to interact with an **existing** NVCC install
- Loading branch information
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of NVIDIA CORPORATION nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
set -xeuo pipefail | ||
|
||
# Default to using `nvcc` to specify `CUDA_HOME`. | ||
if [ -z ${CUDA_HOME+x} ] | ||
then | ||
CUDA_HOME="$(dirname $(dirname $(which nvcc)))" | ||
fi | ||
|
||
# Set `CUDA_HOME` in an activation script. | ||
mkdir -p "${PREFIX}/etc/conda/activate.d" | ||
cat > "${PREFIX}/etc/conda/activate.d/${PKG_NAME}_activate.sh" <<EOF | ||
#!/bin/bash | ||
if [[ ! -d "${CUDA_HOME}" ]] | ||
then | ||
echo "Cannot find: ${CUDA_HOME}" | ||
exit 1 | ||
fi | ||
if [[ ! -f "${CUDA_HOME}/lib64/stubs/libcuda.so" ]] | ||
then | ||
echo "Cannot find: ${CUDA_HOME}/lib64/stubs/libcuda.so" | ||
exit 1 | ||
fi | ||
grep "CUDA Version ${PKG_VERSION}" ${CUDA_HOME}/version.txt &>/dev/null | ||
if [[ $? -ne 0 ]] | ||
then | ||
echo "Version of installed CUDA didn't match package" | ||
exit 1 | ||
fi | ||
export CUDA_HOME="${CUDA_HOME}" | ||
export CFLAGS="\${CFLAGS} -I\${CUDA_HOME}/include" | ||
export CPPFLAGS="\${CPPFLAGS} -I\${CUDA_HOME}/include" | ||
export CXXFLAGS="\${CXXFLAGS} -I\${CUDA_HOME}/include" | ||
EOF | ||
|
||
# Unset `CUDA_HOME` in a deactivation script. | ||
mkdir -p "${PREFIX}/etc/conda/deactivate.d" | ||
cat > "${PREFIX}/etc/conda/deactivate.d/${PKG_NAME}_deactivate.sh" <<EOF | ||
#!/bin/bash | ||
unset CUDA_HOME | ||
unset CFLAGS | ||
unset CPPFLAGS | ||
unset CXXFLAGS | ||
EOF | ||
|
||
# Create `nvcc` script in `bin` so it can be easily run. | ||
mkdir -p "${PREFIX}/bin" | ||
cat > "${PREFIX}/bin/nvcc" <<'EOF' | ||
#!/bin/bash | ||
"${CUDA_HOME}/bin/nvcc" -ccbin "${CXX}" $@ | ||
EOF | ||
chmod +x "${PREFIX}/bin/nvcc" | ||
|
||
# Add `libcuda.so` shared object stub to the compiler sysroot. | ||
# Needed for things that want to link to `libcuda.so`. | ||
# Stub is used to avoid getting driver code linked into binaries. | ||
CONDA_BUILD_SYSROOT="$(${CC} --print-sysroot)" | ||
mkdir -p "${CONDA_BUILD_SYSROOT}/lib" | ||
ln -s "${CUDA_HOME}/lib64/stubs/libcuda.so" "${CONDA_BUILD_SYSROOT}/lib/libcuda.so" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{% set name = "nvcc" %} | ||
{% set version = environ.get("CUDA_VER", "9.2") %} | ||
|
||
package: | ||
name: "{{ name }}" | ||
|
||
build: | ||
number: 0 | ||
skip: true # [not linux] | ||
|
||
outputs: | ||
- name: "{{ name }}_{{ target_platform }}" | ||
version: "{{ version }}" | ||
script: install_nvcc.sh | ||
build: | ||
script_env: | ||
- CUDA_HOME | ||
ignore_run_exports: | ||
- libgcc-ng | ||
run_exports: | ||
strong: | ||
- cudatoolkit {{ version }}|{{ version }}.* | ||
requirements: | ||
host: | ||
# Needed to symlink libcuda into sysroot libs. | ||
- {{ compiler("c") }} | ||
run: | ||
test: | ||
requires: | ||
- {{ compiler("c") }} | ||
# Host code is forwarded to a C++ compiler | ||
- {{ compiler("cxx") }} | ||
files: | ||
- test.cu | ||
commands: | ||
# Verify the symlink to the libcuda stub library exists. | ||
- test -f "$(${CC} --print-sysroot)/lib/libcuda.so" | ||
# Verify the activation scripts are in-place. | ||
{% for state in ["activate", "deactivate"] %} | ||
- test -f "${PREFIX}/etc/conda/{{ state }}.d/{{ PKG_NAME }}_{{ state }}.sh" | ||
{% endfor %} | ||
# Try using the activation scripts. | ||
- if [ -z ${CUDA_HOME+x} ]; then echo "CUDA_HOME is unset after activation" && exit 1; else echo "CUDA_HOME is set to '$CUDA_HOME'"; fi | ||
- source ${PREFIX}/etc/conda/deactivate.d/{{ PKG_NAME }}_deactivate.sh | ||
- if [ -z ${CUDA_HOME+x} ]; then echo "CUDA_HOME is unset after deactivation "; else echo "CUDA_HOME is set to '$CUDA_HOME' after deactivation" && exit 1; fi | ||
- source ${PREFIX}/etc/conda/activate.d/{{ PKG_NAME }}_activate.sh | ||
- if [ -z ${CUDA_HOME+x} ]; then echo "CUDA_HOME is unset after activation" && exit 1; else echo "CUDA_HOME is set to '$CUDA_HOME'"; fi | ||
# Try building something. | ||
- nvcc test.cu | ||
about: | ||
home: https://github.com/conda-forge/nvcc-feedstock | ||
license: BSD 3-Clause | ||
license_file: LICENSE.txt | ||
summary: A meta-package to enable the right nvcc. | ||
|
||
about: | ||
home: https://github.com/conda-forge/nvcc-feedstock | ||
license: BSD 3-Clause | ||
license_file: LICENSE.txt | ||
summary: A meta-package to enable the right nvcc. | ||
|
||
extra: | ||
recipe-maintainers: | ||
- isuruf | ||
- jakirkham |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main() { | ||
return 0; | ||
} |