Nothing Special   »   [go: up one dir, main page]

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

Add embedded compiler-explorer example #444

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

cz4rs
Copy link
Contributor
@cz4rs cz4rs commented Jul 25, 2023

This is not mergeable, just providing actual examples for the next documentation session.

Sphinx allows for html injection with .. raw:: html. That's probably the easiest way to use Share -> Embed in iframe functionality available in compiler-explorer.

See initialization example below (our current approach is kept for comparison):

image

Code used:

.. raw:: html

  <iframe width="800px" height="300px" src="https://godbolt.org/e?hideEditorToolbars=true#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:1,endLineNumber:9,positionColumn:1,positionLineNumber:9,selectionStartColumn:1,selectionStartLineNumber:9,startColumn:1,startLineNumber:9),source:'%23include+%3CKokkos_Core.hpp%3E%0A%0Aint+main(int+argc,+char**+argv)+%7B%0A++Kokkos::initialize(argc,+argv)%3B%0A++Kokkos::View%3Cdouble*%3E+my_view(%22my_view%22,+10)%3B%0A++Kokkos::finalize()%3B%0A++//+my_view+destructor+called+after+Kokkos::finalize+!!%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang1600,deviceViewOpen:'1',filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!((name:kokkos,ver:'4100')),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+16.0.0+(Editor+%231)',t:'0')),header:(),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>

Note: there is some customization available when generating the link (Read only, Hide editor toolbars). Further configuration is contained in the generated link.

@cz4rs
Copy link
Contributor Author
cz4rs commented Jul 31, 2023

Another way to enforce that the code snippets in documentation are compiling: literal include (2e525e9).
If we supplement this with an autogenerated Edit on Compiler Explorer button, we might have a quicker, more lightweight option than embedding CE directly.

image

@cz4rs cz4rs force-pushed the embedded-compiler-explorer branch from 702afc5 to 2e525e9 Compare July 31, 2023 10:47
@crtrott
Copy link
Member
crtrott commented Aug 9, 2023

Hm, interesting, I was thinking of much simpler: i.e. have a code snippet and then a short link to godbolt. Obviously that wouldn't guarantee that they are the same thing.

@ajpowelsnl
Copy link
Contributor

TODO:

  • Cezary: Fix up example for Wed. meeting to demo for the team
  • Discuss in Wed. meeting if we want Compiler Explorer (CE) examples to simply compile, or also generate run-able executable;
    • Simple CE examples (for Documentation, etc.) into existing or new repos?
    • Integrate CE examples into training, teaching & demos?

Comment on lines +87 to +89
.. raw:: html

<a href="https://godbolt.org/z/q9h339vob" target="_blank">Edit on Compiler Explorer</a>
Copy link
Contributor Author

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:
image

Comment on lines +94 to +97
.. ceinclude:: ../../../../../kokkos/example/tutorial/01_hello_world_lambda/hello_world_lambda.cpp
:language: cpp
:start-after: Kokkos::initialize
:end-before: Kokkos::finalize
Copy link
Contributor Author
@cz4rs cz4rs Oct 25, 2023

Choose a reason for hiding this comment

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

helo_world_lambda.cpp + an auto-generated link using clientstate API:

image

See live version.

See ceinclude.py for extension details.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 kokkos-tutorials for more extensive tutorials.

@ajpowelsnl
Copy link
Contributor

@cz4rs , @masterleinad - What do we need to do next to work towards completion of this issue?

@cz4rs
Copy link
Contributor Author
cz4rs commented Jan 10, 2024

@cz4rs , @masterleinad - What do we need to do next to work towards completion of this issue?

Hi @ajpowelsnl! As far as I know there was no decision (or even major discussion) regarding how much integration and how many changes we want to do.

Assuming we just want to update existing snippets with Edit on Compiler Explorer button, we have two options:

  • add manually created shortlinks - Add embedded compiler-explorer example #444 (comment)
    • not great, not terrible - this approach involves manual work and the shortlinks are permanent so we have to remember to update them
  • add auto-generated links - Add embedded compiler-explorer example #444 (comment)
    • replace .. code-block:: cpp with our custom extension (e.g. .. ce-code-block:: cpp) that will wrap the code-block and add Compiler Explorer link
    • this extension will be similar to the ceinclude.py from this PR, only based on code-block instead of literalinclude

IMHO the second option is clearly better (less maintenance!), with the only downside being that the generated links are quite long and ugly:

https://godbolt.org/clientstate/eyJzZXNzaW9ucyI6IFt7ImlkIjogMSwgImxhbmd1YWdlIjogImMrKyIsICJzb3VyY2UiOiAiLy9ASEVBREVSXG4vLyAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKipcbi8vXG4vLyAgICAgICAgICAgICAgICAgICAgICAgIEtva2tvcyB2LiA0LjBcbi8vICAgICAgIENvcHlyaWdodCAoMjAyMikgTmF0aW9uYWwgVGVjaG5vbG9neSAmIEVuZ2luZWVyaW5nXG4vLyAgICAgICAgICAgICAgIFNvbHV0aW9ucyBvZiBTYW5kaWEsIExMQyAoTlRFU1MpLlxuLy9cbi8vIFVuZGVyIHRoZSB0ZXJtcyBvZiBDb250cmFjdCBERS1OQTAwMDM1MjUgd2l0aCBOVEVTUyxcbi8vIHRoZSBVLlMuIEdvdmVybm1lbnQgcmV0YWlucyBjZXJ0YWluIHJpZ2h0cyBpbiB0aGlzIHNvZnR3YXJlL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ICAvLyBZb3UgbXVzdCBjYWxsIGZpbmFsaXplKCkgYWZ0ZXIgeW91IGFyZSBkb25lIHVzaW5nIEtva2tvcy5cbiAgS29ra29zOjpmaW5hbGl6ZSgpO1xufVxuIiwgImNvbXBpbGVycyI6IFt7ImlkIjogImcxMzIiLCAib3B0aW9ucyI6ICItTzMiLCAibGlicyI6IFt7Im5hbWUiOiAia29ra29zIiwgInZlciI6ICI0MTAwIn1dfV19XX0=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants