Skip to content

Commit

Permalink
Decode nvidia gpu names for python versions < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
PedramBakh committed Sep 10, 2023
1 parent b0fc31f commit 9f1367e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
51 changes: 49 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,58 @@ on:
- 'dev-v*.*.*'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests
run: python -m unittest discover

lint:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install flake8 black
- name: Lint with flake8
run: flake8 carbontracker --count --select=E9,F63,F7,F82 --show-source --statistics

- name: Format with Black
run: black --check --line-length 120 carbontracker

build-n-publish:
needs: [test, lint]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
Expand All @@ -24,7 +71,7 @@ jobs:
- name: Build the package
run: python -m build

- name: Publish to Test PyPI
if: startsWith(github.ref, 'refs/tags/dev-v')
uses: pypa/[email protected]
Expand Down
14 changes: 10 additions & 4 deletions carbontracker/components/gpu/nvidia.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
by running queries in batches (initializing and shutdown after each query can
result in more than a 10x slowdown).
"""
import sys

import pynvml
import os

Expand All @@ -16,13 +18,17 @@

class NvidiaGPU(Handler):
def devices(self):
"""Retrieves the name of all GPUs in a list.
"""
Note:
Requires NVML to be initialized.
"""
devices = [pynvml.nvmlDeviceGetName(handle) for handle in self._handles]
return devices
names = [pynvml.nvmlDeviceGetName(handle) for handle in self._handles]

# Decode names if Python version is less than 3.10
if sys.version_info < (3, 10):
names = [name.decode("utf-8") for name in names]

return names

def available(self):
"""Checks if NVML and any GPUs are available."""
Expand Down

0 comments on commit 9f1367e

Please sign in to comment.