|
1 | | -// The C++ side. It imports the generated module and includes nothing: the |
2 | | -// header exists for the island's compiler, which does not read modules. |
| 1 | +// The consumer. It imports the SEAM, not the generated module, and includes |
| 2 | +// nothing: the generated header exists for the island's compiler, which does |
| 3 | +// not read modules. |
| 4 | +// |
| 5 | +// Nothing here names `saxpy_device`. That is the property the seam exists for: |
| 6 | +// which island is underneath -- the device half or the host one -- is not |
| 7 | +// visible from this file, and neither is the fact that a boundary was |
| 8 | +// generated at all. |
3 | 9 | import std; |
4 | | -import island_interface.kernels; |
| 10 | +import island_interface.app; |
5 | 11 |
|
6 | 12 | int main() { |
7 | | - float x[4] = {1, 2, 3, 4}; |
8 | | - float y[4] = {10, 20, 30, 40}; |
9 | | - float out[4] = {}; |
| 13 | + const std::vector<float> x{1, 2, 3, 4}; |
| 14 | + const std::vector<float> y{10, 20, 30, 40}; |
10 | 15 |
|
11 | | - if (saxpy_device(2.0f, x, y, out, 4) != 0) { |
12 | | - std::cout << "BAD: saxpy_device failed\n"; |
| 16 | + auto out = island_interface::saxpy(2.0f, x, y); |
| 17 | + if (!out) { |
| 18 | + std::cout << "BAD: saxpy failed\n"; |
13 | 19 | return 1; |
14 | 20 | } |
15 | | - if (scale_device(0.5f, out, 4) != 0) { |
16 | | - std::cout << "BAD: scale_device failed\n"; |
| 21 | + if (!island_interface::scale(0.5f, *out)) { |
| 22 | + std::cout << "BAD: scale failed\n"; |
17 | 23 | return 1; |
18 | 24 | } |
19 | 25 |
|
20 | 26 | // (2*1+10)/2, (2*2+20)/2, (2*3+30)/2, (2*4+40)/2 |
21 | 27 | const float want[4] = {6, 12, 18, 24}; |
22 | | - bool ok = true; |
23 | | - for (int i = 0; i < 4; ++i) { |
24 | | - std::cout << std::format("out[{}]={} ", i, out[i]); |
25 | | - if (out[i] != want[i]) ok = false; |
| 28 | + bool ok = out->size() == 4; |
| 29 | + for (std::size_t i = 0; ok && i < out->size(); ++i) { |
| 30 | + std::cout << std::format("out[{}]={} ", i, (*out)[i]); |
| 31 | + if ((*out)[i] != want[i]) ok = false; |
26 | 32 | } |
27 | 33 | std::cout << "\n"; |
28 | 34 | // Two entry points rather than one, because a generator that re-exported |
|
0 commit comments