Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .azure-pipelines/ansible-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ steps:
echo "##vso[task.prependpath]$HOME/.local/bin"
displayName: Export path
- script: |
python3 -m pip install .[test]
set -e
python3 -m pip install -c requirements/ansible.txt .[test]
make postinstall
displayName: Install Ansible dependencies
- script: |
Expand Down
3 changes: 2 additions & 1 deletion .azure-pipelines/cpu-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ steps:
echo "##vso[task.prependpath]$HOME/.local/bin"
displayName: Export path
- script: |
set -e
if python3 -c "import sys; exit(0 if sys.version_info < (3, 11) else 1)"; then
python3 -m pip install --upgrade setuptools==65.7
fi
python3 -m pip install --no-cache-dir .[test,cpuworker]
python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[test,cpuworker]
make postinstall
displayName: Install dependencies
- script: |
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/cuda-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ steps:
apt-get install -y -q \
ffmpeg libavcodec-dev libavformat-dev libavutil-dev libboost-program-options-dev libswresample-dev"
python3 -m pip install --upgrade setuptools==65.7
python3 -m pip install .[test,nvworker]
python3 -m pip install -c requirements/ansible.txt .[test,nvworker]
make postinstall
displayName: Install dependencies
- script: |
Expand Down
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ thirdparty:
cd ./third_party/ && make all

postinstall:
ifeq ($(shell which ansible-galaxy),)
$(error 'Cannot find ansible-galaxy')
else
ansible-galaxy collection install ansible.posix ansible.utils community.crypto
endif
@command -v ansible-galaxy >/dev/null || { echo "Cannot find ansible-galaxy" >&2; exit 1; }
@profile=$$(python3 -c 'import sys; print("legacy" if sys.version_info < (3, 11) else "modern")') || exit $$?; \
if [ "$$profile" = legacy ]; then \
collections="ansible.posix:1.5.4 ansible.utils:2.12.0 community.crypto:2.16.0"; \
else \
collections="ansible.posix:2.2.2 ansible.utils:6.1.1 community.crypto:3.5.1"; \
fi; \
for attempt in 1 2 3; do \
timeout 300 ansible-galaxy collection install $$collections && exit 0; \
status=$$?; \
echo "Ansible collections: attempt $$attempt/3 failed (exit $$status)." >&2; \
if [ $$attempt -eq 3 ]; then exit $$status; fi; \
echo "Retrying in $$((attempt * 10)) seconds." >&2; \
sleep $$((attempt * 10)) || exit $$?; \
done
8 changes: 7 additions & 1 deletion dockerfile/cuda11.1.1.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /opt/cmake-3.14.6-Linux-x86_64

ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt
COPY Makefile /opt/sb-ansible/Makefile
RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \
make -C /opt/sb-ansible postinstall

ARG NUM_MAKE_JOBS=

# Install Docker
Expand Down Expand Up @@ -168,5 +175,4 @@ ADD . .
RUN python3 -m pip install --upgrade setuptools==65.7 importlib_metadata==6.8.0 && \
python3 -m pip install --no-cache-dir .[nvworker] && \
make cppbuild && \
make postinstall && \
rm -rf .git
8 changes: 7 additions & 1 deletion dockerfile/cuda12.9.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*

ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt
COPY Makefile /opt/sb-ansible/Makefile
RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \
make -C /opt/sb-ansible postinstall

# Install CMake 3.30.4 for nvbench compatibility
RUN apt-get update && \
apt-get remove -y cmake cmake-data && \
Expand Down Expand Up @@ -191,5 +198,4 @@ ADD . .
RUN python3 -m pip install --upgrade setuptools==78.1.0 && \
python3 -m pip install --no-cache-dir .[nvworker] && \
make cppbuild && \
make postinstall && \
rm -rf .git
8 changes: 7 additions & 1 deletion dockerfile/cuda13.0.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*

ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt
COPY Makefile /opt/sb-ansible/Makefile
RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \
make -C /opt/sb-ansible postinstall

ARG NUM_MAKE_JOBS=
ARG TARGETPLATFORM
ARG TARGETARCH
Expand Down Expand Up @@ -158,5 +165,4 @@ ADD . .
RUN python3 -m pip install --upgrade setuptools==78.1.0 && \
python3 -m pip install --no-cache-dir .[nvworker] && \
make cppbuild && \
make postinstall && \
rm -rf .git
8 changes: 7 additions & 1 deletion dockerfile/cuda13.4.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*

ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt
COPY Makefile /opt/sb-ansible/Makefile
RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \
make -C /opt/sb-ansible postinstall

# Number of parallel jobs for the NVBench build. Override with --build-arg NUM_MAKE_JOBS=...
ARG NUM_MAKE_JOBS=64

Expand Down Expand Up @@ -202,5 +209,4 @@ ADD . .
RUN python3 -m pip install --upgrade setuptools==78.1.0 && \
python3 -m pip install --no-cache-dir .[nvworker] && \
make cppbuild && \
make postinstall && \
rm -rf .git
8 changes: 7 additions & 1 deletion dockerfile/rocm6.3.x.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ RUN apt-get update && \
&& \
rm -rf /tmp/*

ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
Comment thread
gusui-msft marked this conversation as resolved.
Resolved
COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt
COPY Makefile /opt/sb-ansible/Makefile
RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \
make -C /opt/sb-ansible postinstall

# Install Docker
ENV DOCKER_VERSION=27.5.1
RUN cd /tmp && \
Expand Down Expand Up @@ -145,5 +152,4 @@ ENV USE_HIP_DATATYPE=1
ENV USE_HIPBLAS_COMPUTETYPE=1
RUN python3 -m pip install --no-build-isolation .[amdworker] && \
CXX=/opt/rocm/bin/hipcc make cppbuild && \
make postinstall && \
rm -rf .git
8 changes: 7 additions & 1 deletion dockerfile/rocm6.4.x.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /tmp/*

ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \
ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt
COPY Makefile /opt/sb-ansible/Makefile
RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \
make -C /opt/sb-ansible postinstall

ARG NUM_MAKE_JOBS=64

# Check if CMake is installed and its version
Expand Down Expand Up @@ -247,7 +254,6 @@ ENV USE_HIP_DATATYPE=1
ENV USE_HIPBLAS_COMPUTETYPE=1
RUN python3 -m pip install .[amdworker] && \
CXX=/opt/rocm/bin/hipcc make cppbuild && \
make postinstall && \
rm -rf .git

# Fix stale hypothesis plugin from base image (imports removed pkg_resources)
Expand Down
31 changes: 30 additions & 1 deletion docs/developer-guides/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,38 @@ Follow [System Requirements](../getting-started/installation.mdx).
git clone --recurse-submodules -j8 https://github.com/microsoft/superbenchmark
cd superbenchmark

python3 -m pip install -e .[develop]
python3 -m pip install -c requirements/ansible.txt -e .[develop]
make postinstall
```

Use a clean Python environment without the bundled `ansible` distribution.
The Linux control environment needs GNU `timeout`, `openssh-client` and `rsync`.

### Ansible Dependencies

[requirements/ansible.txt](../../requirements/ansible.txt) pins the engine,
runner and Jinja2 for each supported Python family. Other transitive dependencies
remain managed by pip; this is not a complete environment lock.
[Makefile](../../Makefile) pins the three collections, using a legacy set for
Python 3.7-3.10 and a modern set for Python 3.11+. The legacy Ansible 2.10 engine
is end-of-life and remains a compatibility bridge, not a long-term support promise.

`make postinstall` installs collections with at most three attempts, a
300-second timeout per attempt, and 10- and 20-second waits. Exhaustion fails
the build. Pip retains its own retry handling.

The main GPU image stage installs these dependencies before copying application
source or building benchmarks; CUDA 13.4's separate STREAM stage is unchanged.
The images reuse normal Docker layer caching and retain `PIP_CONSTRAINT` for
later pip commands. A cold build still needs the network; the existing Build
Image workflow is unchanged.

To update versions, edit the requirements file and Makefile together. Run
`python3 -m pytest -q tests/runner/test_ansible.py`, the existing Ansible
integration tests, and the affected image builds before merging. Check both
legacy and modern runtimes; local runner tests alone do not qualify GPU images
or remote deployment.

## Lint and Test

Format code using yapf.
Expand Down
12 changes: 12 additions & 0 deletions requirements/ansible.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

ansible-base==2.10.17; python_version < "3.11"
ansible-core==2.19.15; python_version == "3.11"
ansible-core==2.21.6; python_version == "3.12"
ansible-core==2.22.0; python_version >= "3.13"
ansible-runner==2.3.1; python_version < "3.11"
ansible-runner==2.4.3; python_version >= "3.11"
# Ansible 2.10 uses filter imports removed in Jinja2 3.1.
Jinja2==3.0.3; python_version < "3.11"
Jinja2==3.1.6; python_version >= "3.11"
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ def run(self):
'vcs_versioning; python_version>="3.10"',
],
install_requires=[
'ansible;os_name=="posix" and python_version>"3.10"',
'ansible_base>=2.10.9;os_name=="posix" and python_version<="3.10"',
'ansible-core>=2.19,<2.20;os_name=="posix" and python_version=="3.11"',
'ansible-core>=2.21,<2.22;os_name=="posix" and python_version=="3.12"',
'ansible-core>=2.22,<2.23;os_name=="posix" and python_version>="3.13"',
'ansible_base>=2.10.17,<2.11;os_name=="posix" and python_version<="3.10"',
'ansible_runner>=2.0.0rc1, <2.3.2;python_version<="3.10"',
'ansible_runner;python_version>"3.10"',
'ansible_runner>=2.4.3,<2.5;python_version>"3.10"',
'colorlog>=6.7.0',
'importlib_metadata',
'jinja2>=2.10.1',
Expand Down
71 changes: 71 additions & 0 deletions tests/runner/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""SuperBench Ansible Client test."""

import os
import subprocess
import sys
import unittest
import tempfile
from pathlib import Path
Expand All @@ -15,6 +17,61 @@
AnsibleClient = LazyImport('superbench.runner.ansible', 'AnsibleClient')


class AnsiblePostinstallTestCase(unittest.TestCase):
"""Test the shared Makefile entry point without contacting Galaxy."""
def test_bounded_collection_retries(self):
"""Stop on success and propagate exhausted installation failures."""
for codes in [[0], [1, 0], [1, 1, 0], [17, 17, 17], [124, 124, 124]]:
with self.subTest(codes=codes), tempfile.TemporaryDirectory() as directory:
root = Path(directory)
attempts = root / 'attempts'
waits = root / 'waits'
status_codes = root / 'codes'
status_codes.write_text('\n'.join(map(str, codes)) + '\n')
waits.touch()
scripts = {
'ansible-galaxy': (
'printf "%s\\n" "$*" >> "$INSTALL_ATTEMPTS"\n'
'attempt=$(wc -l < "$INSTALL_ATTEMPTS")\n'
'exit "$(sed -n "${attempt}p" "$INSTALL_CODES")"\n'
),
'sleep':
'printf "%s\\n" "$1" >> "$INSTALL_WAITS"\n',
}
for name, body in scripts.items():
script = root / name
script.write_text('#!/bin/sh\nset -eu\n' + body)
script.chmod(0o755)
env = dict(
os.environ,
PATH=str(root) + os.pathsep + os.environ['PATH'],
INSTALL_ATTEMPTS=str(attempts),
INSTALL_WAITS=str(waits),
INSTALL_CODES=str(status_codes),
)
result = subprocess.run(
['make', '--no-print-directory', 'postinstall'],
cwd=Path(__file__).resolve().parents[2],
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
timeout=30,
)
self.assertEqual(result.returncode == 0, codes[-1] == 0, result.stdout)
commands = attempts.read_text().splitlines()
self.assertEqual(len(commands), len(codes), result.stdout)
self.assertEqual(commands, [commands[0]] * len(codes))
self.assertRegex(
commands[0],
r'^collection install ansible\.posix:\d+\.\d+\.\d+ '
r'ansible\.utils:\d+\.\d+\.\d+ community\.crypto:\d+\.\d+\.\d+$',
)
self.assertEqual(waits.read_text().splitlines(), ['10', '20'][:len(codes) - 1])
if codes[-1]:
self.assertIn('attempt 3/3 failed (exit {}).'.format(codes[-1]), result.stdout)


class AnsibleClientTestCase(unittest.TestCase):
"""A class for ansible client test cases."""
def setUp(self):
Expand Down Expand Up @@ -158,3 +215,17 @@ def test_get_playbook_config(self):
'playbook': str(self.ansible_client._playbook_path / 'play'),
}
)

def test_local_execution_and_failure_count(self):
"""Exercise the real runner and preserve nonzero command failures."""
client = AnsibleClient(OmegaConf.create({'host_list': 'localhost'}))
with tempfile.TemporaryDirectory(prefix='sb-ansible-client-') as directory:
for command, expected in [('printf sb-ansible-smoke', 0), ('exit 7', 2)]:
config = client.get_shell_config(command)
config['extravars'] = {'ansible_python_interpreter': sys.executable}
config['envvars'] = {
'ANSIBLE_LOCAL_TEMP': str(Path(directory) / 'local'),
'ANSIBLE_REMOTE_TEMP': str(Path(directory) / 'remote'),
}
self.assertEqual(client.run(config), expected)
self.assertEqual(client.failure_count, 1)
Loading