Skip to content

Use cpu runner to build docs #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 14 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
8 changes: 1 addition & 7 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,11 @@ jobs:
name: Build docs
# The build stage could fail but we want the CI to keep moving.
if: ${{ github.repository_owner == 'nvidia' && !cancelled() }}
# WAR: Building the doc currently requires a GPU (NVIDIA/cuda-python#326,327)
runs-on: linux-amd64-gpu-t4-latest-1
#runs-on: ubuntu-latest
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
# WAR: Building the doc currently requires a GPU (NVIDIA/cuda-python#326,327)
- name: Ensure GPU is working
run: nvidia-smi

- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v4
with:
Expand Down
9 changes: 3 additions & 6 deletions cuda_core/docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ CUDA compilation toolchain
CUDA system information
-----------------------

.. autodata:: cuda.core.experimental.system.driver_version
:no-value:
.. autodata:: cuda.core.experimental.system.num_devices
:no-value:
.. autodata:: cuda.core.experimental.system.devices
:no-value:
.. autoproperty:: cuda.core.experimental.system.driver_version
.. autoproperty:: cuda.core.experimental._system.System.num_devices
.. autoproperty:: cuda.core.experimental._system.System.devices


.. module:: cuda.core.experimental.utils
Expand Down
47 changes: 13 additions & 34 deletions cuda_core/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import os
import sys
from unittest.mock import MagicMock

from cuda.core.experimental._system import System

# sys.path.insert(0, os.path.abspath('.'))

Expand Down Expand Up @@ -104,49 +100,32 @@
napoleon_google_docstring = False
napoleon_numpy_docstring = True


# Mock the System class and its methods
class MockSystem:
def __init__(self, *args, **kwargs):
pass

driver_version = MagicMock()
driver_version.__doc__ = System.driver_version.__doc__
num_devices = MagicMock()
num_devices.__doc__ = System.num_devices.__doc__
devices = MagicMock()
devices.__doc__ = System.devices.__doc__


sys.modules["cuda.core.experimental._system.System"] = MagicMock(System=MockSystem)

# Add 'cuda.core.experimental.system' to autodoc_mock_imports
autodoc_mock_imports = ["cuda.core.experimental.system"]

section_titles = ["Returns"]


def autodoc_process_docstring(app, what, name, obj, options, lines):
if name.startswith("cuda.core.experimental.system"):
if name.startswith("cuda.core.experimental._system.System"):
name = name.replace("._system.System", ".system")
# patch the docstring (in lines) *in-place*. Should docstrings include section titles other than "Returns",
# this will need to be modified to handle them.
while lines:
lines.pop()
attr = name.split(".")[-1]
from cuda.core.experimental._system import System

lines_new = getattr(System, attr).__doc__.split("\n")
formatted_lines = []
for line in lines_new:
original_lines = getattr(System, attr).__doc__.split("\n")
new_lines = []
new_lines.append(f".. py:data:: {name}")
new_lines.append("")
for line in original_lines:
title = line.strip()
if title in section_titles:
formatted_lines.append(line.replace(title, f".. rubric:: {title}"))
new_lines.append(line.replace(title, f".. rubric:: {title}"))
elif line.strip() == "-" * len(title):
formatted_lines.append(" " * len(title))
new_lines.append(" " * len(title))
else:
formatted_lines.append(line)
n_pops = len(lines)
lines.extend(formatted_lines)
for _ in range(n_pops):
lines.pop(0)
new_lines.append(line)
lines.extend(new_lines)


def setup(app):
Expand Down
Loading