Skip to content

Commit

Permalink
device fib example is a standalone executable, takes N from command l…
Browse files Browse the repository at this point in the history
…ine (default = 1000). Does not seem to invoke the kernel
  • Loading branch information
evaleev committed Apr 8, 2024
1 parent 149f33b commit ee5804f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
14 changes: 8 additions & 6 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ list(APPEND ut_src fibonacci-coro.cc)
list(APPEND ut_src device_coro.cc)
if (TTG_HAVE_CUDA)
list(APPEND ut_src cuda_kernel.cu)
# fibonacci device example
list(APPEND ut_src
fibonacci_device.cc
fibonacci_cuda_kernel.h
fibonacci_cuda_kernel.cu
)
endif(TTG_HAVE_CUDA)
list(APPEND ut_libs std::coroutine)

Expand All @@ -36,6 +30,14 @@ add_ttg_executable(serialization serialization.cc unit_main.cpp
add_ttg_executable(serialization_boost serialization_boost.cc
LINK_LIBRARIES ttg-serialization-boost RUNTIMES "parsec")

# Fib device test
if (TTG_HAVE_CUDA)
add_ttg_executable(fibonacci_device fibonacci_device.cc
fibonacci_cuda_kernel.h
fibonacci_cuda_kernel.cu
LINK_LIBRARIES std::coroutine RUNTIMES "parsec")
endif()

# TODO: convert into unit test
#if (TARGET MADworld)
#add_executable(splitmd_serialization splitmd_serialization.cc unit_main.cpp)
Expand Down
25 changes: 18 additions & 7 deletions tests/unit/fibonacci_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ struct Fn : public ttg::TTValue<Fn> {
ttg::ttg_abort();
}
};
extern ttg::Edge<int64_t, Fn> f2f;
extern ttg::Edge<void, Fn> f2p;
auto create_fib_task() {
return ttg::make_tt<ES>(

auto make_ttg_fib_lt(const int64_t F_n_max = 1000) {
ttg::Edge<int64_t, Fn> f2f;
ttg::Edge<void, Fn> f2p;

auto fib = ttg::make_tt<ES>(
[=](int64_t n, Fn&& f_n) -> ttg::device::Task {
assert(n > 0);
ttg::trace("in fib: n=", n, " F_n=", f_n.F[0]);

co_await ttg::device::select(f_n.b);

Expand All @@ -54,18 +57,26 @@ auto create_fib_task() {
},
ttg::edges(f2f), ttg::edges(f2f, f2p), "fib");
auto print = ttg::make_tt(
[](Fn f_n) {
[=](Fn f_n) {
std::cout << "The largest Fibonacci number smaller than " << F_n_max << " is " << f_n.F[1] << std::endl;
},
ttg::edges(f2p), ttg::edges(), "print");

auto ins = std::make_tuple(fib->template in<0>());
std::vector<std::unique_ptr<::ttg::TTBase>> ops;
ops.emplace_back(std::move(fib));
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);
auto fib = create_fib_task();
ttg::trace_on();
auto fib = make_ttg_fib_lt(argc < 1 ? 1000 : std::atoi(argv[1]));

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

ttg::execute(ttg::ttg_default_execution_context());
ttg::fence(ttg::ttg_default_execution_context());
Expand Down

0 comments on commit ee5804f

Please sign in to comment.