diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index 044767d67..3afa10333 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -14,6 +14,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Checkout kokkos + uses: actions/checkout@v3 + with: + repository: kokkos/kokkos + path: kokkos - name: Set up Python ${{ env.python-version }} uses: actions/setup-python@v4 with: diff --git a/docs/source/API/core/parallel-dispatch/parallel_for.rst b/docs/source/API/core/parallel-dispatch/parallel_for.rst index e369e4647..dc59deb6d 100644 --- a/docs/source/API/core/parallel-dispatch/parallel_for.rst +++ b/docs/source/API/core/parallel-dispatch/parallel_for.rst @@ -64,6 +64,9 @@ More Detailed Examples are provided in the ExecutionPolicy documentation. * ``IntegerType`` policy with lambda as the functor. Note that KOKKOS_LAMBDA is the same as [=] KOKKOS_FUNCTION, which means that all of the variables used within the lambda are captured by value. Also, the KOKKOS_LAMBDA and KOKKOS_FUNCTION macros add all of the function specifiers necessary for the target execution space. +.. note:: + Code snippet + a short link to compiler explorer. + .. code-block:: cpp #include @@ -81,6 +84,18 @@ More Detailed Examples are provided in the ExecutionPolicy documentation. Kokkos::finalize(); } +.. raw:: html + + Edit on Compiler Explorer + +.. note:: + Code snippet taken directly from Kokkos Core (``hello_world_lambda.cpp``) + a link containing full source code of the example. + +.. ceinclude:: ../../../../../kokkos/example/tutorial/01_hello_world_lambda/hello_world_lambda.cpp + :language: cpp + :start-after: Kokkos::initialize + :end-before: Kokkos::finalize + * ``TeamPolicy`` policy with C++ struct as functor. Note that the KOKKOS_INLINE_FUNCTION macro adds all of the function specifiers necessary for the target execution space. The TagA/B structs also provide the ability to 'overload' the operators within the same functor. Much like the lambda example, the functor and any member variables contained within are captured by value, which means they must have either implicit or explicit copy constructors. .. code-block:: cpp diff --git a/docs/source/_ext/ceinclude.py b/docs/source/_ext/ceinclude.py new file mode 100644 index 000000000..5b2720338 --- /dev/null +++ b/docs/source/_ext/ceinclude.py @@ -0,0 +1,50 @@ +import base64 +import json + +from docutils import nodes +from sphinx.directives.code import LiteralInclude, container_wrapper +from os import path + +class CeIncludeDirective(LiteralInclude): + """ LiteralInclude with a Compiler Explorer link""" + + def run(self): + retnode = super().run()[0] + + _, filename = self.env.relfn2path(self.arguments[0]) + retnode = container_wrapper(self, retnode, path.basename(filename)) + + source = open(filename, "r").read() + client_state = { + "sessions": [ + { + "id": 1, + "language": "c++", + "source": source, + "compilers": [ + { + "id": "g132", + "options": "-O3", + "libs": [{'name': 'kokkos', 'ver': '4100'}], + } + ], + } + ] + } + + encoded = base64.urlsafe_b64encode(json.dumps(client_state).encode()) + ce_link = "https://godbolt.org/clientstate/" + encoded.decode() + doc_link = f'Edit on Compiler Explorer' + + retnode += nodes.raw(rawsource = doc_link, text = doc_link, format="html") + return [retnode] + + +def setup(app): + app.add_directive("ceinclude", CeIncludeDirective) + + return { + 'version': '0.1', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/docs/source/conf.py b/docs/source/conf.py index 8c18e15c3..5a3e5de64 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -38,7 +38,8 @@ "sphinx.ext.viewcode", "sphinx.ext.intersphinx", "sphinx_copybutton", - "cppkokkos"] + "cppkokkos", + "ceinclude"] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates']