Commit 8e7feca9 authored by Wenhao Xie's avatar Wenhao Xie Committed by GitHub
Browse files

[Doc] Use sphinx to generate docs. (#21)

* [Doc] Use sphinx to generate docs.

* [Doc] Fix a bug on tlcpack_sphinx_addon.

* [Doc] Fix linting issues.
parent 7b777b38
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= python -m sphinx
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Tile Language Documentation
The documentation was built upon [Sphinx](https://www.sphinx-doc.org/en/master/).
## Dependencies
Run the following command in this directory to install dependencies first:
```bash
pip3 install -r requirements.txt
```
## Build the Documentation
Then you can build the documentation by running:
```bash
make html
```
## View the Documentation
Run the following command to start a simple HTTP server:
```bash
cd _build/html
python3 -m http.server
```
Then you can view the documentation in your browser at `http://localhost:8000` (the port can be customized by appending ` -p PORT_NUMBER` in the python command above).
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
# -*- coding: utf-8 -*-
import os
import sys
import tlcpack_sphinx_addon
# -- General configuration ------------------------------------------------
sys.path.insert(0, os.path.abspath("../tilelang"))
sys.path.insert(0, os.path.abspath("../"))
autodoc_mock_imports = ["torch"]
# General information about the project.
project = "tilelang"
author = "Tile Lang Contributors"
copyright = "2025-2025, %s" % author
# Version information.
version = "0.1.0"
release = "0.1.0"
extensions = [
"sphinx_tabs.tabs",
"sphinx_toolbox.collapse",
"sphinxcontrib.httpdomain",
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_reredirects",
]
redirects = {"get_started/try_out": "../index.html#getting-started"}
source_suffix = [".rst"]
language = "en"
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme is set by the make target
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
templates_path = []
html_static_path = []
footer_copyright = "© 2025-2025 Tile Language"
footer_note = " "
html_logo = "_static/img/logo-row.svg"
html_theme_options = {
"logo_only": True,
}
header_links = [
("Home", "https://github.com/tile-ai/tilelang"),
("Github", "https://github.com/tile-ai/tilelang"),
]
html_context = {
"footer_copyright": footer_copyright,
"footer_note": footer_note,
"header_links": header_links,
"display_github": True,
"github_user": "tile-ai",
"github_repo": "tilelang",
"github_version": "main/docs/",
"theme_vcs_pageview_mode": "edit",
# "header_logo": "/path/to/logo",
# "header_logo_link": "",
# "version_selecter": "",
}
# add additional overrides
templates_path += [tlcpack_sphinx_addon.get_templates_path()]
html_static_path += [tlcpack_sphinx_addon.get_static_path()]
Installation Guide
==================
Installing with pip
-------------------
**Prerequisites for installation via wheel or PyPI:**
- **Operating System**: Ubuntu 20.04 or later
- **Python Version**: >= 3.8
- **CUDA Version**: >= 11.0
The easiest way to install TileLang is directly from PyPI using pip. To install the latest version, run the following command in your terminal:
.. code:: bash
pip install tilelang
Alternatively, you may choose to install TileLang using prebuilt packages available on the Release Page:
.. code:: bash
pip install tilelang-0.0.0.dev0+ubuntu.20.4.cu120-py3-none-any.whl
To install the latest version of TileLang from the GitHub repository, you can run the following command:
.. code:: bash
pip install git+https://github.com/tile-ai/tilelang.git
After installing TileLang, you can verify the installation by running:
.. code:: bash
python -c "import tilelang; print(tilelang.__version__)"
Building from Source
--------------------
**Prerequisites for building from source:**
- **Operating System**: Linux
- **Python Version**: >= 3.7
- **CUDA Version**: >= 10.0
We recommend using a Docker container with the necessary dependencies to build TileLang from source. You can use the following command to run a Docker container with the required dependencies:
.. code:: bash
docker run --gpus all -it --rm --ipc=host nvcr.io/nvidia/pytorch:23.01-py3
To build and install TileLang directly from source, follow these steps. This process requires certain pre-requisites from Apache TVM, which can be installed on Ubuntu/Debian-based systems using the following commands:
.. code:: bash
sudo apt-get update
sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
After installing the prerequisites, you can clone the TileLang repository and install it using pip:
.. code:: bash
git clone --recursive https://github.com/tile-ai/tilelang.git
cd TileLang
pip install . # Please be patient, this may take some time.
If you want to install TileLang in development mode, you can run the following command:
.. code:: bash
pip install -e .
We currently provide three methods to install **TileLang**:
1. Install from Source (using your own TVM installation)
2. Install from Source (using the bundled TVM submodule)
3. Install Using the Provided Script
Method 1: Install from Source (Using Your Own TVM Installation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you already have a compatible TVM installation, follow these steps:
1. **Clone the Repository**:
.. code:: bash
git clone --recursive https://github.com/tile-ai/tilelang
cd TileLang
**Note**: Use the `--recursive` flag to include necessary submodules.
2. **Configure Build Options**:
Create a build directory and specify your existing TVM path:
.. code:: bash
mkdir build
cd build
cmake .. -DTVM_PREBUILD_PATH=/your/path/to/tvm/build # e.g., /workspace/tvm/build
make -j 16
3. **Set Environment Variables**:
Update `PYTHONPATH` to include the `tile-lang` Python module:
.. code:: bash
export PYTHONPATH=/your/path/to/tile-lang/python:$PYTHONPATH
# TVM_IMPORT_PYTHON_PATH is used by 3rd-party frameworks to import TVM
export TVM_IMPORT_PYTHON_PATH=/your/path/to/tvm/python
Method 2: Install from Source (Using the Bundled TVM Submodule)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you prefer to use the built-in TVM version, follow these instructions:
1. **Clone the Repository**:
.. code:: bash
git clone --recursive https://github.com/tile-ai/tilelang
cd TileLang
**Note**: Ensure the `--recursive` flag is included to fetch submodules.
2. **Configure Build Options**:
Copy the configuration file and enable the desired backends (e.g., LLVM and CUDA):
.. code:: bash
mkdir build
cp 3rdparty/tvm/cmake/config.cmake build
cd build
echo "set(USE_LLVM ON)" >> config.cmake
echo "set(USE_CUDA ON)" >> config.cmake
# or echo "set(USE_ROCM ON)" >> config.cmake to enable ROCm runtime
cmake ..
make -j 16
The build outputs (e.g., `libtilelang.so`, `libtvm.so`, `libtvm_runtime.so`) will be generated in the `build` directory.
3. **Set Environment Variables**:
Ensure the `tile-lang` Python package is in your `PYTHONPATH`:
.. code:: bash
export PYTHONPATH=/your/path/to/TileLang/python:$PYTHONPATH
Method 3: Install Using the Provided Script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For a simplified installation, use the provided script:
1. **Clone the Repository**:
.. code:: bash
git clone --recursive https://github.com/tile-ai/tilelang
cd TileLang
2. **Run the Installation Script**:
.. code:: bash
bash install.sh
# or bash `install_amd.sh` if you want to enable ROCm runtime
Language reference
=========================
T.Kernel
--------
args: the grid size (0-3 dimension) and the num_threads.
returns: the blockIdx variables
launch a kernel, it must be used in a with statement. There can be
multiple kernels launched sequentially inside a prim function.
T.alloc_shared
--------------
args: shape, dtype
returns: Buffer
Allocate buffer on shared memory, It must be used within T.Kernel scope
and should be allocated at the top of the scope.
Dynamic shared memory is used.
T.alloc_fragment
----------------
args: shape, dtype
returns: Buffer
Allocate buffer on register memory, It must be used within T.Kernel
scope and should be allocated at the top of the scope.
The shape represents the whole shape of the buffer. Each element in the
buffer is distributed stored on each threads, this storage partition
will be inferred by the compiler.
T.copy
------
args: src, dst
Copies data from src to dst, src and dst can be one of (Buffer,
BufferLoad, BufferRegion). If you use BufferLoad that represents a
single starting point, the other params should not be BufferLoad, since
we need to know the copy region.
Zero will be padded if we detect the load is out of boundary.
T.gemm
------
args: A, B, C, transpose_A, transpose_B, policy
Performs gemm operation on A, B and C. C must be a fragment, B must be
on shared memory, A can be either a fragment or shared.
Note that the current implementation has some shape and dtype
constraints, for example, the length of reduction axis must be a
multiple of 32 for fp16 multiplicand case, we will update this later.
T.reduce_max T.reduce_sum
-------------------------
args: src, dst, dim
Performs a reduce operation from src to dst on dimension dim. Currently
we only support src and dst to be a fragment.
T.Parallel
----------
You can use T.Parallel to write a loop. The loop will be partitioned to
all the threads by the compiler (The compiler will consider vectorize
size, the fragment’s thread mapping … ). Note that this is the only way
you can perform arbitrary operation on fragments.
T.Pipelined
-----------
args: start, stop, num_stages
Pipeline the loop, copy from the global memory will be converted to
async operations and reordered to the point after it is consumed.
num_stages is the number of buffer between producer-consumer.
(e.g. Double buffer when num_stages=2)
T.clear T.fill
--------------
nothing special, they will be converted to T.Parallel
T.use_swizzle
-------------
Optimization for L2 cache. The launch of blockIdx.x and blockIdx.y will
be serpentined.
You need to add it in a kernel after buffer is all allocated.
👋 Welcome to Tile Language
===========================
`GitHub <https://github.com/tile-ai/tilelang>`_
Tile Language (tile-lang) is a concise domain-specific language designed to streamline
the development of high-performance GPU/CPU kernels (e.g., GEMM, Dequant GEMM, FlashAttention, LinearAttention).
By employing a Pythonic syntax with an underlying compiler infrastructure on top of TVM,
tile-lang allows developers to focus on productivity without sacrificing the
low-level optimizations necessary for state-of-the-art performance.
.. toctree::
:maxdepth: 2
:caption: Get Started
:hidden:
get_started/Installation.rst
get_started/language_ref.rst
.. toctree::
:maxdepth: 1
:caption: Privacy
:hidden:
privacy.rst
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
if "%1" == "" goto help
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
Privacy
====================
All data stays in users' device and is not collected by the app.
fastapi
pydantic
sphinx == 5.2.3
sphinx-reredirects==0.1.2
sphinx-rtd-theme
sphinx-tabs == 3.4.1
sphinx-toolbox == 3.4.0
sphinxcontrib-napoleon==0.7
sphinxcontrib_httpdomain==1.8.1
git+https://github.com/xwhzz/tlcpack-sphinx-addon.git
uvicorn
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment