Skip to content

Commit d437142

Browse files
erikhuckerikhuck
authored andcommitted
Merge 530abca into 98933dd
0 parents  commit d437142

132 files changed

Lines changed: 13157 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
omit = src/gpu_tracker/__init__.py,src/gpu_tracker/_version.py
3+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish Documentation
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
publish-documentation:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-python@v5
12+
with:
13+
python-version: '3.x'
14+
- name: Upgrade pip, install package, install requirements, build docs
15+
run: |
16+
pip install --upgrade pip
17+
pip install .
18+
if [ -f ./docs/requirements.txt ]; then pip install -r ./docs/requirements.txt; fi
19+
pip install sphinx
20+
sphinx-build docs ./docs/_build/html/
21+
# Create an artifact of the html output.
22+
- uses: actions/upload-artifact@v4
23+
with:
24+
name: DocumentationHTML
25+
path: docs/_build/html/
26+
# Publish built docs to gh-pages branch.
27+
# ===============================
28+
- name: Commit documentation changes
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: |
32+
git config --global user.name "${GITHUB_ACTOR}"
33+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
34+
git clone "https://token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" --branch gh-pages --single-branch gh-pages
35+
cp -r docs/_build/html/* gh-pages/
36+
cd gh-pages
37+
touch .nojekyll
38+
git add .
39+
git commit -m "Update documentation." -a || true
40+
# The above command will fail if no changes were present, so we ignore
41+
# that.
42+
- name: Push changes
43+
uses: ad-m/github-push-action@master
44+
with:
45+
branch: gh-pages
46+
directory: gh-pages
47+
github_token: ${{ secrets.GITHUB_TOKEN }}
48+
# ===============================
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Package and Documentation Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
release-version:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- id: parse-version
12+
name: Parse release version
13+
run: |
14+
echo "version=${RELEASE_VERSION/v/}" >> "$GITHUB_OUTPUT"
15+
env:
16+
RELEASE_VERSION: ${{ github.event.release.tag_name }}
17+
outputs:
18+
version: ${{ steps.parse-version.outputs.version }}
19+
publish-test-pypi:
20+
uses: ./.github/workflows/pypi.yml
21+
with:
22+
repository_url: https://test.pypi.org/legacy/
23+
secrets:
24+
API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
25+
test-test-pypi:
26+
needs: [release-version, publish-test-pypi]
27+
uses: ./.github/workflows/tests.yml
28+
with:
29+
install_command: "python3 -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple gpu-tracker==${{ needs.release-version.outputs.version }}"
30+
publish-pypi:
31+
needs: test-test-pypi
32+
uses: ./.github/workflows/pypi.yml
33+
with:
34+
repository_url: https://upload.pypi.org/legacy/
35+
secrets:
36+
API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
37+
test-pypi:
38+
needs: [release-version, publish-pypi]
39+
uses: ./.github/workflows/tests.yml
40+
with:
41+
install_command: "python3 -m pip install gpu-tracker==${{ needs.release-version.outputs.version }}"
42+
publish-documentation:
43+
needs: test-pypi
44+
uses: ./.github/workflows/documentation.yml

.github/workflows/pull_request.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Pull request
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
pull-request:
14+
uses: ./.github/workflows/tests.yml
15+
with:
16+
install_command: "python3 -m pip install -e ."

.github/workflows/pypi.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish package
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repository_url:
7+
description: The URL of the PyPi distribution
8+
required: true
9+
type: string
10+
secrets:
11+
API_TOKEN:
12+
required: true
13+
14+
jobs:
15+
publish-package:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.x'
22+
- name: Install dependencies
23+
run: |
24+
python3 -m pip install --upgrade pip
25+
python3 -m pip install build
26+
- name: Build package
27+
run: python3 -m build
28+
- name: Publish package to a PyPi distribution
29+
uses: pypa/gh-action-pypi-publish@release/v1
30+
with:
31+
password: ${{ secrets.API_TOKEN }}
32+
repository-url: ${{ inputs.repository_url }}

.github/workflows/tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
install_command:
7+
description: The command for installing the package to test.
8+
required: true
9+
type: string
10+
11+
jobs:
12+
run-tests:
13+
strategy:
14+
matrix:
15+
python-version: ["3.10", "3.11", "3.12"]
16+
os: [ ubuntu-latest, windows-latest, macOS-latest ]
17+
runs-on: ${{matrix.os}}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install testing environment
25+
run: |
26+
python3 -m pip install --upgrade pip
27+
python3 -m pip install pytest pytest-mock pytest-cov deepdiff
28+
- name: Install package
29+
uses: Wandalen/wretry.action@master
30+
with:
31+
command: ${{ inputs.install_command }}
32+
attempt_limit: 10
33+
attempt_delay: 10000
34+
- name: Run tests on package
35+
run: python3 -m pytest tests --cov --cov-branch --cov-report=term-missing
36+
- name: Debug with tmate on failure
37+
if: ${{ failure() }}
38+
uses: mxschmitt/action-tmate@v3
39+
with:
40+
limit-access-to-actor: true

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.coverage*
2+
.env/
3+
.idea/
4+
dist/
5+
**/__pycache__/**
6+
src/gpu_tracker/_version.py
7+
src/gpu_tracker.egg-info
8+
docs/_build/
9+
docs/notebook/.ipynb_checkpoints/

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
The Clear BSD License
2+
3+
Copyright (c) 2024, Erik D. Huckvale, and Hunter N.B. Moseley
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted (subject to the limitations in the disclaimer
8+
below) provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
* Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
15+
16+
* If the source code is used in a published work, then proper citation of the source code must be included with the published work.
17+
18+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
19+
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
POSSIBILITY OF SUCH DAMAGE.

README.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
###########
2+
gpu_tracker
3+
###########
4+
Description
5+
-----------
6+
The ``gpu_tracker`` package provides a ``Tracker`` class and a commandline-interface that tracks (profiles) the usage of compute time, CPU utilization, maximum RAM, GPU utilization, and maximum GPU RAM.
7+
The compute time is a measurement of the real time taken by the task as opposed to the CPU-utilization time.
8+
The GPU tracking is for both Nvidia and AMD GPUs and respectively uses the nvidia-smi and amd-smi command-line tools to pull GPU usage information. Also, if neither the appropriate Nvidia nor AMD driver is installed, then the GPU-related metrics are not tracked and are reported as 0.
9+
Computational resources are tracked throughout the duration of a context manager or the duration of explicit calls to the ``start()`` and ``stop()`` methods of the ``Tracker`` class.
10+
The ``gpu-tracker`` command-line interface alternatively tracks the computational-resource-usage of an arbitrary shell command.
11+
12+
**NOTE: The tracking occurs in a separate process. To maximize the accuracy of the reported resource usage, you may want to have a core available solely for the tracking process e.g. if your job uses 3 workers, you may want to allocate 4 cores.**
13+
14+
**NOTE: Since the tracking process is created using the Python multiprocessing library, if done so using the "spawn" start method (default on MacOS and Windows) or the "forkserver" method, you may get a runtime error after starting the tracking. To prevent this, you'll need to start the tracker after checking** ``if __name__ == '__main__'``. **See "Safe importing of main module" under** `The spawn and forkserver start methods <https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods>`__ **for more information.**
15+
16+
Documentation
17+
-------------
18+
The complete documentation for the ``gpu_tracker`` package, including tutorials, can be found `here <https://moseleybioinformaticslab.github.io/gpu_tracker/>`__.
19+
20+
Installation
21+
------------
22+
Requires python 3.10 and above.
23+
24+
Install on Linux, Mac OS X
25+
~~~~~~~~~~~~~~~~~~~~~~~~~~
26+
.. parsed-literal::
27+
python3 -m pip install gpu-tracker
28+
29+
Install on Windows
30+
~~~~~~~~~~~~~~~~~~
31+
.. parsed-literal::
32+
py -3 -m pip install gpu-tracker
33+
34+
PyPi
35+
~~~~
36+
See our PyPi page `here <https://pypi.org/project/gpu-tracker/>`__.
37+
38+
Questions, Feature Requests, and Bug Reports
39+
--------------------------------------------
40+
Please submit any questions or feature requests you may have and report any potential bugs/errors you observe on `our GitHub issues page <https://github.com/MoseleyBioinformaticsLab/gpu_tracker/issues>`__.
41+
42+
GitHub Repository
43+
-------------------
44+
Code is available on GitHub: https://github.com/MoseleyBioinformaticsLab/gpu_tracker.

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

0 commit comments

Comments
 (0)