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 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
3 changes: 2 additions & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def make_ref(ref_str, ref_view, ref_sufix):


prolog_template = string.Template(
make_ref(
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
1 change: 1 addition & 0 deletions source/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ set_tests_properties(gpu-platform PROPERTIES LABELS gpu)
add_example(queue-parallel)
add_example(queue-single-task)
add_example(usm-implicit-data-movement)
add_example(anatomy)
39 changes: 39 additions & 0 deletions source/examples/anatomy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 The Khronos Group Inc.

#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;
}
7 changes: 7 additions & 0 deletions source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ 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:

.. literalinclude:: /examples/anatomy.cpp
:lines: 5-
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:lines: 5-
:lines: 4-

I think you want this, unless you are intentionally omitting the #include <iostream>

:linenos:
.. seealso:: |SYCL_SPEC_ANATOMY|


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