Skip to content

Commit c3b47c5

Browse files
chhwangCopilot
andauthored
Updated Dev Container (#591)
* Added more features in Dev Container * Made it runnable on AMD platforms --------- Co-authored-by: Copilot <[email protected]>
1 parent af2098b commit c3b47c5

File tree

5 files changed

+212
-16
lines changed

5 files changed

+212
-16
lines changed

.devcontainer/Dockerfile

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,55 @@
11
ARG BASE_IMAGE
22
FROM ${BASE_IMAGE}
3-
ARG USERNAME=mscclpp
3+
ARG USERNAME=devuser
44
ARG USER_UID=1000
55
ARG USER_GID=$USER_UID
6+
ARG SSH_PORT=22345
67

7-
# Create the user
8-
RUN groupadd --gid $USER_GID $USERNAME && \
9-
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \
10-
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
11-
chmod 0440 /etc/sudoers.d/$USERNAME
8+
# Create or modify the user
9+
RUN if getent group $USER_GID > /dev/null; then \
10+
EXISTING_GROUP=$(getent group $USER_GID | cut -d: -f1); \
11+
if [ "$EXISTING_GROUP" != "$USERNAME" ]; then \
12+
groupmod -n $USERNAME $EXISTING_GROUP; \
13+
fi; \
14+
else \
15+
groupadd --gid $USER_GID $USERNAME; \
16+
fi && \
17+
if id -u $USER_UID > /dev/null 2>&1; then \
18+
EXISTING_USER=$(getent passwd $USER_UID | cut -d: -f1); \
19+
if [ "$EXISTING_USER" != "$USERNAME" ]; then \
20+
usermod -l $USERNAME -d /home/$USERNAME -m $EXISTING_USER; \
21+
fi; \
22+
else \
23+
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME; \
24+
fi && \
25+
usermod -g $USERNAME $USERNAME && \
26+
echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
27+
28+
RUN rm -rf /etc/apt/sources.list.d/cuda-* && \
29+
apt-get update && \
30+
apt install -y --no-install-recommends \
31+
clang-format \
32+
openssh-server \
33+
gdb \
34+
doxygen \
35+
graphviz \
36+
&& \
37+
apt-get autoremove -y && \
38+
apt-get clean && \
39+
rm -rf /var/lib/apt/lists/* /tmp/*
40+
41+
RUN python3 -m pip install --no-cache-dir \
42+
black \
43+
pytest \
44+
breathe \
45+
sphinx_rtd_theme \
46+
myst_parser \
47+
sphinxcontrib.mermaid
48+
49+
RUN sed -i "s/^Port 22/Port ${SSH_PORT}/" /etc/ssh/sshd_config && \
50+
mkdir -p /home/$USERNAME/.ssh && \
51+
ssh-keygen -t rsa -f /home/$USERNAME/.ssh/id_rsa -N "" -q && \
52+
cat /home/$USERNAME/.ssh/id_rsa.pub >> /home/$USERNAME/.ssh/authorized_keys && \
53+
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh
1254

1355
USER $USERNAME

.devcontainer/devcontainer.json

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
"build": {
44
"dockerfile": "Dockerfile",
55
"args": {
6-
"BASE_IMAGE": "ghcr.io/microsoft/mscclpp/mscclpp:base-dev-cuda12.8"
6+
"BASE_IMAGE": "ghcr.io/microsoft/mscclpp/mscclpp:base-dev-cuda12.8",
7+
"USERNAME": "devuser",
8+
"SSH_PORT": "22345"
79
}
810
},
9-
"remoteUser": "mscclpp",
11+
"remoteUser": "devuser",
12+
"containerEnv": {
13+
"LC_ALL": "C",
14+
"LANG": "C",
15+
"LANGUAGE": "C"
16+
},
1017
"customizations": {
1118
"vscode": {
1219
"extensions": [
@@ -15,18 +22,32 @@
1522
"ms-python.vscode-pylance",
1623
// C++
1724
"ms-vscode.cpptools",
18-
"ms-vscode.cpptools-extension-pack",
1925
"ms-vscode.cmake-tools"
20-
]
26+
],
27+
"settings": {
28+
"terminal.integrated.defaultProfile.linux": "bash",
29+
"C_Cpp.default.includePath": [
30+
"${workspaceFolder}/**",
31+
"/usr/local/cuda/include",
32+
"/usr/include"
33+
],
34+
"C_Cpp.default.compilerPath": "/usr/bin/gcc",
35+
"C_Cpp.default.cStandard": "c17",
36+
"C_Cpp.default.cppStandard": "c++17",
37+
"C_Cpp.default.intelliSenseMode": "linux-gcc-x64"
38+
}
2139
}
2240
},
2341
"privileged": true,
2442
"runArgs": [
43+
"--cap-add=SYS_PTRACE",
2544
"--net=host",
2645
"--ipc=host",
27-
"--gpus=all",
28-
"--ulimit=memlock=-1:-1"
46+
"--ulimit=memlock=-1:-1",
47+
"--gpus=all"
2948
],
30-
"workspaceFolder": "/home/mscclpp/mscclpp",
31-
"workspaceMount": "source=${localWorkspaceFolder},target=/home/mscclpp/mscclpp,type=bind,consistency=cached"
49+
"workspaceFolder": "/home/devuser/mscclpp",
50+
"workspaceMount": "source=${localWorkspaceFolder},target=/home/devuser/mscclpp,type=bind,consistency=cached",
51+
"postStartCommand": "sudo service ssh start",
52+
"postCreateCommand": "bash /home/devuser/mscclpp/tools/install.sh nvidia /usr"
3253
}

.devcontainer/devcontainer_amd.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "MSCCL++ Dev Container",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"args": {
6+
"BASE_IMAGE": "ghcr.io/microsoft/mscclpp/mscclpp:base-dev-rocm6.2",
7+
"USERNAME": "devuser",
8+
"SSH_PORT": "22345"
9+
}
10+
},
11+
"remoteUser": "devuser",
12+
"containerEnv": {
13+
"LC_ALL": "C",
14+
"LANG": "C",
15+
"LANGUAGE": "C"
16+
},
17+
"customizations": {
18+
"vscode": {
19+
"extensions": [
20+
// Python
21+
"ms-python.python",
22+
"ms-python.vscode-pylance",
23+
// C++
24+
"ms-vscode.cpptools",
25+
"ms-vscode.cmake-tools"
26+
],
27+
"settings": {
28+
"terminal.integrated.defaultProfile.linux": "bash",
29+
"C_Cpp.default.includePath": [
30+
"${workspaceFolder}/**",
31+
"/opt/rocm/include",
32+
"/usr/include"
33+
],
34+
"C_Cpp.default.compilerPath": "/usr/bin/gcc",
35+
"C_Cpp.default.cStandard": "c17",
36+
"C_Cpp.default.cppStandard": "c++17",
37+
"C_Cpp.default.intelliSenseMode": "linux-gcc-x64"
38+
}
39+
}
40+
},
41+
"privileged": true,
42+
"runArgs": [
43+
"--cap-add=SYS_PTRACE",
44+
"--net=host",
45+
"--ipc=host",
46+
"--ulimit=memlock=-1:-1",
47+
"--security-opt=seccomp=unconfined",
48+
"--group-add=video",
49+
"--device=/dev/kfd",
50+
"--device=/dev/dri"
51+
],
52+
"workspaceFolder": "/home/devuser/mscclpp",
53+
"workspaceMount": "source=${localWorkspaceFolder},target=/home/devuser/mscclpp,type=bind,consistency=cached",
54+
"postStartCommand": "sudo service ssh start",
55+
"postCreateCommand": "bash /home/devuser/mscclpp/tools/install.sh amd /usr"
56+
}

tools/install.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
PROJECT_ROOT=$(dirname "$(realpath "$0")")/..
6+
TMP_BUILD_DIR=$(mktemp -d)
7+
INSTALL_DIR=/usr
8+
NVIDIA=false
9+
AMD=false
10+
11+
usage() {
12+
echo "Usage: $0 <nvidia|amd> [install_dir]"
13+
echo " nvidia Install for NVIDIA platforms"
14+
echo " amd Install for AMD platforms"
15+
echo " install_dir Directory to install to (default: /usr)"
16+
}
17+
18+
if [ ! -d "$TMP_BUILD_DIR" ]; then
19+
echo "Error: Failed to create temporary build directory."
20+
exit 1
21+
fi
22+
23+
# Parse arguments
24+
if [ $# -lt 1 ]; then
25+
usage
26+
exit 1
27+
fi
28+
case "$1" in
29+
nvidia)
30+
NVIDIA=true
31+
;;
32+
amd)
33+
AMD=true
34+
;;
35+
*)
36+
echo "Error: Unknown argument '$1'"
37+
usage
38+
exit 1
39+
;;
40+
esac
41+
if [ $# -ge 2 ]; then
42+
INSTALL_DIR="$2"
43+
fi
44+
if [ ! -d "$INSTALL_DIR" ]; then
45+
echo "Error: Install directory '$INSTALL_DIR' does not exist."
46+
exit 1
47+
fi
48+
49+
trap 'rm -rf "$TMP_BUILD_DIR"' EXIT
50+
51+
pushd "$TMP_BUILD_DIR" || exit 1
52+
53+
if $AMD; then
54+
export CXX=/opt/rocm/bin/hipcc
55+
CMAKE="cmake -DMSCCLPP_BYPASS_GPU_CHECK=ON -DMSCCLPP_USE_ROCM=ON"
56+
elif $NVIDIA; then
57+
CMAKE="cmake -DMSCCLPP_BYPASS_GPU_CHECK=ON -DMSCCLPP_USE_CUDA=ON"
58+
else
59+
echo "Error: No valid platform specified."
60+
exit 1
61+
fi
62+
63+
$CMAKE \
64+
-DCMAKE_BUILD_TYPE=Release \
65+
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
66+
-DMSCCLPP_BUILD_PYTHON_BINDINGS=OFF \
67+
-DMSCCLPP_BUILD_TESTS=OFF \
68+
"$PROJECT_ROOT"
69+
70+
make -j$(nproc)
71+
72+
# Use 'make install' to ensure dependency checks are performed for a reliable installation.
73+
sudo make install
74+
75+
popd || exit 1
76+
77+
echo "Installation completed successfully."

tools/lint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fi
4141
if $LINT_CPP; then
4242
echo "Linting C++ code..."
4343
# Find all git-tracked files with .c/.h/.cpp/.hpp/.cc/.cu/.cuh extensions
44-
files=$(git ls-files --cached | grep -E '\.(c|h|cpp|hpp|cc|cu|cuh)$')
44+
files=$(git -C "$PROJECT_ROOT" ls-files --cached | grep -E '\.(c|h|cpp|hpp|cc|cu|cuh)$' | sed "s|^|$PROJECT_ROOT/|")
4545
if [ -n "$files" ]; then
4646
if $DRY_RUN; then
4747
clang-format -style=file --dry-run $files
@@ -54,7 +54,7 @@ fi
5454
if $LINT_PYTHON; then
5555
echo "Linting Python code..."
5656
# Find all git-tracked files with .py extension
57-
files=$(git ls-files --cached | grep -E '\.py$')
57+
files=$(git -C "$PROJECT_ROOT" ls-files --cached | grep -E '\.py$' | sed "s|^|$PROJECT_ROOT/|")
5858
if [ -n "$files" ]; then
5959
if $DRY_RUN; then
6060
python3 -m black --check --diff $files

0 commit comments

Comments
 (0)