diff --git a/source/conf.py b/source/conf.py index 368ab81b..2c048769 100644 --- a/source/conf.py +++ b/source/conf.py @@ -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( diff --git a/source/examples/CMakeLists.txt b/source/examples/CMakeLists.txt index 7f312d25..ec50eca5 100644 --- a/source/examples/CMakeLists.txt +++ b/source/examples/CMakeLists.txt @@ -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) diff --git a/source/examples/anatomy.cpp b/source/examples/anatomy.cpp new file mode 100644 index 00000000..3b8bc280 --- /dev/null +++ b/source/examples/anatomy.cpp @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2024 The Khronos Group Inc. + +#include +#include +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 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; +} diff --git a/source/index.rst b/source/index.rst index b5f243f7..42295458 100644 --- a/source/index.rst +++ b/source/index.rst @@ -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- + :linenos: +.. seealso:: |SYCL_SPEC_ANATOMY| + .. toctree:: :maxdepth: 1