Skip to content

Commit

Permalink
amend Fib<N examples: ttg::execute before sending data
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev committed Jun 10, 2024
1 parent 8afe3d6 commit 2f7c4db
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ The "Hello, World!" example contains a single TT that executes a single task (he
## Execute TTG
To execute a TTG we must make it executable (this will declare the TTG complete). To execute the TTG its root TT must receive at least one message; since in this case the task does not receive either task ID or data the message is empty (i.e., void):
To execute a TTG we must make it executable (this will declare the TTG program complete so no additional changes to the flowgraph are possible). To execute the TTG its root TT must receive at least one message; since in this case the task does not receive either task ID or data the message is empty (i.e., void):
```cpp
ttg::make_graph_executable(tt);
Expand All @@ -154,7 +154,7 @@ To execute a TTG we must make it executable (this will declare the TTG complete)
tt->invoke();
```

Note that we must ensure that only one such message must be generated. Since TTG execution uses the Single Program Multiple Data (SPMD) model,
`ttg::execute()` must occur before, not after, sending any messages. Note also that we must ensure that only one such message must be generated. Since TTG execution uses the Single Program Multiple Data (SPMD) model,
when launching the TTG program as multiple processes only the first process (rank) gets to send the message.

## Finalize TTG
Expand Down Expand Up @@ -303,12 +303,11 @@ int main(int argc, char* argv[]) {
auto fib = make_ttg_fib_lt(N);
ttg::make_graph_executable(fib.get());
ttg::execute();
if (ttg::default_execution_context().rank() == 0)
fib->template in<0>()->send(1, Fn{});;
ttg::execute();
ttg::fence();
ttg::finalize();
return 0;
}
Expand Down Expand Up @@ -397,6 +396,22 @@ auto make_ttg_fib_lt(const int64_t F_n_max = 1000) {
ops.emplace_back(std::move(print));
return make_ttg(std::move(ops), ins, std::make_tuple(), "Fib_n < N");
}

int main(int argc, char* argv[]) {
ttg::initialize(argc, argv, -1);
int64_t N = 1000;
if (argc > 1) N = std::atol(argv[1]);

auto fib = make_ttg_fib_lt(N);
ttg::make_graph_executable(fib.get());
ttg::execute();
if (ttg::default_execution_context().rank() == 0)
fib->template in<0>()->send(1, Fn{});;

ttg::fence();
ttg::finalize();
return 0;
}
```
Although the structure of the device-capable program is nearly identical to the CPU version, there are important differences:
Expand Down
8 changes: 6 additions & 2 deletions doc/dox/dev/devsamp/fibonacci/fibonacci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ int main(int argc, char* argv[]) {
ttg::initialize(argc, argv, -1);
int64_t N = (argc > 1) ? std::atol(argv[1]) : 1000;

// make TTG
auto fib = make_ttg_fib_lt(N);
// program complete, declare it executable
ttg::make_graph_executable(fib.get());
// start execution
ttg::execute();
// start the computation by sending the first message
if (ttg::default_execution_context().rank() == 0)
fib->template in<0>()->send(1, Fn{});;

ttg::execute();
// wait for the computation to finish
ttg::fence();

ttg::finalize();
Expand Down
10 changes: 7 additions & 3 deletions doc/dox/dev/devsamp/fibonacci/fibonacci_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ int main(int argc, char* argv[]) {
ttg::trace_on();
int64_t N = 1000;
if (argc > 1) N = std::atol(argv[1]);
auto fib = make_ttg_fib_lt(N); // computes largest F_n < N

// make TTG
auto fib = make_ttg_fib_lt(N); // computes largest F_n < N
// program complete, declare it executable
ttg::make_graph_executable(fib.get());
// start execution
ttg::execute(ttg::ttg_default_execution_context());
// start the computation by sending the first message
if (ttg::default_execution_context().rank() == 0)
fib->template in<0>()->send(1, Fn{});;

ttg::execute(ttg::ttg_default_execution_context());
// wait for the computation to finish
ttg::fence(ttg::ttg_default_execution_context());

ttg::finalize();
Expand Down

0 comments on commit 2f7c4db

Please sign in to comment.