-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add embedded compiler-explorer example #444
base: main
Are you sure you want to change the base?
Changes from all commits
4bedc40
2e525e9
2c01b32
20088e9
91b9c73
9dc5204
6230b6f
6129d4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Kokkos_Core.hpp> | ||
|
@@ -81,6 +84,18 @@ More Detailed Examples are provided in the ExecutionPolicy documentation. | |
Kokkos::finalize(); | ||
} | ||
|
||
.. raw:: html | ||
|
||
<a href="https://godbolt.org/z/q9h339vob" target="_blank">Edit on Compiler Explorer</a> | ||
|
||
.. 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 | ||
Comment on lines
+94
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
See live version. See There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the number of comments in this file, I would rather not include that one specifically. Other than that, it's a good idea to use examples we run through our CI. I could see that we just reduce the verbosity in these files and refer to |
||
|
||
* ``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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'<a href="{ce_link}" target="_blank">Edit on Compiler Explorer</a>' | ||
|
||
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, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code-block
above + a manually created shortlink to Compiler Explorer: