Skip to content

Commit

Permalink
Clarify some alpaka concepts in cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Yusufoglu authored and bernhardmgruber committed Feb 24, 2024
1 parent dcc87b3 commit 0b94208
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions docs/source/basic/cheatsheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ Create a CPU device for memory allocation on the host side

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

Vec<Dim, Idx> extent = value;
using BufHost = Buf<DevHost, DataType, Dim, Idx>;
// Use alpaka vector as a static array for the extents
alpaka::Vec<Dim, Idx> extent = value;
// Allocate memory for the alpaka buffer, which is a dynamic array
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
Expand All @@ -129,7 +130,8 @@ Create a view to host memory represented by a pointer
.. code-block:: c++

using Dim = alpaka::DimInt<1u>;
Vec<Dim, Idx> extent = size;
// Create an alpaka vector which is a static array
alpaka::Vec<Dim, Idx> extent = size;
DataType* ptr = ...;
auto hostView = createView(devHost, ptr, extent);

Expand Down Expand Up @@ -231,7 +233,7 @@ Access multi-dimensional indices and extents of blocks, threads, and elements
// Origin: Grid, Block, Thread
// Unit: Blocks, Threads, Elems

Access components of and destructuremulti-dimensional indices and extents
Access components of and destructure multi-dimensional indices and extents
.. code-block:: c++

auto idxX = idx[0];
Expand Down
3 changes: 2 additions & 1 deletion docs/source/basic/library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ Memory Management

The memory allocation function of the *alpaka* library (``alpaka::allocBuf<TElem>(device, extents)``) is uniform for all devices, even for the host device.
It does not return raw pointers but reference counted memory buffer objects that remove the necessity for manual freeing and the possibility of memory leaks.
Additionally the memory buffer objects know their extents, their pitches as well as the device they reside on.
Additionally, the memory buffer objects know their extents, their pitches as well as the device they reside on.
Due to padding, the allocated number of bytes may be more than the required storage; the pitch value gives the correct stride for each dimension for row-major access.
This allows buffers that possibly reside on different devices with different pitches to be copied only by providing the buffer objects as well as the extents of the region to copy (``alpaka::memcpy(bufDevA, bufDevB, copyExtents``).

Kernel Execution
Expand Down

0 comments on commit 0b94208

Please sign in to comment.