Skip to content

Commit 8a8e4b6

Browse files
committed
[FFI][DOCS] Initial bringup of cpp docs (apache#18279)
This PR brings up initial version of cpp api docs.
1 parent 42f4efc commit 8a8e4b6

36 files changed

+979
-144
lines changed

docs/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
_build
2-
**/generated/*.rst
2+
**/generated/*

docs/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ help:
2727

2828
.PHONY: help Makefile livehtml clean
2929

30-
# Catch-all target: route all unknown targets to Sphinx using the new
31-
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
32-
%: Makefile
33-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
34-
3530
livehtml:
36-
@sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
31+
@sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) --ignore reference/cpp/generated
3732

3833
clean:
3934
rm -rf $(BUILDDIR)
4035
rm -rf reference/python/generated
36+
rm -rf reference/cpp/generated
37+
38+
# Catch-all target: route all unknown targets to Sphinx using the new
39+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
40+
%: Makefile
41+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@ Then build the doc
3333
```bash
3434
make livehtml
3535
```
36+
37+
## Build with C++ Docs
38+
39+
To build with C++ docs, we need to first install Doxygen. Then
40+
set the environment variable `BUILD_CPP_DOCS=1`, to turn on c++ docs.
41+
42+
```bash
43+
BUILD_CPP_DOCS=1 make livehtml
44+
```
45+
46+
Building c++ docs can take longer, so it is not on by default.

docs/conf.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
os.environ["TVM_FFI_BUILD_DOCS"] = "1"
2525

26+
build_exhale = os.environ.get("BUILD_CPP_DOCS", "0") == "1"
27+
28+
2629
# -- General configuration ------------------------------------------------
2730

2831
# Load version from pyproject.toml
@@ -38,6 +41,7 @@
3841
# -- Extensions and extension configurations --------------------------------
3942

4043
extensions = [
44+
"breathe",
4145
"myst_parser",
4246
"nbsphinx",
4347
"autodocsumm",
@@ -48,6 +52,7 @@
4852
"sphinx.ext.mathjax",
4953
"sphinx.ext.napoleon",
5054
"sphinx.ext.viewcode",
55+
"sphinx.ext.ifconfig",
5156
"sphinx_copybutton",
5257
"sphinx_reredirects",
5358
"sphinx_tabs.tabs",
@@ -56,6 +61,40 @@
5661
"sphinxcontrib.mermaid",
5762
]
5863

64+
if build_exhale:
65+
extensions.append("exhale")
66+
67+
breathe_default_project = "tvm-ffi"
68+
69+
breathe_projects = {"tvm-ffi": "./_build/doxygen/xml"}
70+
71+
exhaleDoxygenStdin = """
72+
INPUT = ../include
73+
PREDEFINED += TVM_FFI_DLL= TVM_FFI_INLINE= TVM_FFI_EXTRA_CXX_API= __cplusplus=201703
74+
75+
EXCLUDE_SYMBOLS += *details* *TypeTraits* std \
76+
*use_default_type_traits_v* *is_optional_type_v* *operator* \
77+
78+
EXCLUDE_PATTERNS += *details.h
79+
ENABLE_PREPROCESSING = YES
80+
MACRO_EXPANSION = YES
81+
"""
82+
83+
exhaleAfterTitleDescription = """
84+
This page contains the full API index for the C++ API.
85+
"""
86+
87+
# Setup the exhale extension
88+
exhale_args = {
89+
"containmentFolder": "reference/cpp/generated",
90+
"rootFileName": "index.rst",
91+
"doxygenStripFromPath": "../include",
92+
"rootFileTitle": "Full API Index",
93+
"createTreeView": True,
94+
"exhaleExecutesDoxygen": True,
95+
"exhaleDoxygenStdin": exhaleDoxygenStdin,
96+
"afterTitleDescription": exhaleAfterTitleDescription,
97+
}
5998
nbsphinx_allow_errors = True
6099
nbsphinx_execute = "never"
61100

@@ -69,6 +108,7 @@
69108
"colon_fence",
70109
"html_image",
71110
"linkify",
111+
"attrs_block",
72112
"substitution",
73113
]
74114

docs/guides/cpp_guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<!--- KIND, either express or implied. See the License for the -->
1515
<!--- specific language governing permissions and limitations -->
1616
<!--- under the License. -->
17+
{#cpp-guide}
18+
1719
# C++ Guide
1820

1921
This guide introduces the tvm-ffi C++ API.

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
Apache TVM FFI Documentation
1919
============================
2020

21+
Welcome to the documentation for TVM FFI. You can get started by reading the get started section,
22+
or reading through the guides and concepts sections.
23+
24+
2125
.. toctree::
2226
:maxdepth: 1
2327
:caption: Get Started
@@ -40,8 +44,10 @@ Apache TVM FFI Documentation
4044

4145
concepts/abi_overview.md
4246

47+
4348
.. toctree::
4449
:maxdepth: 1
4550
:caption: Reference
4651

4752
reference/python/index.rst
53+
reference/cpp/index.rst

docs/reference/cpp/index.rst

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
.. http://www.apache.org/licenses/LICENSE-2.0
10+
11+
.. Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
18+
C++ API
19+
=======
20+
21+
This page contains the API reference for the C++ API. The full API index below
22+
can be a bit dense, so we recommend the following tips first:
23+
24+
- Please read the :ref:`C++ Guide<cpp-guide>` for a high-level overview of the C++ API.
25+
26+
- The C++ Guide and examples will likely be sufficient to get started with most use cases.
27+
28+
- The :ref:`cpp-key-classes` lists the key classes that are most commonly used.
29+
- You can go to the Full API Index at the bottom of this page to access the full list of APIs.
30+
31+
- We usually group the APIs by files. You can look at the file hierarchy in the
32+
full API index and navigate to the specific file to find the APIs in that file.
33+
34+
Header Organization
35+
-------------------
36+
37+
The C++ APIs are organized into the following folders:
38+
39+
.. list-table::
40+
:header-rows: 1
41+
:widths: 30 70
42+
43+
* - Folder
44+
- Description
45+
* - ``tvm/ffi/``
46+
- Core functionalities that support Function, Any, Object, etc.
47+
* - ``tvm/ffi/container/``
48+
- Additional container types such as Array, Map, Shape, Tensor, Variant ...
49+
* - ``tvm/ffi/reflection/``
50+
- Reflection support for function and type information registration.
51+
* - ``tvm/ffi/extra/``
52+
- Extra APIs that are built on top.
53+
54+
55+
.. _cpp-key-classes:
56+
57+
Key Classes
58+
-----------
59+
60+
.. list-table::
61+
:header-rows: 1
62+
:widths: 30 70
63+
64+
* - Class
65+
- Description
66+
* - :cpp:class:`tvm::ffi::Function`
67+
- Type-erased function that implements the ABI.
68+
* - :cpp:class:`tvm::ffi::Any`
69+
- Type-erased container for any supported value.
70+
* - :cpp:class:`tvm::ffi::AnyView`
71+
- Lightweight view of Any without ownership.
72+
* - :cpp:class:`tvm::ffi::Object`
73+
- Base class for all heap-allocated FFI objects.
74+
* - :cpp:class:`tvm::ffi::ObjectRef`
75+
- Reference class for objects.
76+
* - :cpp:class:`tvm::ffi::Tensor`
77+
- Multi-dimensional tensor with DLPack support.
78+
* - :cpp:class:`tvm::ffi::Shape`
79+
- Tensor shape container.
80+
* - :cpp:class:`tvm::ffi::Module`
81+
- Dynamic library module that can load exported functions.
82+
* - :cpp:class:`tvm::ffi::String`
83+
- String type for FFI.
84+
* - :cpp:class:`tvm::ffi::Bytes`
85+
- Byte array type.
86+
* - :cpp:class:`tvm::ffi::Array`
87+
- Dynamic array container.
88+
* - :cpp:class:`tvm::ffi::Tuple`
89+
- Heterogeneous tuple container.
90+
* - :cpp:class:`tvm::ffi::Map`
91+
- Key-value map container.
92+
* - :cpp:class:`tvm::ffi::Optional`
93+
- Optional value wrapper.
94+
* - :cpp:class:`tvm::ffi::Variant`
95+
- Type-safe union container.
96+
97+
98+
99+
.. _cpp-full-api-index:
100+
101+
Full API Index
102+
--------------
103+
104+
.. toctree::
105+
:maxdepth: 2
106+
107+
generated/index.rst

docs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
autodocsumm
2+
exhale
3+
breathe
24
linkify-it-py
35
matplotlib
46
myst-parser

0 commit comments

Comments
 (0)