diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000000..97f56d61cba8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,34 @@ +FROM mcr.microsoft.com/vscode/devcontainers/miniconda:0-3 + +# I am suprised this is needed +RUN conda init + +# Copy environment.yml (if found) to a temp location so we update the environment. Also +# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists. +COPY .devcontainer/cuda/environment.yml .devcontainer/noop.txt /tmp/conda-tmp/ +RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \ + && sudo rm -rf /tmp/conda-tmp + +# Tools needed for llvm +RUN sudo apt-get -y update +RUN sudo apt install -y lsb-release wget software-properties-common gnupg + +# Install CLANG if version is specified +ARG CLANG_VERSION +RUN if [ -n "$CLANG_VERSION" ]; then \ + sudo wget https://apt.llvm.org/llvm.sh; \ + chmod +x llvm.sh; \ + sudo ./llvm.sh "${CLANG_VERSION}"; \ + echo 'export CC=clang' >> ~/.bashrc; \ + echo 'export CXX=clang++' >> ~/.bashrc; \ + sudo apt update; \ + sudo apt install -y clang; \ + sudo apt install -y libomp-dev; \ + fi + + +# Install cuda if version is specified +ARG CUDA_VERSION +RUN if [ -n "$CUDA_VERSION" ]; then \ + conda install cuda -c "nvidia/label/cuda-${CUDA_VERSION}"; \ + fi diff --git a/.devcontainer/cpu/devcontainer.json b/.devcontainer/cpu/devcontainer.json new file mode 100644 index 000000000000..aaca1e0e9066 --- /dev/null +++ b/.devcontainer/cpu/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/anaconda +{ + "name": "PyTorch - CPU", + "build": { + "context": "../..", + "dockerfile": "../Dockerfile", + "args": { + "USERNAME": "vscode", + "BUILDKIT_INLINE_CACHE": "0", + "CLANG_VERSION": "" + } + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + // This is needed for lintrunner + "ghcr.io/devcontainers/features/rust:1" : {} + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bash .devcontainer/scripts/install-dev-tools.sh", + + // Configure tool-specific properties. + // "customizations": {}, + "customizations": { + "vscode": { + "extensions": ["streetsidesoftware.code-spell-checker"] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/cpu/environment.yml b/.devcontainer/cpu/environment.yml new file mode 100644 index 000000000000..6367278e0aaf --- /dev/null +++ b/.devcontainer/cpu/environment.yml @@ -0,0 +1,6 @@ +# This environment is specific to Debian +name: PyTorch +dependencies: + - cmake + - ninja + - libopenblas \ No newline at end of file diff --git a/.devcontainer/cuda/devcontainer.json b/.devcontainer/cuda/devcontainer.json new file mode 100644 index 000000000000..b0d448b8dc47 --- /dev/null +++ b/.devcontainer/cuda/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/anaconda +{ + "name": "PyTorch - CUDA", + "build": { + "context": "../..", + "dockerfile": "../Dockerfile", + "args": { + "USERNAME": "vscode", + "BUILDKIT_INLINE_CACHE": "0", + "CUDA_VERSION": "11.8.0", + "CLANG_VERSION": "" + } + }, + "runArgs": ["--gpus", "all"], +// Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bash .devcontainer/scripts/install-dev-tools.sh", + + // Configure tool-specific properties. + // "customizations": {}, + "customizations": { + "vscode": { + "extensions": ["streetsidesoftware.code-spell-checker"] + } + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + // This is needed for lintrunner + "ghcr.io/devcontainers/features/rust:1" : {} + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/cuda/environment.yml b/.devcontainer/cuda/environment.yml new file mode 100644 index 000000000000..6367278e0aaf --- /dev/null +++ b/.devcontainer/cuda/environment.yml @@ -0,0 +1,6 @@ +# This environment is specific to Debian +name: PyTorch +dependencies: + - cmake + - ninja + - libopenblas \ No newline at end of file diff --git a/.devcontainer/noop.txt b/.devcontainer/noop.txt new file mode 100644 index 000000000000..848dd98523f6 --- /dev/null +++ b/.devcontainer/noop.txt @@ -0,0 +1,3 @@ +This file copied into the container along with environment.yml* from the parent +folder. This file is included to prevents the Dockerfile COPY instruction from +failing if no environment.yml is found. \ No newline at end of file diff --git a/.devcontainer/scripts/install-dev-tools.sh b/.devcontainer/scripts/install-dev-tools.sh new file mode 100644 index 000000000000..a387aacffa96 --- /dev/null +++ b/.devcontainer/scripts/install-dev-tools.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section below +pip install -r requirements.txt +git submodule sync +git submodule update --init --recursive + +# This takes some time +make setup_lint + +# Add CMAKE_PREFIX_PATH to bashrc +echo 'export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}' >> ~/.bashrc diff --git a/.devcontainer/scripts/update_alternatives_clang.sh b/.devcontainer/scripts/update_alternatives_clang.sh new file mode 100755 index 000000000000..ba34b921872d --- /dev/null +++ b/.devcontainer/scripts/update_alternatives_clang.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# update_alternatives_clang.sh +# chmod u+x update_alternatives_clang.sh +# + +update_alternatives() { + local version=${1} + local priority=${2} + local z=${3} + local slaves=${4} + local path=${5} + local cmdln + + cmdln="--verbose --install ${path}${master} ${master} ${path}${master}-${version} ${priority}" + for slave in ${slaves}; do + cmdln="${cmdln} --slave ${path}${slave} ${slave} ${path}${slave}-${version}" + done + sudo update-alternatives ${cmdln} +} + +if [[ ${#} -ne 2 ]]; then + echo usage: "${0}" clang_version priority + exit 1 +fi + +version=${1} +priority=${2} +path="/usr/bin/" + +master="llvm-config" +slaves="llvm-addr2line llvm-ar llvm-as llvm-bcanalyzer llvm-bitcode-strip llvm-cat llvm-cfi-verify llvm-cov llvm-c-test llvm-cvtres llvm-cxxdump llvm-cxxfilt llvm-cxxmap llvm-debuginfod llvm-debuginfod-find llvm-diff llvm-dis llvm-dlltool llvm-dwarfdump llvm-dwarfutil llvm-dwp llvm-exegesis llvm-extract llvm-gsymutil llvm-ifs llvm-install-name-tool llvm-jitlink llvm-jitlink-executor llvm-lib llvm-libtool-darwin llvm-link llvm-lipo llvm-lto llvm-lto2 llvm-mc llvm-mca llvm-ml llvm-modextract llvm-mt llvm-nm llvm-objcopy llvm-objdump llvm-omp-device-info llvm-opt-report llvm-otool llvm-pdbutil llvm-PerfectShuffle llvm-profdata llvm-profgen llvm-ranlib llvm-rc llvm-readelf llvm-readobj llvm-reduce llvm-remark-size-diff llvm-rtdyld llvm-sim llvm-size llvm-split llvm-stress llvm-strings llvm-strip llvm-symbolizer llvm-tapi-diff llvm-tblgen llvm-tli-checker llvm-undname llvm-windres llvm-xray" + +update_alternatives "${version}" "${priority}" "${master}" "${slaves}" "${path}" + +master="clang" +slaves="analyze-build asan_symbolize bugpoint c-index-test clang++ clang-apply-replacements clang-change-namespace clang-check clang-cl clang-cpp clangd clang-doc clang-extdef-mapping clang-format clang-format-diff clang-include-fixer clang-linker-wrapper clang-move clang-nvlink-wrapper clang-offload-bundler clang-offload-packager clang-offload-wrapper clang-pseudo clang-query clang-refactor clang-rename clang-reorder-fields clang-repl clang-scan-deps clang-tidy count diagtool dsymutil FileCheck find-all-symbols git-clang-format hmaptool hwasan_symbolize intercept-build ld64.lld ld.lld llc lld lldb lldb-argdumper lldb-instr lldb-server lldb-vscode lld-link lli lli-child-target modularize not obj2yaml opt pp-trace run-clang-tidy sancov sanstats scan-build scan-build-py scan-view split-file UnicodeNameMappingGenerator verify-uselistorder wasm-ld yaml2obj yaml-bench" + +update_alternatives "${version}" "${priority}" "${master}" "${slaves}" "${path}" \ No newline at end of file