From ee5804f8bc923522f6062816bba4a5962d8e15c6 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 8 Apr 2024 16:55:37 -0400 Subject: [PATCH] device fib example is a standalone executable, takes N from command line (default = 1000). Does not seem to invoke the kernel --- tests/unit/CMakeLists.txt | 14 ++++++++------ tests/unit/fibonacci_device.cc | 25 ++++++++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 7b1417d8c..19ff9c8dd 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -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) @@ -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) diff --git a/tests/unit/fibonacci_device.cc b/tests/unit/fibonacci_device.cc index 4a052eb18..576829d55 100644 --- a/tests/unit/fibonacci_device.cc +++ b/tests/unit/fibonacci_device.cc @@ -32,12 +32,15 @@ struct Fn : public ttg::TTValue { ttg::ttg_abort(); } }; -extern ttg::Edge f2f; -extern ttg::Edge f2p; -auto create_fib_task() { - return ttg::make_tt( + +auto make_ttg_fib_lt(const int64_t F_n_max = 1000) { + ttg::Edge f2f; + ttg::Edge f2p; + + auto fib = ttg::make_tt( [=](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); @@ -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> 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());