You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: framework/doc/content/syntax/Kokkos/index.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,22 +20,22 @@ Here we provide instructions on some programming practices to write an efficient
20
20
21
21
### Separate Memory Space
22
22
23
-
Except for a very few rare cases that provide physically unified memory space for CPU and GPU (such as AMD MI300A), most GPUs have separate memory spaces from their conuterpart CPUs.
24
-
Therefore, the you need to take a special care to properly identify which data are accessible and not accessible on either CPU or GPU and whether the data on CPU and GPU are properly synchronized.
23
+
Except for a very few rare cases that provide physically unified memory space for CPU and GPU (such as AMD MI300A), most GPUs have separate memory spaces from their counterpart CPUs.
24
+
Therefore, you need to take a special care to properly identify which data are accessible and not accessible on either CPU or GPU and whether the data on CPU and GPU are properly synchronized.
25
25
Standard containers such as `std::vector`, `std::set`, `std::map` and others are not usable on GPU, and managed pointers are also inaccessible on GPU.
26
26
Basically, it is safe to assume that any dynamically-allocated data on CPU cannot be accessed on GPU.
27
27
Therefore, we provide alternative data containers to be used on GPU: `Moose::Kokkos::Array`, `Moose::Kokkos::JaggedArray`, and `Moose::Kokkos::Map`.
28
28
29
29
`Moose::Kokkos::Array` is a template class designed to hold arbitrary type of data.
30
30
It receives up to four template arguments: data type, dimension, index type, and layout type.
31
-
It supports multi-dimensional indexing, and up to five-dimensional arrays are supported.
31
+
It supports multi-dimensional indexing.
32
32
The dimension can either be specified through the second template argument with the default being one-dimension or using type aliases: for instance, a three-dimensional array of type `double` can be declared either by `Array<double, 3>` or `Array3D<double>`.
33
33
The entries of an array can be accessed with either `operator()` with multi-dimensional indices or `operator[]` with a flattened, dimensionless index, where the flattening follows a layout in which the innermost dimension varies the fastest.
34
+
They automatically return either CPU or GPU data depending on where they are being accessed.
34
35
The index type template argument is set to 8-byte integer by default to accomodate large arrays.
35
36
However, 8-byte integer computation is significantly more expensive than 4-byte integer computation.
36
37
If your array size is small enough, consider using 4-byte indices to optimize index calculations.
37
38
If having the outermost dimension run the fastest is desired for multi-dimensional arrays, the fourth layout template argument can be optionally set to `Moose::Kokkos::LayoutType::RIGHT` (default is `LEFT`).
38
-
They automatically return either CPU or GPU data depending on where they are being accessed.
39
39
Arrays can be allocated through the following APIs: `create()`, `createHost()`, and `createDevice()`.
40
40
`create()` allocates memories on both CPU and GPU, while `createHost()` or `createDevice()` only allocates memory on either CPU or GPU.
41
41
It is important to note that if the creation APIs are called for an initialized array, the original array will be destroyed and a new array will be created.
@@ -61,14 +61,15 @@ vector.aliasHost(petsc_ptr);
61
61
vector.copyToDevice();
62
62
```
63
63
64
-
If the data type is not default-constructable, `create()` will only allocate a raw block of uninitialized memory using `malloc()`.
65
-
It is your responsibility to loop over the array and perform placement new to properly construct each entry.
64
+
If the data type is not default-constructible or if you do not want to initialize array using the default constructor, you can set an optional template argument to `false` when calling `create()` or `createHost()`.
65
+
It will only allocate a raw chunk of uninitialized memory using `malloc()` instead of `new`.
66
+
Then, it becomes your responsibility to loop over the array and properly construct each entry using placement new.
66
67
For example:
67
68
68
69
```cpp
69
70
Array<NotDefaultConstructable> data;
70
71
71
-
data.create(n);
72
+
data.create<false>(n);
72
73
73
74
for (auto & datum : data)
74
75
new (&datum) NotDefaultConstructable(...);
@@ -139,7 +140,6 @@ It is divided into inner and outer arrays.
139
140
The outer array is the regular part of a jagged array.
140
141
Each entry of the outer array is the inner array, whose size can vary with each other.
141
142
As a result, it is defined with up to five template arguments: the data type, inner array dimension size, outer array dimension size, outer array index type (defaults to 8-byte integer; inner arrays always use 4-byte integer), and inner array layout type (defaults to `Moose::Kokkos::LayoutType::LEFT`).
142
-
Both inner and outer arrays can be up to three-dimensional.
143
143
However, it is not possible to have inner arrays with different dimensions in a single jagged array.
144
144
145
145
The accessors of a jagged array, `operator()` (dimensional) or `operator[]` (dimensionless), receive the indices for the outer array.
Copy file name to clipboardExpand all lines: framework/doc/content/syntax/KokkosMaterials/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ Same applies to a class with in-class member initialization, which is equivalent
40
40
Using a class with dynamic allocations will [incur a significant performance hit](syntax/Kokkos/index.md#kokkos_dynamic_allocation) and will break when it is used for stateful material properties.
41
41
42
42
Instead, the material properties in Kokkos-MOOSE can be multi-dimensional to partially support the needs for dynamically-sized material properties.
43
-
The dimension is provided as the second template argument `dimension`, which has the default value of 0 (scalar) and can be up to 4.
43
+
The dimension is provided as the second template argument `dimension`, which has the default value of 0 (scalar).
44
44
The size of each dimension is provied as a vector as the function argument `dims`.
45
45
When a material property is declared by multiple materials, it should have the same dimension over the entire domain, while the size of each dimension can be different between non-overlapping subdomains.
46
46
However, a material property declared by boundary-restricted materials should have identical dimension sizes over the entire domain, even though the materials do not have overlapping boundaries.
0 commit comments