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

[SYCL][Doc] Initial spec conversion to Sphinx #16540

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Open
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
87 changes: 85 additions & 2 deletions sycl/doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import datetime
from docutils import nodes
import re


# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -48,8 +50,18 @@
source_suffix = [".rst", ".md"]

exclude_patterns = [
# Extensions are mostly in asciidoc which has poor support in Sphinx.
"extensions/*",
# We are migrating the SYCL extensions to reStructuredText, but some of the
# older *.rst files in the extensions directories have errors, so ignore
# them.
"extensions/supported/C-CXX-StandardLibrary.rst",
"extensions/supported/sycl_ext_intel_esimd/*",
# These files are instructions to developers about how to write extensions,
# so do not build them into the extensions documentation.
"extensions/template.rst",
"extensions/*.md",
"extensions/*/*.md",
# These OpenCL and SPIR-V extensions are asciidoc which has poor support in
# Sphinx.
"design/opencl-extensions/*",
"design/spirv-extensions/*",
# Sphinx complains about syntax errors in these files.
Expand Down Expand Up @@ -84,5 +96,76 @@ def on_missing_reference(app, env, node, contnode):
return newnode


# These match only relative URLs because ":" is missing from the
# match set, which means they won't match a URL starting with
# "http:", etc.
reRelativeRstUri = re.compile("([a-z0-9_/.-]*)\.rst")
reRelativeAsciidocUri = re.compile("[a-z0-9_/.-]*\.asciidoc")


# We want the extension specification documents to be readable in either of two
# ways:
#
# * From the HTML that is generated from Sphinx, or
# * By using a web browser to navigate to the .rst file in the repo.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this option?
LLVM and Clang documentation uses :doc: syntax and I guess all users rely on HTML documentation for links to work.

You suggest we use different links style for writing SYCL documentation to enable cross-document links for GitHub rendered documents. I'm not sure how we can catch the use of wrong notation.

Can we ignore the GitHub rendering issue and follow LLVM/Clang link notation (i.e. use https://intel.github.io/llvm/ rendered documentation)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is extremely common for us to point people to the GitHub documentation for extensions. We do this all the time in email and internal trackers too. Does https://intel.github.io/llvm/ get updated automatically to reflect the top of the "sycl" (main) branch in the repo? If so, I guess we could get in the habit of pointing people there instead.

One problem could occur if we need to point people to the documentation in a particular branch of the repo. Maybe this is uncommon enough that it doesn't matter, though.

On the other hand, using the alternate link syntax seems easy to do. Is it really so offensive? It would be nice to be able to continue pointing people to the documentation in the repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does https://intel.github.io/llvm/ get updated automatically to reflect the top of the "sycl" (main) branch in the repo?

Yes. We update it every night and each time anything changes in clang/docs/ or sycl/doc/ directories. Exact rules:

schedule:
- cron: 0 1 * * *
pull_request:
branches:
- sycl
paths:
- '.github/workflows/sycl-docs.yml'
- 'clang/docs/**'
- 'sycl/doc/**'
push:
branches:
- sycl
paths:
- '.github/workflows/sycl-docs.yml'
- 'clang/docs/**'
- 'sycl/doc/**'

I don't know if using alternative style for SYCL documentation references is a real issue for the project, but is using Asciidoc format is a real blocker for upstreaming SYCL?
MLIR project managed to get accepted although they use Markdown format.
To be fair, LLVM and Clang sub-project also use Markdown alongside reStructuredText format, but MLIR rendered version has completely different look than LLVM/Clang documentation as they use Hugo framework to generate website instead of Sphinx.

Copy link
Contributor Author

@gmlueck gmlueck Jan 9, 2025

Choose a reason for hiding this comment

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

I don't know if using alternative style for SYCL documentation references is a real issue for the project, but is using Asciidoc format is a real blocker for upstreaming SYCL?

I'm not sure. When I talked to @AaronBallman, he seemed to think that converting to RST/Sphinx was important. I'm not sure if it's an absolute requirement, though.

I'd be OK with any of these options, but they all have some sort of down-side:

Option 1

  • Upstream only the "supported" and KHR extensions (not the "experimental" ones)
  • Move the "supported" specifications to the Khronos repo and use Asciidoc
  • Keep the "experimental" and "proposed" extensions only in intel/llvm and use Asciidoc for their specs
  • Con: Someone needs to refactor the code to remove all the "experimental" extensions before upstreaming

Option 2

  • Upstream only the KHR extensions (not the "supported" or "experimental" ones)
  • Keep the "supported", "experimental", and "proposed" extensions only in intel/llvm and use Asciidoc for their specs
  • Con: Someone needs to refactor the code to remove all the "supported" and "experimental" extensions before upstreaming

Option 3

  • Upstream the "supported", "experimental", and KHR extensions
  • Upstream the "supported" and "experimental" extension specs also and convert them to RST/Sphinx
  • Con: Someone needs to reformat the extension specs into RST/Sphinx; We need to convert them back to Asciidoc later in order to make them into KHRs.

Option 4

  • Upstream the "supported", "experimental", and KHR extensions
  • Upstream the "supported" and "experimental" extension specs also but leave them in Asciidoc format
  • Con: Unclear if clang community will accept this

To give some idea of the magnitude of the work, there are over 100 extensions ("supported", "experimental", and "proposed" combined), and their specifications total over 40K lines of text.

@bader, have you given any thought to what we will do with all the other SYCL documents in "sycl/doc" that are not extension specifications? Will we convert this to RST/Sphinx? Will the generated HTML be hosted someplace, or will the files just live in the repo?

EDIT: The total count of extension specifications includes "supported", "experimental", and "proposed". A previous version of this comment omitted the word "supported" from that list.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bader, have you given any thought to what we will do with all the other SYCL documents in "sycl/doc" that are not extension specifications? Will we convert this to RST/Sphinx?

I didn't plan any changes in sycl/doc for the upstreaming. From day one, we use Markdown format for SYCL documentation to be upstream-ready. LLVM sub-projects use Markdown in addition to RST (even more extensively after moving to GitHub to be more friendly for first-time/irregular contributors).

Will the generated HTML be hosted someplace, or will the files just live in the repo?

I expect documentation for SYCL library will be in HTML format and will be hosted as at llvm.org as other sub-projects. See https://releases.llvm.org/ for examples. To make this happen we must upstream the minimal version of the working implementation fist.

Tagging @sergey-semenov, in case he has other plans. According to my understanding @sergey-semenov is working on upstreaming everything in sycl directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! That's an interesting point -- at some point, we're going to upstream the library stuff at which point we will basically need a separate website (same as many of the other top-level projects in the monorepo).

Yes, all of the extensions I'm talking about are extensions to the SYCL library. None of them are extensions to the clang compiler proper. I don't suppose that changes your opinion on using Asciidoc? :-)

My thinking is that if the experimental extension is implemented/being implemented in upstream, then we'd want documentation upstream that explains it

That makes sense, and it's aligned with my thinking also.

Really? The website sure reads to me like you can take any format they support as input and output RST (because of ↔︎ = conversion from and to in the docs).

That's not how I read the website. The line for Asciidoc has a right-pointing arrow, which the legend defines as "conversion to". If they supported conversion both ways, I think that line would have a double-headed arrow. In addition, the release notes make several mentions of "asciidoc writer", but there is no mention of "asciidoc reader". For comparison, the release notes mention both "rst writer" and "rst reader".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One more comment for now ... I'm not sure if this is a question to @sergey-semenov or to the group as a whole. How do we expect the upstreamed SYCL documentation to be organized? Looking at the LLVM download page, it seems like there are 7 top-level "entry points" for the documentation:

  • llvm
  • clang
  • lld
  • clang-extra
  • libc++
  • poly
  • flang

Are we thinking that SYCL would be an 8th top-level entry point? Or, would SYCL support be part of "clang"? For comparison, OpenMP documentation is under "clang", so it seems (to me) that it would make sense for SYCL documentation to be there also.

In order for this to work, would we move the SYCL documentation files in the repo to "clang/docs" instead of "sycl/doc"? Or, would we change the CMake rules to build the "clang" documentation from both the "clang/docs" and "sycl/doc" directories?

Copy link
Contributor

Choose a reason for hiding this comment

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

The OpenMP provides compiler pragmas to access features, so it makes sense to have OpenMP documentation as part of the compiler documentation.
SYCL provides a library API, so I think adding another top-level entry fits better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, all of the extensions I'm talking about are extensions to the SYCL library. None of them are extensions to the clang compiler proper. I don't suppose that changes your opinion on using Asciidoc? :-)

It does -- for the SYCL library documentation, I think MLIR is a reasonable precedent to point to for not using RST because it will be its own top-level project in the monorepo and has different needs. I was opposed to mixing and matching within Clang.

That's not how I read the website. The line for Asciidoc has a right-pointing arrow, which the legend defines as "conversion to".

Ah, you may be right! Drat.

SYCL provides a library API, so I think adding another top-level entry fits better.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent! It sounds like we may be converging on Option 4, then:

Option 4

  • Upstream the "supported", "experimental", and KHR extensions
  • Upstream the "supported" and "experimental" extension specs also but leave them in Asciidoc format

Is anyone opposed to this?

Still to do, then, is to add build rules to generate HTML from the Asciidoc files and integrate this into the top-level SYCL website.

#
# The second method works because the GitHub server renders an .rst file into
# HTML when serving its contents to the browser.
#
# One challenge with this are cross-files references. The GitHub server
# approach works well when a reference uses a standard relative URL like:
#
# > This is a `reference`_ to another file.
# >
# > .. _`reference`: relative/path/to/file.rst
#
# However this style of cross-file reference does *not* work well with the
# Sphinx tools. In Sphinx, you would instead normally use the syntax
# ":doc:`relative/path/to/file` for such a cross-file link. However, that
# syntax is not understood by the GitHub server.
#
# In order to have cross-file links that work in both scenarios, we use the
# standard relative URL approach (understood by GitHub) and then establish a
# "doctree-resolved" callback to fix up the links in the Sphinx generated HTML.
def on_doctree_resolved(app, doctree, docname):

# Get the directory that contains the *source* file of the link. These
# files are always relative to the directory containing "conf.py"
# (<top>/sycl/doc). For example, the file "sycl/doc/extension/supported/foo.rst"
# will have a directory "extension/supported/".
refdoc_components = docname.split("/")
dirs = "/".join(refdoc_components[:-1])
if dirs:
dirs += "/"

# Look for references from this file to other files.
for ref in doctree.traverse(nodes.reference):
if "refuri" in ref:
uri = ref["refuri"]

# This is a relative link to another .rst file. We assume the
# target .rst file was also processed by Sphinx, so we just need to
# replace the ".rst" suffix with ".html".
m = reRelativeRstUri.fullmatch(uri)
if m:
ref["refuri"] = m[1] + ".html"
continue

# This is a relative link to an .asciidoc file. These files are not
# processed by Sphinx, so there is no generated HTML. Instead,
# change the link to point to the file in the main branch of the
# GitHub repo. Although this is not ideal, it's better than a
# broken link. We are in the process of migrating the .asciidoc
# specifications to .rst. When that is complete, this
# transformation won't be needed anymore.
m = reRelativeAsciidocUri.fullmatch(uri)
if m:
ref["refuri"] = (
"https://github.com/intel/llvm/tree/sycl/sycl/doc/" + dirs + uri
)
continue


def setup(app):
app.connect("missing-reference", on_missing_reference)
app.connect("doctree-resolved", on_doctree_resolved)
4 changes: 2 additions & 2 deletions sycl/doc/extensions/README-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ is very specific to Intel hardware in which case we use the string "intel".
The template uses the string "oneapi", so you must change occurrences of that
string if your extension is specific to Intel hardware.

[1]: <template.asciidoc>
[1]: <template.rst>
[2]: <https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#chapter.extensions>

Some sections in the template are optional. Remove these sections if they are
Expand All @@ -28,7 +28,7 @@ something appropriate. Use lower case, and separate words with underbars.
Each extension also has a feature-test macro, which is the same as the
extension's name, except it uses all upper case. Finally, the name of the
specification file should match the name of the extension, for example
"sycl\_ext\_oneapi\_myextension.asciidoc".
"sycl\_ext\_oneapi\_myextension.rst".

Usually new extensions are first created in the "proposed" state, so the
document should be added to that directory. However, it is also possible to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,7 @@ is ignored during queue recording.
==== sycl_ext_oneapi_work_group_memory

Using the `work_group_memory` object defined in
link:../experimental/sycl_ext_oneapi_work_group_memory.asciidoc[sycl_ext_oneapi_work_group_memory]
link:../experimental/sycl_ext_oneapi_work_group_memory.rst[sycl_ext_oneapi_work_group_memory]
inside graph kernel nodes is supported.

==== sycl_ext_oneapi_work_group_scratch_memory
Expand Down
Loading
Loading