Skip to content

Commit

Permalink
Update cheatsheet.rst
Browse files Browse the repository at this point in the history
Removed deprecated command
Changed from alapka enqueue to alpaka exec
Added entries to get
- pitches
- mdspan
- kernelFunctionAttributes
- NDIndex
  • Loading branch information
ikbuibui authored Sep 17, 2024
1 parent a017c60 commit 2bd782c
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions docs/source/basic/cheatsheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ Allocate a buffer in host memory
using BufHost = alpaka::Buf<DevHost, DataType, Dim, Idx>;
BufHost bufHost = allocBuf<DataType, Idx>(devHost, extent);

(Optional, affects CPU – GPU memory copies) Prepare it for asynchronous memory copies
.. code-block:: c++

prepareForAsyncCopy(bufHost);

Create a view to host memory represented by a pointer
.. code-block:: c++

Expand Down Expand Up @@ -154,6 +149,18 @@ Get a raw pointer to a buffer or view initialization, etc.
DataType* raw = view::getPtrNative(bufHost);
DataType* rawViewPtr = view::getPtrNative(hostView);

Get the pitches (memory in bytes to the next element in the buffer along the pitch dimension) of a buffer
.. code-block:: c++

auto pitchBufAcc = alpaka::getPitchesInBytes(bufAcc)
auto pitchViewAcc = alpaka::getPitchesInBytes(viewAcc)

Get a mdspan to a buffer or view initialization, etc.
.. code-block:: c++

auto bufMdSpan = alpaka::experimental::getMdSpan(bufAcc)
auto viewMdSpan = alpaka::experimental::getMdSpan(viewAcc)

Allocate a buffer in device memory
.. code-block:: c++

Expand Down Expand Up @@ -216,18 +223,24 @@ Manually set a kernel launch configuration
threadsPerBlock,
elementsPerThread};

Instantiate a kernel and create a task that will run it (does not launch it yet)

Instantiate a kernel (does not launch it yet)
.. code-block:: c++

Kernel kernel{argumentsForConstructor};
auto taskRunKernel = createTaskKernel<Acc>(workDiv, kernel, parameters);

acc parameter of the kernel is provided automatically, does not need to be specified here

Get information about the kernel from the device (size, maxThreadsPerBlock, sharedMemSize, registers, etc.)
.. code-block:: c++

auto kernelFunctionAttributes = alpaka::getFunctionAttributes<Acc>(devAcc, kernel, parameters...);


Put the kernel for execution
.. code-block:: c++

enqueue(queue, taskRunKernel);
exec(queue, workDiv, kernel, parameters...);

Kernel Implementation
---------------------
Expand Down Expand Up @@ -259,6 +272,12 @@ Access components of and destructure multi-dimensional indices and extents
Linearize multi-dimensional vectors
.. code-block:: c++

auto linearIdx = mapIdx<1u>(idxND, extentND);

More generally, index multi-dimensional vectors with a different dimensionality
.. code-block:: c++

auto idxND = alpaka::mapIdx<N>(idxMD, extentMD);
auto linearIdx = mapIdx<1u>(idx, extent);

.. raw:: pdf
Expand Down

0 comments on commit 2bd782c

Please sign in to comment.