-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51637b2
commit f45533c
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
marp: true | ||
theme: ginkgo | ||
headingDivider: 2 | ||
--- | ||
|
||
|
||
## Passing Data out of Ginkgo | ||
|
||
**Note:** Only possible as views. | ||
|
||
Examples for accessing the underlying pointer(s): | ||
|
||
- Array: `arr.get_data()` | ||
- Dense vector: `vec.get_values()` | ||
- CSR matrix: `mtx.get_row_ptrs()`, `mtx.get_col_idxs()`, `mtx.get_values()` | ||
|
||
|
||
## Example: Calling BLAS Routine with Ginkgo Data | ||
|
||
```c++ | ||
auto x = gko::matrix::Dense<float>::create(exec, gko::dim<2>{n_row, 1}); | ||
auto y = gko::matrix::Dense<float>::create(exec, gko::dim<2>{n_row, 1}); | ||
|
||
cblas_srot(n_row, x->get_values(), x->get_stride(), y->get_values(), y->get_stride(), | ||
cos, sin); | ||
|
||
``` | ||
## Example: Passing Ginkgo Data to Kokkos | ||
Special case for passing data to Kokkos via `gko::ext::kokkos::map_data`. | ||
Works for `gko::array` and `gko::matrix::Dense`. | ||
```c++ | ||
auto g_vec = gko::matrix::Dense<float>::create(exec, gko::dim<2>{n_row, 1}); | ||
auto k_vec = gko::ext::kokkos::map_data(g_vec); // this is a 2D Kokkos::View | ||
Kokkos::parallel_for( | ||
n_row, KOKKOS_LAMBDA(int i){ | ||
const float h = 1.0f / (discretization_points + 1); | ||
const float xi = ValueType(i + 1) * h; | ||
k_vec[i] = xi * xi; | ||
} | ||
); | ||
``` | ||
|
||
# Advanced `gko::array<T>` Topics | ||
|
||
<!-- _class: lead --> | ||
|
||
|
||
|
||
## Cross Executor Copy and Move | ||
|
||
Scenario: copy construct (assign) arrays with different executors | ||
|
||
```c++ | ||
auto cpu_exec = gko::OmpExecutor::create(); | ||
auto gpu_exec = gko::CudaExecutor::create(0, cpu_exec); | ||
|
||
gko::array<int> arr_cpu(cpu_exec, ...); | ||
gko::array<int> arr_gpu(gpu_exec); | ||
|
||
arr_gpu = arr_cpu; | ||
``` | ||
The data will be automatically copied between the CPU and GPU. | ||
Using `arr_gpu = std::move(arr_cpu)` involves a copy instead of a move. | ||
**Note:** `gko::array<int> arr_gpu(arr_cpu)` will create `arr_gpu` using the executor from `arr_cpu`. | ||
## Executor behavior | ||
The executor *doesn't* change implicitly. | ||
After assignment `arr_a = arr_b` the executor of `arr_a` will be *the same as before* the assignment. | ||
The same holds for move assignments. | ||
Explicitly change executor with `arr.set_executor(other_exec)` | ||
**Exceptions:** | ||
When `arr_a` was *default constructed*, the assignment changes the executor. | ||
Default constructed array has no executor | ||
Change executor with `array.set_executor(other_exec)` |