Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions brev/entrypoint-jupyter-user.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set -euo pipefail

export HOME="${ACH_TARGET_HOME}"

# Generate Jupyter plugin settings
/accelerated-computing-hub/brev/jupyter-generate-plugin-settings.bash
# Generate JupyterLab user settings
/accelerated-computing-hub/brev/jupyter-generate-settings.bash

mkdir -p /accelerated-computing-hub/logs

Expand Down
38 changes: 36 additions & 2 deletions brev/entrypoint-jupyter.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,39 @@

set -euo pipefail

# Switch to user and run user-level entrypoint
exec gosu "${ACH_TARGET_USER}" /accelerated-computing-hub/brev/entrypoint-jupyter-user.bash "$@"
# Keep this root wrapper alive so a clean Jupyter shutdown can restart its
# sibling Nsight services through the Docker socket. External container stop
# signals skip the sibling restarts.
TERMINATING=0
JUPYTER_PID=""

# shellcheck disable=SC2317 # Invoked indirectly by the signal traps below.
terminate_jupyter() {
TERMINATING=1
if [ -n "${JUPYTER_PID}" ] && kill -0 "${JUPYTER_PID}" 2>/dev/null; then
kill -TERM "${JUPYTER_PID}"
fi
}

trap terminate_jupyter TERM INT

gosu "${ACH_TARGET_USER}" /accelerated-computing-hub/brev/entrypoint-jupyter-user.bash "$@" &
JUPYTER_PID=$!

set +e
wait "${JUPYTER_PID}"
JUPYTER_STATUS=$?
if [ "${TERMINATING}" -eq 1 ] && kill -0 "${JUPYTER_PID}" 2>/dev/null; then
wait "${JUPYTER_PID}"
JUPYTER_STATUS=$?
fi
set -e

if [ "${TERMINATING}" -eq 0 ] && [ "${JUPYTER_STATUS}" -eq 0 ] && [ -n "${ACH_PORT_FORWARDS:-}" ]; then
echo "Jupyter exited cleanly; restarting Nsight services."
if ! python3 /accelerated-computing-hub/brev/restart-compose-services.py nsys ncu; then
echo "Error: Failed to restart one or more Nsight services." >&2
fi
fi

exit "${JUPYTER_STATUS}"
59 changes: 0 additions & 59 deletions brev/jupyter-generate-plugin-settings.bash

This file was deleted.

23 changes: 23 additions & 0 deletions brev/jupyter-generate-settings.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /bin/bash

set -eu

# Theme
mkdir -p "${HOME}/.jupyter/lab/user-settings/@jupyterlab/apputils-extension"
cat << EOF > "${HOME}/.jupyter/lab/user-settings/@jupyterlab/apputils-extension/themes.jupyterlab-settings"
{
"theme": "JupyterLab Dark",
"adaptive-theme": true,
"preferred-light-theme": "JupyterLab Light",
"preferred-dark-theme": "JupyterLab Dark",
"theme-scrollbars": false
}
EOF

# Execution timing
mkdir -p "${HOME}/.jupyter/lab/user-settings/@jupyterlab/notebook-extension"
cat << EOF > "${HOME}/.jupyter/lab/user-settings/@jupyterlab/notebook-extension/tracker.jupyterlab-settings"
{
"recordTiming": true
}
EOF
94 changes: 94 additions & 0 deletions brev/restart-compose-services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
"""Restart sibling Docker Compose services through the Docker Engine socket."""

import http.client
import json
import os
import socket
import sys
import urllib.parse


DOCKER_SOCKET = "/var/run/docker.sock"


class UnixHTTPConnection(http.client.HTTPConnection):
def __init__(self, socket_path):
super().__init__("localhost")
self.socket_path = socket_path

def connect(self):
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(self.socket_path)


def docker_request(method, path):
connection = UnixHTTPConnection(DOCKER_SOCKET)
try:
connection.request(method, path)
response = connection.getresponse()
body = response.read()
finally:
connection.close()

if response.status >= 300:
detail = body.decode("utf-8", errors="replace")
raise RuntimeError(
f"Docker API {method} {path} returned {response.status}: {detail}"
)
return body


def main():
services = sys.argv[1:]
if not services:
print(f"Usage: {sys.argv[0]} <service> [<service> ...]", file=sys.stderr)
return 2
if not os.path.exists(DOCKER_SOCKET):
print(f"Error: Docker socket not found at {DOCKER_SOCKET}", file=sys.stderr)
return 1

container_name = socket.gethostname()
container_path = urllib.parse.quote(container_name, safe="")
container = json.loads(
docker_request("GET", f"/containers/{container_path}/json")
)
labels = container.get("Config", {}).get("Labels", {}) or {}
project = labels.get("com.docker.compose.project")
if not project:
print(
"Error: Current container has no com.docker.compose.project label",
file=sys.stderr,
)
return 1

failed = False
for service in services:
filters = json.dumps(
{
"label": [
f"com.docker.compose.project={project}",
f"com.docker.compose.service={service}",
]
}
)
query = urllib.parse.urlencode({"all": "1", "filters": filters})
containers = json.loads(docker_request("GET", f"/containers/json?{query}"))
if not containers:
print(
f"Error: No {service!r} container found in Compose project {project!r}",
file=sys.stderr,
)
failed = True
continue

for sibling in containers:
container_id = sibling["Id"]
docker_request("POST", f"/containers/{container_id}/restart?t=10")
print(f"Restarted Compose service {project}/{service}")

return 1 if failed else 0


if __name__ == "__main__":
sys.exit(main())
1 change: 0 additions & 1 deletion tutorials/accelerated-python/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ x-config:
count: all
capabilities: [gpu]
common-env: &common-env
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_TEST_ARGS: ${ACH_TEST_ARGS:-}
Expand Down
1 change: 0 additions & 1 deletion tutorials/accelerated-python/brev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jupyter-dark-detect == 0.1.0
jupyter == 1.1.1
jupyter-server-proxy == 4.4.0
jupyterlab == 4.5.7
jupyterlab-nvidia-nsight == 1.0.0
jupyterlab-execute-time == 3.3.0

# CUDA
Expand Down
1 change: 0 additions & 1 deletion tutorials/cuda-cpp/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ x-config:
count: all
capabilities: [gpu]
common-env: &common-env
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_TEST_ARGS: ${ACH_TEST_ARGS:-}
Expand Down
1 change: 0 additions & 1 deletion tutorials/cuda-cpp/brev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jupyter-dark-detect == 0.1.0
# Jupyter
jupyter
jupyter-server-proxy
jupyterlab-nvidia-nsight
jupyterlab-execute-time

# NVIDIA devtools
Expand Down
1 change: 0 additions & 1 deletion tutorials/cuda-tile/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ x-config:
count: all
capabilities: [gpu]
common-env: &common-env
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_TEST_ARGS: ${ACH_TEST_ARGS:-}
Expand Down
1 change: 0 additions & 1 deletion tutorials/cuda-tile/brev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jupyter-dark-detect == 0.1.0
jupyter
jupyter-server-proxy
jupyterlab
jupyterlab-nvidia-nsight
jupyterlab-execute-time

# CUDA
Expand Down
1 change: 0 additions & 1 deletion tutorials/floating-point-emulation/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ x-config:
- accelerated-computing-hub:/accelerated-computing-hub
- /var/run/docker.sock:/var/run/docker.sock
environment:
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_USER: ${ACH_USER:-ach}
Expand Down
1 change: 0 additions & 1 deletion tutorials/floating-point-emulation/brev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ matplotlib

# Jupyter
jupyterlab
jupyterlab-nvidia-nsight
jupyterlab-execute-time
ipywidgets
ipykernel
Expand Down
1 change: 0 additions & 1 deletion tutorials/gpu-deployment/gpu-deployment-from-scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ To be able to visualize the file, we can download it an use [nsight-systems](htt

Further reading:
- [Nsight Documentation](https://developer.nvidia.com/nsight-systems/get-started)
- [Jupyter Lab Nsight extension](https://pypi.org/project/jupyterlab-nvidia-nsight/)
- [Towards Data Science community guide](https://medium.com/data-science/profiling-cuda-using-nsight-systems-a-numba-example-fc65003f8c52)


Expand Down
1 change: 0 additions & 1 deletion tutorials/nvmath-python/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ x-config:
count: all
capabilities: [gpu]
common-env: &common-env
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_TEST_ARGS: ${ACH_TEST_ARGS:-}
Expand Down
1 change: 0 additions & 1 deletion tutorials/nvmath-python/brev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jupyter-dark-detect == 0.1.0
# Jupyter
jupyter-server-proxy
jupyterlab
jupyterlab-nvidia-nsight
jupyterlab-execute-time
ipywidgets
ipykernel
Expand Down
1 change: 0 additions & 1 deletion tutorials/stdpar/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ x-config:
count: all
capabilities: [gpu]
common-env: &common-env
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_TEST_ARGS: ${ACH_TEST_ARGS:-}
Expand Down
1 change: 0 additions & 1 deletion tutorials/stdpar/brev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ conan
# Jupyter
jupyter
jupyter-server-proxy
jupyterlab-nvidia-nsight
jupyterlab-execute-time

# NVIDIA devtools
Expand Down
1 change: 0 additions & 1 deletion tutorials/warp/brev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ x-config:
count: all
capabilities: [gpu]
common-env: &common-env
BREV_ENV_ID: ${BREV_ENV_ID:-}
ACH_TUTORIAL: *tutorial-name
ACH_RUN_TESTS: ${ACH_RUN_TESTS:-}
ACH_TEST_ARGS: ${ACH_TEST_ARGS:-}
Expand Down
Loading