-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdspan-demo.cpp
More file actions
38 lines (30 loc) · 1010 Bytes
/
mdspan-demo.cpp
File metadata and controls
38 lines (30 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// mdspan-demo.cpp
// SPDX-License-Identifier: MIT
#include <iostream>
// kokkos/mdspan
#include <experimental/mdspan>
namespace stdx = std::experimental;
#include "malloc-client-mdspan.hpp"
int main()
{
std::cout << "malloc REST client: mdspan-demo" << std::endl;
constexpr int N = 10;
// allocate remote memory on malloc-server
mc::RemoteMemory rmem;
mc::RemoteAddress addr = rmem.malloc(sizeof(int) * N);
// create `mdspan` as a view of remote memory
using extents_type = stdx::dextents<size_t, 1>; // 1D-array[dynamic]
using mapping_type = stdx::layout_right::mapping<extents_type>;
using accessor_type = mc::RemoteMemoryAccessor<int>;
stdx::mdspan arr{addr, mapping_type{extents_type{N}}, accessor_type{rmem}};
// write to remote memory
for (size_t i = 0; i < arr.extent(0); i++) {
arr[i] = i;
}
// read from remote memory
for (size_t i = 0; i < arr.extent(0); i++) {
std::cout << (i ? " " : "") << arr[i];
}
std::cout << std::endl;
rmem.free(addr);
}