Skip to content
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

[libshortfin] Enable building docs with Sphinx #209

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
20 changes: 20 additions & 0 deletions libshortfin/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Python API Docs

Documentation for the Python API is build with Sphinx under this directory.

## Building docs

The Python modules will be automatically imported if installed or if the build
is located at `../build`, relative to this file.

### Install dependencies

```shell
python3 -m pip install -r requirements.txt
```

### Build the docs

```shell
sphinx-build -b html . _build
```
42 changes: 42 additions & 0 deletions libshortfin/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Configuration file for the Sphinx documentation builder.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add license/copyright header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a copyright header to the files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can they use the standard format? https://github.com/nod-ai/SHARK-Platform/blob/19834ee1e1d476a116679afb9521ea0cccdeb308/shortfin/shortfin/framework/session.py#L1-L5

# Copyright 2024 Advanced Micro Devices, Inc.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import sys

try:
import _shortfin_default
except ImportError:
sys.path.insert(0, os.path.abspath("../build/python/"))
import _shortfin_default

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "libshortfin"
copyright = "2024, Advanced Micro Devices, Inc"
author = "libshortfin Authors"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try other themes? Wonder if there is something that AMD recommends

https://rocm.docs.amd.com/en/latest/contribute/toolchain.html points to https://sphinx-book-theme.readthedocs.io/en/latest/

Copy link
Collaborator Author

@marbre marbre Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No not yet. I wasn't able to figure out if there is some common theme used and that's at least in line with the IREE Python API docs.

html_static_path = ["_static"]
27 changes: 27 additions & 0 deletions libshortfin/docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. Copyright 2024 Advanced Micro Devices, Inc.

.. libshortfin documentation master file, created by
sphinx-quickstart on Fri Sep 6 16:31:45 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to libshortfin's documentation!
=======================================

.. toctree::
:maxdepth: 2
:caption: Contents

.. toctree::
:maxdepth: 2
:caption: Reference

reference


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
58 changes: 58 additions & 0 deletions libshortfin/docs/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. Copyright 2024 Advanced Micro Devices, Inc.

.. py:module:: _shortfin_default.lib

.. _reference:

API Reference
=============

Array
--------------
.. automodule:: _shortfin_default.lib.array
.. autoclass:: DType
.. autoclass:: storage
:members:
.. autoclass:: base_array
.. autoclass:: device_array

Local
--------------

.. automodule:: _shortfin_default.lib.local

.. autoclass:: SystemBuilder
.. autoclass:: System
.. autoclass:: Node
.. autoclass:: Device
.. autoclass:: DeviceAffinity
.. autoclass:: Program
.. autoclass:: ProgramFunction
:members:
.. autoclass:: ProgramModule
.. autoclass:: ProgramInvocation
.. autoclass:: Fiber
.. autoclass:: ScopedDevice
.. autoclass:: Worker
.. autoclass:: Process
.. autoclass:: CompletionEvent
.. autoclass:: Message
.. autoclass:: Queue
.. autoclass:: QueueWriter
.. autoclass:: QueueReader
.. autoclass:: Future
.. autoclass:: VoidFuture
.. autoclass:: MessageFuture


AMD GPU
^^^^^^^
.. automodule:: _shortfin_default.lib.local.amdgpu
.. autoclass:: SystemBuilder
.. autoclass:: AMDGPUDevice

Host
^^^^^^^
.. automodule:: _shortfin_default.lib.local.host
.. autoclass:: CPUSystemBuilder
.. autoclass:: HostCPUDevice
2 changes: 2 additions & 0 deletions libshortfin/docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx==7.4.7
sphinx_rtd_theme==2.0.0
6 changes: 3 additions & 3 deletions libshortfin/python/array_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ static const char DOCSTRING_STORAGE_MAP[] =

Support kwargs of:

read: Enables read access to the mapped memory.
write: Enables write access to the mapped memory and will flush upon close
| read: Enables read access to the mapped memory.
| write: Enables write access to the mapped memory and will flush upon close
(for non-unified memory systems).
discard: Indicates that the entire memory map should be treated as if it will
| discard: Indicates that the entire memory map should be treated as if it will
be overwritten. Initial contents will be undefined. Implies `write=True`.

Mapping memory for access from the host requires a compatible buffer that has
Expand Down
Loading