Skip to content

Commit

Permalink
kokkos#120: API/core/view/layoutStride little fix
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinemeyer5 authored and fnrizzi committed Dec 10, 2023
1 parent 79682e2 commit 32da51b
Showing 1 changed file with 102 additions and 93 deletions.
195 changes: 102 additions & 93 deletions docs/source/API/core/view/layoutStride.rst
Original file line number Diff line number Diff line change
@@ -1,116 +1,125 @@
``LayoutStride``
================

.. role:: cpp(code)
:language: cpp
.. role:: cppkokkos(code)
:language: cppkokkos

Header File: ``Kokkos_Layout.hpp``
Header File: ``<Kokkos_Layout.hpp>``

Usage:
This Kokkos Layout, when provided to a multidimensional View, lays out memory with an arbitrary stride. Most frequently encountered when taking a noncontiguous subview of some larger view.

Usage
-----

.. code-block:: c++

Kokkos::View<float***> full_mesh; // an entire mesh
Kokkos::View<float**, Kokkos::LayoutStride> mesh_subcomponent;
mesh_subcomponent = Kokkos::subview(full_mesh,Kokkos::ALL(), 0, Kokkos::ALL()); // take x and z components
Kokkos::View<float***> full_mesh; // an entire mesh
Kokkos::View<float**, Kokkos::LayoutStride> mesh_subcomponent;
mesh_subcomponent = Kokkos::subview(full_mesh,Kokkos::ALL(), 0, Kokkos::ALL()); // take x and z components

Synopsis
--------

.. code-block:: cpp
struct LayoutStride {
typedef LayoutStride array_layout;
size_t dimension[ARRAY_LAYOUT_MAX_RANK];
size_t stride[ARRAY_LAYOUT_MAX_RANK];
enum { is_extent_constructible = false };
LayoutStride(LayoutStride const&) = default;
LayoutStride(LayoutStride&&) = default;
LayoutStride& operator=(LayoutStride const&) = default;
LayoutStride& operator=(LayoutStride&&) = default;
struct LayoutStride {
typedef LayoutStride array_layout;
template <typename iTypeOrder, typename iTypeDimen>
KOKKOS_INLINE_FUNCTION static LayoutStride order_dimensions(
int const rank, iTypeOrder const* const order,
iTypeDimen const* const dimen);
size_t dimension[ARRAY_LAYOUT_MAX_RANK];
size_t stride[ARRAY_LAYOUT_MAX_RANK];
KOKKOS_INLINE_FUNCTION
explicit constexpr LayoutStride(size_t N0 = 0, size_t S0 = 0, size_t N1 = 0,
size_t S1 = 0, size_t N2 = 0, size_t S2 = 0,
size_t N3 = 0, size_t S3 = 0, size_t N4 = 0,
size_t S4 = 0, size_t N5 = 0, size_t S5 = 0,
size_t N6 = 0, size_t S6 = 0, size_t N7 = 0,
size_t S7 = 0);
};
enum { is_extent_constructible = false };
LayoutStride(LayoutStride const&) = default;
LayoutStride(LayoutStride&&) = default;
LayoutStride& operator=(LayoutStride const&) = default;
LayoutStride& operator=(LayoutStride&&) = default;
Class Interface
---------------
template <typename iTypeOrder, typename iTypeDimen>
KOKKOS_INLINE_FUNCTION static LayoutStride order_dimensions(
int const rank, iTypeOrder const* const order,
iTypeDimen const* const dimen);
.. cpp:class:: LayoutLeft
KOKKOS_INLINE_FUNCTION
explicit constexpr LayoutStride(size_t N0 = 0, size_t S0 = 0, size_t N1 = 0,
size_t S1 = 0, size_t N2 = 0, size_t S2 = 0,
size_t N3 = 0, size_t S3 = 0, size_t N4 = 0,
size_t S4 = 0, size_t N5 = 0, size_t S5 = 0,
size_t N6 = 0, size_t S6 = 0, size_t N7 = 0,
size_t S7 = 0);
};
This Kokkos Layout, when provided to a multidimensional View, lays out memory with an arbitrary stride. Most frequently encountered when taking a noncontiguous subview of some larger view.
Public Class Members
--------------------

.. rubric:: Public Member Variables
.. cppkokkos:member:: static constexpr unsigned dimension
.. cpp:member:: static constexpr bool is_extent_constructible
* An array containing the size of each dimension of the Layout

A boolean enum to allow detection that this class is extent constructible
.. cppkokkos:member:: static constexpr unsigned stride
.. cpp:member:: static constexpr unsigned dimension
* An array containing the stride for each dimension of the Layout

An array containing the size of each dimension of the Layout
Typedefs
--------

.. cpp:member:: static constexpr unsigned stride
.. cppkokkos:type:: array_layout
An array containing the stride for each dimension of the Layout
* A tag signifying that this models the Layout concept

.. rubric:: Other Types
Enums
-----

.. cpp:type:: array_layout
.. cppkokkos:member:: static constexpr bool is_extent_constructible
A tag signifying that this models the Layout concept
* A boolean enum to allow detection that this class is extent constructible

.. rubric:: Constructors
Constructors
~~~~~~~~~~~~

.. cpp:function:: LayoutStride(LayoutStride const&)
.. cppkokkos:function:: LayoutStride(LayoutStride const&) = default;
Default copy constructor, element-wise copies the other Layout
* Default copy constructor, element-wise copies the other Layout

.. cpp:function:: LayoutStride(LayoutStride&&)
.. cppkokkos:function:: LayoutStride(LayoutStride&&) = default;
Default move constructor, element-wise moves the other Layout
* Default move constructor, element-wise moves the other Layout

.. code-block:: cpp
.. code-block:: cpp
KOKKOS_INLINE_FUNCTION
explicit constexpr LayoutStride(size_t N0 = 0, size_t S0 = 0, size_t N1 = 0,
size_t S1 = 0, size_t N2 = 0, size_t S2 = 0,
size_t N3 = 0, size_t S3 = 0, size_t N4 = 0,
size_t S4 = 0, size_t N5 = 0, size_t S5 = 0,
size_t N6 = 0, size_t S6 = 0, size_t N7 = 0,
size_t S7 = 0);
KOKKOS_INLINE_FUNCTION
explicit constexpr LayoutStride(size_t N0 = 0, size_t S0 = 0, size_t N1 = 0,
size_t S1 = 0, size_t N2 = 0, size_t S2 = 0,
size_t N3 = 0, size_t S3 = 0, size_t N4 = 0,
size_t S4 = 0, size_t N5 = 0, size_t S5 = 0,
size_t N6 = 0, size_t S6 = 0, size_t N7 = 0,
size_t S7 = 0);
Constructor that takes in up to 8 sizes, to set the sizes of the corresponding dimensions of the Layout
\
* Constructor that takes in up to 8 sizes, to set the sizes of the corresponding dimensions of the Layout

.. rubric:: Assignment operators
Assignment operators
~~~~~~~~~~~~~~~~~~~~

.. cpp:function:: LayoutStride& operator=(LayoutStride const&) = default
.. cppkokkos:function:: LayoutStride& operator=(LayoutStride const&) = default;
Default copy assignment, element-wise copies the other Layout
* Default copy assignment, element-wise copies the other Layout

.. cpp:function:: LayoutStride& operator=(LayoutStride&&) = default
.. cppkokkos:function:: LayoutStride& operator=(LayoutStride&&) = default;
Default move assignment, element-wise moves the other Layout
* Default move assignment, element-wise moves the other Layout

.. rubric:: Functions
Functions
~~~~~~~~~

.. cpp:function:: static LayoutStride order_dimensions(int const rank, iTypeOrder const* const order, iTypeDimen const* const dimen)
.. code-block:: cpp
KOKKOS_INLINE_FUNCTION static LayoutStride order_dimensions(
int const rank, iTypeOrder const* const order,
iTypeDimen const* const dimen);
:return: Calculates the strides given ordered dimensions
\
* Calculates the strides given ordered dimensions

Example
-------
Expand All @@ -119,34 +128,34 @@ Creating a 3D unmanaged strided view around a ptr. (You can also just have a vie

.. code-block:: cpp
#include<Kokkos_Core.hpp>
int main(int argc, char* argv[]) {
Kokkos::initialize(argc,argv);
{
// Some storage
int* ptr = new int[80];
// Creating a layout object
Kokkos::LayoutStride layout(3,1,3,5,4,20);
// Create a unmanaged view from a pointer and a layout
Kokkos::View<int***, Kokkos::LayoutStride, Kokkos::HostSpace> a(ptr,layout);
// Get strides
int strides[8];
a.stride(strides);
// Print extents and strides
printf("Extents: %d %d %d\n",a.extent(0),a.extent(1),a.extent(2));
printf("Strides: %i %i %i\n",strides[0],strides[1],strides[2]);
// delete storage
delete [] ptr;
}
Kokkos::finalize();
}
#include<Kokkos_Core.hpp>
int main(int argc, char* argv[]) {
Kokkos::initialize(argc,argv);
{
// Some storage
int* ptr = new int[80];
// Creating a layout object
Kokkos::LayoutStride layout(3,1,3,5,4,20);
// Create a unmanaged view from a pointer and a layout
Kokkos::View<int***, Kokkos::LayoutStride, Kokkos::HostSpace> a(ptr,layout);
// Get strides
int strides[8];
a.stride(strides);
// Print extents and strides
printf("Extents: %d %d %d\n",a.extent(0),a.extent(1),a.extent(2));
printf("Strides: %i %i %i\n",strides[0],strides[1],strides[2]);
// delete storage
delete [] ptr;
}
Kokkos::finalize();
}
Output:

.. code-block::
Extents: 3 3 4
Strides: 1 5 20
Extents: 3 3 4
Strides: 1 5 20

0 comments on commit 32da51b

Please sign in to comment.