forked from triton-lang/triton
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Dev Container for consistent dev setup
Added a Dev Container configuration to streamline development and onboarding. This setup ensures a consistent, isolated environment with all necessary tools and dependencies for building and running Triton-CPU. The configuration supports use in both VS Code locally and GitHub Codespaces. Signed-off-by: Maryam Tahhan <[email protected]>
- Loading branch information
1 parent
c0b74b0
commit 899b376
Showing
6 changed files
with
184 additions
and
4 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,24 @@ | ||
FROM registry.access.redhat.com/ubi9/python-312 | ||
|
||
ARG USERNAME=1001 | ||
ARG USER_UID=1000 | ||
ARG USER_GID=$USER_UID | ||
|
||
USER 0 | ||
COPY user.sh user.sh | ||
# Create the user | ||
RUN ./user.sh -u $USERNAME -g $USER_GID | ||
# Set the user | ||
USER $USERNAME | ||
|
||
ENV PYTHON_VERSION=3.12 \ | ||
PATH=$HOME/.local/bin/:$PATH \ | ||
PYTHONUNBUFFERED=1 \ | ||
TRITON_CPU_BACKEND=1 | ||
|
||
# install dependencies | ||
RUN pip install --upgrade pip | ||
RUN pip install --upgrade setuptools | ||
RUN pip install ninja cmake wheel pybind11; | ||
RUN pip install pre-commit | ||
RUN echo "export MAX_JOBS=$(nproc --all)" >> "${HOME}"/.bashrc |
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,38 @@ | ||
{ | ||
"name": "Triton-CPU", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"args": { | ||
// root (not recommended) | ||
"USERNAME": "${localEnv:USER}", | ||
"USER_UID": 1000, | ||
"USER_GID": 1000 | ||
} | ||
}, | ||
"remoteUser": "${localEnv:USER}", | ||
"containerUser": "${localEnv:USER}", | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-python.debugpy", | ||
"ms-python.flake8", | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"ms-vscode.cmake-tools", | ||
"ms-vscode.cpptools", | ||
"ms-vscode.cpptools-extension-pack", | ||
"ms-vscode.cpptools-themes", | ||
"twxs.cmake" | ||
], | ||
} | ||
}, | ||
"features": {}, | ||
"postStartCommand": "${containerWorkspaceFolder}/.devcontainer/triton-cpu/postStartCommand.sh", | ||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind", | ||
"workspaceFolder": "/workspace", | ||
"hostRequirements": { | ||
"cpus": 4, | ||
"gpu": false | ||
} | ||
} |
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,20 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
git submodule init | ||
git submodule update | ||
pre-commit install |
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,100 @@ | ||
#!/bin/sh | ||
|
||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
set -euo pipefail | ||
|
||
username="" | ||
userid="" | ||
|
||
usage() { | ||
cat >&2 <<EOF | ||
Usage: $0 | ||
-u | --user <username> | ||
-g | --gid <userid> | ||
EOF | ||
exit 1 | ||
} | ||
|
||
# Parse command-line arguments | ||
args=$(getopt -o u:g: --long user:,gid: -n "$0" -- "$@") | ||
if [ $? -ne 0 ]; then usage; fi | ||
|
||
eval set -- "$args" | ||
while [ $# -gt 0 ]; do | ||
case $1 in | ||
-h | --help) | ||
usage | ||
;; | ||
-u | --user) | ||
username=$2 | ||
shift 2 | ||
;; | ||
-g | --gid) | ||
userid=$2 | ||
shift 2 | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
*) | ||
echo "Unsupported option: $1" >&2 | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
# Validate required parameters | ||
if [ -z "$username" ] || [ -z "$userid" ]; then | ||
echo "Error: --user and --gid are required." >&2 | ||
usage | ||
fi | ||
|
||
USER_NAME="$username" | ||
USER_UID="$userid" | ||
USER_GID="$USER_UID" | ||
HOME_DIR="/home/$USER_NAME" | ||
|
||
# Exit if the user is root | ||
if [ "$USER_NAME" = "root" ]; then | ||
exit 0 | ||
fi | ||
|
||
if ! [ $(getent group $USER_NAME) ]; then | ||
groupadd --gid $USER_GID $USER_NAME | ||
fi | ||
|
||
if ! [ $(getent passwd $USER_NAME) ]; then | ||
useradd --uid $USER_UID --gid $USER_GID -m $USER_NAME | ||
fi | ||
|
||
# Ensure $HOME exists when starting | ||
if [ ! -d "${HOME}" ]; then | ||
mkdir -p "${HOME}" | ||
fi | ||
|
||
# Add current (arbitrary) user to /etc/passwd and /etc/group | ||
if [ -w /etc/passwd ]; then | ||
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd | ||
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group | ||
fi | ||
|
||
# Fix up permissions | ||
chown $USER_NAME:$USER_GID -R /home/$USER_NAME | ||
chown $USER_NAME:$USER_GID -R /opt | ||
mkdir -p /run/user/$USER_UID | ||
chown $USER_NAME:$USER_GID /run/user/$USER_UID |
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
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 |
---|---|---|
|
@@ -749,6 +749,7 @@ def get_git_commit_hash(length=8): | |
"matplotlib", | ||
"pandas", | ||
"tabulate", | ||
"torch", | ||
], | ||
}, | ||
) |