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 anatomy example to index page #182

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions source/anatomy.cpp
tomdeakin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2011-2024 The Khronos Group, Inc.
tomdeakin marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: Apache-2.0

#include <iostream>
#include <sycl/sycl.hpp>
using namespace sycl; // (optional) avoids need for "sycl::" before SYCL names

int main() {
int data[1024]; // Allocate data to be worked on

// Create a default queue to enqueue work to the default device
queue myQueue;

// By wrapping all the SYCL work in a {} block, we ensure
// all SYCL tasks must complete before exiting the block,
// because the destructor of resultBuf will wait
{
// Wrap our data variable in a buffer
buffer<int, 1> resultBuf { data, range<1> { 1024 } };

// Create a command group to issue commands to the queue
myQueue.submit([&](handler& cgh) {
// Request write access to the buffer without initialization
accessor writeResult { resultBuf, cgh, write_only, no_init };

// Enqueue a parallel_for task with 1024 work-items
cgh.parallel_for(1024, [=](id<1> idx) {
// Initialize each buffer element with its own rank number starting at 0
writeResult[idx] = idx;
}); // End of the kernel function
}); // End of our commands for this queue
} // End of scope, so we wait for work producing resultBuf to complete

// Print result
for (int i = 0; i < 1024; i++)
std::cout << "data[" << i << "] = " << data[i] << std::endl;

return 0;
}
3 changes: 3 additions & 0 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def make_ref(ref_str, ref_view, ref_sufix):

prolog_template = string.Template(
make_ref(
"SYCL_SPEC_ANATOMY", "Section 3.2", "#sec:anatomy"
)
+ make_ref(
"SYCL_SPEC_HEADER_FILES", "Section 4.3", "#sec:headers-and-namespaces"
)
+ make_ref(
Expand Down
8 changes: 8 additions & 0 deletions source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ you see something wrong, something that could be better, or want to
contribute examples or descriptions, feel free to use the buttons at
the top right to file an issue on GitHub or suggest an edit.

A basic SYCL program, taken from the SYCL 2020 specification, looks like this:

[source,,linenums]
----
include::anatomy.cpp[lines=4..-1]
----
Copy link
Contributor

Choose a reason for hiding this comment

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

This is Asciidoc syntax, which causes a build error because these docs are using reStructuredText (rst). I don't know this documentation tool well, but you can see an example of how to add a code snippet in "source/iface/device-selector.rst":

.. literalinclude:: /examples/gpu-selector.cpp
   :lines: 5-
   :linenos:

I think you want something like that.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @gmlueck - I'm struggling to get local builds working on my machine. Do you know if there is a straight forward way to get all the plugins installed locally?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was a while ago, but I think I just installed Python 3 and then:

$ pip install -r requirements.txt

Copy link
Contributor

Choose a reason for hiding this comment

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

Then to do a build:

$ make html

The output is in "build/html"

.. seealso:: |SYCL_SPEC_ANATOMY|


.. toctree::
:maxdepth: 1
Expand Down
Loading